4 * The mouse cursor related stuff.
6 * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
7 * Written by Pawel W. Olszta, <olszta@sourceforge.net>
8 * Creation date: Thu Dec 16 1999
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 #define G_LOG_DOMAIN "freeglut-cursor"
34 #include "../include/GL/freeglut.h"
35 #include "freeglut_internal.h"
37 #if TARGET_HOST_UNIX_X11
38 #include <X11/cursorfont.h>
42 * TODO BEFORE THE STABLE RELEASE:
44 * fgDisplayCursor() -- this waits for better times
45 * glutSetCursor() -- both X and Win32 mappings are incomplete
47 * It would be good to use custom mouse cursor shapes, and introduce
48 * an option to display them using glBitmap() and/or texture mapping,
49 * apart from the windowing system version.
52 /* -- INTERNAL FUNCTIONS --------------------------------------------------- */
55 * Display the mouse cursor using OpenGL calls
57 void fgDisplayCursor( void )
60 * Do nothing for the moment
65 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
68 * Set the cursor image to be used for the current window
70 void FGAPIENTRY glutSetCursor( int cursorID )
73 * Make sure freeglut is ready and there is a current window set
75 freeglut_assert_ready; freeglut_assert_window;
77 #if TARGET_HOST_UNIX_X11
82 * For now we'll limit ourselves to the X cursor fonts...
84 # define MAP_CURSOR(a,b) case a: cursor = XCreateFontCursor( fgDisplay.Display, b ); break;
88 MAP_CURSOR( GLUT_CURSOR_RIGHT_ARROW, XC_left_ptr );
89 MAP_CURSOR( GLUT_CURSOR_LEFT_ARROW, XC_right_ptr );
90 MAP_CURSOR( GLUT_CURSOR_INFO, XC_question_arrow );
91 MAP_CURSOR( GLUT_CURSOR_DESTROY, XC_target );
92 MAP_CURSOR( GLUT_CURSOR_HELP, XC_question_arrow );
93 MAP_CURSOR( GLUT_CURSOR_CYCLE, XC_circle );
94 MAP_CURSOR( GLUT_CURSOR_SPRAY, XC_spraycan );
95 MAP_CURSOR( GLUT_CURSOR_WAIT, XC_watch );
96 MAP_CURSOR( GLUT_CURSOR_TEXT, XC_draft_large );
97 MAP_CURSOR( GLUT_CURSOR_CROSSHAIR, XC_crosshair );
98 MAP_CURSOR( GLUT_CURSOR_NONE, XC_trek );
101 MAP_CURSOR( GLUT_CURSOR_UP_DOWN, XC_arrow );
105 * Define a window's cursor now
107 XDefineCursor( fgDisplay.Display, fgStructure.Window->Window.Handle, cursor );
110 #elif TARGET_HOST_WIN32
112 * This is a temporary solution only...
114 /* Set the cursor AND change it for this window class. */
115 # define MAP_CURSOR(a,b) case a: SetCursor( LoadCursor( NULL, b ) ); \
116 SetClassLong(fgStructure.Window->Window.Handle,GCL_HCURSOR,(LONG)LoadCursor(NULL,b)); \
118 /* Nuke the cursor AND change it for this window class. */
119 # define ZAP_CURSOR(a,b) case a: SetCursor( NULL ); \
120 SetClassLong(fgStructure.Window->Window.Handle,GCL_HCURSOR,(LONG)NULL); \
125 MAP_CURSOR( GLUT_CURSOR_RIGHT_ARROW, IDC_ARROW );
126 MAP_CURSOR( GLUT_CURSOR_LEFT_ARROW, IDC_ARROW );
127 MAP_CURSOR( GLUT_CURSOR_INFO, IDC_HELP );
128 MAP_CURSOR( GLUT_CURSOR_DESTROY, IDC_CROSS );
129 MAP_CURSOR( GLUT_CURSOR_HELP, IDC_HELP );
130 MAP_CURSOR( GLUT_CURSOR_CYCLE, IDC_SIZEALL );
131 MAP_CURSOR( GLUT_CURSOR_SPRAY, IDC_CROSS );
132 MAP_CURSOR( GLUT_CURSOR_WAIT, IDC_WAIT );
133 MAP_CURSOR( GLUT_CURSOR_TEXT, IDC_UPARROW );
134 MAP_CURSOR( GLUT_CURSOR_CROSSHAIR, IDC_CROSS );
135 /* MAP_CURSOR( GLUT_CURSOR_NONE, IDC_NO ); */
136 ZAP_CURSOR( GLUT_CURSOR_NONE, NULL );
139 MAP_CURSOR( GLUT_CURSOR_UP_DOWN, IDC_ARROW );
145 * Remember the currently selected cursor
147 fgStructure.Window->State.Cursor = cursorID;
151 * Moves the mouse pointer to given window coordinates
153 void FGAPIENTRY glutWarpPointer( int x, int y )
155 freeglut_assert_ready; freeglut_assert_window;
157 #if TARGET_HOST_UNIX_X11
159 * Move the mouse pointer to given window coordinates
164 fgStructure.Window->Window.Handle,
169 XFlush( fgDisplay.Display );
171 #elif TARGET_HOST_WIN32
173 POINT coords = { x, y };
176 * First of all, we need to find the new screen-relative coordinates of the mouse cursor
178 ClientToScreen( fgStructure.Window->Window.Handle, &coords );
181 * Now set the new mouse cursor position...
183 SetCursorPos( coords.x, coords.y );
189 /*** END OF FILE ***/