Navigation Menu

Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Cursor support added
Browse files Browse the repository at this point in the history
  • Loading branch information
Szymon Wilczek committed Aug 5, 2008
1 parent a1f6dc4 commit 66a97b5
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 6 deletions.
1 change: 1 addition & 0 deletions include/SDL_events.h
Expand Up @@ -180,6 +180,7 @@ typedef struct SDL_MouseMotionEvent
int pressure_min; /**< Minimum value of the pressure reported by the device*/
int rotation; /**<For future use */
int tilt; /**<For future use */
int cursor; /**< The cursor being used in the event */
int xrel; /**< The relative motion in the X direction */
int yrel; /**< The relative motion in the Y direction */
SDL_WindowID windowID; /**< The window with mouse focus, if any */
Expand Down
2 changes: 2 additions & 0 deletions include/SDL_mouse.h
Expand Up @@ -208,6 +208,8 @@ extern DECLSPEC int SDLCALL SDL_GetNumOfMice(void);

extern DECLSPEC char* SDLCALL SDL_GetMouseName(int index);

extern DECLSPEC int SDLCALL SDL_GetCursorsNumber(int index);

#define SDL_BUTTON(X) (1 << ((X)-1))
#define SDL_BUTTON_LEFT 1
#define SDL_BUTTON_MIDDLE 2
Expand Down
25 changes: 24 additions & 1 deletion src/events/SDL_mouse.c
Expand Up @@ -52,7 +52,8 @@ SDL_GetMouse(int index)
}

int
SDL_AddMouse(const SDL_Mouse * mouse, int index, char* name,int pressure_max,int pressure_min)
SDL_AddMouse(const SDL_Mouse * mouse, int index, char* name,int pressure_max,\
int pressure_min, int ends)
{
SDL_Mouse **mice;
int selected_mouse;
Expand Down Expand Up @@ -98,6 +99,8 @@ SDL_AddMouse(const SDL_Mouse * mouse, int index, char* name,int pressure_max,int
thanx to that, the users that don't want to use many mouses don't have to
worry about anything*/
SDL_mice[index]->relative_mode=SDL_FALSE;
SDL_mice[index]->current_end=0;
SDL_mice[index]->total_ends=ends;
SDL_SelectMouse(selected_mouse);

return index;
Expand Down Expand Up @@ -460,6 +463,7 @@ SDL_SendMouseMotion(int id, int relative, int x, int y,int z)
event.motion.windowID = mouse->focus;
event.motion.pressure_max=mouse->pressure_max;
event.motion.pressure_min=mouse->pressure_min;
event.motion.cursor=SDL_mice[index]->current_end;
posted = (SDL_PushEvent(&event) > 0);
}
last_x=x;
Expand Down Expand Up @@ -796,5 +800,24 @@ void SDL_UpdateCoordinates(int x, int y)
x_max=x;
y_max=y;
}

void SDL_ChangeEnd(int id, int end)
{
int index=SDL_GetIndexById(id);
SDL_mice[index]->current_end=end;
}

int SDL_GetCursorsNumber(int index)
{
if(index>=SDL_num_mice)
{
return -1;
}
if(SDL_mice[index]==NULL)
{
return -1;
}
return SDL_mice[index]->total_ends;
}
/* vi: set ts=4 sw=4 expandtab: */

9 changes: 8 additions & 1 deletion src/events/SDL_mouse_c.h
Expand Up @@ -62,6 +62,8 @@ struct SDL_Mouse
int pressure_min;
int tilt;/*for future use*/
int rotation;/*for future use*/
int total_ends;
int current_end;

/* Data common to all mice */
SDL_WindowID focus;
Expand Down Expand Up @@ -96,7 +98,8 @@ extern SDL_Mouse *SDL_GetMouse(int index);
/* Add a mouse, possibly reattaching at a particular index (or -1),
returning the index of the mouse, or -1 if there was an error.
*/
extern int SDL_AddMouse(const SDL_Mouse * mouse, int index, char* name, int pressure_max, int pressure_min);
extern int SDL_AddMouse(const SDL_Mouse * mouse, int index, char* name,\
int pressure_max, int pressure_min, int ends);

/* Remove a mouse at an index, clearing the slot for later */
extern void SDL_DelMouse(int index);
Expand Down Expand Up @@ -129,6 +132,10 @@ extern char* SDL_GetMouseName(int index);

extern void SDL_UpdateCoordinates(int x, int y);

extern void SDL_ChangeEnd(int id, int end);

extern int SDL_GetCursorsNumber(int index);

#endif /* _SDL_mouse_c_h */

/* vi: set ts=4 sw=4 expandtab: */
Expand Down
3 changes: 2 additions & 1 deletion src/video/win32/SDL_win32events.c
Expand Up @@ -32,7 +32,7 @@
#include "SDL_vkeys.h"
#include "../../events/SDL_events_c.h"
#include <wintab.h>
#define PACKETDATA ( PK_X | PK_Y | PK_BUTTONS | PK_NORMAL_PRESSURE)
#define PACKETDATA ( PK_X | PK_Y | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_CURSOR)
#define PACKETMODE 0
#include <pktdef.h>

Expand Down Expand Up @@ -141,6 +141,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
/*if we receive such data we need to update the pressure*/
if (WTPacket((HCTX)lParam, wParam, &packet))
{
SDL_ChangeEnd(tablet, (int)packet.pkCursor);
pressure=(int)packet.pkNormalPressure;
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/video/win32/SDL_win32mouse.c
Expand Up @@ -34,7 +34,7 @@
#include "../../events/SDL_mouse_c.h"

#include <wintab.h>
#define PACKETDATA ( PK_X | PK_Y | PK_BUTTONS | PK_NORMAL_PRESSURE)
#define PACKETDATA ( PK_X | PK_Y | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_CURSOR)
#define PACKETMODE 0
#include <pktdef.h>

Expand Down Expand Up @@ -176,12 +176,14 @@ WIN_InitMouse(_THIS)
if(tablet==index)
{
AXIS pressure;
int cursors;
WTInfo(WTI_DEVICES,DVC_NPRESSURE, &pressure);
data->mouse = SDL_AddMouse(&mouse, index,device_name,pressure.axMax,pressure.axMin);
WTInfo(WTI_DEVICES,DVC_NCSRTYPES, &cursors);
data->mouse = SDL_AddMouse(&mouse, index,device_name,pressure.axMax,pressure.axMin,cursors);
}
else
{
data->mouse = SDL_AddMouse(&mouse, index,device_name,0,0);
data->mouse = SDL_AddMouse(&mouse, index,device_name,0,0,1);
}
++index;

Expand Down

0 comments on commit 66a97b5

Please sign in to comment.