Skip to content

Latest commit

 

History

History
358 lines (292 loc) · 9 KB

SDL_riscosmouse.c

File metadata and controls

358 lines (292 loc) · 9 KB
 
1
2
/*
SDL - Simple DirectMedia Layer
Dec 31, 2011
Dec 31, 2011
3
Copyright (C) 1997-2012 Sam Lantinga
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
Feb 1, 2006
Feb 1, 2006
20
slouken@libsdl.org
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Feb 12, 2005
Feb 12, 2005
25
File added by Alan Buckley (alan_baa@hotmail.com) for RISC OS compatability
26
27
28
29
30
31
27 March 2003
Implements mouse cursor shape definitions and positioning
*/
#include "SDL_mouse.h"
Feb 16, 2006
Feb 16, 2006
32
#include "../../events/SDL_events_c.h"
33
34
35
36
37
38
39
#include "SDL_riscosmouse_c.h"
#include "kernel.h"
#include "swis.h"
static WMcursor *current_cursor = NULL;
Dec 23, 2005
Dec 23, 2005
40
static WMcursor *defined_cursor = NULL;
Dec 23, 2005
Dec 23, 2005
42
43
44
45
46
47
48
49
50
/* Area to save cursor palette colours changed by SDL.
Actual values will be read before we change to the SDL cursor */
static Uint8 wimp_cursor_palette[2][5] = {
{1, 25, 255, 255, 255},
{3, 25, 255, 255, 255}
};
static int cursor_palette_saved = 0;
Jun 1, 2019
Jun 1, 2019
51
52
static void WIMP_SaveCursorPalette();
static void WIMP_SetSDLCursorPalette();
Dec 23, 2005
Dec 23, 2005
53
54
55
56
void RISCOS_FreeWMCursor(_THIS, WMcursor *cursor)
{
Feb 7, 2006
Feb 7, 2006
57
58
SDL_free(cursor->data);
SDL_free(cursor);
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
}
WMcursor *RISCOS_CreateWMCursor(_THIS,
Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y)
{
WMcursor *cursor;
Uint8 *cursor_data;
Uint8 *ptr;
int i,j,k;
int data_byte, mask_byte;
/* Check to make sure the cursor size is okay */
if ( (w > 32) || (h > 32) ) {
SDL_SetError("Only with width and height <= 32 pixels are allowed");
return(NULL);
}
/* Allocate the cursor */
Feb 7, 2006
Feb 7, 2006
77
cursor = (WMcursor *)SDL_malloc(sizeof(*cursor));
78
79
80
81
82
83
if ( cursor == NULL ) {
SDL_SetError("Out of memory");
return(NULL);
}
/* Note: SDL says width must be a multiple of 8 */
Feb 7, 2006
Feb 7, 2006
84
cursor_data = SDL_malloc(w/4 * h);
85
86
if (cursor_data == NULL)
{
Feb 7, 2006
Feb 7, 2006
87
SDL_free(cursor);
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
SDL_SetError("Out of memory");
return(NULL);
}
cursor->w = w;
cursor->h = h;
cursor->hot_x = hot_x;
cursor->hot_y = hot_y;
cursor->data = cursor_data;
/* Data / Mask Resulting pixel on screen
0 / 1 White
1 / 1 Black
0 / 0 Transparent
1 / 0 Inverted color if possible, black if not.
*/
ptr = cursor_data;
for ( i=0; i<h; ++i )
{
for (j = 0; j < w/8; ++j)
{
data_byte = *data;
mask_byte = *mask;
*ptr++ = 0; /* Sets whole byte transparent */
*ptr = 0;
for (k = 0; k < 8; k++)
{
(*ptr) <<= 2;
if (data_byte & 1) *ptr |= 3; /* Black or inverted */
else if(mask_byte & 1) *ptr |= 1; /* White */
if ((k&3) == 3) ptr--;
data_byte >>= 1;
mask_byte >>= 1;
}
ptr+=3;
data++;
mask++;
}
}
return(cursor);
}
int RISCOS_ShowWMCursor(_THIS, WMcursor *cursor)
{
Dec 23, 2005
Dec 23, 2005
136
137
current_cursor = cursor;
138
139
140
if (cursor == NULL)
{
_kernel_osbyte(106,0,0);
Dec 23, 2005
Dec 23, 2005
141
defined_cursor = NULL;
142
143
} else
{
Dec 23, 2005
Dec 23, 2005
144
WMcursor *old_cursor = defined_cursor;
Dec 23, 2005
Dec 23, 2005
146
if (cursor != defined_cursor)
147
148
149
150
151
152
153
154
155
156
157
158
159
160
{
Uint8 cursor_def[10];
cursor_def[0] = 0;
cursor_def[1] = 2; /* Use shape number 2 */
cursor_def[2] = cursor->w/4; /* Width in bytes */
cursor_def[3] = cursor->h; /* Height (h) in pixels */
cursor_def[4] = cursor->hot_x; /* ActiveX in pixels from left */
cursor_def[5] = cursor->hot_y; /* ActiveY in pixels from top */
cursor_def[6] = ((int)(cursor->data) & 0xFF); /* Least significant byte of pointer to data */
cursor_def[7] = ((int)(cursor->data) >> 8) & 0xFF; /* ... */
cursor_def[8] = ((int)(cursor->data) >> 16) & 0xFF; /* ... */
cursor_def[9] = ((int)(cursor->data) >> 24) & 0xFF; /* Most significant byte of pointer to data */
Dec 23, 2005
Dec 23, 2005
161
if (_kernel_osword(21, (int *)cursor_def) != 0)
162
163
164
165
{
SDL_SetError("RISCOS couldn't create the cursor to show");
return(0);
}
Dec 23, 2005
Dec 23, 2005
166
defined_cursor = cursor;
Dec 23, 2005
Dec 23, 2005
169
170
171
172
173
174
175
176
177
178
179
if (old_cursor == NULL)
{
/* First time or reshow in window, so save/setup palette */
if (!cursor_palette_saved)
{
WIMP_SaveCursorPalette();
}
WIMP_SetSDLCursorPalette();
}
_kernel_osbyte(106, 2, 0);
180
181
182
183
184
185
186
187
188
}
return(1);
}
void FULLSCREEN_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
{
Uint8 move_block[5];
int os_x, os_y;
Jun 1, 2019
Jun 1, 2019
189
int topLeftY;
Jun 1, 2019
Jun 1, 2019
191
topLeftY = (this->hidden->height << this->hidden->yeig) - 1; /* As per RISCOS_PollMouseHelper */
Jun 1, 2019
Jun 1, 2019
193
194
os_x = x << this->hidden->xeig;
os_y = topLeftY - (y << this->hidden->yeig);
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
move_block[0] = 3; /* Move cursor */
move_block[1] = os_x & 0xFF;
move_block[2] = (os_x >> 8) & 0xFF;
move_block[3] = os_y & 0xFF;
move_block[4] = (os_y >> 8) & 0xFF;
_kernel_osword(21, (int *)move_block);
SDL_PrivateMouseMotion(0, 0, x, y);
}
/* Reshow cursor when mouse re-enters the window */
void WIMP_ReshowCursor(_THIS)
{
Dec 23, 2005
Dec 23, 2005
210
211
212
defined_cursor = NULL;
cursor_palette_saved = 0;
RISCOS_ShowWMCursor(this, current_cursor);
213
214
215
216
217
218
219
220
221
222
223
224
225
}
void WIMP_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
{
_kernel_swi_regs regs;
int window_state[9];
char block[5];
int osX, osY;
window_state[0] = this->hidden->window_handle;
regs.r[1] = (unsigned int)window_state;
_kernel_swi(Wimp_GetWindowState, &regs, &regs);
Jun 1, 2019
Jun 1, 2019
226
/* 90 DPI mapping from SDL pixels to OS units */
May 26, 2019
May 26, 2019
227
228
osX = (x << 1) + window_state[1];
osY = window_state[4] - (y << 1);
229
230
231
232
233
234
235
block[0] = 3;
block[1] = osX & 0xFF;
block[2] = (osX >> 8) & 0xFF;
block[3] = osY & 0xFF;
block[4] = (osY >> 8) & 0xFF;
Apr 26, 2019
Apr 26, 2019
236
_kernel_osword(21, (int *)block);
237
238
239
240
241
242
SDL_PrivateMouseMotion(0, 0, x, y);
}
int WIMP_ShowWMCursor(_THIS, WMcursor *cursor)
{
if (mouseInWindow) return RISCOS_ShowWMCursor(this, cursor);
Dec 23, 2005
Dec 23, 2005
243
244
else current_cursor = cursor;
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
return 1;
}
SDL_GrabMode RISCOS_GrabInput(_THIS, SDL_GrabMode mode)
{
/* In fullscreen mode we don't need to do anything */
if (mode < SDL_GRAB_FULLSCREEN)
{
_kernel_swi_regs regs;
unsigned char block[9];
block[0] = 1; /* Define mouse cursor bounding block */
if ( mode == SDL_GRAB_OFF )
{
/* Clip to whole screen */
int r = (this->hidden->screen_width << this->hidden->xeig) - 1;
int t = (this->hidden->screen_height << this->hidden->yeig) - 1;
block[1] = 0; block[2] = 0; /* Left*/
block[3] = 0; block[4] = 0; /* Bottom */
block[5] = r & 0xFF; block[6] = (r >> 8) & 0xFF; /* Right */
block[7] = t & 0xFF; block[8] = (t >> 8) & 0xFF; /* Top */
} else
{
/* Clip to window */
unsigned char window_state[36];
*((int *)window_state) = this->hidden->window_handle;
regs.r[1] = (unsigned int)window_state;
_kernel_swi(Wimp_GetWindowState, &regs, &regs);
block[1] = window_state[4];
block[2] = window_state[5];
block[3] = window_state[8];
block[4] = window_state[9];
block[5] = window_state[12];
block[6] = window_state[13];
block[7] = window_state[16];
block[8] = window_state[17];
}
Apr 26, 2019
Apr 26, 2019
288
_kernel_osword(21, (int *)block);
289
290
291
292
}
return mode;
}
Dec 23, 2005
Dec 23, 2005
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/* Save mouse cursor palette to be restore when we are no longer
defining a cursor */
void WIMP_SaveCursorPalette()
{
_kernel_swi_regs regs;
int colour;
for (colour = 0; colour < 2; colour++)
{
regs.r[0] = (int)wimp_cursor_palette[colour][0];
regs.r[1] = 25;
/* Read settings with OS_ReadPalette */
Apr 26, 2019
Apr 26, 2019
307
if (_kernel_swi(OS_ReadPalette, &regs, &regs) == NULL)
Dec 23, 2005
Dec 23, 2005
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
{
wimp_cursor_palette[colour][2] = (unsigned char)((regs.r[2] >> 8) & 0xFF);
wimp_cursor_palette[colour][3] = (unsigned char)((regs.r[2] >> 16) & 0xFF);
wimp_cursor_palette[colour][4] = (unsigned char)((regs.r[2] >> 24) & 0xFF);
}
}
cursor_palette_saved = 1;
}
/* Restore the WIMP's cursor when we leave the SDL window */
void WIMP_RestoreWimpCursor()
{
int colour;
/* Reset to pointer shape 1 */
_kernel_osbyte(106, 1, 0);
/* Reset pointer colours */
if (cursor_palette_saved)
{
for (colour = 0; colour < 2; colour++)
{
_kernel_osword(12, (int *)wimp_cursor_palette[colour]);
}
}
cursor_palette_saved = 0;
}
/* Set palette used for SDL mouse cursors */
void WIMP_SetSDLCursorPalette()
{
/* First time set up the mouse colours */
Uint8 block[5];
/* Set up colour 1 as white */
block[0] = 1; /* Colour to change 1 - 3 */
block[1] = 25; /* Set pointer colour */
block[2] = 255; /* red component*/
block[3] = 255; /* green component */
block[4] = 255; /* blue component*/
_kernel_osword(12, (int *)block);
/* Set colour 3 to back */
block[0] = 3; /* Colour to change 1 - 3 */
block[1] = 25; /* Set pointer colour*/
block[2] = 0; /* red component*/
block[3] = 0; /* green component */
block[4] = 0; /* blue component*/
_kernel_osword(12, (int *)block);
}