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