Mercurial > sdl-ios-xcode
annotate src/video/photon/SDL_ph_mouse.c @ 252:e8157fcb3114
Updated the source with the correct e-mail address
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 14 Dec 2001 12:38:15 +0000 |
parents | 74212992fb08 |
children | c6abdda2f666 |
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; | |
88 cursor->ph_cursor->size2.y = (short)h; | |
89 cursor->ph_cursor->offset2.x = (short)hot_x; | |
90 cursor->ph_cursor->offset2.y = (short)hot_y; | |
91 cursor->ph_cursor->bytesperline2 = (char)w/8; | |
92 cursor->ph_cursor->color2 = Pg_BLACK; | |
93 | |
94 clen = (w/8)*h; | |
95 | |
96 /* Copy the mask and the data to different | |
97 bitmap planes */ | |
98 for ( i=0; i<clen; ++i ) { | |
99 cursor->ph_cursor->images[i] = data[i]; | |
100 cursor->ph_cursor->images[i+clen] = mask[i]; | |
101 } | |
102 | |
103 //#bytes following the hdr struct | |
104 cursor->ph_cursor->hdr.len =sizeof(PhCursorDef_t) + clen*2 - sizeof(PhRegionDataHdr_t); | |
105 | |
106 return (cursor); | |
107 } | |
108 | |
109 | |
110 PhCursorDef_t ph_GetWMPhCursor(WMcursor *cursor) | |
111 { | |
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 | |
124 | |
125 /* Don't do anything if the display is gone */ | |
126 if ( window == NULL ) { | |
127 return(0); | |
128 } | |
129 | |
130 /* Set the photon cursor cursor, or blank if cursor is NULL */ | |
131 if ( window ) { | |
132 | |
133 if ( cursor != NULL ) { | |
134 PtSetArg( &args[0], Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP, 0 ); | |
135 // Could set next to any PgColor_t value | |
136 PtSetArg( &args[1], Pt_ARG_CURSOR_COLOR,Ph_CURSOR_DEFAULT_COLOR , 0 ); | |
137 PtSetArg( &args[2], Pt_ARG_BITMAP_CURSOR, cursor->ph_cursor, (cursor->ph_cursor->hdr.len + sizeof(PhRegionDataHdr_t)) ); | |
138 nargs = 3; | |
139 cursor_is_defined = 1; | |
140 } | |
141 else // Ph_CURSOR_NONE | |
142 { | |
143 PtSetArg( &args[0], Pt_ARG_CURSOR_TYPE,Ph_CURSOR_NONE, 0); | |
144 nargs = 1; | |
145 cursor_is_defined = 1; | |
146 } | |
147 if (cursor_is_defined) | |
148 { | |
149 SDL_Lock_EventThread(); | |
150 | |
151 if (PtSetResources( window, nargs, args ) < 0 ) | |
152 { | |
153 return(0); | |
154 } | |
155 | |
156 SDL_Unlock_EventThread(); | |
157 } | |
158 else | |
159 return(0); | |
160 } | |
161 return(1); | |
162 } | |
163 | |
164 void ph_WarpWMCursor(_THIS, Uint16 x, Uint16 y) | |
165 { | |
166 | |
167 SDL_Lock_EventThread(); | |
168 PhMoveCursorRel( PhInputGroup(NULL), x, y ); | |
169 SDL_Unlock_EventThread(); | |
170 } | |
171 | |
172 | |
173 void ph_CheckMouseMode(_THIS) | |
174 { | |
175 | |
176 mouse_relative = 1; | |
177 } |