1 /* 2 SDL - Simple DirectMedia Layer 3 Copyright (C) 1997-2012 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 (at) 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 #include "SDL_gemvideo.h" 37 #include "../ataricommon/SDL_xbiosevents_c.h" 38 39 /* Defines */ 40 41 /*#define DEBUG_VIDEO_GEM 1*/ 42 43 #define MAXCURWIDTH 16 44 #define MAXCURHEIGHT 16 45 46 void GEM_FreeWMCursor(_THIS, WMcursor *cursor) 47 { 48 #ifdef DEBUG_VIDEO_GEM 49 printf("sdl:video:gem: free cursor\n"); 50 #endif 51 52 if (cursor == NULL) 53 return; 54 55 graf_mouse(ARROW, NULL); 56 57 if (cursor->mform_p != NULL) 58 SDL_free(cursor->mform_p); 59 60 SDL_free(cursor); 61 } 62 63 WMcursor *GEM_CreateWMCursor(_THIS, 64 Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y) 65 { 66 WMcursor *cursor; 67 MFORM *new_mform; 68 int i; 69 70 #ifdef DEBUG_VIDEO_GEM 71 Uint16 *data1, *mask1; 72 73 printf("sdl:video:gem: create cursor\n"); 74 #endif 75 76 /* Check the size */ 77 if ( (w > MAXCURWIDTH) || (h > MAXCURHEIGHT) ) { 78 SDL_SetError("Only cursors of dimension (%dx%d) are allowed", 79 MAXCURWIDTH, MAXCURHEIGHT); 80 return(NULL); 81 } 82 83 /* Allocate the cursor memory */ 84 cursor = (WMcursor *)SDL_malloc(sizeof(WMcursor)); 85 if ( cursor == NULL ) { 86 SDL_OutOfMemory(); 87 return(NULL); 88 } 89 90 /* Allocate mform */ 91 new_mform = (MFORM *)SDL_malloc(sizeof(MFORM)); 92 if (new_mform == NULL) { 93 SDL_free(cursor); 94 SDL_OutOfMemory(); 95 return(NULL); 96 } 97 98 cursor->mform_p = new_mform; 99 100 new_mform->mf_xhot = hot_x; 101 new_mform->mf_yhot = hot_y; 102 new_mform->mf_nplanes = 1; 103 new_mform->mf_fg = 0; 104 new_mform->mf_bg = 1; 105 106 for (i=0;i<MAXCURHEIGHT;i++) { 107 new_mform->mf_mask[i]=0; 108 new_mform->mf_data[i]=0; 109 #ifdef DEBUG_VIDEO_GEM 110 data1 = (Uint16 *) &data[i<<1]; 111 mask1 = (Uint16 *) &mask[i<<1]; 112 printf("sdl:video:gem: source: line %d: data=0x%04x, mask=0x%04x\n", 113 i, data1[i], mask1[i]); 114 #endif 115 } 116 117 if (w<=8) { 118 for (i=0;i<h;i++) { 119 new_mform->mf_mask[i]= mask[i]<<8; 120 new_mform->mf_data[i]= data[i]<<8; 121 } 122 } else { 123 for (i=0;i<h;i++) { 124 new_mform->mf_mask[i]= (mask[i<<1]<<8) | mask[(i<<1)+1]; 125 new_mform->mf_data[i]= (data[i<<1]<<8) | data[(i<<1)+1]; 126 } 127 } 128 129 #ifdef DEBUG_VIDEO_GEM 130 for (i=0; i<h ;i++) { 131 printf("sdl:video:gem: cursor: line %d: data=0x%04x, mask=0x%04x\n", 132 i, new_mform->mf_data[i], new_mform->mf_mask[i]); 133 } 134 135 printf("sdl:video:gem: CreateWMCursor(): done\n"); 136 #endif 137 138 return cursor; 139 } 140 141 int GEM_ShowWMCursor(_THIS, WMcursor *cursor) 142 { 143 GEM_cursor = cursor; 144 145 GEM_CheckMouseMode(this); 146 147 #ifdef DEBUG_VIDEO_GEM 148 printf("sdl:video:gem: ShowWMCursor(0x%08x)\n", (long) cursor); 149 #endif 150 151 return 1; 152 } 153 154 #if 0 155 void GEM_WarpWMCursor(_THIS, Uint16 x, Uint16 y) 156 { 157 /* This seems to work only on AES 3.4 (Falcon) */ 158 159 EVNTREC warpevent; 160 161 warpevent.ap_event = APPEVNT_MOUSE; 162 warpevent.ap_value = (x << 16) | y; 163 164 appl_tplay(&warpevent, 1, 1000); 165 } 166 #endif 167 168 void GEM_CheckMouseMode(_THIS) 169 { 170 const Uint8 full_focus = (SDL_APPACTIVE|SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS); 171 int set_system_cursor = 1, show_system_cursor = 1; 172 173 #ifdef DEBUG_VIDEO_GEM 174 printf("sdl:video:gem: check mouse mode\n"); 175 #endif 176 177 /* If the mouse is hidden and input is grabbed, we use relative mode */ 178 GEM_mouse_relative = (!(SDL_cursorstate & CURSOR_VISIBLE)) 179 && (this->input_grab != SDL_GRAB_OFF) 180 && (SDL_GetAppState() & SDL_APPACTIVE); 181 SDL_AtariXbios_LockMousePosition(GEM_mouse_relative); 182 183 if (SDL_cursorstate & CURSOR_VISIBLE) { 184 /* Application defined cursor only over the application window */ 185 if ((SDL_GetAppState() & full_focus) == full_focus) { 186 if (GEM_cursor) { 187 graf_mouse(USER_DEF, GEM_cursor->mform_p); 188 set_system_cursor = 0; 189 } else { 190 show_system_cursor = 0; 191 } 192 } 193 } else { 194 /* Mouse cursor hidden only over the application window */ 195 if ((SDL_GetAppState() & full_focus) == full_focus) { 196 set_system_cursor = 0; 197 show_system_cursor = 0; 198 } 199 } 200 201 graf_mouse(show_system_cursor ? M_ON : M_OFF, NULL); 202 if (set_system_cursor) { 203 graf_mouse(ARROW, NULL); 204 } 205 } 206