comparison src/video/photon/SDL_ph_mouse.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
30 { 30 {
31 PhCursorDef_t *ph_cursor; 31 PhCursorDef_t *ph_cursor;
32 }; 32 };
33 33
34 void 34 void
35 ph_FreeWMCursor (_THIS, WMcursor * cursor) 35 ph_FreeWMCursor(_THIS, WMcursor * cursor)
36 { 36 {
37 if (window != NULL) { 37 if (window != NULL) {
38 SDL_Lock_EventThread (); 38 SDL_Lock_EventThread();
39 39
40 if (PtSetResource (window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_INHERIT, 0) 40 if (PtSetResource(window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_INHERIT, 0)
41 < 0) { 41 < 0) {
42 /* TODO: output error msg */ 42 /* TODO: output error msg */
43 } 43 }
44 44
45 SDL_Unlock_EventThread (); 45 SDL_Unlock_EventThread();
46 } 46 }
47 47
48 SDL_free (cursor); 48 SDL_free(cursor);
49 } 49 }
50 50
51 WMcursor * 51 WMcursor *
52 ph_CreateWMCursor (_THIS, Uint8 * data, Uint8 * mask, int w, int h, int hot_x, 52 ph_CreateWMCursor(_THIS, Uint8 * data, Uint8 * mask, int w, int h, int hot_x,
53 int hot_y) 53 int hot_y)
54 { 54 {
55 WMcursor *cursor; 55 WMcursor *cursor;
56 int clen, i; 56 int clen, i;
57 unsigned char bit, databit, maskbit; 57 unsigned char bit, databit, maskbit;
58 58
59 /* Allocate and initialize the cursor memory */ 59 /* Allocate and initialize the cursor memory */
60 if ((cursor = (WMcursor *) SDL_malloc (sizeof (WMcursor))) == NULL) { 60 if ((cursor = (WMcursor *) SDL_malloc(sizeof(WMcursor))) == NULL) {
61 SDL_OutOfMemory (); 61 SDL_OutOfMemory();
62 return (NULL); 62 return (NULL);
63 } 63 }
64 SDL_memset (cursor, 0, sizeof (WMcursor)); 64 SDL_memset(cursor, 0, sizeof(WMcursor));
65 65
66 cursor->ph_cursor = 66 cursor->ph_cursor =
67 (PhCursorDef_t *) SDL_malloc (sizeof (PhCursorDef_t) + 32 * 4 * 2); 67 (PhCursorDef_t *) SDL_malloc(sizeof(PhCursorDef_t) + 32 * 4 * 2);
68 68
69 if (cursor->ph_cursor == NULL) { 69 if (cursor->ph_cursor == NULL) {
70 SDL_SetError ("ph_CreateWMCursor(): cursor malloc failed !\n"); 70 SDL_SetError("ph_CreateWMCursor(): cursor malloc failed !\n");
71 return NULL; 71 return NULL;
72 } 72 }
73 73
74 SDL_memset (cursor->ph_cursor, 0, (sizeof (PhCursorDef_t) + 32 * 4 * 2)); 74 SDL_memset(cursor->ph_cursor, 0, (sizeof(PhCursorDef_t) + 32 * 4 * 2));
75 75
76 cursor->ph_cursor->hdr.type = Ph_RDATA_CURSOR; 76 cursor->ph_cursor->hdr.type = Ph_RDATA_CURSOR;
77 cursor->ph_cursor->size1.x = (short) w; 77 cursor->ph_cursor->size1.x = (short) w;
78 cursor->ph_cursor->size1.y = (short) h; 78 cursor->ph_cursor->size1.y = (short) h;
79 cursor->ph_cursor->offset1.x = (short) hot_x; 79 cursor->ph_cursor->offset1.x = (short) hot_x;
102 } 102 }
103 } 103 }
104 104
105 /* #bytes following the hdr struct */ 105 /* #bytes following the hdr struct */
106 cursor->ph_cursor->hdr.len = 106 cursor->ph_cursor->hdr.len =
107 sizeof (PhCursorDef_t) + clen * 2 - sizeof (PhRegionDataHdr_t); 107 sizeof(PhCursorDef_t) + clen * 2 - sizeof(PhRegionDataHdr_t);
108 108
109 return (cursor); 109 return (cursor);
110 } 110 }
111 111
112 PhCursorDef_t 112 PhCursorDef_t
113 ph_GetWMPhCursor (WMcursor * cursor) 113 ph_GetWMPhCursor(WMcursor * cursor)
114 { 114 {
115 return (*cursor->ph_cursor); 115 return (*cursor->ph_cursor);
116 } 116 }
117 117
118 int 118 int
119 ph_ShowWMCursor (_THIS, WMcursor * cursor) 119 ph_ShowWMCursor(_THIS, WMcursor * cursor)
120 { 120 {
121 PtArg_t args[3]; 121 PtArg_t args[3];
122 int nargs = 0; 122 int nargs = 0;
123 123
124 /* Don't do anything if the display is gone */ 124 /* Don't do anything if the display is gone */
136 } 136 }
137 } 137 }
138 138
139 /* Set the photon cursor, or blank if cursor is NULL */ 139 /* Set the photon cursor, or blank if cursor is NULL */
140 if (cursor != NULL) { 140 if (cursor != NULL) {
141 PtSetArg (&args[0], Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP, 0); 141 PtSetArg(&args[0], Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP, 0);
142 /* Could set next to any PgColor_t value */ 142 /* Could set next to any PgColor_t value */
143 PtSetArg (&args[1], Pt_ARG_CURSOR_COLOR, Ph_CURSOR_DEFAULT_COLOR, 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, 144 PtSetArg(&args[2], Pt_ARG_BITMAP_CURSOR, cursor->ph_cursor,
145 (cursor->ph_cursor->hdr.len + sizeof (PhRegionDataHdr_t))); 145 (cursor->ph_cursor->hdr.len + sizeof(PhRegionDataHdr_t)));
146 nargs = 3; 146 nargs = 3;
147 } else { /* Ph_CURSOR_NONE */ 147 } else { /* Ph_CURSOR_NONE */
148 148
149 PtSetArg (&args[0], Pt_ARG_CURSOR_TYPE, Ph_CURSOR_NONE, 0); 149 PtSetArg(&args[0], Pt_ARG_CURSOR_TYPE, Ph_CURSOR_NONE, 0);
150 nargs = 1; 150 nargs = 1;
151 } 151 }
152 152
153 SDL_Lock_EventThread (); 153 SDL_Lock_EventThread();
154 154
155 if (PtSetResources (window, nargs, args) < 0) { 155 if (PtSetResources(window, nargs, args) < 0) {
156 return (0); 156 return (0);
157 } 157 }
158 158
159 SDL_Unlock_EventThread (); 159 SDL_Unlock_EventThread();
160 160
161 return (1); 161 return (1);
162 } 162 }
163 163
164 164
165 void 165 void
166 ph_WarpWMCursor (_THIS, Uint16 x, Uint16 y) 166 ph_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
167 { 167 {
168 short abs_x, abs_y; 168 short abs_x, abs_y;
169 169
170 SDL_Lock_EventThread (); 170 SDL_Lock_EventThread();
171 PtGetAbsPosition (window, &abs_x, &abs_y); 171 PtGetAbsPosition(window, &abs_x, &abs_y);
172 PhMoveCursorAbs (PhInputGroup (NULL), x + abs_x, y + abs_y); 172 PhMoveCursorAbs(PhInputGroup(NULL), x + abs_x, y + abs_y);
173 SDL_Unlock_EventThread (); 173 SDL_Unlock_EventThread();
174 } 174 }
175 175
176 176
177 void 177 void
178 ph_CheckMouseMode (_THIS) 178 ph_CheckMouseMode(_THIS)
179 { 179 {
180 /* If the mouse is hidden and input is grabbed, we use relative mode */ 180 /* If the mouse is hidden and input is grabbed, we use relative mode */
181 if (!(SDL_cursorstate & CURSOR_VISIBLE) 181 if (!(SDL_cursorstate & CURSOR_VISIBLE)
182 && (this->input_grab != SDL_GRAB_OFF)) { 182 && (this->input_grab != SDL_GRAB_OFF)) {
183 mouse_relative = 1; 183 mouse_relative = 1;
186 } 186 }
187 } 187 }
188 188
189 189
190 void 190 void
191 ph_UpdateMouse (_THIS) 191 ph_UpdateMouse(_THIS)
192 { 192 {
193 PhCursorInfo_t phcursor; 193 PhCursorInfo_t phcursor;
194 short abs_x; 194 short abs_x;
195 short abs_y; 195 short abs_y;
196 196
197 /* Lock the event thread, in multi-threading environments */ 197 /* Lock the event thread, in multi-threading environments */
198 SDL_Lock_EventThread (); 198 SDL_Lock_EventThread();
199 199
200 /* synchronizing photon mouse cursor position and SDL mouse position, if cursor appears over window. */ 200 /* synchronizing photon mouse cursor position and SDL mouse position, if cursor appears over window. */
201 PtGetAbsPosition (window, &abs_x, &abs_y); 201 PtGetAbsPosition(window, &abs_x, &abs_y);
202 PhQueryCursor (PhInputGroup (NULL), &phcursor); 202 PhQueryCursor(PhInputGroup(NULL), &phcursor);
203 if (((phcursor.pos.x >= abs_x) 203 if (((phcursor.pos.x >= abs_x)
204 && (phcursor.pos.x <= abs_x + this->screen->w)) 204 && (phcursor.pos.x <= abs_x + this->screen->w))
205 && ((phcursor.pos.y >= abs_y) 205 && ((phcursor.pos.y >= abs_y)
206 && (phcursor.pos.y <= abs_y + this->screen->h))) { 206 && (phcursor.pos.y <= abs_y + this->screen->h))) {
207 SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS); 207 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
208 SDL_PrivateMouseMotion (0, 0, phcursor.pos.x - abs_x, 208 SDL_PrivateMouseMotion(0, 0, phcursor.pos.x - abs_x,
209 phcursor.pos.y - abs_y); 209 phcursor.pos.y - abs_y);
210 } else { 210 } else {
211 SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS); 211 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
212 } 212 }
213 213
214 /* Unlock the event thread, in multi-threading environments */ 214 /* Unlock the event thread, in multi-threading environments */
215 SDL_Unlock_EventThread (); 215 SDL_Unlock_EventThread();
216 } 216 }
217 217
218 /* vi: set ts=4 sw=4 expandtab: */ 218 /* vi: set ts=4 sw=4 expandtab: */