src/video/gem/SDL_gemmouse.c
author Ozkan Sezer <sezeroz@gmail.com>
Sun, 14 Oct 2018 15:25:04 +0300
branchSDL-1.2
changeset 12325 c4f2eeda176f
parent 11564 eb391d3461f1
permissions -rw-r--r--
remove symlink for libSDL-1.0.so.0 from the rpm spec file.

also fix a changelog date.
slouken@281
     1
/*
slouken@281
     2
    SDL - Simple DirectMedia Layer
slouken@6137
     3
    Copyright (C) 1997-2012 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"
patmandin@1857
    36
#include "SDL_gemvideo.h"
patmandin@5649
    37
#include "../ataricommon/SDL_xbiosevents_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
void GEM_FreeWMCursor(_THIS, WMcursor *cursor)
slouken@281
    47
{
patmandin@1857
    48
#ifdef DEBUG_VIDEO_GEM
patmandin@1857
    49
	printf("sdl:video:gem: free cursor\n");
patmandin@1857
    50
#endif
patmandin@1857
    51
slouken@281
    52
	if (cursor == NULL)
slouken@281
    53
		return;
patmandin@11564
    54
slouken@281
    55
	graf_mouse(ARROW, NULL);
patmandin@11564
    56
	GEM_prev_cursor = NULL;
slouken@281
    57
slouken@281
    58
	if (cursor->mform_p != NULL)
slouken@1336
    59
		SDL_free(cursor->mform_p);
slouken@281
    60
slouken@1336
    61
	SDL_free(cursor);
slouken@281
    62
}
slouken@281
    63
slouken@281
    64
WMcursor *GEM_CreateWMCursor(_THIS,
slouken@281
    65
		Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y)
slouken@281
    66
{
slouken@281
    67
	WMcursor *cursor;
slouken@281
    68
	MFORM *new_mform;
slouken@281
    69
	int i;
slouken@281
    70
patmandin@1857
    71
#ifdef DEBUG_VIDEO_GEM
patmandin@1857
    72
	Uint16 *data1, *mask1;
patmandin@1857
    73
patmandin@1857
    74
	printf("sdl:video:gem: create cursor\n");
patmandin@1857
    75
#endif
patmandin@1857
    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@1336
    85
	cursor = (WMcursor *)SDL_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 */
patmandin@11564
    92
	new_mform = (MFORM *)SDL_malloc(sizeof(MFORM));
slouken@281
    93
	if (new_mform == NULL) {
slouken@1336
    94
		SDL_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;
patmandin@1857
   110
#ifdef DEBUG_VIDEO_GEM
patmandin@1857
   111
		data1 = (Uint16 *) &data[i<<1];
patmandin@1857
   112
		mask1 = (Uint16 *) &mask[i<<1];
patmandin@1857
   113
		printf("sdl:video:gem: source: line %d: data=0x%04x, mask=0x%04x\n",
patmandin@1857
   114
			i, data1[i], mask1[i]);
patmandin@1857
   115
#endif
slouken@281
   116
	}
slouken@281
   117
slouken@281
   118
	if (w<=8) {
patmandin@736
   119
		for (i=0;i<h;i++) {
slouken@281
   120
			new_mform->mf_mask[i]= mask[i]<<8;
slouken@281
   121
			new_mform->mf_data[i]= data[i]<<8;
slouken@281
   122
		}
slouken@281
   123
	} else {
patmandin@736
   124
		for (i=0;i<h;i++) {
patmandin@1857
   125
			new_mform->mf_mask[i]= (mask[i<<1]<<8) | mask[(i<<1)+1];
patmandin@1857
   126
			new_mform->mf_data[i]= (data[i<<1]<<8) | data[(i<<1)+1];
slouken@281
   127
		}
slouken@281
   128
	}
slouken@281
   129
patmandin@736
   130
#ifdef DEBUG_VIDEO_GEM
patmandin@736
   131
	for (i=0; i<h ;i++) {
patmandin@1857
   132
		printf("sdl:video:gem: cursor: line %d: data=0x%04x, mask=0x%04x\n",
patmandin@1857
   133
			i, new_mform->mf_data[i], new_mform->mf_mask[i]);
patmandin@736
   134
	}
patmandin@736
   135
patmandin@736
   136
	printf("sdl:video:gem: CreateWMCursor(): done\n");
patmandin@736
   137
#endif
patmandin@736
   138
slouken@281
   139
	return cursor;
slouken@281
   140
}
slouken@281
   141
