src/video/gem/SDL_gemmouse.c
author Patrice Mandin <patmandin@gmail.com>
Wed, 12 Nov 2003 18:49:29 +0000
changeset 736 028e03e273c8
parent 319 189a6a3416c7
child 769 b8d311d90021
permissions -rw-r--r--
Use new C2P routine + corrections for iconification window
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
patmandin@736
    46
/*#define DEBUG_VIDEO_GEM 1*/
patmandin@736
    47
slouken@281
    48
#define MAXCURWIDTH 16
slouken@281
    49
#define MAXCURHEIGHT 16
slouken@281
    50
slouken@281
    51
/* The implementation dependent data for the window manager cursor */
slouken@281
    52
struct WMcursor {
slouken@281
    53
	MFORM *mform_p;
slouken@281
    54
};
slouken@281
    55
slouken@281
    56
slouken@281
    57
void GEM_FreeWMCursor(_THIS, WMcursor *cursor)
slouken@281
    58
{
slouken@281
    59
	if (cursor == NULL)
slouken@281
    60
		return;
slouken@281
    61
	
slouken@281
    62
	graf_mouse(ARROW, NULL);
slouken@281
    63
slouken@281
    64
	if (cursor->mform_p != NULL)
slouken@281
    65
		free(cursor->mform_p);
slouken@281
    66
slouken@281
    67
	free(cursor);
slouken@281
    68
}
slouken@281
    69
slouken@281
    70
WMcursor *GEM_CreateWMCursor(_THIS,
slouken@281
    71
		Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y)
slouken@281
    72
{
slouken@281
    73
	WMcursor *cursor;
slouken@281
    74
	MFORM *new_mform;
slouken@281
    75
	int i;
slouken@281
    76
slouken@281
    77
	/* Check the size */
slouken@281
    78
	if ( (w > MAXCURWIDTH) || (h > MAXCURHEIGHT) ) {
slouken@281
    79
		SDL_SetError("Only cursors of dimension (%dx%d) are allowed",
slouken@281
    80
							MAXCURWIDTH, MAXCURHEIGHT);
slouken@281
    81
		return(NULL);
slouken@281
    82
	}
slouken@281
    83
slouken@281
    84
	/* Allocate the cursor memory */
slouken@281
    85
	cursor = (WMcursor *)malloc(sizeof(WMcursor));
slouken@281
    86
	if ( cursor == NULL ) {
slouken@281
    87
		SDL_OutOfMemory();
slouken@281
    88
		return(NULL);
slouken@281
    89
	}
slouken@281
    90
slouken@281
    91
	/* Allocate mform */
slouken@281
    92
	new_mform = (MFORM *)malloc(sizeof(MFORM));		
slouken@281
    93
	if (new_mform == NULL) {
slouken@281
    94
		free(cursor);
slouken@281
    95
		SDL_OutOfMemory();
slouken@281
    96
		return(NULL);
slouken@281
    97
	}
slouken@281
    98
slouken@281
    99
	cursor->mform_p = new_mform;
slouken@281
   100
slouken@281
   101
	new_mform->mf_xhot = hot_x;
slouken@281
   102
	new_mform->mf_yhot = hot_y;
slouken@281
   103
	new_mform->mf_nplanes = 1;
slouken@281
   104
	new_mform->mf_fg = 0;
slouken@281
   105
	new_mform->mf_bg = 1;
slouken@281
   106
patmandin@736
   107
	for (i=0;i<MAXCURHEIGHT;i++) {
slouken@281
   108
		new_mform->mf_mask[i]=0;
slouken@281
   109
		new_mform->mf_data[i]=0;
slouken@281
   110
	}
slouken@281
   111
slouken@281
   112
	if (w<=8) {
patmandin@736
   113
		for (i=0;i<h;i++) {
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 {
patmandin@736
   118
		for (i=0;i<h;i++) {
slouken@281
   119
			new_mform->mf_mask[i]= mask[i<<1]<<8 | mask[(i<<1)+1];
slouken@281
   120
			new_mform->mf_data[i]= data[i<<1]<<8 | data[(i<<1)+1];
slouken@281
   121
		}
slouken@281
   122
	}
slouken@281
   123
patmandin@736
   124
#ifdef DEBUG_VIDEO_GEM
patmandin@736
   125
	for (i=0; i<h ;i++) {
patmandin@736
   126
		printf("sdl:video:gem: cursor, line %d = 0x%04x\n", i, new_mform->mf_mask[i]);
patmandin@736
   127
	}
patmandin@736
   128
patmandin@736
   129
	printf("sdl:video:gem: CreateWMCursor(): done\n");
patmandin@736
   130
#endif
patmandin@736
   131
slouken@281
   132
	return cursor;
slouken@281
   133
}
slouken@281
   134
slouken@281
   135
int GEM_ShowWMCursor(_THIS, WMcursor *cursor)
slouken@281
   136
{
patmandin@736
   137
/*
slouken@281
   138
	if (cursor == NULL) {
slouken@281
   139
		graf_mouse(M_OFF, NULL);
slouken@281
   140
	} else if (cursor->mform_p) {
slouken@281
   141
		graf_mouse(USER_DEF, cursor->mform_p);
slouken@281
   142
	}
patmandin@736
   143
*/
patmandin@736
   144
#ifdef DEBUG_VIDEO_GEM
patmandin@736
   145
	printf("sdl:video:gem: ShowWMCursor(0x%08x)\n", (long) cursor);
patmandin@736
   146
#endif
slouken@281
   147
slouken@281
   148
	return 1;
slouken@281
   149
}
slouken@281
   150
slouken@319
   151
#if 0
slouken@281
   152
void GEM_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
slouken@281
   153
{
slouken@319
   154
	/* This seems to work only on AES 3.4 (Falcon) */
slouken@319
   155
slouken@281
   156
	EVNTREC	warpevent;
slouken@281
   157
	
slouken@281
   158
	warpevent.ap_event = APPEVNT_MOUSE; 
slouken@319
   159
	warpevent.ap_value = (x << 16) | y;
slouken@281
   160
slouken@281
   161
	appl_tplay(&warpevent, 1, 1000);
slouken@281
   162
}
slouken@319
   163
#endif
slouken@281
   164
slouken@281
   165
void GEM_CheckMouseMode(_THIS)
slouken@281
   166
{
slouken@281
   167
	/* If the mouse is hidden and input is grabbed, we use relative mode */
slouken@281
   168
	if ( !(SDL_cursorstate & CURSOR_VISIBLE) &&
slouken@319
   169
		(this->input_grab != SDL_GRAB_OFF) &&
slouken@319
   170
             (SDL_GetAppState() & SDL_APPACTIVE) ) {
slouken@281
   171
		GEM_mouse_relative = SDL_TRUE;
slouken@281
   172
	} else {
slouken@281
   173
		GEM_mouse_relative = SDL_FALSE;
slouken@281
   174
	}
slouken@281
   175
}