Mercurial > sdl-ios-xcode
annotate src/video/photon/SDL_ph_mouse.c @ 279:04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 14 Feb 2002 02:15:15 +0000 |
parents | c6abdda2f666 |
children | 3d8b6b9f1e18 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga | |
4 | |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 #include <stdlib.h> | |
29 #include <stdio.h> | |
30 #include <string.h> | |
31 | |
32 #include "SDL_error.h" | |
33 #include "SDL_mouse.h" | |
34 #include "SDL_events_c.h" | |
35 #include "SDL_cursor_c.h" | |
36 #include "SDL_ph_mouse_c.h" | |
37 | |
38 struct WMcursor { | |
39 PhCursorDef_t *ph_cursor ; | |
40 }; | |
41 | |
42 | |
43 void ph_FreeWMCursor(_THIS, WMcursor *cursor) | |
44 { | |
45 | |
46 if ( window != NULL ) { | |
47 SDL_Lock_EventThread(); | |
48 | |
49 if (PtSetResource( window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_INHERIT, 0 ) < 0) | |
50 { | |
51 //TODO: output error msg | |
52 } | |
53 | |
54 SDL_Unlock_EventThread(); | |
55 } | |
56 //free(cursor->ph_cursor.images); | |
57 free(cursor); | |
58 } | |
59 | |
60 WMcursor *ph_CreateWMCursor(_THIS, | |
61 Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y) | |
62 { | |
63 WMcursor* cursor; | |
64 int clen, i; | |
65 | |
66 /* Allocate and initialize the cursor memory */ | |
67 if ((cursor = (WMcursor*)malloc(sizeof(WMcursor))) == NULL) | |
68 { | |
69 SDL_OutOfMemory(); | |
70 return(NULL); | |
71 } | |
72 memset(cursor,0,sizeof(WMcursor)); | |
73 | |
74 cursor->ph_cursor = (PhCursorDef_t *) malloc(sizeof(PhCursorDef_t) + 32*4*2); | |
75 if(cursor->ph_cursor == NULL) | |
76 printf("cursor malloc failed\n"); | |
77 | |
78 memset(cursor->ph_cursor,0,(sizeof(PhCursorDef_t) + 32*4*2)); | |
79 | |
80 cursor->ph_cursor->hdr.type =Ph_RDATA_CURSOR; | |
81 cursor->ph_cursor->size1.x = (short)w; | |
82 cursor->ph_cursor->size1.y = (short)h; | |
83 cursor->ph_cursor->offset1.x = (short)hot_x; | |
84 cursor->ph_cursor->offset1.y = (short)hot_y; | |
85 cursor->ph_cursor->bytesperline1 = (char)w/8; | |
86 cursor->ph_cursor->color1 = Pg_WHITE; | |
87 cursor->ph_cursor->size2.x = (short)w; | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
88 cursor->ph_cursor->size2.y = (short)h; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
89 cursor->ph_cursor->offset2.x = (short)hot_x; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
90 cursor->ph_cursor->offset2.y = (short)hot_y; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
91 cursor->ph_cursor->bytesperline2 = (char)w/8; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
92 cursor->ph_cursor->color2 = Pg_BLACK; |
0 | 93 |
94 clen = (w/8)*h; | |
95 | |
96 /* Copy the mask and the data to different | |
97 bitmap planes */ | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
98 for ( i=0; i<clen; ++i ) |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
99 { |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
100 cursor->ph_cursor->images[i] = data[i]; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
101 cursor->ph_cursor->images[i+clen] = mask[i]; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
102 } |
0 | 103 |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
104 //#bytes following the hdr struct |
0 | 105 cursor->ph_cursor->hdr.len =sizeof(PhCursorDef_t) + clen*2 - sizeof(PhRegionDataHdr_t); |
106 | |
107 return (cursor); | |
108 } | |
109 | |
110 | |
111 PhCursorDef_t ph_GetWMPhCursor(WMcursor *cursor) | |
112 { | |
113 return(*cursor->ph_cursor); | |
114 } | |
115 | |
116 | |
117 int ph_ShowWMCursor(_THIS, WMcursor *cursor) | |
118 { | |
119 PtArg_t args[3]; | |
120 int nargs = 0; | |
121 short cursor_is_defined = 0; | |
122 | |
123 /* Don't do anything if the display is gone */ | |
124 if ( window == NULL ) { | |
125 return(0); | |
126 } | |
127 | |
128 /* Set the photon cursor cursor, or blank if cursor is NULL */ | |
129 if ( window ) { | |
130 | |
131 if ( cursor != NULL ) { | |
132 PtSetArg( &args[0], Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP, 0 ); | |
133 // Could set next to any PgColor_t value | |
134 PtSetArg( &args[1], Pt_ARG_CURSOR_COLOR,Ph_CURSOR_DEFAULT_COLOR , 0 ); | |
135 PtSetArg( &args[2], Pt_ARG_BITMAP_CURSOR, cursor->ph_cursor, (cursor->ph_cursor->hdr.len + sizeof(PhRegionDataHdr_t)) ); | |
136 nargs = 3; | |
137 cursor_is_defined = 1; | |
138 } | |
139 else // Ph_CURSOR_NONE | |
140 { | |
141 PtSetArg( &args[0], Pt_ARG_CURSOR_TYPE,Ph_CURSOR_NONE, 0); | |
142 nargs = 1; | |
143 cursor_is_defined = 1; | |
144 } | |
145 if (cursor_is_defined) | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
146 { |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
147 SDL_Lock_EventThread(); |
0 | 148 |
149 if (PtSetResources( window, nargs, args ) < 0 ) | |
150 { | |
151 return(0); | |
152 } | |
153 | |
154 SDL_Unlock_EventThread(); | |
155 } | |
156 else | |
157 return(0); | |
158 } | |
159 return(1); | |
160 } | |
161 | |
162 void ph_WarpWMCursor(_THIS, Uint16 x, Uint16 y) | |
163 { | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
164 SDL_Lock_EventThread(); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
165 PhMoveCursorRel( PhInputGroup(NULL), x, y ); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
166 SDL_Unlock_EventThread(); |
0 | 167 } |
168 | |
169 | |
170 void ph_CheckMouseMode(_THIS) | |
171 { | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
172 mouse_relative = 1; |
0 | 173 } |