• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2     SDL - Simple DirectMedia Layer
3     Copyright (C) 1997-2006 Sam Lantinga
4 
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Lesser General Public
7     License as published by the Free Software Foundation; either
8     version 2.1 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     Lesser General Public License for more details.
14 
15     You should have received a copy of the GNU Lesser General Public
16     License along with this library; if not, write to the Free Software
17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18 
19     Sam Lantinga
20     slouken@libsdl.org
21 */
22 #include "SDL_config.h"
23 
24 /*
25  *	GEM Mouse manager
26  *
27  *	Patrice Mandin
28  */
29 
30 #include <gem.h>
31 
32 #include "SDL_mouse.h"
33 #include "../../events/SDL_events_c.h"
34 #include "../SDL_cursor_c.h"
35 #include "SDL_gemmouse_c.h"
36 #include "SDL_gemvideo.h"
37 
38 /* Defines */
39 
40 /*#define DEBUG_VIDEO_GEM 1*/
41 
42 #define MAXCURWIDTH 16
43 #define MAXCURHEIGHT 16
44 
GEM_FreeWMCursor(_THIS,WMcursor * cursor)45 void GEM_FreeWMCursor(_THIS, WMcursor *cursor)
46 {
47 #ifdef DEBUG_VIDEO_GEM
48 	printf("sdl:video:gem: free cursor\n");
49 #endif
50 
51 	if (cursor == NULL)
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 }
61 
GEM_CreateWMCursor(_THIS,Uint8 * data,Uint8 * mask,int w,int h,int hot_x,int hot_y)62 WMcursor *GEM_CreateWMCursor(_THIS,
63 		Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y)
64 {
65 	WMcursor *cursor;
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 
GEM_ShowWMCursor(_THIS,WMcursor * cursor)140 int GEM_ShowWMCursor(_THIS, WMcursor *cursor)
141 {
142 	GEM_cursor = cursor;
143 
144 	GEM_CheckMouseMode(this);
145 
146 #ifdef DEBUG_VIDEO_GEM
147 	printf("sdl:video:gem: ShowWMCursor(0x%08x)\n", (long) cursor);
148 #endif
149 
150 	return 1;
151 }
152 
153 #if 0
154 void GEM_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
155 {
156 	/* This seems to work only on AES 3.4 (Falcon) */
157 
158 	EVNTREC	warpevent;
159 
160 	warpevent.ap_event = APPEVNT_MOUSE;
161 	warpevent.ap_value = (x << 16) | y;
162 
163 	appl_tplay(&warpevent, 1, 1000);
164 }
165 #endif
166 
GEM_CheckMouseMode(_THIS)167 void GEM_CheckMouseMode(_THIS)
168 {
169 	const Uint8 full_focus = (SDL_APPACTIVE|SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS);
170 	int set_system_cursor = 1, show_system_cursor = 1;
171 
172 #ifdef DEBUG_VIDEO_GEM
173 	printf("sdl:video:gem: check mouse mode\n");
174 #endif
175 
176 	/* If the mouse is hidden and input is grabbed, we use relative mode */
177 	GEM_mouse_relative = (!(SDL_cursorstate & CURSOR_VISIBLE))
178 		&& (this->input_grab != SDL_GRAB_OFF)
179 		&& (SDL_GetAppState() & SDL_APPACTIVE);
180 	SDL_AtariXbios_LockMousePosition(GEM_mouse_relative);
181 
182 	if (SDL_cursorstate & CURSOR_VISIBLE) {
183 		/* Application defined cursor only over the application window */
184 		if ((SDL_GetAppState() & full_focus) == full_focus) {
185 			if (GEM_cursor) {
186 				graf_mouse(USER_DEF, GEM_cursor->mform_p);
187 				set_system_cursor = 0;
188 			} else {
189 				show_system_cursor = 0;
190 			}
191 		}
192 	} else {
193 		/* Mouse cursor hidden only over the application window */
194 		if ((SDL_GetAppState() & full_focus) == full_focus) {
195 			set_system_cursor = 0;
196 			show_system_cursor = 0;
197 		}
198 	}
199 
200 	graf_mouse(show_system_cursor ? M_ON : M_OFF, NULL);
201 	if (set_system_cursor) {
202 		graf_mouse(ARROW, NULL);
203 	}
204 }
205