From 39de8f8682808d020ebc7eb7f13fe49bdc07406a Mon Sep 17 00:00:00 2001 From: Diederick Niehorster Date: Sat, 6 Apr 2013 14:08:59 +0000 Subject: [PATCH] Menu's work again in gamemode too now. We have to do a normal ShowWindow in gamemode, or the menu won't pop up over the gamemode window. Also now using fgState.ActiveMenus instead of enumerating to see if there is an active menu git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@1612 7f0cb862-5218-0410-a997-914c9d46530a --- src/fg_menu.c | 22 +++++++++++----------- src/mswin/fg_main_mswin.c | 12 ++++++------ src/mswin/fg_menu_mswin.c | 13 ++++++++++--- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/fg_menu.c b/src/fg_menu.c index d3c435f..f302cdd 100644 --- a/src/fg_menu.c +++ b/src/fg_menu.c @@ -632,7 +632,7 @@ GLboolean fgCheckActiveMenu ( SFG_Window *window, int button, GLboolean pressed, is_handled = GL_TRUE; } - else if ( fgStructure.Menus.First ) /* Don't have to check whether this was a downpress or an uppress, there is no way to get an uppress in another window before a downpress... */ + else if ( fgState.ActiveMenus ) /* Don't have to check whether this was a downpress or an uppress, there is no way to get an uppress in another window before a downpress... */ { /* if another window than the one clicked in has an open menu, close it */ SFG_Menu *menu = fgGetActiveMenu(); @@ -784,7 +784,7 @@ int FGAPIENTRY glutCreateMenu( FGCBMenu callback ) { /* The menu object creation code resides in freeglut_structure.c */ FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateMenu" ); - if (fgGetActiveMenu()) + if (fgState.ActiveMenus) fgError("Menu manipulation not allowed while menus in use."); return fgCreateMenu( callback )->ID; @@ -801,7 +801,7 @@ void FGAPIENTRY glutDestroyMenu( int menuID ) menu = fgMenuByID( menuID ); freeglut_return_if_fail( menu ); - if (fgGetActiveMenu()) + if (fgState.ActiveMenus) fgError("Menu manipulation not allowed while menus in use."); /* The menu object destruction code resides in freeglut_structure.c */ @@ -846,7 +846,7 @@ void FGAPIENTRY glutAddMenuEntry( const char* label, int value ) menuEntry = (SFG_MenuEntry *)calloc( sizeof(SFG_MenuEntry), 1 ); freeglut_return_if_fail( fgStructure.CurrentMenu ); - if (fgGetActiveMenu()) + if (fgState.ActiveMenus) fgError("Menu manipulation not allowed while menus in use."); menuEntry->Text = strdup( label ); @@ -871,7 +871,7 @@ void FGAPIENTRY glutAddSubMenu( const char *label, int subMenuID ) subMenu = fgMenuByID( subMenuID ); freeglut_return_if_fail( fgStructure.CurrentMenu ); - if (fgGetActiveMenu()) + if (fgState.ActiveMenus) fgError("Menu manipulation not allowed while menus in use."); freeglut_return_if_fail( subMenu ); @@ -895,7 +895,7 @@ void FGAPIENTRY glutSetMenuFont( int menuID, void* fontID ) menu = fgMenuByID( menuID ); freeglut_return_if_fail( menu ); - if (fgGetActiveMenu()) + if (fgState.ActiveMenus) fgError("Menu manipulation not allowed while menus in use."); font = fghFontByID( fontID ); @@ -919,7 +919,7 @@ void FGAPIENTRY glutChangeToMenuEntry( int item, const char* label, int value ) FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutChangeToMenuEntry" ); freeglut_return_if_fail( fgStructure.CurrentMenu ); - if (fgGetActiveMenu()) + if (fgState.ActiveMenus) fgError("Menu manipulation not allowed while menus in use."); /* Get n-th menu entry in the current menu, starting from one: */ @@ -949,7 +949,7 @@ void FGAPIENTRY glutChangeToSubMenu( int item, const char* label, FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutChangeToSubMenu" ); freeglut_return_if_fail( fgStructure.CurrentMenu ); - if (fgGetActiveMenu()) + if (fgState.ActiveMenus) fgError("Menu manipulation not allowed while menus in use."); /* Get handle to sub menu */ @@ -982,7 +982,7 @@ void FGAPIENTRY glutRemoveMenuItem( int item ) FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutRemoveMenuItem" ); freeglut_return_if_fail( fgStructure.CurrentMenu ); - if (fgGetActiveMenu()) + if (fgState.ActiveMenus) fgError("Menu manipulation not allowed while menus in use."); /* Get n-th menu entry in the current menu, starting from one: */ @@ -1008,7 +1008,7 @@ void FGAPIENTRY glutAttachMenu( int button ) freeglut_return_if_fail( fgStructure.CurrentWindow ); freeglut_return_if_fail( fgStructure.CurrentMenu ); - if (fgGetActiveMenu()) + if (fgState.ActiveMenus) fgError("Menu manipulation not allowed while menus in use."); freeglut_return_if_fail( button >= 0 ); @@ -1027,7 +1027,7 @@ void FGAPIENTRY glutDetachMenu( int button ) freeglut_return_if_fail( fgStructure.CurrentWindow ); freeglut_return_if_fail( fgStructure.CurrentMenu ); - if (fgGetActiveMenu()) + if (fgState.ActiveMenus) fgError("Menu manipulation not allowed while menus in use."); freeglut_return_if_fail( button >= 0 ); diff --git a/src/mswin/fg_main_mswin.c b/src/mswin/fg_main_mswin.c index 4b34089..7e43eaf 100644 --- a/src/mswin/fg_main_mswin.c +++ b/src/mswin/fg_main_mswin.c @@ -39,7 +39,7 @@ extern void fgNewWGLCreateContext( SFG_Window* window ); extern GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly, unsigned char layer_type ); -extern void fgPlatformCheckMenuDeactivate(); +extern void fgPlatformCheckMenuDeactivate(HWND newFocusWnd); #ifdef WM_TOUCH typedef BOOL (WINAPI *pGetTouchInputInfo)(HTOUCHINPUT,UINT,PTOUCHINPUT,int); @@ -969,14 +969,14 @@ LRESULT CALLBACK fgPlatformWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPAR lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ); /* Check if there are any open menus that need to be closed */ - fgPlatformCheckMenuDeactivate(); + fgPlatformCheckMenuDeactivate((HWND)wParam); break; case WM_MOUSEACTIVATE: /* Clicks should not activate the menu. * Especially important when clicking on a menu's submenu item which has no effect. */ - printf("WM_MOUSEACTIVATE\n"); + /*printf("WM_MOUSEACTIVATE\n");*/ if (window->IsMenu) lRet = MA_NOACTIVATEANDEAT; else @@ -988,7 +988,7 @@ LRESULT CALLBACK fgPlatformWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPAR case WM_NCRBUTTONDOWN: { SFG_Menu *menu; - if (fgStructure.Menus.First && (menu = fgGetActiveMenu())) + if (fgState.ActiveMenus && (menu = fgGetActiveMenu())) /* user clicked non-client area of window while a menu is open. Close menu */ fgDeactivateMenu(menu->ParentWindow); @@ -1767,8 +1767,8 @@ void fgPlatformProcessWork(SFG_Window *window) win = win->Parent; break; case DesireNormalState: - if (win->IsMenu) - cmdShow = SW_SHOWNA; /* Just show, don't activate if its a menu */ + if (win->IsMenu && (!fgStructure.GameModeWindow || win->ActiveMenu->ParentWindow != fgStructure.GameModeWindow)) + cmdShow = SW_SHOWNA; /* Just show, don't activate window if its a menu. Only exception is when the parent is a gamemode window as the menu would pop under it when we do this... */ else cmdShow = SW_SHOW; break; diff --git a/src/mswin/fg_menu_mswin.c b/src/mswin/fg_menu_mswin.c index 9c3e952..93c538e 100644 --- a/src/mswin/fg_menu_mswin.c +++ b/src/mswin/fg_menu_mswin.c @@ -37,18 +37,25 @@ GLvoid fgPlatformGetGameModeVMaxExtent( SFG_Window* window, int* x, int* y ) *y = glutGet ( GLUT_SCREEN_HEIGHT ); } -void fgPlatformCheckMenuDeactivate() +void fgPlatformCheckMenuDeactivate(HWND newFocusWnd) { /* User/system switched application focus. * If we have an open menu, close it. */ SFG_Menu* menu = NULL; - if ( fgStructure.Menus.First ) + if ( fgState.ActiveMenus ) menu = fgGetActiveMenu(); if ( menu ) - fgDeactivateMenu(menu->ParentWindow); + { + if (newFocusWnd != menu->Window->Window.Handle) + /* When in GameMode, the menu's parent window will lose focus when the menu is opened. + * This is sadly necessary as we need to do an activating ShowWindow() for the menu + * to pop up over the gamemode window + */ + fgDeactivateMenu(menu->ParentWindow); + } }; -- 1.7.10.4