diff options
author | StapleButter <thetotalworm@gmail.com> | 2017-11-23 21:02:24 +0100 |
---|---|---|
committer | StapleButter <thetotalworm@gmail.com> | 2017-11-23 21:02:24 +0100 |
commit | 85c375cce7e56e9e5962e051adaf6d1afc4ed813 (patch) | |
tree | 8fb74bd650a8392a5779ed995a451b6fc31e6868 /src/libui_sdl | |
parent | aa4f427ed4aa6482172c1e26ddc368c0a74623ce (diff) |
* remember screen rotation/gap/etc settings
* fix menu cleanup to take submenus into account properly, so it doesn't crash when exiting
Diffstat (limited to 'src/libui_sdl')
-rw-r--r-- | src/libui_sdl/libui/windows/menu.cpp | 15 | ||||
-rw-r--r-- | src/libui_sdl/main.cpp | 21 |
2 files changed, 33 insertions, 3 deletions
diff --git a/src/libui_sdl/libui/windows/menu.cpp b/src/libui_sdl/libui/windows/menu.cpp index 1f721b6..ccf5c9c 100644 --- a/src/libui_sdl/libui/windows/menu.cpp +++ b/src/libui_sdl/libui/windows/menu.cpp @@ -14,6 +14,7 @@ static BOOL hasAbout = FALSE; struct uiMenu { WCHAR *name; + HMENU handle; uiMenuItem **items; BOOL ischild; size_t len; @@ -292,6 +293,7 @@ static HMENU makeMenu(uiMenu *m) menu = CreatePopupMenu(); if (menu == NULL) logLastError(L"error creating menu"); + m->handle = menu; for (i = 0; i < m->len; i++) appendMenuItem(menu, m->items[i]); return menu; @@ -363,21 +365,28 @@ static void freeMenu(uiMenu *m, HMENU submenu) item->hmenus[j] = item->hmenus[j + 1]; item->hmenus[j] = NULL; item->len--; + + if (item->popupchild) + freeMenu(item->popupchild, item->popupchild->handle); } } void freeMenubar(HMENU menubar) { size_t i; + size_t j = 0; MENUITEMINFOW mi; - for (i = 0; i < len; i++) { + for (i = 0; i < len; i++) + { + if (menus[i]->ischild) continue; ZeroMemory(&mi, sizeof (MENUITEMINFOW)); mi.cbSize = sizeof (MENUITEMINFOW); mi.fMask = MIIM_SUBMENU; - if (GetMenuItemInfoW(menubar, i, TRUE, &mi) == 0) + if (GetMenuItemInfoW(menubar, j, TRUE, &mi) == 0) logLastError(L"error getting menu to delete item references from"); freeMenu(menus[i], mi.hSubMenu); + j++; } // no need to worry about destroying any menus; destruction of the window they're in will do it for us } @@ -396,7 +405,7 @@ void uninitMenus(void) if (item->len != 0) // LONGTERM userbug()? implbug("menu item %p (%ws) still has uiWindows attached; did you forget to destroy some windows?", item, item->name); - if (item->name != NULL) + if (item->type != typeSubmenu && item->name != NULL) uiFree(item->name); if (item->hmenus != NULL) uiFree(item->hmenus); diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index b745e5b..1b5dfb3 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -865,6 +865,8 @@ void OnSetScreenRotation(uiMenuItem* item, uiWindow* window, void* param) w = blarg; uiWindowSetContentSize(window, w, h); + Config::WindowWidth = w; + Config::WindowHeight = h; } } else if (ScreenLayout == 1) // vertical @@ -1139,6 +1141,20 @@ int main(int argc, char** argv) uiControlSetMinSize(uiControl(MainDrawArea), 256, 384); uiAreaSetBackgroundColor(MainDrawArea, 0, 0, 0); // TODO: make configurable? + ScreenRotation = Config::ScreenRotation; + ScreenGap = Config::ScreenGap; + ScreenLayout = Config::ScreenLayout; + ScreenSizing = Config::ScreenSizing; + +#define SANITIZE(var, min, max) if ((var < min) || (var > max)) var = 0; + SANITIZE(ScreenRotation, 0, 3); + SANITIZE(ScreenGap, 0, 5); + SANITIZE(ScreenLayout, 0, 2); + SANITIZE(ScreenSizing, 0, 3); +#undef SANITIZE + + OnSetScreenRotation(MenuItem_ScreenRot[ScreenRotation], MainWindow, (void*)&kScreenRot[ScreenRotation]); + EmuRunning = 2; RunningSomething = false; EmuThread = SDL_CreateThread(EmuThreadFunc, "melonDS magic", NULL); @@ -1165,6 +1181,11 @@ int main(int argc, char** argv) EmuRunning = 0; SDL_WaitThread(EmuThread, NULL); + Config::ScreenRotation = ScreenRotation; + Config::ScreenGap = ScreenGap; + Config::ScreenLayout = ScreenLayout; + Config::ScreenSizing = ScreenSizing; + Config::Save(); if (ScreenBitmap) uiDrawFreeBitmap(ScreenBitmap); |