[Scummvm-cvs-logs] CVS: scummvm/backends/sdl sdl-common.h,1.14,1.15 sdl-common.cpp,1.29,1.30
Jonathan Gray
khalek at users.sourceforge.net
Mon Jan 20 08:30:05 CET 2003
Update of /cvsroot/scummvm/scummvm/backends/sdl
In directory sc8-pr-cvs1:/tmp/cvs-serv726
Modified Files:
sdl-common.h sdl-common.cpp
Log Message:
start of joystick support, just selects first joystick for now and only maps first two buttons to first two mouse buttons. Will add more button mappings and a -j options to specify joystick in future
Index: sdl-common.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/sdl/sdl-common.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- sdl-common.h 9 Jan 2003 08:07:13 -0000 1.14
+++ sdl-common.h 20 Jan 2003 16:29:26 -0000 1.15
@@ -181,6 +181,9 @@
MousePos() : x(0), y(0), w(0), h(0) {}
};
+ // joystick
+ SDL_Joystick *_joystick;
+
bool _mouseVisible;
bool _mouseDrawn;
byte *_mouseData;
@@ -214,6 +217,7 @@
void setup_icon();
void kbd_mouse();
+ void init_joystick() { _joystick = SDL_JoystickOpen(0); }
static OSystem_SDL_Common *create();
};
Index: sdl-common.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/sdl/sdl-common.cpp,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- sdl-common.cpp 15 Jan 2003 02:11:36 -0000 1.29
+++ sdl-common.cpp 20 Jan 2003 16:29:26 -0000 1.30
@@ -42,7 +42,7 @@
syst->_mode = gfx_mode;
syst->_full_screen = full_screen;
- if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) ==-1) {
+ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK) ==-1) {
error("Could not initialize SDL: %s.\n", SDL_GetError());
}
@@ -62,6 +62,12 @@
atexit(atexit_proc);
#endif
+ // enable joystick
+ if (SDL_NumJoysticks() > 0) {
+ printf("Using joystick: %s\n", SDL_JoystickName(0));
+ syst->init_joystick();
+ }
+
return syst;
}
@@ -85,6 +91,7 @@
// reset mouse state
memset(&km, 0, sizeof(km));
+
}
OSystem_SDL_Common::~OSystem_SDL_Common()
@@ -639,6 +646,52 @@
event->mouse.x /= _scaleFactor;
event->mouse.y /= _scaleFactor;
return true;
+
+ case SDL_JOYBUTTONDOWN:
+ if (ev.jbutton.button == 0) {
+ event->event_code = EVENT_LBUTTONDOWN;
+ }
+ if (ev.jbutton.button == 1) {
+ event->event_code = EVENT_RBUTTONDOWN;
+ }
+ return true;
+
+ case SDL_JOYBUTTONUP:
+ if (ev.jbutton.button == 0) {
+ event->event_code = EVENT_LBUTTONUP;
+ }
+ if (ev.jbutton.button == 1) {
+ event->event_code = EVENT_RBUTTONUP;
+ }
+ return true;
+
+ case SDL_JOYAXISMOTION:
+ if ( ev.jaxis.axis == 0) {
+ if (ev.jaxis.value < -3200) { // left
+ km.x_vel = -1;
+ km.x_down_count = 1;
+ } else if (ev.jaxis.value > 3200) { // right
+ km.x_vel = 1;
+ km.x_down_count = 1;
+ } else { // neither
+ km.x_vel = 0;
+ km.x_down_count = 0;
+ }
+
+
+ } else if (ev.jaxis.axis == 1) {
+ if (ev.jaxis.value < -3200) { // up
+ km.y_vel = -1;
+ km.y_down_count = 1;
+ } else if (ev.jaxis.value > 3200) { // down
+ km.y_vel = 1;
+ km.y_down_count = 1;
+ } else {
+ km.y_vel = 0;
+ km.y_down_count = 0;
+ }
+ }
+ return true;
case SDL_QUIT:
quit();
More information about the Scummvm-git-logs
mailing list