src/video/gem/SDL_gemmouse.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 21 Feb 2006 08:46:50 +0000
changeset 1402 d910939febfa
parent 1361 19418e4422cb
child 1662 782fd950bd46
child 1857 417f2af2bd52
permissions -rw-r--r--
Use consistent identifiers for the various platforms we support.
Make sure every source file includes SDL_config.h, so the proper system
headers are chosen.
slouken@281
     1
/*
slouken@281
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@281
     4
slouken@281
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@281
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@281
     9
slouken@281
    10
    This library is distributed in the hope that it will be useful,
slouken@281
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@281
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@281
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@281
    18
slouken@281
    19
    Sam Lantinga
slouken@281
    20
    slouken@libsdl.org
slouken@281
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@281
    23
slouken@281
    24
/*
slouken@281
    25
 *	GEM Mouse manager
slouken@281
    26
 *
slouken@281
    27
 *	Patrice Mandin
slouken@281
    28
 */
slouken@281
    29
slouken@281
    30
#include <gem.h>
slouken@281
    31
slouken@281
    32
#include "SDL_mouse.h"
slouken@1361
    33
#include "../../events/SDL_events_c.h"
slouken@1361
    34
#include "../SDL_cursor_c.h"
slouken@281
    35
#include "SDL_gemmouse_c.h"
slouken@281
    36
slouken@281
    37
/* Defines */
slouken@281
    38
patmandin@736
    39
/*#define DEBUG_VIDEO_GEM 1*/
patmandin@736
    40
slouken@281
    41
#define MAXCURWIDTH 16
slouken@281
    42
#define MAXCURHEIGHT 16
slouken@281
    43
slouken@281
    44
/* The implementation dependent data for the window manager cursor */
slouken@281
    45
struct WMcursor {
slouken@281
    46
	MFORM *mform_p;
slouken@281
    47
};
slouken@281
    48
slouken@281
    49
slouken@281
    50
void GEM_FreeWMCursor(_THIS, WMcursor *cursor)
slouken@281
    51
{
slouken@281
    52
	if (cursor == NULL)
slouken@281
    53
		return;
slouken@281
    54
	
slouken@281
    55
	graf_mouse(ARROW, NULL);
slouken@281
    56
slouken@281
    57
	if (cursor->mform_p != NULL)
slouken@1336
    58
		SDL_free(cursor->mform_p);
slouken@281
    59
slouken@1336
    60
	SDL_free(cursor);
slouken@281
    61
}
slouken@281
    62
slouken@281
    63
WMcursor *GEM_CreateWMCursor(_THIS,
slouken@281
    64
		Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y)
