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 * XXX Just delete fgDisplayCursor?
46 * glutSetCursor() -- Win32 mappings are incomplete
47 * X mappings are nearly right.
49 * It would be good to use custom mouse cursor shapes, and introduce
50 * an option to display them using glBitmap() and/or texture mapping,
51 * apart from the windowing system version.
54 /* -- INTERNAL FUNCTIONS --------------------------------------------------- */
57 * Display the mouse cursor using OpenGL calls
59 void fgDisplayCursor( void )
64 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
67 * Set the cursor image to be used for the current window
69 void FGAPIENTRY glutSetCursor( int cursorID )
71 freeglut_assert_ready;
72 freeglut_assert_window;
74 #if TARGET_HOST_UNIX_X11
77 * (a) GLUT_CURSOR_NONE doesn't do what it should. We can probably
78 * build an empty pixmap for it, though, quite painlessly.
79 * (b) Are we allocating resources, or causing X to do so?
80 * If yes, we should arrange to deallocate!
81 * (c) No error checking. Is that a problem?
82 * (d) FULL_CROSSHAIR demotes to plain CROSSHAIR. Old GLUT allows
83 * for this, but if there is a system that easily supports a full-
84 * window (or full-screen) crosshair, we might consider it.
85 * (e) Out-of-range cursor-types are ignored. Should we abort?
86 * Print a warning message?
90 #define MAP_CURSOR(a,b) case a: cursor = XCreateFontCursor( fgDisplay.Display, b ); break;
91 if( GLUT_CURSOR_FULL_CROSSHAIR == cursorID )
92 cursorID = GLUT_CURSOR_CROSSHAIR;
95 MAP_CURSOR( GLUT_CURSOR_RIGHT_ARROW, XC_right_ptr);
96 MAP_CURSOR( GLUT_CURSOR_LEFT_ARROW, XC_left_ptr);
97 MAP_CURSOR( GLUT_CURSOR_INFO, XC_hand1);
98 MAP_CURSOR( GLUT_CURSOR_DESTROY, XC_pirate);
99 MAP_CURSOR( GLUT_CURSOR_HELP, XC_question_arrow);
100 MAP_CURSOR( GLUT_CURSOR_CYCLE, XC_exchange);
101 MAP_CURSOR( GLUT_CURSOR_SPRAY, XC_spraycan);
102 MAP_CURSOR( GLUT_CURSOR_WAIT, XC_watch);
103 MAP_CURSOR( GLUT_CURSOR_TEXT, XC_xterm);
104 MAP_CURSOR( GLUT_CURSOR_CROSSHAIR, XC_crosshair);
105 MAP_CURSOR( GLUT_CURSOR_UP_DOWN, XC_sb_v_double_arrow);
106 MAP_CURSOR( GLUT_CURSOR_LEFT_RIGHT, XC_sb_h_double_arrow);
107 MAP_CURSOR( GLUT_CURSOR_TOP_SIDE, XC_top_side);
108 MAP_CURSOR( GLUT_CURSOR_BOTTOM_SIDE, XC_bottom_side);
109 MAP_CURSOR( GLUT_CURSOR_LEFT_SIDE, XC_left_side);
110 MAP_CURSOR( GLUT_CURSOR_RIGHT_SIDE, XC_right_side);
111 MAP_CURSOR( GLUT_CURSOR_TOP_LEFT_CORNER, XC_top_left_corner);
112 MAP_CURSOR( GLUT_CURSOR_TOP_RIGHT_CORNER, XC_top_right_corner);
113 MAP_CURSOR( GLUT_CURSOR_BOTTOM_RIGHT_CORNER, XC_bottom_right_corner);
114 MAP_CURSOR( GLUT_CURSOR_BOTTOM_LEFT_CORNER, XC_bottom_left_corner);
115 MAP_CURSOR( GLUT_CURSOR_NONE, XC_bogosity);
116 case GLUT_CURSOR_INHERIT:
122 if( GLUT_CURSOR_INHERIT == cursorID )
123 XUndefineCursor( fgDisplay.Display, fgStructure.Window->Window.Handle );
125 XDefineCursor( fgDisplay.Display, fgStructure.Window->Window.Handle, cursor );
128 #elif TARGET_HOST_WIN32
131 * This is a temporary solution only...
133 /* Set the cursor AND change it for this window class. */
134 # define MAP_CURSOR(a,b) case a: SetCursor( LoadCursor( NULL, b ) ); \
135 SetClassLong(fgStructure.Window->Window.Handle,GCL_HCURSOR,(LONG)LoadCursor(NULL,b)); \
137 /* Nuke the cursor AND change it for this window class. */
138 # define ZAP_CURSOR(a,b) case a: SetCursor( NULL ); \
139 SetClassLong(fgStructure.Window->Window.Handle,GCL_HCURSOR,(LONG)NULL); \
144 MAP_CURSOR( GLUT_CURSOR_RIGHT_ARROW, IDC_ARROW );
145 MAP_CURSOR( GLUT_CURSOR_LEFT_ARROW, IDC_ARROW );
146 MAP_CURSOR( GLUT_CURSOR_INFO, IDC_HELP );
147 MAP_CURSOR( GLUT_CURSOR_DESTROY, IDC_CROSS );
148 MAP_CURSOR( GLUT_CURSOR_HELP, IDC_HELP );
149 MAP_CURSOR( GLUT_CURSOR_CYCLE, IDC_SIZEALL );
150 MAP_CURSOR( GLUT_CURSOR_SPRAY, IDC_CROSS );
151 MAP_CURSOR( GLUT_CURSOR_WAIT, IDC_WAIT );
152 MAP_CURSOR( GLUT_CURSOR_TEXT, IDC_UPARROW );
153 MAP_CURSOR( GLUT_CURSOR_CROSSHAIR, IDC_CROSS );
154 /* MAP_CURSOR( GLUT_CURSOR_NONE, IDC_NO ); */
155 ZAP_CURSOR( GLUT_CURSOR_NONE, NULL );
158 MAP_CURSOR( GLUT_CURSOR_UP_DOWN, IDC_ARROW );
162 fgStructure.Window->State.Cursor = cursorID;
166 * Moves the mouse pointer to given window coordinates
168 void FGAPIENTRY glutWarpPointer( int x, int y )
170 freeglut_assert_ready;
171 freeglut_assert_window;
173 #if TARGET_HOST_UNIX_X11
178 fgStructure.Window->Window.Handle,
182 XFlush( fgDisplay.Display );
184 #elif TARGET_HOST_WIN32
187 POINT coords = { x, y };
189 * ClientToScreen() translates {coords} for us.
191 ClientToScreen( fgStructure.Window->Window.Handle, &coords );
192 SetCursorPos( coords.x, coords.y );
199 /*** END OF FILE ***/