Mercurial > sdl-ios-xcode
comparison src/video/gem/SDL_gemmouse.c @ 281:c5010ab8ba35
Added initial support for Atari (thanks Patrice!)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 17 Feb 2002 19:54:28 +0000 |
parents | |
children | f6ffac90895c |
comparison
equal
deleted
inserted
replaced
280:0ddcea45d829 | 281:c5010ab8ba35 |
---|---|
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 | |
20 slouken@libsdl.org | |
21 */ | |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 /* | |
29 * GEM Mouse manager | |
30 * | |
31 * Patrice Mandin | |
32 */ | |
33 | |
34 #include <stdlib.h> | |
35 | |
36 #include <gem.h> | |
37 | |
38 #include "SDL_error.h" | |
39 #include "SDL_mouse.h" | |
40 #include "SDL_events_c.h" | |
41 #include "SDL_cursor_c.h" | |
42 #include "SDL_gemmouse_c.h" | |
43 | |
44 /* Defines */ | |
45 | |
46 #define MAXCURWIDTH 16 | |
47 #define MAXCURHEIGHT 16 | |
48 | |
49 /* The implementation dependent data for the window manager cursor */ | |
50 struct WMcursor { | |
51 MFORM *mform_p; | |
52 }; | |
53 | |
54 | |
55 void GEM_FreeWMCursor(_THIS, WMcursor *cursor) | |
56 { | |
57 if (cursor == NULL) | |
58 return; | |
59 | |
60 graf_mouse(ARROW, NULL); | |
61 | |
62 if (cursor->mform_p != NULL) | |
63 free(cursor->mform_p); | |
64 | |
65 free(cursor); | |
66 } | |
67 | |
68 WMcursor *GEM_CreateWMCursor(_THIS, | |
69 Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y) | |
70 { | |
71 WMcursor *cursor; | |
72 MFORM *new_mform; | |
73 int i; | |
74 | |
75 /* Check the size */ | |
76 if ( (w > MAXCURWIDTH) || (h > MAXCURHEIGHT) ) { | |
77 SDL_SetError("Only cursors of dimension (%dx%d) are allowed", | |
78 MAXCURWIDTH, MAXCURHEIGHT); | |
79 return(NULL); | |
80 } | |
81 | |
82 /* Allocate the cursor memory */ | |
83 cursor = (WMcursor *)malloc(sizeof(WMcursor)); | |
84 if ( cursor == NULL ) { | |
85 SDL_OutOfMemory(); | |
86 return(NULL); | |
87 } | |
88 | |
89 /* Allocate mform */ | |
90 new_mform = (MFORM *)malloc(sizeof(MFORM)); | |
91 if (new_mform == NULL) { | |
92 free(cursor); | |
93 SDL_OutOfMemory(); | |
94 return(NULL); | |
95 } | |
96 | |
97 cursor->mform_p = new_mform; | |
98 | |
99 new_mform->mf_xhot = hot_x; | |
100 new_mform->mf_yhot = hot_y; | |
101 new_mform->mf_nplanes = 1; | |
102 new_mform->mf_fg = 0; | |
103 new_mform->mf_bg = 1; | |
104 | |
105 for (i=0;i<MAXCURHEIGHT;i++) | |
106 { | |
107 new_mform->mf_mask[i]=0; | |
108 new_mform->mf_data[i]=0; | |
109 } | |
110 | |
111 if (w<=8) { | |
112 for (i=0;i<h;i++) | |
113 { | |
114 new_mform->mf_mask[i]= mask[i]<<8; | |
115 new_mform->mf_data[i]= data[i]<<8; | |
116 } | |
117 } else { | |
118 for (i=0;i<h;i++) | |
119 { | |
120 new_mform->mf_mask[i]= mask[i<<1]<<8 | mask[(i<<1)+1]; | |
121 new_mform->mf_data[i]= data[i<<1]<<8 | data[(i<<1)+1]; | |
122 } | |
123 } | |
124 | |
125 return cursor; | |
126 } | |
127 | |
128 int GEM_ShowWMCursor(_THIS, WMcursor *cursor) | |
129 { | |
130 if (cursor == NULL) { | |
131 graf_mouse(M_OFF, NULL); | |
132 } else if (cursor->mform_p) { | |
133 graf_mouse(USER_DEF, cursor->mform_p); | |
134 } | |
135 | |
136 return 1; | |
137 } | |
138 | |
139 void GEM_WarpWMCursor(_THIS, Uint16 x, Uint16 y) | |
140 { | |
141 EVNTREC warpevent; | |
142 | |
143 warpevent.ap_event = APPEVNT_MOUSE; | |
144 warpevent.ap_value = (y << 16) | x; | |
145 | |
146 appl_tplay(&warpevent, 1, 1000); | |
147 } | |
148 | |
149 void GEM_CheckMouseMode(_THIS) | |
150 { | |
151 /* If the mouse is hidden and input is grabbed, we use relative mode */ | |
152 if ( !(SDL_cursorstate & CURSOR_VISIBLE) && | |
153 (this->input_grab != SDL_GRAB_OFF) ) { | |
154 GEM_mouse_relative = SDL_TRUE; | |
155 } else { | |
156 GEM_mouse_relative = SDL_FALSE; | |
157 } | |
158 } |