slouken@281
    65
{
slouken@281
    66
	WMcursor *cursor;
slouken@281
    67
	MFORM *new_mform;
slouken@281
    68
	int i;
slouken@281
    69
slouken@281
    70
	/* Check the size */
slouken@281
    71
	if ( (w > MAXCURWIDTH) || (h > MAXCURHEIGHT) ) {
slouken@281
    72
		SDL_SetError("Only cursors of dimension (%dx%d) are allowed",
slouken@281
    73
							MAXCURWIDTH, MAXCURHEIGHT);
slouken@281
    74
		return(NULL);
slouken@281
    75
	}
slouken@281
    76
slouken@281
    77
	/* Allocate the cursor memory */
slouken@1336
    78
	cursor = (WMcursor *)SDL_malloc(sizeof(WMcursor));
slouken@281
    79
	if ( cursor == NULL ) {
slouken@281
    80
		SDL_OutOfMemory();
slouken@281
    81
		return(NULL);
slouken@281
    82
	}
slouken@281
    83
slouken@281
    84
	/* Allocate mform */
slouken@1336
    85
	new_mform = (MFORM *)SDL_malloc(sizeof(MFORM));		
slouken@281
    86
	if (new_mform == NULL) {
slouken@1336
    87
		SDL_free(cursor);
slouken@281
    88
		SDL_OutOfMemory();
slouken@281
    89
		return(NULL);
slouken@281
    90
	}
slouken@281
    91
slouken@281
    92
	cursor->mform_p = new_mform;
slouken@281
    93
slouken@281
    94
	new_mform->mf_xhot = hot_x;
slouken@281
    95
	new_mform->mf_yhot = hot_y;
slouken@281
    96
	new_mform->mf_nplanes = 1;
slouken@281
    97
	new_mform->mf_fg = 0;
slouken@281
    98
	new_mform->mf_bg = 1;
slouken@281
    99
patmandin@736
   100
	for (i=0;i<MAXCURHEIGHT;i++) {
slouken@281
   101
		new_mform->mf_mask[i]=0;
slouken@281
   102
		new_mform->mf_data[i]=0;
slouken@281
   103
	}
slouken@281
   104
slouken@281
   105
	if (w<=8) {
patmandin@736
   106
		for (i=0;i<h;i++) {
slouken@281
   107
			new_mform->mf_mask[i]= mask[i]<<8;
slouken@281
   108
			new_mform->mf_data[i]= data[i]<<8;
slouken@281
   109
		}
slouken@281
   110
	} else {
patmandin@736
   111
		for (i=0;i<h;i++) {
slouken@281
   112
			new_mform->mf_mask[i]= mask[i<<1]<<8 | mask[(i<<1)+1];
slouken@281
   113
			new_mform->mf_data[i]= data[i<<1]<<8 | data[(i<<1)+1];
slouken@281
   114
		}
slouken@281
   115
	}
slouken@281
   116
patmandin@736
   117
#ifdef DEBUG_VIDEO_GEM
patmandin@736
   118
	for (i=0; i<h ;i++) {
patmandin@736
   119
		printf("sdl:video:gem: cursor, line %d = 0x%04x\n", i, new_mform->mf_mask[i]);
patmandin@736
   120
	}
patmandin@736
   121
patmandin@736
   122
	printf("sdl:video:gem: CreateWMCursor(): done\n");
patmandin@736
   123
#endif
patmandin@736
   124
slouken@281
   125
	return cursor;
slouken@281
   126
}
slouken@281
   127
slouken@281
   128
int GEM_ShowWMCursor(_THIS, WMcursor *cursor)
slouken@281
   129
{
patmandin@736
   130
/*
slouken@281
   131
	if (cursor == NULL) {
slouken@281
   132
		graf_mouse(M_OFF, NULL);
slouken@281
   133
	} else if (cursor->mform_p) {
slouken@281
   134
		graf_mouse(USER_DEF, cursor->mform_p);
slouken@281
   135
	}
patmandin@736
   136
*/
patmandin@736
   137
#ifdef DEBUG_VIDEO_GEM
patmandin@736
   138
	printf("sdl:video:gem: ShowWMCursor(0x%08x)\n", (long) cursor);
patmandin@736
   139
#endif
slouken@281
   140
slouken@281
   141
	return 1;
slouken@281
   142
}
slouken@281
   143
slouken@319
   144
#if 0
slouken@281
   145
void GEM_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
slouken@281
   146
{
slouken@319
   147
	/* This seems to work only on AES 3.4 (Falcon) */
slouken@319
   148
slouken@281
   149
	EVNTREC	warpevent;
slouken@281
   150
	
slouken@281
   151
	warpevent.ap_event = APPEVNT_MOUSE; 
slouken@319
   152
	warpevent.ap_value = (x << 16) | y;
slouken@281
   153
slouken@281
   154
	appl_tplay(&warpevent, 1, 1000);
slouken@281
   155
}
slouken@319
   156
#endif
slouken@281
   157
slouken@281
   158
void GEM_CheckMouseMode(_THIS)
slouken@281
   159
{
slouken@281
   160
	/* If the mouse is hidden and input is grabbed, we use relative mode */
patmandin@1267
   161
	if ( (!(SDL_cursorstate & CURSOR_VISIBLE)) &&
patmandin@1267
   162
		/*(this->input_grab != SDL_GRAB_OFF) && */ /* Damn GEM can not grab */
slouken@319
   163
             (SDL_GetAppState() & SDL_APPACTIVE) ) {
slouken@281
   164
		GEM_mouse_relative = SDL_TRUE;
slouken@281
   165
	} else {
slouken@281
   166
		GEM_mouse_relative = SDL_FALSE;
slouken@281
   167
	}
slouken@281
   168
}