src/video/gem/SDL_gemmouse.c
author Patrice Mandin <patmandin@gmail.com>
Fri, 08 Sep 2006 19:18:02 +0000
changeset 2020 091bb215baf9
parent 1895 c121d94672cb
child 2025 7312feb88dad
permissions -rw-r--r--
Forgot to reshow mouse cursor when exiting grab/hide mode
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2006 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 #include "SDL_config.h"
    23 
    24 /*
    25  *	GEM Mouse manager
    26  *
    27  *	Patrice Mandin
    28  */
    29 
    30 #include <gem.h>
    31 
    32 #include "SDL_mouse.h"
    33 #include "../../events/SDL_events_c.h"
    34 #include "../SDL_cursor_c.h"
    35 #include "SDL_gemmouse_c.h"
    36 
    37 /* Defines */
    38 
    39 /*#define DEBUG_VIDEO_GEM 1*/
    40 
    41 #define MAXCURWIDTH 16
    42 #define MAXCURHEIGHT 16
    43 
    44 /* The implementation dependent data for the window manager cursor */
    45 struct WMcursor
    46 {
    47     MFORM *mform_p;
    48 };
    49 
    50 
    51 void
    52 GEM_FreeWMCursor(_THIS, WMcursor * cursor)
    53 {
    54     if (cursor == NULL)
    55         return;
    56 
    57     graf_mouse(ARROW, NULL);
    58 
    59     if (cursor->mform_p != NULL)
    60         SDL_free(cursor->mform_p);
    61 
    62     SDL_free(cursor);
    63 }
    64 
    65 WMcursor *
    66 GEM_CreateWMCursor(_THIS,
    67                    Uint8 * data, Uint8 * mask, int w, int h, int hot_x,
    68                    int hot_y)
    69 {
    70     WMcursor *cursor;
    71     MFORM *new_mform;
    72     int i;
    73 
    74     /* Check the size */
    75     if ((w > MAXCURWIDTH) || (h > MAXCURHEIGHT)) {
    76         SDL_SetError("Only cursors of dimension (%dx%d) are allowed",
    77                      MAXCURWIDTH, MAXCURHEIGHT);
    78         return (NULL);
    79     }
    80 
    81     /* Allocate the cursor memory */
    82     cursor = (WMcursor *) SDL_malloc(sizeof(WMcursor));
    83     if (cursor == NULL) {
    84         SDL_OutOfMemory();
    85         return (NULL);
    86     }
    87 
    88     /* Allocate mform */
    89     new_mform = (MFORM *) SDL_malloc(sizeof(MFORM));
    90     if (new_mform == NULL) {
    91         SDL_free(cursor);
    92         SDL_OutOfMemory();
    93         return (NULL);
    94     }
    95 
    96     cursor->mform_p = new_mform;
    97 
    98     new_mform->mf_xhot = hot_x;
    99     new_mform->mf_yhot = hot_y;
   100     new_mform->mf_nplanes = 1;
   101     new_mform->mf_fg = 0;
   102     new_mform->mf_bg = 1;
   103 
   104     for (i = 0; i < MAXCURHEIGHT; i++) {
   105         new_mform->mf_mask[i] = 0;
   106         new_mform->mf_data[i] = 0;
   107     }
   108 
   109     if (w <= 8) {
   110         for (i = 0; i < h; i++) {
   111             new_mform->mf_mask[i] = mask[i] << 8;
   112             new_mform->mf_data[i] = data[i] << 8;
   113         }
   114     } else {
   115         for (i = 0; i < h; i++) {
   116             new_mform->mf_mask[i] = mask[i << 1] << 8 | mask[(i << 1) + 1];
   117             new_mform->mf_data[i] = data[i << 1] << 8 | data[(i << 1) + 1];
   118         }
   119     }
   120 
   121 #ifdef DEBUG_VIDEO_GEM
   122     for (i = 0; i < h; i++) {
   123         printf("sdl:video:gem: cursor, line %d = 0x%04x\n", i,
   124                new_mform->mf_mask[i]);
   125     }
   126 
   127     printf("sdl:video:gem: CreateWMCursor(): done\n");
   128 #endif
   129 
   130     return cursor;
   131 }
   132 
   133 int
   134 GEM_ShowWMCursor(_THIS, WMcursor * cursor)
   135 {
   136 /*
   137 	if (cursor == NULL) {
   138 		graf_mouse(M_OFF, NULL);
   139 	} else if (cursor->mform_p) {
   140 		graf_mouse(USER_DEF, cursor->mform_p);
   141 	}
   142 */
   143 #ifdef DEBUG_VIDEO_GEM
   144     printf("sdl:video:gem: ShowWMCursor(0x%08x)\n", (long) cursor);
   145 #endif
   146 
   147     return 1;
   148 }
   149 
   150 #if 0
   151 void
   152 GEM_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
   153 {
   154     /* This seems to work only on AES 3.4 (Falcon) */
   155 
   156     EVNTREC warpevent;
   157 
   158     warpevent.ap_event = APPEVNT_MOUSE;
   159     warpevent.ap_value = (x << 16) | y;
   160 
   161     appl_tplay(&warpevent, 1, 1000);
   162 }
   163 #endif
   164 
   165 void
   166 GEM_CheckMouseMode(_THIS)
   167 {
   168     /* If the mouse is hidden and input is grabbed, we use relative mode */
   169     if ((!(SDL_cursorstate & CURSOR_VISIBLE)) &&
   170         /*(this->input_grab != SDL_GRAB_OFF) && *//* Damn GEM can not grab */
   171         (SDL_GetAppState() & SDL_APPACTIVE)) {
   172         GEM_mouse_relative = SDL_TRUE;
   173     } else {
   174         GEM_mouse_relative = SDL_FALSE;
   175         graf_mouse(M_ON, NULL);
   176     }
   177 }
   178 
   179 /* vi: set ts=4 sw=4 expandtab: */