diff options
Diffstat (limited to 'src/libui_sdl/main.cpp')
-rw-r--r-- | src/libui_sdl/main.cpp | 145 |
1 files changed, 135 insertions, 10 deletions
diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index 5408586..ed5e80d 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -46,6 +46,8 @@ #include "../Savestate.h" +#include "OSD.h" + // savestate slot mapping // 1-8: regular slots (quick access) @@ -110,6 +112,7 @@ uiDrawBitmap* ScreenBitmap[2] = {NULL,NULL}; GLuint GL_ScreenShader[3]; GLuint GL_ScreenShaderAccel[3]; +GLuint GL_ScreenShaderOSD[3]; struct { float uScreenSize[2]; @@ -156,6 +159,7 @@ s16* MicWavBuffer; u32 MicCommand; +bool HotkeyFPSToggle = false; void SetupScreenRects(int width, int height); @@ -196,6 +200,29 @@ bool GLScreen_InitShader(GLuint* shader, const char* fs) return true; } +bool GLScreen_InitOSDShader(GLuint* shader) +{ + if (!OpenGL_BuildShaderProgram(kScreenVS_OSD, kScreenFS_OSD, shader, "ScreenShaderOSD")) + return false; + + glBindAttribLocation(shader[2], 0, "vPosition"); + glBindFragDataLocation(shader[2], 0, "oColor"); + + if (!OpenGL_LinkShaderProgram(shader)) + return false; + + GLuint uni_id; + + uni_id = glGetUniformBlockIndex(shader[2], "uConfig"); + glUniformBlockBinding(shader[2], uni_id, 16); + + glUseProgram(shader[2]); + uni_id = glGetUniformLocation(shader[2], "OSDTex"); + glUniform1i(uni_id, 0); + + return true; +} + bool GLScreen_Init() { // TODO: consider using epoxy? @@ -211,6 +238,8 @@ bool GLScreen_Init() return false; if (!GLScreen_InitShader(GL_ScreenShaderAccel, kScreenFS_Accel)) return false; + if (!GLScreen_InitOSDShader(GL_ScreenShaderOSD)) + return false; memset(&GL_ShaderConfig, 0, sizeof(GL_ShaderConfig)); @@ -253,6 +282,7 @@ void GLScreen_DeInit() OpenGL_DeleteShaderProgram(GL_ScreenShader); OpenGL_DeleteShaderProgram(GL_ScreenShaderAccel); + OpenGL_DeleteShaderProgram(GL_ScreenShaderOSD); } void GLScreen_DrawScreen() @@ -394,7 +424,7 @@ void GLScreen_DrawScreen() else OpenGL_UseShaderProgram(GL_ScreenShaderAccel); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, uiGLGetFramebuffer(GLContext)); + glBindFramebuffer(GL_FRAMEBUFFER, uiGLGetFramebuffer(GLContext)); glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT); @@ -432,6 +462,9 @@ void GLScreen_DrawScreen() glDrawArrays(GL_TRIANGLES, 0, 4*3); } + OpenGL_UseShaderProgram(GL_ScreenShaderOSD); + OSD::Update(true, NULL); + glFlush(); uiGLSwapBuffers(GLContext); } @@ -707,7 +740,6 @@ int EmuThreadFunc(void* burp) else { GPU3D::InitRenderer(false); - GPU::SetDisplaySettings(false); } Touching = false; @@ -807,6 +839,27 @@ int EmuThreadFunc(void* burp) HotkeyMask |= 0x1; } + if (JoyButtonPressed(Config::HKJoyMapping[HK_FastForwardToggle], njoybuttons, joybuttons, joyhat)) + { + HotkeyFPSToggle = !HotkeyFPSToggle; + Config::LimitFPS = !Config::LimitFPS; + uiMenuItemSetChecked(MenuItem_LimitFPS, Config::LimitFPS==1); + } + + if (!HotkeyFPSToggle) // For fast forward (hold) hotkey + { + if (JoyButtonHeld(Config::HKJoyMapping[HK_FastForward], njoybuttons, joybuttons, joyhat)) + { + Config::LimitFPS = false; + uiMenuItemSetChecked(MenuItem_LimitFPS, false); + } + else if (!Config::LimitFPS) + { + Config::LimitFPS = true; + uiMenuItemSetChecked(MenuItem_LimitFPS, true); + } + } + if (JoyButtonHeld(Config::HKJoyMapping[HK_Mic], njoybuttons, joybuttons, joyhat)) MicCommand |= 2; else @@ -944,10 +997,20 @@ int EmuThreadFunc(void* burp) if (joybuttons) delete[] joybuttons; + if (Screen_UseGL) uiGLMakeContextCurrent(GLContext); + NDS::DeInit(); Platform::LAN_DeInit(); - if (Screen_UseGL) GLScreen_DeInit(); + if (Screen_UseGL) + { + OSD::DeInit(true); + GLScreen_DeInit(); + } + else + OSD::DeInit(false); + + if (Screen_UseGL) uiGLMakeContextCurrent(NULL); return 44203; } @@ -961,8 +1024,8 @@ void OnAreaDraw(uiAreaHandler* handler, uiArea* area, uiAreaDrawParams* params) if (ScreenBitmap[1]) uiDrawFreeBitmap(ScreenBitmap[1]); ScreenDrawInited = true; - ScreenBitmap[0] = uiDrawNewBitmap(params->Context, 256, 192); - ScreenBitmap[1] = uiDrawNewBitmap(params->Context, 256, 192); + ScreenBitmap[0] = uiDrawNewBitmap(params->Context, 256, 192, 0); + ScreenBitmap[1] = uiDrawNewBitmap(params->Context, 256, 192, 0); } int frontbuf = GPU::FrontBuffer; @@ -984,6 +1047,8 @@ void OnAreaDraw(uiAreaHandler* handler, uiArea* area, uiAreaDrawParams* params) uiDrawTransform(params->Context, &BottomScreenTrans); uiDrawBitmapDraw(params->Context, ScreenBitmap[1], &bot, &BottomScreenRect, Config::ScreenFilter==1); uiDrawRestore(params->Context); + + OSD::Update(false, params); } void OnAreaMouseEvent(uiAreaHandler* handler, uiArea* area, uiAreaMouseEvent* evt) @@ -1083,6 +1148,19 @@ int OnAreaKeyEvent(uiAreaHandler* handler, uiArea* area, uiAreaKeyEvent* evt) if (evt->Scancode == Config::HKKeyMapping[HK_Mic]) MicCommand &= ~1; + + if (evt->Scancode == Config::HKKeyMapping[HK_FastForwardToggle]) + { + HotkeyFPSToggle = !HotkeyFPSToggle; + Config::LimitFPS = !Config::LimitFPS; + uiMenuItemSetChecked(MenuItem_LimitFPS, Config::LimitFPS==1); + } + + if (evt->Scancode == Config::HKKeyMapping[HK_FastForward] && !HotkeyFPSToggle) + { + Config::LimitFPS = true; + uiMenuItemSetChecked(MenuItem_LimitFPS, Config::LimitFPS==1); + } } else if (!evt->Repeat) { @@ -1114,8 +1192,15 @@ int OnAreaKeyEvent(uiAreaHandler* handler, uiArea* area, uiAreaKeyEvent* evt) if (evt->Scancode == Config::HKKeyMapping[HK_Mic]) MicCommand |= 1; + if (evt->Scancode == Config::HKKeyMapping[HK_FastForward] && !HotkeyFPSToggle) + { + Config::LimitFPS = false; + uiMenuItemSetChecked(MenuItem_LimitFPS, Config::LimitFPS==1); + } + if (evt->Scancode == 0x57) // F11 - NDS::debug(0); + OSD::AddMessage(0x00FFFF, "OSD test"); + //NDS::debug(0); } return 1; @@ -1371,20 +1456,30 @@ void OnAreaResize(uiAreaHandler* handler, uiArea* area, int width, int height) WindowWidth = width; WindowHeight = height; - int max = uiWindowMaximized(MainWindow); - int min = uiWindowMinimized(MainWindow); + int ismax = uiWindowMaximized(MainWindow); + int ismin = uiWindowMinimized(MainWindow); - Config::WindowMaximized = max; - if (!max && !min) + Config::WindowMaximized = ismax; + if (!ismax && !ismin) { Config::WindowWidth = width; Config::WindowHeight = height; } + + OSD::WindowResized(Screen_UseGL); } void Run() { + if (GPU3D::Renderer != Config::_3DRenderer) + { + if (Screen_UseGL) uiGLMakeContextCurrent(GLContext); + GPU3D::DeInitRenderer(); + GPU3D::InitRenderer(Screen_UseGL); + if (Screen_UseGL) uiGLMakeContextCurrent(NULL); + } + EmuRunning = 1; RunningSomething = true; @@ -1537,6 +1632,11 @@ void LoadState(int slot) if (!Platform::FileExists(filename)) { + char msg[64]; + if (slot > 0) sprintf(msg, "State slot %d is empty", slot); + else sprintf(msg, "State file does not exist"); + OSD::AddMessage(0xFFA0A0, msg); + EmuRunning = prevstatus; return; } @@ -1577,6 +1677,11 @@ void LoadState(int slot) NDS::RelocateSave(SRAMPath, false); } + char msg[64]; + if (slot > 0) sprintf(msg, "State loaded from slot %d", slot); + else sprintf(msg, "State loaded from file"); + OSD::AddMessage(0, msg); + SavestateLoaded = true; uiMenuItemEnable(MenuItem_UndoStateLoad); } @@ -1636,6 +1741,11 @@ void SaveState(int slot) } } + char msg[64]; + if (slot > 0) sprintf(msg, "State saved to slot %d", slot); + else sprintf(msg, "State saved to file"); + OSD::AddMessage(0, msg); + EmuRunning = prevstatus; } @@ -1660,6 +1770,8 @@ void UndoStateLoad() NDS::RelocateSave(SRAMPath, false); } + OSD::AddMessage(0, "State load undone"); + EmuRunning = prevstatus; } @@ -2008,6 +2120,7 @@ void OnSetLimitFPS(uiMenuItem* item, uiWindow* window, void* blarg) int chk = uiMenuItemChecked(item); if (chk != 0) Config::LimitFPS = true; else Config::LimitFPS = false; + HotkeyFPSToggle = !Config::LimitFPS; // ensure that the hotkey toggle indicator is synced with this menu item } void ApplyNewSettings(int type) @@ -2050,6 +2163,10 @@ void ApplyNewSettings(int type) if (Screen_UseGL) uiGLMakeContextCurrent(NULL); } + if (Screen_UseGL) uiGLMakeContextCurrent(GLContext); + OSD::DeInit(Screen_UseGL); + if (Screen_UseGL) uiGLMakeContextCurrent(NULL); + Screen_UseGL = usegl; RecreateMainWindow(usegl); @@ -2232,6 +2349,7 @@ void CreateMainWindowMenu() uiMenuAppendSubmenu(menu, submenu); } + MenuItem_ScreenFilter = uiMenuAppendCheckItem(menu, "Screen filtering"); uiMenuItemOnClicked(MenuItem_ScreenFilter, OnSetScreenFiltering, NULL); @@ -2274,6 +2392,11 @@ void CreateMainWindow(bool opengl) { uiGLMakeContextCurrent(GLContext); if (!GLScreen_Init()) opengl_good = false; + if (opengl_good) + { + OpenGL_UseShaderProgram(GL_ScreenShaderOSD); + OSD::Init(true); + } uiGLMakeContextCurrent(NULL); } @@ -2283,6 +2406,8 @@ void CreateMainWindow(bool opengl) RecreateMainWindow(false); Screen_UseGL = false; } + + if (!opengl) OSD::Init(false); } void DestroyMainWindow() |