diff options
-rw-r--r-- | src/ui/util.c | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/src/ui/util.c b/src/ui/util.c index 5327e103..a8d9b04e 100644 --- a/src/ui/util.c +++ b/src/ui/util.c | |||
@@ -1022,7 +1022,23 @@ void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, int menuOpenFlags) { | |||
1022 | setFlags_Widget(d, hidden_WidgetFlag, iFalse); | 1022 | setFlags_Widget(d, hidden_WidgetFlag, iFalse); |
1023 | setFlags_Widget(d, commandOnMouseMiss_WidgetFlag, iTrue); | 1023 | setFlags_Widget(d, commandOnMouseMiss_WidgetFlag, iTrue); |
1024 | setFlags_Widget(findChild_Widget(d, "menu.cancel"), disabled_WidgetFlag, iFalse); | 1024 | setFlags_Widget(findChild_Widget(d, "menu.cancel"), disabled_WidgetFlag, iFalse); |
1025 | if (isUsingMenuPopupWindows_()) { | 1025 | arrange_Widget(d); |
1026 | #if defined (LAGRANGE_ENABLE_POPUP_MENUS) | ||
1027 | /* Determine total display bounds where the popup may appear. */ | ||
1028 | iRect displayRect = zero_Rect(); | ||
1029 | for (int i = 0; i < SDL_GetNumVideoDisplays(); i++) { | ||
1030 | SDL_Rect dispBounds; | ||
1031 | SDL_GetDisplayBounds(i, &dispBounds); | ||
1032 | displayRect = union_Rect( | ||
1033 | displayRect, init_Rect(dispBounds.x, dispBounds.y, dispBounds.w, dispBounds.h)); | ||
1034 | } | ||
1035 | iRect winRect; | ||
1036 | SDL_Window *sdlWin = get_Window()->win; | ||
1037 | SDL_GetWindowPosition(sdlWin, &winRect.pos.x, &winRect.pos.y); | ||
1038 | SDL_GetWindowSize(sdlWin, &winRect.size.x, &winRect.size.y); | ||
1039 | iRect visibleWinRect = intersect_Rect(winRect, displayRect); | ||
1040 | /* Only use a popup window if the menu can't fit inside the main window. */ | ||
1041 | if (height_Widget(d) > visibleWinRect.size.y && isUsingMenuPopupWindows_()) { | ||
1026 | if (postCommands) { | 1042 | if (postCommands) { |
1027 | postCommand_Widget(d, "menu.opened"); | 1043 | postCommand_Widget(d, "menu.opened"); |
1028 | } | 1044 | } |
@@ -1032,14 +1048,11 @@ void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, int menuOpenFlags) { | |||
1032 | setUserData_Object(d, parent_Widget(d)); | 1048 | setUserData_Object(d, parent_Widget(d)); |
1033 | iAssert(userData_Object(d)); | 1049 | iAssert(userData_Object(d)); |
1034 | removeChild_Widget(parent_Widget(d), d); /* we'll borrow the widget for a while */ | 1050 | removeChild_Widget(parent_Widget(d), d); /* we'll borrow the widget for a while */ |
1035 | SDL_Window *sdlWin = get_Window()->win; | ||
1036 | iInt2 winPos; | 1051 | iInt2 winPos; |
1037 | SDL_GetWindowPosition(sdlWin, &winPos.x, &winPos.y); | 1052 | SDL_GetWindowPosition(sdlWin, &winPos.x, &winPos.y); |
1038 | // const iRect winRect = | ||
1039 | const float pixelRatio = get_Window()->pixelRatio; | 1053 | const float pixelRatio = get_Window()->pixelRatio; |
1040 | iInt2 menuPos = add_I2(winPos, | 1054 | iInt2 menuPos = add_I2(winPos, |
1041 | divf_I2(sub_I2(windowCoord, divi_I2(gap2_UI, 2)), pixelRatio)); | 1055 | divf_I2(sub_I2(windowCoord, divi_I2(gap2_UI, 2)), pixelRatio)); |
1042 | arrange_Widget(d); | ||
1043 | /* Check display bounds. */ { | 1056 | /* Check display bounds. */ { |
1044 | const iInt2 menuSize = divf_I2(d->rect.size, pixelRatio); | 1057 | const iInt2 menuSize = divf_I2(d->rect.size, pixelRatio); |
1045 | if (menuOpenFlags & center_MenuOpenFlags) { | 1058 | if (menuOpenFlags & center_MenuOpenFlags) { |
@@ -1047,13 +1060,6 @@ void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, int menuOpenFlags) { | |||
1047 | SDL_GetWindowSize(sdlWin, &winSize.x, &winSize.y); | 1060 | SDL_GetWindowSize(sdlWin, &winSize.x, &winSize.y); |
1048 | menuPos = sub_I2(add_I2(winPos, divi_I2(winSize, 2)), divi_I2(menuSize, 2)); | 1061 | menuPos = sub_I2(add_I2(winPos, divi_I2(winSize, 2)), divi_I2(menuSize, 2)); |
1049 | } | 1062 | } |
1050 | iRect displayRect = zero_Rect(); | ||
1051 | for (int i = 0; i < SDL_GetNumVideoDisplays(); i++) { | ||
1052 | SDL_Rect dispBounds; | ||
1053 | SDL_GetDisplayBounds(i, &dispBounds); | ||
1054 | displayRect = union_Rect( | ||
1055 | displayRect, init_Rect(dispBounds.x, dispBounds.y, dispBounds.w, dispBounds.h)); | ||
1056 | } | ||
1057 | menuPos.x = iMin(menuPos.x, right_Rect(displayRect) - menuSize.x); | 1063 | menuPos.x = iMin(menuPos.x, right_Rect(displayRect) - menuSize.x); |
1058 | menuPos.y = iMin(menuPos.y, bottom_Rect(displayRect) - menuSize.y); | 1064 | menuPos.y = iMin(menuPos.y, bottom_Rect(displayRect) - menuSize.y); |
1059 | } | 1065 | } |
@@ -1066,6 +1072,7 @@ void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, int menuOpenFlags) { | |||
1066 | setCurrent_Root(oldRoot); | 1072 | setCurrent_Root(oldRoot); |
1067 | return; | 1073 | return; |
1068 | } | 1074 | } |
1075 | #endif | ||
1069 | raise_Widget(d); | 1076 | raise_Widget(d); |
1070 | if (isPortraitPhone) { | 1077 | if (isPortraitPhone) { |
1071 | setFlags_Widget(d, arrangeWidth_WidgetFlag | resizeChildrenToWidestChild_WidgetFlag, iFalse); | 1078 | setFlags_Widget(d, arrangeWidth_WidgetFlag | resizeChildrenToWidestChild_WidgetFlag, iFalse); |
@@ -1134,9 +1141,8 @@ void closeMenu_Widget(iWidget *d) { | |||
1134 | if (d == NULL || flags_Widget(d) & hidden_WidgetFlag) { | 1141 | if (d == NULL || flags_Widget(d) & hidden_WidgetFlag) { |
1135 | return; /* Already closed. */ | 1142 | return; /* Already closed. */ |
1136 | } | 1143 | } |
1137 | if (isUsingMenuPopupWindows_()) { | 1144 | iWindow *win = window_Widget(d); |
1138 | iWindow *win = window_Widget(d); | 1145 | if (type_Window(win) == popup_WindowType) { |
1139 | iAssert(type_Window(win) == popup_WindowType); | ||
1140 | iWidget *originalParent = userData_Object(d); | 1146 | iWidget *originalParent = userData_Object(d); |
1141 | setUserData_Object(d, NULL); | 1147 | setUserData_Object(d, NULL); |
1142 | win->roots[0]->widget = NULL; | 1148 | win->roots[0]->widget = NULL; |