MenuStatusCallback when menu was closed did not return location of pointer relative to child window's top-left, it only worked for top level windows.
To make this work, fghPlatformGetCursorPos now can return cursor pos relative to top-left of a specified window's client area (this is untested on X11) git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@1550 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
parent
5398d76b76
commit
5e97fed06a
@ -76,7 +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);
|
||||
extern void fghPlatformGetCursorPos(const SFG_Window *window, GLboolean client, SFG_XYUse *mouse_pos);
|
||||
|
||||
/* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
|
||||
|
||||
@ -534,7 +534,7 @@ static void fghActivateMenu( SFG_Window* window, int button )
|
||||
* origin when looking at a child window
|
||||
* for parent windows: window->State.MouseX + glutGet( GLUT_WINDOW_X ) == mouse_pos.X
|
||||
*/
|
||||
fghPlatformGetCursorPos(&mouse_pos);
|
||||
fghPlatformGetCursorPos(NULL, GL_FALSE, &mouse_pos);
|
||||
menu->X = mouse_pos.X;
|
||||
menu->Y = mouse_pos.Y;
|
||||
|
||||
@ -744,12 +744,9 @@ void fgDeactivateMenu( SFG_Window *window )
|
||||
fgState.MenuStateCallback(GLUT_MENU_NOT_IN_USE);
|
||||
if (fgState.MenuStatusCallback)
|
||||
{
|
||||
/* Get cursor position on screen and convert to relative to parent_window's client area */
|
||||
/* Get cursor position relative to parent_window's client area */
|
||||
SFG_XYUse mouse_pos;
|
||||
fghPlatformGetCursorPos(&mouse_pos);
|
||||
|
||||
mouse_pos.X -= glutGet( GLUT_WINDOW_X );
|
||||
mouse_pos.Y -= glutGet( GLUT_WINDOW_Y );
|
||||
fghPlatformGetCursorPos(parent_window, GL_TRUE, &mouse_pos);
|
||||
|
||||
fgState.MenuStatusCallback(GLUT_MENU_NOT_IN_USE, mouse_pos.X, mouse_pos.Y);
|
||||
}
|
||||
|
@ -128,13 +128,18 @@ void fgPlatformWarpPointer ( int x, int y )
|
||||
}
|
||||
|
||||
|
||||
void fghPlatformGetCursorPos(SFG_XYUse *mouse_pos)
|
||||
void fghPlatformGetCursorPos(const SFG_Window *window, GLboolean client, SFG_XYUse *mouse_pos)
|
||||
{
|
||||
/* Get current pointer location in screen coordinates
|
||||
/* Get current pointer location in screen coordinates (if client is false or window is NULL), else
|
||||
* Get current pointer location relative to top-left of client area of window (if client is true and window is not NULL)
|
||||
*/
|
||||
POINT pos;
|
||||
GetCursorPos(&pos);
|
||||
|
||||
/* convert to client coords if wanted */
|
||||
if (client && window && window->Window.Handle)
|
||||
ScreenToClient(window->Window.Handle,&pos);
|
||||
|
||||
mouse_pos->X = pos.x;
|
||||
mouse_pos->Y = pos.y;
|
||||
mouse_pos->Use = GL_TRUE;
|
||||
|
@ -349,7 +349,7 @@ static SFG_Window* fghWindowUnderCursor(SFG_Window *window)
|
||||
*/
|
||||
if (window && window->Children.First) /* This window has childs */
|
||||
{
|
||||
SFG_WindowHandleType hwnd;
|
||||
HWND hwnd;
|
||||
SFG_Window* child_window;
|
||||
|
||||
/* Get mouse position at time of message */
|
||||
|
@ -149,18 +149,27 @@ void fgPlatformWarpPointer ( int x, int y )
|
||||
XFlush( fgDisplay.pDisplay.Display );
|
||||
}
|
||||
|
||||
void fghPlatformGetCursorPos(SFG_XYUse *mouse_pos)
|
||||
void fghPlatformGetCursorPos(const SFG_Window *window, GLboolean client, SFG_XYUse *mouse_pos)
|
||||
{
|
||||
/* Get current pointer location in screen coordinates
|
||||
/* Get current pointer location in screen coordinates (if client is false or window is NULL), else
|
||||
* Get current pointer location relative to top-left of client area of window (if client is true and window is not NULL)
|
||||
*/
|
||||
Window w = (client && window && window->Window.Handle)? window->Window.Handle: fgDisplay.pDisplay.RootWindow;
|
||||
Window junk_window;
|
||||
unsigned int junk_mask;
|
||||
int junk_pos;
|
||||
int clientX, clientY;
|
||||
|
||||
XQueryPointer(fgDisplay.pDisplay.Display, fgDisplay.pDisplay.RootWindow,
|
||||
XQueryPointer(fgDisplay.pDisplay.Display, w,
|
||||
&junk_window, &junk_window,
|
||||
&mouse_pos->X, &mouse_pos->Y,
|
||||
&junk_pos, &junk_pos, &junk_mask);
|
||||
&mouse_pos->X, &mouse_pos->Y, /* Screen coords relative to root window's top-left */
|
||||
&clientX, &clientY, /* Client coords relative to window's top-left */
|
||||
&junk_mask);
|
||||
|
||||
if (client && window && window->Window.Handle)
|
||||
{
|
||||
mouse_pos->X = clientX;
|
||||
mouse_pos->Y = clientY;
|
||||
}
|
||||
|
||||
mouse_pos->Use = GL_TRUE;
|
||||
}
|
||||
|
Reference in New Issue
Block a user