src/video/gem/SDL_gemmouse.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 26 Mar 2002 17:37:31 +0000
changeset 319 189a6a3416c7
parent 297 f6ffac90895c
child 736 028e03e273c8
permissions -rw-r--r--
*** empty log message ***
slouken@281
     1
/*
slouken@281
     2
    SDL - Simple DirectMedia Layer
slouken@297
     3
    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
slouken@281
     4
slouken@281
     5
    This library is free software; you can redistribute it and/or
slouken@281
     6
    modify it under the terms of the GNU Library General Public
slouken@281
     7
    License as published by the Free Software Foundation; either
slouken@281
     8
    version 2 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@281
    13
    Library General Public License for more details.
slouken@281
    14
slouken@281
    15
    You should have received a copy of the GNU Library General Public
slouken@281
    16
    License along with this library; if not, write to the Free
slouken@281
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@281
    18
slouken@281
    19
    Sam Lantinga
slouken@281
    20
    slouken@libsdl.org
slouken@281
    21
*/
slouken@281
    22
slouken@281
    23
#ifdef SAVE_RCSID
slouken@281
    24
static char rcsid =
slouken@281
    25
 "@(#) $Id$";
slouken@281
    26
#endif
slouken@281
    27
slouken@281
    28
/*
slouken@281
    29
 *	GEM Mouse manager
slouken@281
    30
 *
slouken@281
    31
 *	Patrice Mandin
slouken@281
    32
 */
slouken@281
    33
slouken@281
    34
#include <stdlib.h>
slouken@281
    35
slouken@281
    36
#include <gem.h>
slouken@281
    37
slouken@281
    38
#include "SDL_error.h"
slouken@281
    39
#include "SDL_mouse.h"
slouken@281
    40
#include "SDL_events_c.h"
slouken@281
    41
#include "SDL_cursor_c.h"
slouken@281
    42
#include "SDL_gemmouse_c.h"
slouken@281
    43
slouken@281
    44
/* Defines */
slouken@281
    45
slouken@281
    46
#define MAXCURWIDTH 16
slouken@281
    47
#define MAXCURHEIGHT 16
slouken@281
    48
slouken@281
    49
/* The implementation dependent data for the window manager cursor */
slouken@281
    50
struct WMcursor {
slouken@281
    51
	MFORM *mform_p;
slouken@281
    52
};
slouken@281
    53
slouken@281
    54
slouken@281
    55
void GEM_FreeWMCursor(_THIS, WMcursor *cursor)
slouken@281
    56
{
slouken@281
    57
	if (cursor == NULL)
slouken@281
    58
		return;
slouken@281
    59
	
slouken@281
    60
	graf_mouse(ARROW, NULL);
slouken@281
    61
slouken@281
    62
	if (cursor->mform_p != NULL)
slouken@281
    63
		free(cursor->mform_p);
slouken@281
    64
slouken@281
    65
	free(cursor);
slouken@281
    66
}
slouken@281
    67
slouken@281
    68
WMcursor *GEM_CreateWMCursor(_THIS,
slouken@281
    69
		Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y)
