X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2FCommon%2Ffreeglut_cursor.c;h=140c0ea2d78815f58f02f6256ffc5de9fd2878e5;hb=83a7f1444d1388983a7b756dde26b0cc74101b13;hp=e4673534c5396380c50e1504e45b7fd0142338d9;hpb=d2f7ea29ea6d946f455f4363c3f058ff2bdfba35;p=freeglut diff --git a/src/Common/freeglut_cursor.c b/src/Common/freeglut_cursor.c index e467353..140c0ea 100644 --- a/src/Common/freeglut_cursor.c +++ b/src/Common/freeglut_cursor.c @@ -39,6 +39,9 @@ /* -- PRIVATE FUNCTIONS --------------------------------------------------- */ +extern void fgPlatformSetCursor ( SFG_Window *window, int cursorID ); +extern void fgPlatformWarpPointer ( int x, int y ); + #if TARGET_HOST_POSIX_X11 || TARGET_HOST_MAC_OSX || TARGET_HOST_SOLARIS #include @@ -54,14 +57,14 @@ static Cursor getEmptyCursor( void ) Pixmap cursorNonePixmap; memset( cursorNoneBits, 0, sizeof( cursorNoneBits ) ); memset( &dontCare, 0, sizeof( dontCare ) ); - cursorNonePixmap = XCreateBitmapFromData ( fgDisplay.Display, - fgDisplay.RootWindow, + cursorNonePixmap = XCreateBitmapFromData ( fgDisplay.pDisplay.Display, + fgDisplay.pDisplay.RootWindow, cursorNoneBits, 16, 16 ); if( cursorNonePixmap != None ) { - cursorNone = XCreatePixmapCursor( fgDisplay.Display, + cursorNone = XCreatePixmapCursor( fgDisplay.pDisplay.Display, cursorNonePixmap, cursorNonePixmap, &dontCare, &dontCare, 0, 0 ); - XFreePixmap( fgDisplay.Display, cursorNonePixmap ); + XFreePixmap( fgDisplay.pDisplay.Display, cursorNonePixmap ); } } return cursorNone; @@ -101,7 +104,7 @@ static cursorCacheEntry cursorCache[] = { { XC_bottom_left_corner, None } /* GLUT_CURSOR_BOTTOM_LEFT_CORNER */ }; -static void fghSetCursor ( SFG_Window *window, int cursorID ) +void fgPlatformSetCursor ( SFG_Window *window, int cursorID ) { Cursor cursor; /* @@ -117,7 +120,7 @@ static void fghSetCursor ( SFG_Window *window, int cursorID ) cursorCacheEntry *entry = &cursorCache[ cursorIDToUse ]; if( entry->cachedCursor == None ) { entry->cachedCursor = - XCreateFontCursor( fgDisplay.Display, entry->cursorShape ); + XCreateFontCursor( fgDisplay.pDisplay.Display, entry->cursorShape ); } cursor = entry->cachedCursor; } else { @@ -138,111 +141,26 @@ static void fghSetCursor ( SFG_Window *window, int cursorID ) } if ( cursorIDToUse == GLUT_CURSOR_INHERIT ) { - XUndefineCursor( fgDisplay.Display, window->Window.Handle ); + XUndefineCursor( fgDisplay.pDisplay.Display, window->Window.Handle ); } else if ( cursor != None ) { - XDefineCursor( fgDisplay.Display, window->Window.Handle, cursor ); + XDefineCursor( fgDisplay.pDisplay.Display, window->Window.Handle, cursor ); } else if ( cursorIDToUse != GLUT_CURSOR_NONE ) { fgError( "Failed to create cursor" ); } } -static void fghWarpPointer ( int x, int y ) +void fgPlatformWarpPointer ( int x, int y ) { XWarpPointer( - fgDisplay.Display, + fgDisplay.pDisplay.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. - */ - /* Set the cursor AND change it for this window class. */ -#if !defined(__MINGW64__) && _MSC_VER <= 1200 -# define MAP_CURSOR(a,b) \ - case a: \ - SetCursor( LoadCursor( NULL, b ) ); \ - SetClassLong( window->Window.Handle, \ - GCL_HCURSOR, \ - ( LONG )LoadCursor( NULL, b ) ); \ - break; - /* Nuke the cursor AND change it for this window class. */ -# define ZAP_CURSOR(a,b) \ - case a: \ - SetCursor( NULL ); \ - SetClassLong( window->Window.Handle, \ - GCL_HCURSOR, ( LONG )NULL ); \ - break; -#else -# define MAP_CURSOR(a,b) \ - case a: \ - SetCursor( LoadCursor( NULL, b ) ); \ - SetClassLongPtr( window->Window.Handle, \ - GCLP_HCURSOR, \ - ( LONG )( LONG_PTR )LoadCursor( NULL, b ) ); \ - break; - /* Nuke the cursor AND change it for this window class. */ -# define ZAP_CURSOR(a,b) \ - case a: \ - SetCursor( NULL ); \ - SetClassLongPtr( window->Window.Handle, \ - GCLP_HCURSOR, ( LONG )( LONG_PTR )NULL ); \ - break; -#endif - - switch( cursorID ) - { - MAP_CURSOR( GLUT_CURSOR_RIGHT_ARROW, IDC_ARROW ); - MAP_CURSOR( GLUT_CURSOR_LEFT_ARROW, IDC_ARROW ); - MAP_CURSOR( GLUT_CURSOR_INFO, IDC_HELP ); - MAP_CURSOR( GLUT_CURSOR_DESTROY, IDC_CROSS ); - MAP_CURSOR( GLUT_CURSOR_HELP, IDC_HELP ); - MAP_CURSOR( GLUT_CURSOR_CYCLE, IDC_SIZEALL ); - MAP_CURSOR( GLUT_CURSOR_SPRAY, IDC_CROSS ); - MAP_CURSOR( GLUT_CURSOR_WAIT, IDC_WAIT ); - MAP_CURSOR( GLUT_CURSOR_TEXT, IDC_IBEAM ); - MAP_CURSOR( GLUT_CURSOR_CROSSHAIR, IDC_CROSS ); - MAP_CURSOR( GLUT_CURSOR_UP_DOWN, IDC_SIZENS ); - MAP_CURSOR( GLUT_CURSOR_LEFT_RIGHT, IDC_SIZEWE ); - MAP_CURSOR( GLUT_CURSOR_TOP_SIDE, IDC_ARROW ); /* XXX ToDo */ - MAP_CURSOR( GLUT_CURSOR_BOTTOM_SIDE, IDC_ARROW ); /* XXX ToDo */ - MAP_CURSOR( GLUT_CURSOR_LEFT_SIDE, IDC_ARROW ); /* XXX ToDo */ - MAP_CURSOR( GLUT_CURSOR_RIGHT_SIDE, IDC_ARROW ); /* XXX ToDo */ - MAP_CURSOR( GLUT_CURSOR_TOP_LEFT_CORNER, IDC_SIZENWSE ); - MAP_CURSOR( GLUT_CURSOR_TOP_RIGHT_CORNER, IDC_SIZENESW ); - MAP_CURSOR( GLUT_CURSOR_BOTTOM_RIGHT_CORNER, IDC_SIZENWSE ); - MAP_CURSOR( GLUT_CURSOR_BOTTOM_LEFT_CORNER, IDC_SIZENESW ); - MAP_CURSOR( GLUT_CURSOR_INHERIT, IDC_ARROW ); /* XXX ToDo */ - ZAP_CURSOR( GLUT_CURSOR_NONE, NULL ); - MAP_CURSOR( GLUT_CURSOR_FULL_CROSSHAIR, IDC_CROSS ); /* XXX ToDo */ - - default: - 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 ); + XFlush( fgDisplay.pDisplay.Display ); } #endif @@ -250,7 +168,7 @@ static void fghWarpPointer ( int x, int y ) /* -- INTERNAL FUNCTIONS ---------------------------------------------------- */ void fgSetCursor ( SFG_Window *window, int cursorID ) { - fghSetCursor ( window, cursorID ); + fgPlatformSetCursor ( window, cursorID ); } @@ -264,7 +182,7 @@ void FGAPIENTRY glutSetCursor( int cursorID ) FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetCursor" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetCursor" ); - fghSetCursor ( fgStructure.CurrentWindow, cursorID ); + fgPlatformSetCursor ( fgStructure.CurrentWindow, cursorID ); fgStructure.CurrentWindow->State.Cursor = cursorID; } @@ -276,7 +194,7 @@ void FGAPIENTRY glutWarpPointer( int x, int y ) FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWarpPointer" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutWarpPointer" ); - fghWarpPointer ( x, y ); + fgPlatformWarpPointer ( x, y ); } /*** END OF FILE ***/