src/video/gem/SDL_gemmouse.c
changeset 1895 c121d94672cb
parent 1857 417f2af2bd52
child 2020 091bb215baf9
     1.1 --- a/src/video/gem/SDL_gemmouse.c	Thu Jul 06 18:01:37 2006 +0000
     1.2 +++ b/src/video/gem/SDL_gemmouse.c	Mon Jul 10 21:04:37 2006 +0000
     1.3 @@ -33,7 +33,6 @@
     1.4  #include "../../events/SDL_events_c.h"
     1.5  #include "../SDL_cursor_c.h"
     1.6  #include "SDL_gemmouse_c.h"
     1.7 -#include "SDL_gemvideo.h"
     1.8  
     1.9  /* Defines */
    1.10  
    1.11 @@ -42,144 +41,138 @@
    1.12  #define MAXCURWIDTH 16
    1.13  #define MAXCURHEIGHT 16
    1.14  
    1.15 -void GEM_FreeWMCursor(_THIS, WMcursor *cursor)
    1.16 +/* The implementation dependent data for the window manager cursor */
    1.17 +struct WMcursor
    1.18  {
    1.19 -#ifdef DEBUG_VIDEO_GEM
    1.20 -	printf("sdl:video:gem: free cursor\n");
    1.21 -#endif
    1.22 +    MFORM *mform_p;
    1.23 +};
    1.24 +
    1.25  
    1.26 -	if (cursor == NULL)
    1.27 -		return;
    1.28 -	
    1.29 -	graf_mouse(ARROW, NULL);
    1.30 +void
    1.31 +GEM_FreeWMCursor(_THIS, WMcursor * cursor)
    1.32 +{
    1.33 +    if (cursor == NULL)
    1.34 +        return;
    1.35  
    1.36 -	if (cursor->mform_p != NULL)
    1.37 -		SDL_free(cursor->mform_p);
    1.38 +    graf_mouse(ARROW, NULL);
    1.39  
    1.40 -	SDL_free(cursor);
    1.41 +    if (cursor->mform_p != NULL)
    1.42 +        SDL_free(cursor->mform_p);
    1.43 +
    1.44 +    SDL_free(cursor);
    1.45  }
    1.46  
    1.47 -WMcursor *GEM_CreateWMCursor(_THIS,
    1.48 -		Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y)
    1.49 +WMcursor *
    1.50 +GEM_CreateWMCursor(_THIS,
    1.51 +                   Uint8 * data, Uint8 * mask, int w, int h, int hot_x,
    1.52 +                   int hot_y)
    1.53  {
    1.54 -	WMcursor *cursor;
    1.55 -	MFORM *new_mform;
    1.56 -	int i;
    1.57 +    WMcursor *cursor;
    1.58 +    MFORM *new_mform;
    1.59 +    int i;
    1.60 +
    1.61 +    /* Check the size */
    1.62 +    if ((w > MAXCURWIDTH) || (h > MAXCURHEIGHT)) {
    1.63 +        SDL_SetError("Only cursors of dimension (%dx%d) are allowed",
    1.64 +                     MAXCURWIDTH, MAXCURHEIGHT);
    1.65 +        return (NULL);
    1.66 +    }
    1.67 +
    1.68 +    /* Allocate the cursor memory */
    1.69 +    cursor = (WMcursor *) SDL_malloc(sizeof(WMcursor));
    1.70 +    if (cursor == NULL) {
    1.71 +        SDL_OutOfMemory();
    1.72 +        return (NULL);
    1.73 +    }
    1.74 +
    1.75 +    /* Allocate mform */
    1.76 +    new_mform = (MFORM *) SDL_malloc(sizeof(MFORM));
    1.77 +    if (new_mform == NULL) {
    1.78 +        SDL_free(cursor);
    1.79 +        SDL_OutOfMemory();
    1.80 +        return (NULL);
    1.81 +    }
    1.82 +
    1.83 +    cursor->mform_p = new_mform;
    1.84 +
    1.85 +    new_mform->mf_xhot = hot_x;
    1.86 +    new_mform->mf_yhot = hot_y;
    1.87 +    new_mform->mf_nplanes = 1;
    1.88 +    new_mform->mf_fg = 0;
    1.89 +    new_mform->mf_bg = 1;
    1.90 +
    1.91 +    for (i = 0; i < MAXCURHEIGHT; i++) {
    1.92 +        new_mform->mf_mask[i] = 0;
    1.93 +        new_mform->mf_data[i] = 0;
    1.94 +    }
    1.95 +
    1.96 +    if (w <= 8) {
    1.97 +        for (i = 0; i < h; i++) {
    1.98 +            new_mform->mf_mask[i] = mask[i] << 8;
    1.99 +            new_mform->mf_data[i] = data[i] << 8;
   1.100 +        }
   1.101 +    } else {
   1.102 +        for (i = 0; i < h; i++) {
   1.103 +            new_mform->mf_mask[i] = mask[i << 1] << 8 | mask[(i << 1) + 1];
   1.104 +            new_mform->mf_data[i] = data[i << 1] << 8 | data[(i << 1) + 1];
   1.105 +        }
   1.106 +    }
   1.107  
   1.108  #ifdef DEBUG_VIDEO_GEM
   1.109 -	Uint16 *data1, *mask1;
   1.110 +    for (i = 0; i < h; i++) {
   1.111 +        printf("sdl:video:gem: cursor, line %d = 0x%04x\n", i,
   1.112 +               new_mform->mf_mask[i]);
   1.113 +    }
   1.114  
   1.115 -	printf("sdl:video:gem: create cursor\n");
   1.116 +    printf("sdl:video:gem: CreateWMCursor(): done\n");
   1.117  #endif
   1.118  
   1.119 -	/* Check the size */
   1.120 -	if ( (w > MAXCURWIDTH) || (h > MAXCURHEIGHT) ) {
   1.121 -		SDL_SetError("Only cursors of dimension (%dx%d) are allowed",
   1.122 -							MAXCURWIDTH, MAXCURHEIGHT);
   1.123 -		return(NULL);
   1.124 -	}
   1.125 -
   1.126 -	/* Allocate the cursor memory */
   1.127 -	cursor = (WMcursor *)SDL_malloc(sizeof(WMcursor));
   1.128 -	if ( cursor == NULL ) {
   1.129 -		SDL_OutOfMemory();
   1.130 -		return(NULL);
   1.131 -	}
   1.132 -
   1.133 -	/* Allocate mform */
   1.134 -	new_mform = (MFORM *)SDL_malloc(sizeof(MFORM));		
   1.135 -	if (new_mform == NULL) {
   1.136 -		SDL_free(cursor);
   1.137 -		SDL_OutOfMemory();
   1.138 -		return(NULL);
   1.139 -	}
   1.140 -
   1.141 -	cursor->mform_p = new_mform;
   1.142 -
   1.143 -	new_mform->mf_xhot = hot_x;
   1.144 -	new_mform->mf_yhot = hot_y;
   1.145 -	new_mform->mf_nplanes = 1;
   1.146 -	new_mform->mf_fg = 0;
   1.147 -	new_mform->mf_bg = 1;
   1.148 -
   1.149 -	for (i=0;i<MAXCURHEIGHT;i++) {
   1.150 -		new_mform->mf_mask[i]=0;
   1.151 -		new_mform->mf_data[i]=0;
   1.152 -#ifdef DEBUG_VIDEO_GEM
   1.153 -		data1 = (Uint16 *) &data[i<<1];
   1.154 -		mask1 = (Uint16 *) &mask[i<<1];
   1.155 -		printf("sdl:video:gem: source: line %d: data=0x%04x, mask=0x%04x\n",
   1.156 -			i, data1[i], mask1[i]);
   1.157 -#endif
   1.158 -	}
   1.159 -
   1.160 -	if (w<=8) {
   1.161 -		for (i=0;i<h;i++) {
   1.162 -			new_mform->mf_mask[i]= mask[i]<<8;
   1.163 -			new_mform->mf_data[i]= data[i]<<8;
   1.164 -		}
   1.165 -	} else {
   1.166 -		for (i=0;i<h;i++) {
   1.167 -			new_mform->mf_mask[i]= (mask[i<<1]<<8) | mask[(i<<1)+1];
   1.168 -			new_mform->mf_data[i]= (data[i<<1]<<8) | data[(i<<1)+1];
   1.169 -		}
   1.170 -	}
   1.171 -
   1.172 -#ifdef DEBUG_VIDEO_GEM
   1.173 -	for (i=0; i<h ;i++) {
   1.174 -		printf("sdl:video:gem: cursor: line %d: data=0x%04x, mask=0x%04x\n",
   1.175 -			i, new_mform->mf_data[i], new_mform->mf_mask[i]);
   1.176 -	}
   1.177 -
   1.178 -	printf("sdl:video:gem: CreateWMCursor(): done\n");
   1.179 -#endif
   1.180 -
   1.181 -	return cursor;
   1.182 +    return cursor;
   1.183  }
   1.184  
   1.185 -int GEM_ShowWMCursor(_THIS, WMcursor *cursor)
   1.186 +int
   1.187 +GEM_ShowWMCursor(_THIS, WMcursor * cursor)
   1.188  {
   1.189 -	GEM_cursor = cursor;
   1.190 +/*
   1.191  	if (cursor == NULL) {
   1.192  		graf_mouse(M_OFF, NULL);
   1.193 -		GEM_cursor = (void *) -1;
   1.194  	} else if (cursor->mform_p) {
   1.195  		graf_mouse(USER_DEF, cursor->mform_p);
   1.196  	}
   1.197 -
   1.198 +*/
   1.199  #ifdef DEBUG_VIDEO_GEM
   1.200 -	printf("sdl:video:gem: ShowWMCursor(0x%08x)\n", (long) cursor);
   1.201 +    printf("sdl:video:gem: ShowWMCursor(0x%08x)\n", (long) cursor);
   1.202  #endif
   1.203  
   1.204 -	return 1;
   1.205 +    return 1;
   1.206  }
   1.207  
   1.208  #if 0
   1.209 -void GEM_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
   1.210 +void
   1.211 +GEM_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
   1.212  {
   1.213 -	/* This seems to work only on AES 3.4 (Falcon) */
   1.214 +    /* This seems to work only on AES 3.4 (Falcon) */
   1.215  
   1.216 -	EVNTREC	warpevent;
   1.217 -	
   1.218 -	warpevent.ap_event = APPEVNT_MOUSE; 
   1.219 -	warpevent.ap_value = (x << 16) | y;
   1.220 +    EVNTREC warpevent;
   1.221  
   1.222 -	appl_tplay(&warpevent, 1, 1000);
   1.223 +    warpevent.ap_event = APPEVNT_MOUSE;
   1.224 +    warpevent.ap_value = (x << 16) | y;
   1.225 +
   1.226 +    appl_tplay(&warpevent, 1, 1000);
   1.227  }
   1.228  #endif
   1.229  
   1.230 -void GEM_CheckMouseMode(_THIS)
   1.231 +void
   1.232 +GEM_CheckMouseMode(_THIS)
   1.233  {
   1.234 -#ifdef DEBUG_VIDEO_GEM
   1.235 -	printf("sdl:video:gem: check mouse mode\n");
   1.236 -#endif
   1.237 +    /* If the mouse is hidden and input is grabbed, we use relative mode */
   1.238 +    if ((!(SDL_cursorstate & CURSOR_VISIBLE)) &&
   1.239 +        /*(this->input_grab != SDL_GRAB_OFF) && *//* Damn GEM can not grab */
   1.240 +        (SDL_GetAppState() & SDL_APPACTIVE)) {
   1.241 +        GEM_mouse_relative = SDL_TRUE;
   1.242 +    } else {
   1.243 +        GEM_mouse_relative = SDL_FALSE;
   1.244 +    }
   1.245 +}
   1.246  
   1.247 -	/* If the mouse is hidden and input is grabbed, we use relative mode */
   1.248 -	if ( (!(SDL_cursorstate & CURSOR_VISIBLE)) &&
   1.249 -		/*(this->input_grab != SDL_GRAB_OFF) && */ /* Damn GEM can not grab */
   1.250 -             (SDL_GetAppState() & SDL_APPACTIVE) ) {
   1.251 -		GEM_mouse_relative = SDL_TRUE;
   1.252 -	} else {
   1.253 -		GEM_mouse_relative = SDL_FALSE;
   1.254 -	}
   1.255 -}
   1.256 +/* vi: set ts=4 sw=4 expandtab: */