src/video/gem/SDL_gemmouse.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 01 Feb 2006 06:32:25 +0000
changeset 1312 c9b51268668f
parent 1267 fdc7ef6ecab4
child 1336 3692456e7b0f
permissions -rw-r--r--
Updated copyright information and removed rcs id lines (problematic in branch merges)
I batch edited these files, so please let me know if I've accidentally removed anybody's
credit here.
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@281
    22
slouken@281
    23
/*
slouken@281
    24
 *	GEM Mouse manager
slouken@281
    25
 *
slouken@281
    26
 *	Patrice Mandin
slouken@281
    27
 */
slouken@281
    28
slouken@281
    29
#include <stdlib.h>
slouken@281
    30
slouken@281
    31
#include <gem.h>
slouken@281
    32
slouken@281
    33
#include "SDL_error.h"
slouken@281
    34
#include "SDL_mouse.h"
slouken@281
    35
#include "SDL_events_c.h"
slouken@281
    36
#include "SDL_cursor_c.h"
slouken@281
    37
#include "SDL_gemmouse_c.h"
slouken@281
    38
slouken@281
    39
/* Defines */
slouken@281
    40
patmandin@736
    41
/*#define DEBUG_VIDEO_GEM 1*/
patmandin@736
    42
slouken@281
    43
#define MAXCURWIDTH 16
slouken@281
    44
#define MAXCURHEIGHT 16
slouken@281
    45
slouken@281
    46
/* The implementation dependent data for the window manager cursor */
slouken@281
    47
struct WMcursor {
slouken@281
    48
	MFORM *mform_p;
slouken@281
    49
};
slouken@281
    50
slouken@281
    51
slouken@281
    52
void GEM_FreeWMCursor(_THIS, WMcursor *cursor)
slouken@281
    53
{
slouken@281
    54
	if (cursor == NULL)
slouken@281
    55
		return;
slouken@281
    56
	
slouken@281
    57
	graf_mouse(ARROW, NULL);
slouken@281
    58
slouken@281
    59
	if (cursor->mform_p != NULL)
slouken@281
    60
		free(cursor->mform_p);
slouken@281
    61
slouken@281
    62
	free(cursor);
slouken@281
    63
}
slouken@281
    64
slouken@281
    65
WMcursor *GEM_CreateWMCursor(_THIS,
slouken@281
    66
		Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y)
