diff options
author | StapleButter <thetotalworm@gmail.com> | 2017-11-23 20:01:43 +0100 |
---|---|---|
committer | StapleButter <thetotalworm@gmail.com> | 2017-11-23 20:01:43 +0100 |
commit | aa4f427ed4aa6482172c1e26ddc368c0a74623ce (patch) | |
tree | 1abe2e4df3cc42d6bff8b5ca831af32c78d51c3b | |
parent | 8e6d834f13e21efe02eb540a9ca0cf1800e183de (diff) |
properly resize window when changing display settings, etc
begin polishing things
-rw-r--r-- | src/libui_sdl/main.cpp | 74 |
1 files changed, 67 insertions, 7 deletions
diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index ba0668a..b745e5b 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -644,6 +644,20 @@ void SetupScreenRects(int width, int height) } } +void SetMinSize(int w, int h) +{ + int cw, ch; + uiWindowContentSize(MainWindow, &cw, &ch); + + uiControlSetMinSize(uiControl(MainDrawArea), w, h); + if ((cw < w) || (ch < h)) + { + if (cw < w) cw = w; + if (ch < h) ch = h; + uiWindowSetContentSize(MainWindow, cw, ch); + } +} + void OnAreaResize(uiAreaHandler* handler, uiArea* area, int width, int height) { SetupScreenRects(width, height); @@ -831,13 +845,44 @@ void OnSetScreenRotation(uiMenuItem* item, uiWindow* window, void* param) int oldrot = ScreenRotation; ScreenRotation = rot; - // TODO: adjust window size - if (rot == 1 || rot == 3) - uiControlSetMinSize(uiControl(MainDrawArea), 384, 256); - else - uiControlSetMinSize(uiControl(MainDrawArea), 256, 384); + int w, h; + uiWindowContentSize(window, &w, &h); - SetupScreenRects(Config::WindowWidth, Config::WindowHeight); + bool isHori = (rot == 1 || rot == 3); + bool wasHori = (oldrot == 1 || oldrot == 3); + + if (ScreenLayout == 0) // natural + { + if (isHori) + SetMinSize(384+ScreenGap, 256); + else + SetMinSize(256, 384+ScreenGap); + + if (isHori ^ wasHori) + { + int blarg = h; + h = w; + w = blarg; + + uiWindowSetContentSize(window, w, h); + } + } + else if (ScreenLayout == 1) // vertical + { + if (isHori) + SetMinSize(192, 512+ScreenGap); + else + SetMinSize(256, 384+ScreenGap); + } + else // horizontal + { + if (isHori) + SetMinSize(384+ScreenGap, 256); + else + SetMinSize(512+ScreenGap, 192); + } + + SetupScreenRects(w, h); for (int i = 0; i < 4; i++) uiMenuItemSetChecked(MenuItem_ScreenRot[i], i==ScreenRotation); @@ -865,13 +910,20 @@ void OnSetScreenGap(uiMenuItem* item, uiWindow* window, void* param) } SetupScreenRects(Config::WindowWidth, Config::WindowHeight); + + for (int i = 0; i < 6; i++) + uiMenuItemSetChecked(MenuItem_ScreenGap[i], kScreenGap[i]==ScreenGap); } void OnSetScreenLayout(uiMenuItem* item, uiWindow* window, void* param) { int layout = *(int*)param; ScreenLayout = layout; - // TODO trigger resize + + SetupScreenRects(Config::WindowWidth, Config::WindowHeight); + + for (int i = 0; i < 3; i++) + uiMenuItemSetChecked(MenuItem_ScreenLayout[i], i==ScreenLayout); } void OnSetScreenSizing(uiMenuItem* item, uiWindow* window, void* param) @@ -880,6 +932,9 @@ void OnSetScreenSizing(uiMenuItem* item, uiWindow* window, void* param) ScreenSizing = sizing; SetupScreenRects(Config::WindowWidth, Config::WindowHeight); + + for (int i = 0; i < 4; i++) + uiMenuItemSetChecked(MenuItem_ScreenSizing[i], i==ScreenSizing); } @@ -1047,6 +1102,11 @@ int main(int argc, char** argv) uiMenuAppendSubmenu(menu, submenu); } + uiMenuItemSetChecked(MenuItem_ScreenRot[ScreenRotation], 1); + uiMenuItemSetChecked(MenuItem_ScreenGap[ScreenGap], 1); + uiMenuItemSetChecked(MenuItem_ScreenLayout[ScreenLayout], 1); + uiMenuItemSetChecked(MenuItem_ScreenSizing[ScreenSizing], 1); + int w = Config::WindowWidth; int h = Config::WindowHeight; |