Mercurial > sdl-ios-xcode
annotate src/video/photon/SDL_ph_mouse.c @ 421:195dd37b3d86
Bugfix from Corona688: don't reference a string before we've initialized it.
Fixes crashbug on WinCE (PocketPC).
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Tue, 02 Jul 2002 04:07:01 +0000 |
parents | bce7171e7a85 |
children | 8e3ce997621c |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
297
f6ffac90895c
Updated copyright information for 2002
Sam Lantinga <slouken@libsdl.org>
parents:
283
diff
changeset
|
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga |
0 | 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 { | |
315
3333b6e68289
Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
39 PhCursorDef_t *ph_cursor ; |
0 | 40 }; |
41 | |
42 | |
43 void ph_FreeWMCursor(_THIS, WMcursor *cursor) | |
44 { | |
315
3333b6e68289
Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
45 if (window != NULL) |
3333b6e68289
Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
46 { |
3333b6e68289
Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
47 SDL_Lock_EventThread(); |
0 | 48 |
315
3333b6e68289
Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
49 if (PtSetResource( window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_INHERIT, 0 ) < 0) |
3333b6e68289
Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
50 { |
3333b6e68289
Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
51 /* TODO: output error msg */ |
3333b6e68289
Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
52 } |
3333b6e68289
Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
53 |
3333b6e68289
Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
54 SDL_Unlock_EventThread(); |
3333b6e68289
Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
55 } |
3333b6e68289
Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
56 /* free(cursor->ph_cursor.images); */ |
3333b6e68289
Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
57 free(cursor); |
0 | 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; | |
283
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
65 unsigned char bit, databit, maskbit; |
0 | 66 |
67 /* Allocate and initialize the cursor memory */ | |
68 if ((cursor = (WMcursor*)malloc(sizeof(WMcursor))) == NULL) | |
69 { | |
380
bce7171e7a85
Date: Wed, 22 May 2002 22:30:58 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
315
diff
changeset
|
70 SDL_OutOfMemory(); |
bce7171e7a85
Date: Wed, 22 May 2002 22:30:58 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
315
diff
changeset
|
71 return(NULL); |
0 | 72 } |
73 memset(cursor,0,sizeof(WMcursor)); | |
283
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
74 |
0 | 75 cursor->ph_cursor = (PhCursorDef_t *) malloc(sizeof(PhCursorDef_t) + 32*4*2); |
76 if(cursor->ph_cursor == NULL) | |
77 printf("cursor malloc failed\n"); | |
78 | |
79 memset(cursor->ph_cursor,0,(sizeof(PhCursorDef_t) + 32*4*2)); | |
283
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
80 |
0 | 81 cursor->ph_cursor->hdr.type =Ph_RDATA_CURSOR; |
82 cursor->ph_cursor->size1.x = (short)w; | |
83 cursor->ph_cursor->size1.y = (short)h; | |
84 cursor->ph_cursor->offset1.x = (short)hot_x; | |
85 cursor->ph_cursor->offset1.y = (short)hot_y; | |
86 cursor->ph_cursor->bytesperline1 = (char)w/8; | |
87 cursor->ph_cursor->color1 = Pg_WHITE; | |
88 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
|
89 cursor->ph_cursor->size2.y = (short)h; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
90 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
|
91 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
|
92 cursor->ph_cursor->bytesperline2 = (char)w/8; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
93 cursor->ph_cursor->color2 = Pg_BLACK; |
283
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
94 |
0 | 95 clen = (w/8)*h; |
96 | |
97 /* Copy the mask and the data to different | |
98 bitmap planes */ | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
99 for ( i=0; i<clen; ++i ) |
283
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
100 { |
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
101 for ( bit = 0; bit < 8; bit++ ) |
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
102 { |
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
103 databit = data[i] & (1 << bit); |
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
104 maskbit = mask[i] & (1 << bit); |
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
105 |
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
106 cursor->ph_cursor->images[i] |= |
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
107 (databit == 0) ? maskbit : 0; |
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
108 /* If the databit != 0, treat it as a black pixel and |
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
109 * ignore the maskbit (can't do an inverted color) */ |
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
110 cursor->ph_cursor->images[i+clen] |= databit; |
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
111 } |
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
112 } |
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
113 |
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
114 /* #bytes following the hdr struct */ |
0 | 115 cursor->ph_cursor->hdr.len =sizeof(PhCursorDef_t) + clen*2 - sizeof(PhRegionDataHdr_t); |
116 | |
117 return (cursor); | |
118 } | |
119 | |
120 | |
121 PhCursorDef_t ph_GetWMPhCursor(WMcursor *cursor) | |
122 { | |
315
3333b6e68289
Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
123 return(*cursor->ph_cursor); |
0 | 124 } |
125 | |
126 int ph_ShowWMCursor(_THIS, WMcursor *cursor) | |
127 { | |
128 PtArg_t args[3]; | |
129 int nargs = 0; | |
130 short cursor_is_defined = 0; | |
131 | |
132 /* Don't do anything if the display is gone */ | |
133 if ( window == NULL ) { | |
134 return(0); | |
135 } | |
136 | |
137 /* Set the photon cursor cursor, or blank if cursor is NULL */ | |
138 if ( window ) { | |
139 | |
140 if ( cursor != NULL ) { | |
141 PtSetArg( &args[0], Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP, 0 ); | |
283
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
142 /* Could set next to any PgColor_t value */ |
0 | 143 PtSetArg( &args[1], Pt_ARG_CURSOR_COLOR,Ph_CURSOR_DEFAULT_COLOR , 0 ); |
144 PtSetArg( &args[2], Pt_ARG_BITMAP_CURSOR, cursor->ph_cursor, (cursor->ph_cursor->hdr.len + sizeof(PhRegionDataHdr_t)) ); | |
145 nargs = 3; | |
146 cursor_is_defined = 1; | |
147 } | |
283
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
148 else /* Ph_CURSOR_NONE */ |
0 | 149 { |
150 PtSetArg( &args[0], Pt_ARG_CURSOR_TYPE,Ph_CURSOR_NONE, 0); | |
151 nargs = 1; | |
152 cursor_is_defined = 1; | |
153 } | |
154 if (cursor_is_defined) | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
155 { |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
156 SDL_Lock_EventThread(); |
0 | 157 |
158 if (PtSetResources( window, nargs, args ) < 0 ) | |
159 { | |
160 return(0); | |
161 } | |
162 | |
163 SDL_Unlock_EventThread(); | |
164 } | |
165 else | |
166 return(0); | |
167 } | |
168 return(1); | |
169 } | |
170 | |
171 void ph_WarpWMCursor(_THIS, Uint16 x, Uint16 y) | |
172 { | |
315
3333b6e68289
Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
173 short abs_x, abs_y; |
283
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
174 |
315
3333b6e68289
Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
175 SDL_Lock_EventThread(); |
3333b6e68289
Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
176 PtGetAbsPosition( window, &abs_x, &abs_y ); |
3333b6e68289
Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
177 PhMoveCursorAbs( PhInputGroup(NULL), x + abs_x, y + abs_y ); |
3333b6e68289
Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
178 SDL_Unlock_EventThread(); |
0 | 179 } |
180 | |
181 | |
182 void ph_CheckMouseMode(_THIS) | |
183 { | |
315
3333b6e68289
Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
184 /* If the mouse is hidden and input is grabbed, we use relative mode */ |
3333b6e68289
Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
185 if ( !(SDL_cursorstate & CURSOR_VISIBLE) && (this->input_grab != SDL_GRAB_OFF)) |
3333b6e68289
Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
186 { |
3333b6e68289
Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
187 mouse_relative = 1; |
3333b6e68289
Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
188 } |
3333b6e68289
Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
189 else |
3333b6e68289
Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
190 { |
3333b6e68289
Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
191 mouse_relative = 0; |
3333b6e68289
Date: Sat, 23 Mar 2002 13:53:37 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
192 } |
0 | 193 } |