slouken@281
    67
{
slouken@281
    68
	WMcursor *cursor;
slouken@281
    69
	MFORM *new_mform;
slouken@281
    70
	int i;
slouken@281
    71
slouken@281
    72
	/* Check the size */
slouken@281
    73
	if ( (w > MAXCURWIDTH) || (h > MAXCURHEIGHT) ) {
slouken@281
    74
		SDL_SetError("Only cursors of dimension (%dx%d) are allowed",
slouken@281
    75
							MAXCURWIDTH, MAXCURHEIGHT);
slouken@281
    76
		return(NULL);
slouken@281
    77
	}
slouken@281
    78
slouken@281
    79
	/* Allocate the cursor memory */
slouken@281
    80
	cursor = (WMcursor *)malloc(sizeof(WMcursor));
slouken@281
    81
	if ( cursor == NULL ) {
slouken@281
    82
		SDL_OutOfMemory();
slouken@281
    83
		return(NULL);
slouken@281
    84
	}
slouken@281
    85
slouken@281
    86
	/* Allocate mform */
slouken@281
    87
	new_mform = (MFORM *)malloc(sizeof(MFORM));		
slouken@281
    88
	if (new_mform == NULL) {
slouken@281
    89
		free(cursor);
slouken@281
    90
		SDL_OutOfMemory();
slouken@281
    91
		return(NULL);
slouken@281
    92
	}
slouken@281
    93
slouken@281
    94
	cursor->mform_p = new_mform;
slouken@281
    95
slouken@281
    96
	new_mform->mf_xhot = hot_x;
slouken@281
    97
	new_mform->mf_yhot = hot_y;
slouken@281
    98
	new_mform->mf_nplanes = 1;
slouken@281
    99
	new_mform->mf_fg = 0;
slouken@281
   100
	new_mform->mf_bg = 1;
slouken@281
   101
patmandin@736
   102
	for (i=0;i<MAXCURHEIGHT;i++) {
slouken@281
   103
		new_mform->mf_mask[i]=0;
slouken@281
   104
		new_mform->mf_data[i]=0;
slouken@281
   105
	}
slouken@281
   106
slouken@281
   107
	if (w<=8) {
patmandin@736
   108
		for (i=0;i<h;i++) {
slouken@281
   109
			new_mform->mf_mask[i]= mask[i]<<8;
slouken@281
   110
			new_mform->mf_data[i]= data[i]<<8;
slouken@281
   111
		}
slouken@281
   112
	} else {
patmandin@736
   113
		for (i=0;i<h;i++) {
slouken@281
   114
			new_mform->mf_mask[i]= mask[i<<1]<<8 | mask[(i<<1)+1];
slouken@281
   115
			new_mform->mf_data[i]= data[i<<1]<<8 | data[(i<<1)+1];
slouken@281
   116
		}
slouken@281
   117
	}
slouken@281
   118
patmandin@736
   119
#ifdef DEBUG_VIDEO_GEM
patmandin@736
   120
	for (i=0; i<h ;i++) {
patmandin@736
   121
		printf("sdl:video:gem: cursor, line %d = 0x%04x\n", i, new_mform->mf_mask[i]);
patmandin@736
   122
	}
patmandin@736
   123
patmandin@736
   124
	printf("sdl:video:gem: CreateWMCursor(): done\n");
patmandin@736
   125
#endif
patmandin@736
   126
slouken@281
   127
	return cursor;
slouken@281
   128
}
slouken@281
   129
slouken@281
   130
int GEM_ShowWMCursor(_THIS, WMcursor *cursor)
slouken@281
   131
{
patmandin@736
   132
/*
slouken@281
   133
	if (cursor == NULL) {
slouken@281
   134
		graf_mouse(M_OFF, NULL);
slouken@281
   135
	} else if (cursor->mform_p) {
slouken@281
   136
		graf_mouse(USER_DEF, cursor->mform_p);
slouken@281
   137
	}
patmandin@736
   138
*/
patmandin@736
   139
#ifdef DEBUG_VIDEO_GEM
patmandin@736
   140
	printf("sdl:video:gem: ShowWMCursor(0x%08x)\n", (long) cursor);
patmandin@736
   141
#endif
slouken@281
   142
slouken@281
   143
	return 1;
slouken@281
   144
}
slouken@281
   145
slouken@319
   146
#if 0
slouken@281
   147
void GEM_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
slouken@281
   148
{
slouken@319
   149
	/* This seems to work only on AES 3.4 (Falcon) */
slouken@319
   150
slouken@281
   151
	EVNTREC	warpevent;
slouken@281
   152
	
slouken@281
   153
	warpevent.ap_event = APPEVNT_MOUSE; 
slouken@319
   154
	warpevent.ap_value = (x << 16) | y;
slouken@281
   155
slouken@281
   156
	appl_tplay(&warpevent, 1, 1000);
slouken@281
   157
}
slouken@319
   158
#endif
slouken@281
   159
slouken@281
   160
void GEM_CheckMouseMode(_THIS)
slouken@281
   161
{
slouken@281
   162
	/* If the mouse is hidden and input is grabbed, we use relative mode */
patmandin@1267
   163
	if ( (!(SDL_cursorstate & CURSOR_VISIBLE)) &&
patmandin@1267
   164
		/*(this->input_grab != SDL_GRAB_OFF) && */ /* Damn GEM can not grab */
slouken@319
   165
             (SDL_GetAppState() & SDL_APPACTIVE) ) {
slouken@281
   166
		GEM_mouse_relative = SDL_TRUE;
slouken@281
   167
	} else {
slouken@281
   168
		GEM_mouse_relative = SDL_FALSE;
slouken@281
   169
	}
slouken@281
   170
}