slouken@281
   142
int GEM_ShowWMCursor(_THIS, WMcursor *cursor)
slouken@281
   143
{
patmandin@1857
   144
	GEM_cursor = cursor;
patmandin@4060
   145
patmandin@4060
   146
	GEM_CheckMouseMode(this);
patmandin@1857
   147
patmandin@736
   148
#ifdef DEBUG_VIDEO_GEM
patmandin@736
   149
	printf("sdl:video:gem: ShowWMCursor(0x%08x)\n", (long) cursor);
patmandin@736
   150
#endif
slouken@281
   151
slouken@281
   152
	return 1;
slouken@281
   153
}
slouken@281
   154
slouken@319
   155
#if 0
slouken@281
   156
void GEM_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
slouken@281
   157
{
slouken@319
   158
	/* This seems to work only on AES 3.4 (Falcon) */
slouken@319
   159
slouken@281
   160
	EVNTREC	warpevent;
patmandin@11564
   161
patmandin@11564
   162
	warpevent.ap_event = APPEVNT_MOUSE;
slouken@319
   163
	warpevent.ap_value = (x << 16) | y;
slouken@281
   164
slouken@281
   165
	appl_tplay(&warpevent, 1, 1000);
slouken@281
   166
}
slouken@319
   167
#endif
slouken@281
   168
slouken@281
   169
void GEM_CheckMouseMode(_THIS)
slouken@281
   170
{
patmandin@4060
   171
	const Uint8 full_focus = (SDL_APPACTIVE|SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS);
patmandin@9058
   172
	int set_system_cursor = 1;
patmandin@9058
   173
	SDL_bool hide_system_cursor = SDL_FALSE;
patmandin@4060
   174
patmandin@1857
   175
#ifdef DEBUG_VIDEO_GEM
patmandin@1857
   176
	printf("sdl:video:gem: check mouse mode\n");
patmandin@1857
   177
#endif
patmandin@1857
   178
slouken@281
   179
	/* If the mouse is hidden and input is grabbed, we use relative mode */
patmandin@4060
   180
	GEM_mouse_relative = (!(SDL_cursorstate & CURSOR_VISIBLE))
patmandin@4060
   181
		&& (this->input_grab != SDL_GRAB_OFF)
patmandin@4060
   182
		&& (SDL_GetAppState() & SDL_APPACTIVE);
patmandin@4060
   183
	SDL_AtariXbios_LockMousePosition(GEM_mouse_relative);
patmandin@4060
   184
patmandin@4060
   185
	if (SDL_cursorstate & CURSOR_VISIBLE) {
patmandin@4060
   186
		/* Application defined cursor only over the application window */
patmandin@4060
   187
		if ((SDL_GetAppState() & full_focus) == full_focus) {
patmandin@4060
   188
			if (GEM_cursor) {
patmandin@11564
   189
				if (GEM_cursor != GEM_prev_cursor) {
patmandin@11564
   190
					graf_mouse(USER_DEF, GEM_cursor->mform_p);
patmandin@11564
   191
					GEM_prev_cursor = GEM_cursor;
patmandin@11564
   192
				}
patmandin@4060
   193
				set_system_cursor = 0;
patmandin@4060
   194
			} else {
patmandin@9058
   195
				hide_system_cursor = SDL_TRUE;
patmandin@4060
   196
			}
patmandin@4060
   197
		}
slouken@281
   198
	} else {
patmandin@4060
   199
		/* Mouse cursor hidden only over the application window */
patmandin@4060
   200
		if ((SDL_GetAppState() & full_focus) == full_focus) {
patmandin@4060
   201
			set_system_cursor = 0;
patmandin@9058
   202
			hide_system_cursor = SDL_TRUE;
patmandin@4060
   203
		}
patmandin@4060
   204
	}
patmandin@4060
   205
patmandin@9058
   206
	if (hide_system_cursor != GEM_cursor_hidden) {
patmandin@9058
   207
		graf_mouse(hide_system_cursor ? M_OFF : M_ON, NULL);
patmandin@9058
   208
		GEM_cursor_hidden = hide_system_cursor;
patmandin@9058
   209
	}
patmandin@9058
   210
patmandin@11564
   211
	if (set_system_cursor && GEM_prev_cursor) {
patmandin@4060
   212
		graf_mouse(ARROW, NULL);
patmandin@11564
   213
		GEM_prev_cursor = NULL;
slouken@281
   214
	}
slouken@281
   215
}