X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ffreeglut_cursor.c;h=9732a2d039d29e4952e1ccc8d0594a5d0e3c5435;hb=d3069af045ceb4de1acfe6dac1308315565bd801;hp=0d48e9941eb78000c843adfbf0dc2ad957c21642;hpb=24fcc4c83143dfcfc68b0c4a20f32cdf706be834;p=freeglut diff --git a/src/freeglut_cursor.c b/src/freeglut_cursor.c index 0d48e99..9732a2d 100644 --- a/src/freeglut_cursor.c +++ b/src/freeglut_cursor.c @@ -28,10 +28,6 @@ #include #include "freeglut_internal.h" -#if TARGET_HOST_POSIX_X11 - #include -#endif - /* * TODO BEFORE THE STABLE RELEASE: * glutSetCursor() -- Win32 mappings are incomplete. @@ -44,6 +40,8 @@ /* -- PRIVATE FUNCTIONS --------------------------------------------------- */ #if TARGET_HOST_POSIX_X11 + #include + /* * A factory method for an empty cursor */ @@ -102,62 +100,71 @@ static cursorCacheEntry cursorCache[] = { { XC_bottom_right_corner, None }, /* GLUT_CURSOR_BOTTOM_RIGHT_CORNER */ { XC_bottom_left_corner, None } /* GLUT_CURSOR_BOTTOM_LEFT_CORNER */ }; -#endif - -/* -- INTERNAL FUNCTIONS ---------------------------------------------------- */ -/* - * Set the cursor image to be used for the current window - */ -void fgSetCursor ( SFG_Window *window, int cursorID ) +static void fghSetCursor ( SFG_Window *window, int cursorID ) { -#if TARGET_HOST_POSIX_X11 - { - Cursor cursor; - /* - * XXX FULL_CROSSHAIR demotes to plain CROSSHAIR. Old GLUT allows - * for this, but if there is a system that easily supports a full- - * window (or full-screen) crosshair, we might consider it. - */ - int cursorIDToUse = - ( cursorID == GLUT_CURSOR_FULL_CROSSHAIR ) ? GLUT_CURSOR_CROSSHAIR : cursorID; + Cursor cursor; + /* + * XXX FULL_CROSSHAIR demotes to plain CROSSHAIR. Old GLUT allows + * for this, but if there is a system that easily supports a full- + * window (or full-screen) crosshair, we might consider it. + */ + int cursorIDToUse = + ( cursorID == GLUT_CURSOR_FULL_CROSSHAIR ) ? GLUT_CURSOR_CROSSHAIR : cursorID; - if( ( cursorIDToUse >= 0 ) && - ( cursorIDToUse < sizeof( cursorCache ) / sizeof( cursorCache[0] ) ) ) { - cursorCacheEntry *entry = &cursorCache[ cursorIDToUse ]; - if( entry->cachedCursor == None ) { - entry->cachedCursor = - XCreateFontCursor( fgDisplay.Display, entry->cursorShape ); - } - cursor = entry->cachedCursor; - } else { - switch( cursorIDToUse ) - { - case GLUT_CURSOR_NONE: - cursor = getEmptyCursor( ); - break; + if( ( cursorIDToUse >= 0 ) && + ( cursorIDToUse < sizeof( cursorCache ) / sizeof( cursorCache[0] ) ) ) { + cursorCacheEntry *entry = &cursorCache[ cursorIDToUse ]; + if( entry->cachedCursor == None ) { + entry->cachedCursor = + XCreateFontCursor( fgDisplay.Display, entry->cursorShape ); + } + cursor = entry->cachedCursor; + } else { + switch( cursorIDToUse ) + { + case GLUT_CURSOR_NONE: + cursor = getEmptyCursor( ); + break; - case GLUT_CURSOR_INHERIT: - cursor = None; - break; + case GLUT_CURSOR_INHERIT: + cursor = None; + break; - default: - fgError( "Unknown cursor type: %d", cursorIDToUse ); - return; - } + default: + fgError( "Unknown cursor type: %d", cursorIDToUse ); + return; } + } - if ( cursorIDToUse == GLUT_CURSOR_INHERIT ) { - XUndefineCursor( fgDisplay.Display, window->Window.Handle ); - } else if ( cursor != None ) { - XDefineCursor( fgDisplay.Display, window->Window.Handle, cursor ); - } else if ( cursorIDToUse != GLUT_CURSOR_NONE ) { - fgError( "Failed to create cursor" ); - } + if ( cursorIDToUse == GLUT_CURSOR_INHERIT ) { + XUndefineCursor( fgDisplay.Display, window->Window.Handle ); + } else if ( cursor != None ) { + XDefineCursor( fgDisplay.Display, window->Window.Handle, cursor ); + } else if ( cursorIDToUse != GLUT_CURSOR_NONE ) { + fgError( "Failed to create cursor" ); } +} -#elif TARGET_HOST_MS_WINDOWS +static void fghWarpPointer ( int x, int y ) +{ + XWarpPointer( + fgDisplay.Display, + None, + fgStructure.CurrentWindow->Window.Handle, + 0, 0, 0, 0, + x, y + ); + /* Make the warp visible immediately. */ + XFlush( fgDisplay.Display ); +} +#endif + + +#if TARGET_HOST_MS_WINDOWS +static void fghSetCursor ( SFG_Window *window, int cursorID ) +{ /* * Joe Krahn is re-writing the following code. */ @@ -224,11 +231,29 @@ void fgSetCursor ( SFG_Window *window, int cursorID ) fgError( "Unknown cursor type: %d", cursorID ); break; } +} + + +static void fghWarpPointer ( int x, int y ) +{ + POINT coords; + coords.x = x; + coords.y = y; + + /* ClientToScreen() translates {coords} for us. */ + ClientToScreen( fgStructure.CurrentWindow->Window.Handle, &coords ); + SetCursorPos( coords.x, coords.y ); +} #endif - window->State.Cursor = cursorID; + +/* -- INTERNAL FUNCTIONS ---------------------------------------------------- */ +void fgSetCursor ( SFG_Window *window, int cursorID ) +{ + fghSetCursor ( window, cursorID ); } + /* -- INTERFACE FUNCTIONS -------------------------------------------------- */ /* @@ -239,7 +264,8 @@ void FGAPIENTRY glutSetCursor( int cursorID ) FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetCursor" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetCursor" ); - fgSetCursor ( fgStructure.CurrentWindow, cursorID ); + fghSetCursor ( fgStructure.CurrentWindow, cursorID ); + fgStructure.CurrentWindow->State.Cursor = cursorID; } /* @@ -250,31 +276,7 @@ void FGAPIENTRY glutWarpPointer( int x, int y ) FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWarpPointer" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutWarpPointer" ); -#if TARGET_HOST_POSIX_X11 - - XWarpPointer( - fgDisplay.Display, - None, - fgStructure.CurrentWindow->Window.Handle, - 0, 0, 0, 0, - x, y - ); - /* Make the warp visible immediately. */ - XFlush( fgDisplay.Display ); - -#elif TARGET_HOST_MS_WINDOWS - - { - POINT coords; - coords.x = x; - coords.y = y; - - /* ClientToScreen() translates {coords} for us. */ - ClientToScreen( fgStructure.CurrentWindow->Window.Handle, &coords ); - SetCursorPos( coords.x, coords.y ); - } - -#endif + fghWarpPointer ( x, y ); } /*** END OF FILE ***/