slouken@281
    70
{
slouken@281
    71
	WMcursor *cursor;
slouken@281
    72
	MFORM *new_mform;
slouken@281
    73
	int i;
slouken@281
    74
slouken@281
    75
	/* Check the size */
slouken@281
    76
	if ( (w > MAXCURWIDTH) || (h > MAXCURHEIGHT) ) {
slouken@281
    77
		SDL_SetError("Only cursors of dimension (%dx%d) are allowed",
slouken@281
    78
							MAXCURWIDTH, MAXCURHEIGHT);
slouken@281
    79
		return(NULL);
slouken@281
    80
	}
slouken@281
    81
slouken@281
    82
	/* Allocate the cursor memory */
slouken@281
    83
	cursor = (WMcursor *)malloc(sizeof(WMcursor));
slouken@281
    84
	if ( cursor == NULL ) {
slouken@281
    85
		SDL_OutOfMemory();
slouken@281
    86
		return(NULL);
slouken@281
    87
	}
slouken@281
    88
slouken@281
    89
	/* Allocate mform */
slouken@281
    90
	new_mform = (MFORM *)malloc(sizeof(MFORM));		
slouken@281
    91
	if (new_mform == NULL) {
slouken@281
    92
		free(cursor);
slouken@281
    93
		SDL_OutOfMemory();
slouken@281
    94
		return(NULL);
slouken@281
    95
	}
slouken@281
    96
slouken@281
    97
	cursor->mform_p = new_mform;
slouken@281
    98
slouken@281
    99
	new_mform->mf_xhot = hot_x;
slouken@281
   100
	new_mform->mf_yhot = hot_y;
slouken@281
   101
	new_mform->mf_nplanes = 1;
slouken@281
   102
	new_mform->mf_fg = 0;
slouken@281
   103
	new_mform->mf_bg = 1;
slouken@281
   104
slouken@281
   105
	for (i=0;i<MAXCURHEIGHT;i++)
slouken@281
   106
	{
slouken@281
   107
		new_mform->mf_mask[i]=0;
slouken@281
   108
		new_mform->mf_data[i]=0;
slouken@281
   109
	}
slouken@281
   110
slouken@281
   111
	if (w<=8) {
slouken@281
   112
		for (i=0;i<h;i++)
slouken@281
   113
		{
slouken@281
   114
			new_mform->mf_mask[i]= mask[i]<<8;
slouken@281
   115
			new_mform->mf_data[i]= data[i]<<8;
slouken@281
   116
		}
slouken@281
   117
	} else {
slouken@281
   118
		for (i=0;i<h;i++)
slouken@281
   119
		{
slouken@281
   120
			new_mform->mf_mask[i]= mask[i<<1]<<8 | mask[(i<<1)+1];
slouken@281
   121
			new_mform->mf_data[i]= data[i<<1]<<8 | data[(i<<1)+1];
slouken@281
   122
		}
slouken@281
   123
	}
slouken@281
   124
slouken@281
   125
	return cursor;
slouken@281
   126
}
slouken@281
   127
slouken@281
   128
int GEM_ShowWMCursor(_THIS, WMcursor *cursor)
slouken@281
   129
{
slouken@281
   130
	if (cursor == NULL) {
slouken@281
   131
		graf_mouse(M_OFF, NULL);
slouken@281
   132
	} else if (cursor->mform_p) {
slouken@281
   133
		graf_mouse(USER_DEF, cursor->mform_p);
slouken@281
   134
	}
slouken@281
   135
slouken@281
   136
	return 1;
slouken@281
   137
}
slouken@281
   138
slouken@319
   139
#if 0
slouken@281
   140
void GEM_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
slouken@281
   141
{
slouken@319
   142
	/* This seems to work only on AES 3.4 (Falcon) */
slouken@319
   143
slouken@281
   144
	EVNTREC	warpevent;
slouken@281
   145
	
slouken@281
   146
	warpevent.ap_event = APPEVNT_MOUSE; 
slouken@319
   147
	warpevent.ap_value = (x << 16) | y;
slouken@281
   148
slouken@281
   149
	appl_tplay(&warpevent, 1, 1000);
slouken@281
   150
}
slouken@319
   151
#endif
slouken@281
   152
slouken@281
   153
void GEM_CheckMouseMode(_THIS)
slouken@281
   154
{
slouken@281
   155
	/* If the mouse is hidden and input is grabbed, we use relative mode */
slouken@281
   156
	if ( !(SDL_cursorstate & CURSOR_VISIBLE) &&
slouken@319
   157
		(this->input_grab != SDL_GRAB_OFF) &&
slouken@319
   158
             (SDL_GetAppState() & SDL_APPACTIVE) ) {
slouken@281
   159
		GEM_mouse_relative = SDL_TRUE;
slouken@281
   160
	} else {
slouken@281
   161
		GEM_mouse_relative = SDL_FALSE;
slouken@281
   162
	}
slouken@281
   163
}