comparison src/video/gem/SDL_gemmouse.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents 417f2af2bd52
children 091bb215baf9
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
31 31
32 #include "SDL_mouse.h" 32 #include "SDL_mouse.h"
33 #include "../../events/SDL_events_c.h" 33 #include "../../events/SDL_events_c.h"
34 #include "../SDL_cursor_c.h" 34 #include "../SDL_cursor_c.h"
35 #include "SDL_gemmouse_c.h" 35 #include "SDL_gemmouse_c.h"
36 #include "SDL_gemvideo.h"
37 36
38 /* Defines */ 37 /* Defines */
39 38
40 /*#define DEBUG_VIDEO_GEM 1*/ 39 /*#define DEBUG_VIDEO_GEM 1*/
41 40
42 #define MAXCURWIDTH 16 41 #define MAXCURWIDTH 16
43 #define MAXCURHEIGHT 16 42 #define MAXCURHEIGHT 16
44 43
45 void GEM_FreeWMCursor(_THIS, WMcursor *cursor) 44 /* The implementation dependent data for the window manager cursor */
45 struct WMcursor
46 { 46 {
47 MFORM *mform_p;
48 };
49
50
51 void
52 GEM_FreeWMCursor(_THIS, WMcursor * cursor)
53 {
54 if (cursor == NULL)
55 return;
56
57 graf_mouse(ARROW, NULL);
58
59 if (cursor->mform_p != NULL)
60 SDL_free(cursor->mform_p);
61
62 SDL_free(cursor);
63 }
64
65 WMcursor *
66 GEM_CreateWMCursor(_THIS,
67 Uint8 * data, Uint8 * mask, int w, int h, int hot_x,
68 int hot_y)
69 {
70 WMcursor *cursor;
71 MFORM *new_mform;
72 int i;
73
74 /* Check the size */
75 if ((w > MAXCURWIDTH) || (h > MAXCURHEIGHT)) {
76 SDL_SetError("Only cursors of dimension (%dx%d) are allowed",
77 MAXCURWIDTH, MAXCURHEIGHT);
78 return (NULL);
79 }
80
81 /* Allocate the cursor memory */
82 cursor = (WMcursor *) SDL_malloc(sizeof(WMcursor));
83 if (cursor == NULL) {
84 SDL_OutOfMemory();
85 return (NULL);
86 }
87
88 /* Allocate mform */
89 new_mform = (MFORM *) SDL_malloc(sizeof(MFORM));
90 if (new_mform == NULL) {
91 SDL_free(cursor);
92 SDL_OutOfMemory();
93 return (NULL);
94 }
95
96 cursor->mform_p = new_mform;
97
98 new_mform->mf_xhot = hot_x;
99 new_mform->mf_yhot = hot_y;
100 new_mform->mf_nplanes = 1;
101 new_mform->mf_fg = 0;
102 new_mform->mf_bg = 1;
103
104 for (i = 0; i < MAXCURHEIGHT; i++) {
105 new_mform->mf_mask[i] = 0;
106 new_mform->mf_data[i] = 0;
107 }
108
109 if (w <= 8) {
110 for (i = 0; i < h; i++) {
111 new_mform->mf_mask[i] = mask[i] << 8;
112 new_mform->mf_data[i] = data[i] << 8;
113 }
114 } else {
115 for (i = 0; i < h; i++) {
116 new_mform->mf_mask[i] = mask[i << 1] << 8 | mask[(i << 1) + 1];
117 new_mform->mf_data[i] = data[i << 1] << 8 | data[(i << 1) + 1];
118 }
119 }
120
47 #ifdef DEBUG_VIDEO_GEM 121 #ifdef DEBUG_VIDEO_GEM
48 printf("sdl:video:gem: free cursor\n"); 122 for (i = 0; i < h; i++) {
123 printf("sdl:video:gem: cursor, line %d = 0x%04x\n", i,
124 new_mform->mf_mask[i]);
125 }
126
127 printf("sdl:video:gem: CreateWMCursor(): done\n");
49 #endif 128 #endif
50 129
51 if (cursor == NULL) 130 return cursor;
52 return;
53
54 graf_mouse(ARROW, NULL);
55
56 if (cursor->mform_p != NULL)
57 SDL_free(cursor->mform_p);
58
59 SDL_free(cursor);
60 } 131 }
61 132
62 WMcursor *GEM_CreateWMCursor(_THIS, 133 int
63 Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y) 134 GEM_ShowWMCursor(_THIS, WMcursor * cursor)
64 { 135 {
65 WMcursor *cursor; 136 /*
66 MFORM *new_mform;
67 int i;
68
69 #ifdef DEBUG_VIDEO_GEM
70 Uint16 *data1, *mask1;
71
72 printf("sdl:video:gem: create cursor\n");
73 #endif
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 *)SDL_malloc(sizeof(WMcursor));
84 if ( cursor == NULL ) {
85 SDL_OutOfMemory();
86 return(NULL);
87 }
88
89 /* Allocate mform */
90 new_mform = (MFORM *)SDL_malloc(sizeof(MFORM));
91 if (new_mform == NULL) {
92 SDL_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 new_mform->mf_mask[i]=0;
107 new_mform->mf_data[i]=0;
108 #ifdef DEBUG_VIDEO_GEM
109 data1 = (Uint16 *) &data[i<<1];
110 mask1 = (Uint16 *) &mask[i<<1];
111 printf("sdl:video:gem: source: line %d: data=0x%04x, mask=0x%04x\n",
112 i, data1[i], mask1[i]);
113 #endif
114 }
115
116 if (w<=8) {
117 for (i=0;i<h;i++) {
118 new_mform->mf_mask[i]= mask[i]<<8;
119 new_mform->mf_data[i]= data[i]<<8;
120 }
121 } else {
122 for (i=0;i<h;i++) {
123 new_mform->mf_mask[i]= (mask[i<<1]<<8) | mask[(i<<1)+1];
124 new_mform->mf_data[i]= (data[i<<1]<<8) | data[(i<<1)+1];
125 }
126 }
127
128 #ifdef DEBUG_VIDEO_GEM
129 for (i=0; i<h ;i++) {
130 printf("sdl:video:gem: cursor: line %d: data=0x%04x, mask=0x%04x\n",
131 i, new_mform->mf_data[i], new_mform->mf_mask[i]);
132 }
133
134 printf("sdl:video:gem: CreateWMCursor(): done\n");
135 #endif
136
137 return cursor;
138 }
139
140 int GEM_ShowWMCursor(_THIS, WMcursor *cursor)
141 {
142 GEM_cursor = cursor;
143 if (cursor == NULL) { 137 if (cursor == NULL) {
144 graf_mouse(M_OFF, NULL); 138 graf_mouse(M_OFF, NULL);
145 GEM_cursor = (void *) -1;
146 } else if (cursor->mform_p) { 139 } else if (cursor->mform_p) {
147 graf_mouse(USER_DEF, cursor->mform_p); 140 graf_mouse(USER_DEF, cursor->mform_p);
148 } 141 }
149 142 */
150 #ifdef DEBUG_VIDEO_GEM 143 #ifdef DEBUG_VIDEO_GEM
151 printf("sdl:video:gem: ShowWMCursor(0x%08x)\n", (long) cursor); 144 printf("sdl:video:gem: ShowWMCursor(0x%08x)\n", (long) cursor);
152 #endif 145 #endif
153 146
154 return 1; 147 return 1;
155 } 148 }
156 149
157 #if 0 150 #if 0
158 void GEM_WarpWMCursor(_THIS, Uint16 x, Uint16 y) 151 void
152 GEM_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
159 { 153 {
160 /* This seems to work only on AES 3.4 (Falcon) */ 154 /* This seems to work only on AES 3.4 (Falcon) */
161 155
162 EVNTREC warpevent; 156 EVNTREC warpevent;
163
164 warpevent.ap_event = APPEVNT_MOUSE;
165 warpevent.ap_value = (x << 16) | y;
166 157
167 appl_tplay(&warpevent, 1, 1000); 158 warpevent.ap_event = APPEVNT_MOUSE;
159 warpevent.ap_value = (x << 16) | y;
160
161 appl_tplay(&warpevent, 1, 1000);
168 } 162 }
169 #endif 163 #endif
170 164
171 void GEM_CheckMouseMode(_THIS) 165 void
166 GEM_CheckMouseMode(_THIS)
172 { 167 {
173 #ifdef DEBUG_VIDEO_GEM 168 /* If the mouse is hidden and input is grabbed, we use relative mode */
174 printf("sdl:video:gem: check mouse mode\n"); 169 if ((!(SDL_cursorstate & CURSOR_VISIBLE)) &&
175 #endif 170 /*(this->input_grab != SDL_GRAB_OFF) && *//* Damn GEM can not grab */
171 (SDL_GetAppState() & SDL_APPACTIVE)) {
172 GEM_mouse_relative = SDL_TRUE;
173 } else {
174 GEM_mouse_relative = SDL_FALSE;
175 }
176 }
176 177
177 /* If the mouse is hidden and input is grabbed, we use relative mode */ 178 /* vi: set ts=4 sw=4 expandtab: */
178 if ( (!(SDL_cursorstate & CURSOR_VISIBLE)) &&
179 /*(this->input_grab != SDL_GRAB_OFF) && */ /* Damn GEM can not grab */
180 (SDL_GetAppState() & SDL_APPACTIVE) ) {
181 GEM_mouse_relative = SDL_TRUE;
182 } else {
183 GEM_mouse_relative = SDL_FALSE;
184 }
185 }