summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ui/root.c3
-rw-r--r--src/ui/util.c20
-rw-r--r--src/ui/util.h7
3 files changed, 22 insertions, 8 deletions
diff --git a/src/ui/root.c b/src/ui/root.c
index c014ffa8..e0a12665 100644
--- a/src/ui/root.c
+++ b/src/ui/root.c
@@ -324,8 +324,7 @@ static iBool handleRootCommands_(iWidget *root, const char *cmd) {
324 else if (equal_Command(cmd, "splitmenu.open")) { 324 else if (equal_Command(cmd, "splitmenu.open")) {
325 setFocus_Widget(NULL); 325 setFocus_Widget(NULL);
326 iWidget *menu = findWidget_Root("splitmenu"); 326 iWidget *menu = findWidget_Root("splitmenu");
327 openMenu_Widget(menu, zero_I2()); 327 openMenuFlags_Widget(menu, zero_I2(), postCommands_MenuOpenFlags | center_MenuOpenFlags);
328 setPos_Widget(menu, sub_I2(divi_I2(size_Root(get_Root()), 2), divi_I2(menu->rect.size, 2)));
329 return iTrue; 328 return iTrue;
330 } 329 }
331 else if (equal_Command(cmd, "contextclick")) { 330 else if (equal_Command(cmd, "contextclick")) {
diff --git a/src/ui/util.c b/src/ui/util.c
index 244eb24d..872a91ab 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -855,7 +855,7 @@ iWidget *makeMenu_Widget(iWidget *parent, const iMenuItem *items, size_t n) {
855} 855}
856 856
857void openMenu_Widget(iWidget *d, iInt2 windowCoord) { 857void openMenu_Widget(iWidget *d, iInt2 windowCoord) {
858 openMenuFlags_Widget(d, windowCoord, iTrue); 858 openMenuFlags_Widget(d, windowCoord, postCommands_MenuOpenFlags);
859} 859}
860 860
861static void updateMenuItemFonts_Widget_(iWidget *d) { 861static void updateMenuItemFonts_Widget_(iWidget *d) {
@@ -1002,7 +1002,8 @@ void releaseNativeMenu_Widget(iWidget *d) {
1002#endif 1002#endif
1003} 1003}
1004 1004
1005void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, iBool postCommands) { 1005void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, int menuOpenFlags) {
1006 const iBool postCommands = (menuOpenFlags & postCommands_MenuOpenFlags) != 0;
1006#if defined (iHaveNativeContextMenus) 1007#if defined (iHaveNativeContextMenus)
1007 const iArray *items = userData_Object(d); 1008 const iArray *items = userData_Object(d);
1008 iAssert(flags_Widget(d) & nativeMenu_WidgetFlag); 1009 iAssert(flags_Widget(d) & nativeMenu_WidgetFlag);
@@ -1020,6 +1021,7 @@ void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, iBool postCommands) {
1020 processEvents_App(postedEventsOnly_AppEventMode); 1021 processEvents_App(postedEventsOnly_AppEventMode);
1021 setFlags_Widget(d, hidden_WidgetFlag, iFalse); 1022 setFlags_Widget(d, hidden_WidgetFlag, iFalse);
1022 setFlags_Widget(d, commandOnMouseMiss_WidgetFlag, iTrue); 1023 setFlags_Widget(d, commandOnMouseMiss_WidgetFlag, iTrue);
1024 setFlags_Widget(findChild_Widget(d, "menu.cancel"), disabled_WidgetFlag, iFalse);
1023 if (isUsingMenuPopupWindows_()) { 1025 if (isUsingMenuPopupWindows_()) {
1024 if (postCommands) { 1026 if (postCommands) {
1025 postCommand_Widget(d, "menu.opened"); 1027 postCommand_Widget(d, "menu.opened");
@@ -1030,12 +1032,21 @@ void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, iBool postCommands) {
1030 setUserData_Object(d, parent_Widget(d)); 1032 setUserData_Object(d, parent_Widget(d));
1031 iAssert(userData_Object(d)); 1033 iAssert(userData_Object(d));
1032 removeChild_Widget(parent_Widget(d), d); /* we'll borrow the widget for a while */ 1034 removeChild_Widget(parent_Widget(d), d); /* we'll borrow the widget for a while */
1035 SDL_Window *sdlWin = get_Window()->win;
1036 iInt2 winPos;
1037 SDL_GetWindowPosition(sdlWin, &winPos.x, &winPos.y);
1038// const iRect winRect =
1033 const float pixelRatio = get_Window()->pixelRatio; 1039 const float pixelRatio = get_Window()->pixelRatio;
1034 iInt2 menuPos = add_I2(get_MainWindow()->place.normalRect.pos, 1040 iInt2 menuPos = add_I2(winPos,
1035 divf_I2(sub_I2(windowCoord, divi_I2(gap2_UI, 2)), pixelRatio)); 1041 divf_I2(sub_I2(windowCoord, divi_I2(gap2_UI, 2)), pixelRatio));
1036 arrange_Widget(d); 1042 arrange_Widget(d);
1037 /* Check display bounds. */ { 1043 /* Check display bounds. */ {
1038 const iInt2 menuSize = divf_I2(d->rect.size, pixelRatio); 1044 const iInt2 menuSize = divf_I2(d->rect.size, pixelRatio);
1045 if (menuOpenFlags & center_MenuOpenFlags) {
1046 iInt2 winSize;
1047 SDL_GetWindowSize(sdlWin, &winSize.x, &winSize.y);
1048 menuPos = sub_I2(add_I2(winPos, divi_I2(winSize, 2)), divi_I2(menuSize, 2));
1049 }
1039 SDL_Rect displayRect; 1050 SDL_Rect displayRect;
1040 SDL_GetDisplayBounds(SDL_GetWindowDisplayIndex(get_Window()->win), &displayRect); 1051 SDL_GetDisplayBounds(SDL_GetWindowDisplayIndex(get_Window()->win), &displayRect);
1041 menuPos.x = iMin(menuPos.x, displayRect.x + displayRect.w - menuSize.x); 1052 menuPos.x = iMin(menuPos.x, displayRect.x + displayRect.w - menuSize.x);
@@ -1051,7 +1062,6 @@ void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, iBool postCommands) {
1051 return; 1062 return;
1052 } 1063 }
1053 raise_Widget(d); 1064 raise_Widget(d);
1054 setFlags_Widget(findChild_Widget(d, "menu.cancel"), disabled_WidgetFlag, iFalse);
1055 if (isPortraitPhone) { 1065 if (isPortraitPhone) {
1056 setFlags_Widget(d, arrangeWidth_WidgetFlag | resizeChildrenToWidestChild_WidgetFlag, iFalse); 1066 setFlags_Widget(d, arrangeWidth_WidgetFlag | resizeChildrenToWidestChild_WidgetFlag, iFalse);
1057 setFlags_Widget(d, resizeWidthOfChildren_WidgetFlag | drawBackgroundToBottom_WidgetFlag, iTrue); 1067 setFlags_Widget(d, resizeWidthOfChildren_WidgetFlag | drawBackgroundToBottom_WidgetFlag, iTrue);
@@ -1106,7 +1116,7 @@ void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, iBool postCommands) {
1106 postCommand_Widget(d, "menu.opened"); 1116 postCommand_Widget(d, "menu.opened");
1107 } 1117 }
1108 setupMenuTransition_Mobile(d, iTrue); 1118 setupMenuTransition_Mobile(d, iTrue);
1109#endif 1119#endif
1110} 1120}
1111 1121
1112void closeMenu_Widget(iWidget *d) { 1122void closeMenu_Widget(iWidget *d) {
diff --git a/src/ui/util.h b/src/ui/util.h
index 5d092700..f64fac7e 100644
--- a/src/ui/util.h
+++ b/src/ui/util.h
@@ -226,10 +226,15 @@ struct Impl_MenuItem {
226 }; 226 };
227}; 227};
228 228
229enum iMenuOpenFlags {
230 postCommands_MenuOpenFlags = iBit(1),
231 center_MenuOpenFlags = iBit(2),
232};
233
229iWidget * makeMenu_Widget (iWidget *parent, const iMenuItem *items, size_t n); /* returns no ref */ 234iWidget * makeMenu_Widget (iWidget *parent, const iMenuItem *items, size_t n); /* returns no ref */
230void makeMenuItems_Widget (iWidget *menu, const iMenuItem *items, size_t n); 235void makeMenuItems_Widget (iWidget *menu, const iMenuItem *items, size_t n);
231void openMenu_Widget (iWidget *, iInt2 windowCoord); 236void openMenu_Widget (iWidget *, iInt2 windowCoord);
232void openMenuFlags_Widget (iWidget *, iInt2 windowCoord, iBool postCommands); 237void openMenuFlags_Widget (iWidget *, iInt2 windowCoord, int flags);
233void closeMenu_Widget (iWidget *); 238void closeMenu_Widget (iWidget *);
234void releaseNativeMenu_Widget (iWidget *); 239void releaseNativeMenu_Widget (iWidget *);
235 240