* remember screen rotation/gap/etc settings

* fix menu cleanup to take submenus into account properly, so it doesn't crash when exiting
This commit is contained in:
StapleButter 2017-11-23 21:02:24 +01:00
parent aa4f427ed4
commit 85c375cce7
4 changed files with 48 additions and 3 deletions

View File

@ -31,6 +31,11 @@ int JoyMapping[12];
int WindowWidth; int WindowWidth;
int WindowHeight; int WindowHeight;
int ScreenRotation;
int ScreenGap;
int ScreenLayout;
int ScreenSizing;
int DirectBoot; int DirectBoot;
int Threaded3D; int Threaded3D;
@ -79,6 +84,11 @@ ConfigEntry ConfigFile[] =
{"WindowWidth", 0, &WindowWidth, 256, NULL, 0}, {"WindowWidth", 0, &WindowWidth, 256, NULL, 0},
{"WindowHeight", 0, &WindowHeight, 384, NULL, 0}, {"WindowHeight", 0, &WindowHeight, 384, NULL, 0},
{"ScreenRotation", 0, &ScreenRotation, 0, NULL, 0},
{"ScreenGap", 0, &ScreenGap, 0, NULL, 0},
{"ScreenLayout", 0, &ScreenLayout, 0, NULL, 0},
{"ScreenSizing", 0, &ScreenSizing, 0, NULL, 0},
{"DirectBoot", 0, &DirectBoot, 1, NULL, 0}, {"DirectBoot", 0, &DirectBoot, 1, NULL, 0},
{"Threaded3D", 0, &Threaded3D, 1, NULL, 0}, {"Threaded3D", 0, &Threaded3D, 1, NULL, 0},

View File

@ -33,6 +33,11 @@ extern int JoyMapping[12];
extern int WindowWidth; extern int WindowWidth;
extern int WindowHeight; extern int WindowHeight;
extern int ScreenRotation;
extern int ScreenGap;
extern int ScreenLayout;
extern int ScreenSizing;
extern int DirectBoot; extern int DirectBoot;
extern int Threaded3D; extern int Threaded3D;

View File

@ -14,6 +14,7 @@ static BOOL hasAbout = FALSE;
struct uiMenu { struct uiMenu {
WCHAR *name; WCHAR *name;
HMENU handle;
uiMenuItem **items; uiMenuItem **items;
BOOL ischild; BOOL ischild;
size_t len; size_t len;
@ -292,6 +293,7 @@ static HMENU makeMenu(uiMenu *m)
menu = CreatePopupMenu(); menu = CreatePopupMenu();
if (menu == NULL) if (menu == NULL)
logLastError(L"error creating menu"); logLastError(L"error creating menu");
m->handle = menu;
for (i = 0; i < m->len; i++) for (i = 0; i < m->len; i++)
appendMenuItem(menu, m->items[i]); appendMenuItem(menu, m->items[i]);
return menu; return menu;
@ -363,21 +365,28 @@ static void freeMenu(uiMenu *m, HMENU submenu)
item->hmenus[j] = item->hmenus[j + 1]; item->hmenus[j] = item->hmenus[j + 1];
item->hmenus[j] = NULL; item->hmenus[j] = NULL;
item->len--; item->len--;
if (item->popupchild)
freeMenu(item->popupchild, item->popupchild->handle);
} }
} }
void freeMenubar(HMENU menubar) void freeMenubar(HMENU menubar)
{ {
size_t i; size_t i;
size_t j = 0;
MENUITEMINFOW mi; MENUITEMINFOW mi;
for (i = 0; i < len; i++) { for (i = 0; i < len; i++)
{
if (menus[i]->ischild) continue;
ZeroMemory(&mi, sizeof (MENUITEMINFOW)); ZeroMemory(&mi, sizeof (MENUITEMINFOW));
mi.cbSize = sizeof (MENUITEMINFOW); mi.cbSize = sizeof (MENUITEMINFOW);
mi.fMask = MIIM_SUBMENU; 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"); logLastError(L"error getting menu to delete item references from");
freeMenu(menus[i], mi.hSubMenu); 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 // 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) if (item->len != 0)
// LONGTERM userbug()? // LONGTERM userbug()?
implbug("menu item %p (%ws) still has uiWindows attached; did you forget to destroy some windows?", item, item->name); 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); uiFree(item->name);
if (item->hmenus != NULL) if (item->hmenus != NULL)
uiFree(item->hmenus); uiFree(item->hmenus);

View File

@ -865,6 +865,8 @@ void OnSetScreenRotation(uiMenuItem* item, uiWindow* window, void* param)
w = blarg; w = blarg;
uiWindowSetContentSize(window, w, h); uiWindowSetContentSize(window, w, h);
Config::WindowWidth = w;
Config::WindowHeight = h;
} }
} }
else if (ScreenLayout == 1) // vertical else if (ScreenLayout == 1) // vertical
@ -1139,6 +1141,20 @@ int main(int argc, char** argv)
uiControlSetMinSize(uiControl(MainDrawArea), 256, 384); uiControlSetMinSize(uiControl(MainDrawArea), 256, 384);
uiAreaSetBackgroundColor(MainDrawArea, 0, 0, 0); // TODO: make configurable? 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; EmuRunning = 2;
RunningSomething = false; RunningSomething = false;
EmuThread = SDL_CreateThread(EmuThreadFunc, "melonDS magic", NULL); EmuThread = SDL_CreateThread(EmuThreadFunc, "melonDS magic", NULL);
@ -1165,6 +1181,11 @@ int main(int argc, char** argv)
EmuRunning = 0; EmuRunning = 0;
SDL_WaitThread(EmuThread, NULL); SDL_WaitThread(EmuThread, NULL);
Config::ScreenRotation = ScreenRotation;
Config::ScreenGap = ScreenGap;
Config::ScreenLayout = ScreenLayout;
Config::ScreenSizing = ScreenSizing;
Config::Save(); Config::Save();
if (ScreenBitmap) uiDrawFreeBitmap(ScreenBitmap); if (ScreenBitmap) uiDrawFreeBitmap(ScreenBitmap);