Project part 2 gsoc2008_manymouse
authorSzymon Wilczek
Wed, 30 Jul 2008 16:20:32 +0000
branchgsoc2008_manymouse
changeset 3769fe32943f86ec
parent 3768 1b87a8beab9d
child 3770 81b649bad6d2
Project part 2
src/events/SDL_mouse.c
src/events/SDL_mouse_c.h
     1.1 --- a/src/events/SDL_mouse.c	Wed Jul 30 16:09:24 2008 +0000
     1.2 +++ b/src/events/SDL_mouse.c	Wed Jul 30 16:20:32 2008 +0000
     1.3 @@ -56,7 +56,8 @@
     1.4  {
     1.5      SDL_Mouse **mice;
     1.6      int selected_mouse;
     1.7 -    //char* temp_name;
     1.8 +	int length;
     1.9 +
    1.10      /* Add the mouse to the list of mice */
    1.11      if (index < 0 || index >= SDL_num_mice || SDL_mice[index]) {
    1.12          mice =
    1.13 @@ -76,8 +77,10 @@
    1.14          return -1;
    1.15      }
    1.16      *SDL_mice[index] = *mouse;
    1.17 -    SDL_mice[index]->name=SDL_malloc(SDL_strlen(name)*sizeof(char));
    1.18 -    SDL_strlcpy(SDL_mice[index]->name,name,255);
    1.19 +	length=0;
    1.20 +	length=SDL_strlen(name);
    1.21 +    SDL_mice[index]->name=SDL_malloc((length+1)*sizeof(char));
    1.22 +    SDL_strlcpy(SDL_mice[index]->name,name,length);
    1.23      SDL_mice[index]->pressure_max=pressure_max;
    1.24      SDL_mice[index]->pressure_min=pressure_min;
    1.25      SDL_mice[index]->cursor_shown = SDL_TRUE;
    1.26 @@ -356,7 +359,14 @@
    1.27      int posted;
    1.28      int xrel;
    1.29      int yrel;
    1.30 -
    1.31 +	if(x>x_max)
    1.32 +	{
    1.33 +		x=x_max;
    1.34 +	}
    1.35 +	if(y>y_max)
    1.36 +	{
    1.37 +		y=y_max;
    1.38 +	}
    1.39      if (!mouse || mouse->flush_motion) {
    1.40          return 0;
    1.41      }
    1.42 @@ -430,7 +440,7 @@
    1.43      if (SDL_ProcessEvents[SDL_MOUSEMOTION] == SDL_ENABLE && SDL_mice[index]->proximity==SDL_TRUE) {
    1.44          SDL_Event event;
    1.45          event.motion.type = SDL_MOUSEMOTION;
    1.46 -event.motion.which = (Uint8) index;
    1.47 +		event.motion.which = (Uint8) index;
    1.48          event.motion.state = mouse->buttonstate;
    1.49          event.motion.x = mouse->x;
    1.50          event.motion.y = mouse->y;
    1.51 @@ -572,7 +582,7 @@
    1.52      /* Make sure the width is a multiple of 8 */
    1.53      w = ((w + 7) & ~7);
    1.54  
    1.55 -    /* Create the surface from a bitmap */
    1.56 +    /* Create the surface from a bitmap*/
    1.57      surface =
    1.58          SDL_CreateRGBSurface(0, w, h, 32, 0x00FF0000, 0x0000FF00, 0x000000FF,
    1.59                               0xFF000000);
    1.60 @@ -777,3 +787,4 @@
    1.61      y_max=y;
    1.62  }
    1.63  /* vi: set ts=4 sw=4 expandtab: */
    1.64 +
     2.1 --- a/src/events/SDL_mouse_c.h	Wed Jul 30 16:09:24 2008 +0000
     2.2 +++ b/src/events/SDL_mouse_c.h	Wed Jul 30 16:20:32 2008 +0000
     2.3 @@ -1,131 +1,132 @@
     2.4 -/*
     2.5 -    SDL - Simple DirectMedia Layer
     2.6 -    Copyright (C) 1997-2006 Sam Lantinga
     2.7 -
     2.8 -    This library is free software; you can redistribute it and/or
     2.9 -    modify it under the terms of the GNU Lesser General Public
    2.10 -    License as published by the Free Software Foundation; either
    2.11 -    version 2.1 of the License, or (at your option) any later version.
    2.12 -
    2.13 -    This library is distributed in the hope that it will be useful,
    2.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    2.16 -    Lesser General Public License for more details.
    2.17 -
    2.18 -    You should have received a copy of the GNU Lesser General Public
    2.19 -    License along with this library; if not, write to the Free Software
    2.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    2.21 -
    2.22 -    Sam Lantinga
    2.23 -    slouken@libsdl.org
    2.24 -*/
    2.25 -#include "SDL_config.h"
    2.26 -
    2.27 -#ifndef _SDL_mouse_c_h
    2.28 -#define _SDL_mouse_c_h
    2.29 -
    2.30 -typedef struct SDL_Mouse SDL_Mouse;
    2.31 -
    2.32 -struct SDL_Cursor
    2.33 -{
    2.34 -    SDL_Mouse *mouse;
    2.35 -
    2.36 -    SDL_Cursor *next;
    2.37 -
    2.38 -    void *driverdata;
    2.39 -};
    2.40 -
    2.41 -struct SDL_Mouse
    2.42 -{
    2.43 -    /* Create a cursor from a surface */
    2.44 -    SDL_Cursor *(*CreateCursor) (SDL_Surface * surface, int hot_x, int hot_y);
    2.45 -
    2.46 -    /* Show the specified cursor, or hide if cursor is NULL */
    2.47 -    int (*ShowCursor) (SDL_Cursor * cursor);
    2.48 -
    2.49 -    /* This is called when a mouse motion event occurs */
    2.50 -    void (*MoveCursor) (SDL_Cursor * cursor);
    2.51 -
    2.52 -    /* Free a window manager cursor */
    2.53 -    void (*FreeCursor) (SDL_Cursor * cursor);
    2.54 -
    2.55 -    /* Warp the mouse to (x,y) */
    2.56 -    void (*WarpMouse) (SDL_Mouse * mouse, SDL_WindowID windowID, int x,
    2.57 -                       int y);
    2.58 -
    2.59 -    /* Free the mouse when it's time */
    2.60 -    void (*FreeMouse) (SDL_Mouse * mouse);
    2.61 -
    2.62 -    /* Data common to all mice */
    2.63 -    SDL_WindowID focus;
    2.64 -    int which;
    2.65 -    int x;
    2.66 -    int y;
    2.67 -    int z;/*for future use*/
    2.68 -    int xdelta;
    2.69 -    int ydelta;
    2.70 -    int pressure;
    2.71 -    int pressure_max;
    2.72 -    int pressure_min;
    2.73 -    int tilt;/*for future use*/
    2.74 -    int rotation;/*for future use*/
    2.75 -    char* name;
    2.76 -    Uint8 buttonstate;
    2.77 -    SDL_bool relative_mode;
    2.78 -    SDL_bool proximity;
    2.79 -    SDL_bool flush_motion;
    2.80 -
    2.81 -    SDL_Cursor *cursors;
    2.82 -    SDL_Cursor *def_cursor;
    2.83 -    SDL_Cursor *cur_cursor;
    2.84 -    SDL_bool cursor_shown;
    2.85 -
    2.86 -    void *driverdata;
    2.87 -};
    2.88 -
    2.89 -
    2.90 -/* Initialize the mouse subsystem */
    2.91 -extern int SDL_MouseInit(void);
    2.92 -
    2.93 -/* Get the mouse at an index */
    2.94 -extern SDL_Mouse *SDL_GetMouse(int index);
    2.95 -
    2.96 -/* Add a mouse, possibly reattaching at a particular index (or -1),
    2.97 -   returning the index of the mouse, or -1 if there was an error.
    2.98 - */
    2.99 -extern int SDL_AddMouse(const SDL_Mouse * mouse, int index, char* name, int pressure_max, int pressure_min);
   2.100 -
   2.101 -/* Remove a mouse at an index, clearing the slot for later */
   2.102 -extern void SDL_DelMouse(int index);
   2.103 -
   2.104 -/* Clear the button state of a mouse at an index */
   2.105 -extern void SDL_ResetMouse(int index);
   2.106 -
   2.107 -/* Set the mouse focus window */
   2.108 -extern void SDL_SetMouseFocus(int index, SDL_WindowID windowID);
   2.109 -
   2.110 -/* Send a mouse motion event for a mouse at an index */
   2.111 -extern int SDL_SendMouseMotion(int index, int relative, int x, int y, int z);
   2.112 -
   2.113 -/* Send a mouse button event for a mouse at an index */
   2.114 -extern int SDL_SendMouseButton(int index, Uint8 state, Uint8 button);
   2.115 -
   2.116 -/* Send a mouse wheel event for a mouse at an index */
   2.117 -extern int SDL_SendMouseWheel(int index, int x, int y);
   2.118 -
   2.119 -/* Shutdown the mouse subsystem */
   2.120 -extern void SDL_MouseQuit(void);
   2.121 -
   2.122 -extern int SDL_GetIndexById(int id);
   2.123 -
   2.124 -extern int SDL_SetIndexId(int id, int index);
   2.125 -
   2.126 -extern int SDL_GetNumOfMice(void);
   2.127 -
   2.128 -extern char* SDL_GetMouseName(int index);
   2.129 -
   2.130 -extern void SDL_UpdateCoordinates(int x, int y);
   2.131 -
   2.132 -#endif /* _SDL_mouse_c_h */
   2.133 -
   2.134 -/* vi: set ts=4 sw=4 expandtab: */
   2.135 +/*
   2.136 +    SDL - Simple DirectMedia Layer
   2.137 +    Copyright (C) 1997-2006 Sam Lantinga
   2.138 +
   2.139 +    This library is free software; you can redistribute it and/or
   2.140 +    modify it under the terms of the GNU Lesser General Public
   2.141 +    License as published by the Free Software Foundation; either
   2.142 +    version 2.1 of the License, or (at your option) any later version.
   2.143 +
   2.144 +    This library is distributed in the hope that it will be useful,
   2.145 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   2.146 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   2.147 +    Lesser General Public License for more details.
   2.148 +
   2.149 +    You should have received a copy of the GNU Lesser General Public
   2.150 +    License along with this library; if not, write to the Free Software
   2.151 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   2.152 +
   2.153 +    Sam Lantinga
   2.154 +    slouken@libsdl.org
   2.155 +*/
   2.156 +#include "SDL_config.h"
   2.157 +
   2.158 +#ifndef _SDL_mouse_c_h
   2.159 +#define _SDL_mouse_c_h
   2.160 +
   2.161 +typedef struct SDL_Mouse SDL_Mouse;
   2.162 +
   2.163 +struct SDL_Cursor
   2.164 +{
   2.165 +    SDL_Mouse *mouse;
   2.166 +
   2.167 +    SDL_Cursor *next;
   2.168 +
   2.169 +    void *driverdata;
   2.170 +};
   2.171 +
   2.172 +struct SDL_Mouse
   2.173 +{
   2.174 +    /* Create a cursor from a surface */
   2.175 +    SDL_Cursor *(*CreateCursor) (SDL_Surface * surface, int hot_x, int hot_y);
   2.176 +
   2.177 +    /* Show the specified cursor, or hide if cursor is NULL */
   2.178 +    int (*ShowCursor) (SDL_Cursor * cursor);
   2.179 +
   2.180 +    /* This is called when a mouse motion event occurs */
   2.181 +    void (*MoveCursor) (SDL_Cursor * cursor);
   2.182 +
   2.183 +    /* Free a window manager cursor */
   2.184 +    void (*FreeCursor) (SDL_Cursor * cursor);
   2.185 +
   2.186 +    /* Warp the mouse to (x,y) */
   2.187 +    void (*WarpMouse) (SDL_Mouse * mouse, SDL_WindowID windowID, int x,
   2.188 +                       int y);
   2.189 +
   2.190 +    /* Free the mouse when it's time */
   2.191 +    void (*FreeMouse) (SDL_Mouse * mouse);
   2.192 +
   2.193 +    /* Data common to all mice */
   2.194 +    SDL_WindowID focus;
   2.195 +    int which;
   2.196 +    int x;
   2.197 +    int y;
   2.198 +    int z;/*for future use*/
   2.199 +    int xdelta;
   2.200 +    int ydelta;
   2.201 +    int pressure;
   2.202 +    int pressure_max;
   2.203 +    int pressure_min;
   2.204 +    int tilt;/*for future use*/
   2.205 +    int rotation;/*for future use*/
   2.206 +    char* name;
   2.207 +    Uint8 buttonstate;
   2.208 +    SDL_bool relative_mode;
   2.209 +    SDL_bool proximity;
   2.210 +    SDL_bool flush_motion;
   2.211 +
   2.212 +    SDL_Cursor *cursors;
   2.213 +    SDL_Cursor *def_cursor;
   2.214 +    SDL_Cursor *cur_cursor;
   2.215 +    SDL_bool cursor_shown;
   2.216 +
   2.217 +    void *driverdata;
   2.218 +};
   2.219 +
   2.220 +
   2.221 +/* Initialize the mouse subsystem */
   2.222 +extern int SDL_MouseInit(void);
   2.223 +
   2.224 +/* Get the mouse at an index */
   2.225 +extern SDL_Mouse *SDL_GetMouse(int index);
   2.226 +
   2.227 +/* Add a mouse, possibly reattaching at a particular index (or -1),
   2.228 +   returning the index of the mouse, or -1 if there was an error.
   2.229 + */
   2.230 +extern int SDL_AddMouse(const SDL_Mouse * mouse, int index, char* name, int pressure_max, int pressure_min);
   2.231 +
   2.232 +/* Remove a mouse at an index, clearing the slot for later */
   2.233 +extern void SDL_DelMouse(int index);
   2.234 +
   2.235 +/* Clear the button state of a mouse at an index */
   2.236 +extern void SDL_ResetMouse(int index);
   2.237 +
   2.238 +/* Set the mouse focus window */
   2.239 +extern void SDL_SetMouseFocus(int index, SDL_WindowID windowID);
   2.240 +
   2.241 +/* Send a mouse motion event for a mouse at an index */
   2.242 +extern int SDL_SendMouseMotion(int index, int relative, int x, int y, int z);
   2.243 +
   2.244 +/* Send a mouse button event for a mouse at an index */
   2.245 +extern int SDL_SendMouseButton(int index, Uint8 state, Uint8 button);
   2.246 +
   2.247 +/* Send a mouse wheel event for a mouse at an index */
   2.248 +extern int SDL_SendMouseWheel(int index, int x, int y);
   2.249 +
   2.250 +/* Shutdown the mouse subsystem */
   2.251 +extern void SDL_MouseQuit(void);
   2.252 +
   2.253 +extern int SDL_GetIndexById(int id);
   2.254 +
   2.255 +extern int SDL_SetIndexId(int id, int index);
   2.256 +
   2.257 +extern int SDL_GetNumOfMice(void);
   2.258 +
   2.259 +extern char* SDL_GetMouseName(int index);
   2.260 +
   2.261 +extern void SDL_UpdateCoordinates(int x, int y);
   2.262 +
   2.263 +#endif /* _SDL_mouse_c_h */
   2.264 +
   2.265 +/* vi: set ts=4 sw=4 expandtab: */
   2.266 +