X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ffg_menu.c;h=9b40bfef8e0f6002f5f43906c1145f81108c9c1e;hb=ffd287a3d20b3fb6f1b74fd7e782ca7eef23a60e;hp=fb5f4a5e79e86a9443beff3a10becca69eaa91ac;hpb=5c4e5aa5fbb92111a003d176677c0aff04dc2048;p=freeglut diff --git a/src/fg_menu.c b/src/fg_menu.c index fb5f4a5..9b40bfe 100644 --- a/src/fg_menu.c +++ b/src/fg_menu.c @@ -76,6 +76,7 @@ static float menu_pen_hback [4] = FREEGLUT_MENU_PEN_HBACK_COLORS; extern GLvoid fgPlatformGetGameModeVMaxExtent( SFG_Window* window, int* x, int* y ); +extern void fghPlatformGetCursorPos(SFG_XYUse *mouse_pos); /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */ @@ -508,6 +509,7 @@ void fgDisplayMenu( void ) static void fghActivateMenu( SFG_Window* window, int button ) { int max_x, max_y; + SFG_XYUse mouse_pos; /* We'll be referencing this menu a lot, so remember its address: */ SFG_Menu* menu = window->Menu[ button ]; @@ -526,9 +528,17 @@ static void fghActivateMenu( SFG_Window* window, int button ) /* Set up the initial menu position now: */ fghGetVMaxExtent(menu->ParentWindow, &max_x, &max_y); fgSetWindow( window ); - menu->X = window->State.MouseX + glutGet( GLUT_WINDOW_X ); - menu->Y = window->State.MouseY + glutGet( GLUT_WINDOW_Y ); + /* get mouse position on screen (window->State.MouseX and window->State.MouseY + * are relative to client area origin), and not easy to correct given that + * glutGet( GLUT_WINDOW_X ) and glutGet( GLUT_WINDOW_Y ) return relative to parent + * origin when looking at a child window + * for parent windows: window->State.MouseX + glutGet( GLUT_WINDOW_X ) == mouse_pos.X + */ + fghPlatformGetCursorPos(&mouse_pos); + menu->X = mouse_pos.X; + menu->Y = mouse_pos.Y; + /* Make sure the whole menu is on the screen */ if( menu->X + menu->Width > max_x ) menu->X -=menu->Width; @@ -539,13 +549,11 @@ static void fghActivateMenu( SFG_Window* window, int button ) menu->Y = 0; } - menu->Window->State.MouseX = - window->State.MouseX + glutGet( GLUT_WINDOW_X ) - menu->X; - menu->Window->State.MouseY = - window->State.MouseY + glutGet( GLUT_WINDOW_Y ) - menu->Y; + /* Set position of mouse relative to top-left menu in menu's window state (could as well set 0 at creation time...) */ + menu->Window->State.MouseX = mouse_pos.X - menu->X; + menu->Window->State.MouseY = mouse_pos.Y - menu->Y; /* Menu status callback */ - printf("Menu status callback: %p\n",fgState.MenuStatusCallback); if (fgState.MenuStateCallback || fgState.MenuStatusCallback) { fgStructure.CurrentMenu = menu; @@ -553,6 +561,7 @@ static void fghActivateMenu( SFG_Window* window, int button ) if (fgState.MenuStateCallback) fgState.MenuStateCallback(GLUT_MENU_IN_USE); if (fgState.MenuStatusCallback) + /* window->State.MouseX and window->State.MouseY are relative to client area origin, as needed */ fgState.MenuStatusCallback(GLUT_MENU_IN_USE, window->State.MouseX, window->State.MouseY); } @@ -721,12 +730,13 @@ void fgDeactivateMenu( SFG_Window *window ) if (fgState.MenuStatusCallback) { /* Get cursor position on screen and convert to relative to parent_window's client area */ - POINT mouse_pos; - GetCursorPos(&mouse_pos); - mouse_pos.x -= glutGet( GLUT_WINDOW_X ); - mouse_pos.y -= glutGet( GLUT_WINDOW_Y ); + SFG_XYUse mouse_pos; + fghPlatformGetCursorPos(&mouse_pos); + + mouse_pos.X -= glutGet( GLUT_WINDOW_X ); + mouse_pos.Y -= glutGet( GLUT_WINDOW_Y ); - fgState.MenuStatusCallback(GLUT_MENU_NOT_IN_USE, mouse_pos.x, mouse_pos.y); + fgState.MenuStatusCallback(GLUT_MENU_NOT_IN_USE, mouse_pos.X, mouse_pos.Y); } } }