2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2005-01-23 01:36:29 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2008-04-16 22:40:48 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2005-01-23 01:36:29 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-01-23 01:36:29 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): snailrose.
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2005-01-23 01:36:29 +00:00
|
|
|
*/
|
2011-02-25 13:32:11 +00:00
|
|
|
|
|
|
|
/** \file gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp
|
|
|
|
* \ingroup gamelogic
|
|
|
|
*/
|
|
|
|
|
2011-10-20 00:19:21 +00:00
|
|
|
#ifdef WITH_SDL
|
|
|
|
# include <SDL.h>
|
2008-10-07 05:09:24 +00:00
|
|
|
#endif
|
|
|
|
|
2005-01-23 01:36:29 +00:00
|
|
|
#include "SCA_Joystick.h"
|
|
|
|
#include "SCA_JoystickPrivate.h"
|
|
|
|
|
2005-03-25 10:33:39 +00:00
|
|
|
|
2011-10-20 00:19:21 +00:00
|
|
|
#ifdef WITH_SDL
|
2008-09-02 06:12:19 +00:00
|
|
|
void SCA_Joystick::OnAxisMotion(SDL_Event* sdl_event)
|
2005-01-23 01:36:29 +00:00
|
|
|
{
|
2009-05-25 06:24:23 +00:00
|
|
|
if(sdl_event->jaxis.axis >= JOYAXIS_MAX)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_axis_array[sdl_event->jaxis.axis]= sdl_event->jaxis.value;
|
2008-10-08 03:16:19 +00:00
|
|
|
m_istrig_axis = 1;
|
2005-01-23 01:36:29 +00:00
|
|
|
}
|
|
|
|
|
2009-05-28 13:44:32 +00:00
|
|
|
/* See notes below in the event loop */
|
2008-09-02 06:12:19 +00:00
|
|
|
void SCA_Joystick::OnHatMotion(SDL_Event* sdl_event)
|
2005-01-23 01:36:29 +00:00
|
|
|
{
|
2009-06-03 04:12:59 +00:00
|
|
|
if(sdl_event->jhat.hat >= JOYHAT_MAX)
|
2009-05-25 06:24:23 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
m_hat_array[sdl_event->jhat.hat]= sdl_event->jhat.value;
|
2008-10-08 03:16:19 +00:00
|
|
|
m_istrig_hat = 1;
|
2005-01-23 01:36:29 +00:00
|
|
|
}
|
|
|
|
|
2009-05-28 13:44:32 +00:00
|
|
|
/* See notes below in the event loop */
|
2008-09-02 06:12:19 +00:00
|
|
|
void SCA_Joystick::OnButtonUp(SDL_Event* sdl_event)
|
2005-01-23 01:36:29 +00:00
|
|
|
{
|
2008-10-08 03:16:19 +00:00
|
|
|
m_istrig_button = 1;
|
2005-01-23 01:36:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-02 06:12:19 +00:00
|
|
|
void SCA_Joystick::OnButtonDown(SDL_Event* sdl_event)
|
2005-01-23 01:36:29 +00:00
|
|
|
{
|
2009-05-28 13:44:32 +00:00
|
|
|
//if(sdl_event->jbutton.button > m_buttonmax) /* unsigned int so always above 0 */
|
|
|
|
// return;
|
|
|
|
// sdl_event->jbutton.button;
|
|
|
|
|
|
|
|
m_istrig_button = 1;
|
2005-01-23 01:36:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-02 06:12:19 +00:00
|
|
|
void SCA_Joystick::OnNothing(SDL_Event* sdl_event)
|
2005-01-23 01:36:29 +00:00
|
|
|
{
|
2008-10-08 03:16:19 +00:00
|
|
|
m_istrig_axis = m_istrig_button = m_istrig_hat = 0;
|
2005-01-23 01:36:29 +00:00
|
|
|
}
|
2008-09-02 06:12:19 +00:00
|
|
|
|
|
|
|
void SCA_Joystick::HandleEvents(void)
|
|
|
|
{
|
|
|
|
SDL_Event sdl_event;
|
2008-10-07 05:09:24 +00:00
|
|
|
|
|
|
|
int i;
|
2009-05-28 13:44:32 +00:00
|
|
|
for (i=0; i<m_joynum; i++) { /* could use JOYINDEX_MAX but no reason to */
|
2008-10-11 00:56:49 +00:00
|
|
|
if(SCA_Joystick::m_instance[i])
|
|
|
|
SCA_Joystick::m_instance[i]->OnNothing(&sdl_event);
|
2008-10-07 05:09:24 +00:00
|
|
|
}
|
|
|
|
|
2009-05-28 13:44:32 +00:00
|
|
|
while(SDL_PollEvent(&sdl_event))
|
2008-09-02 06:12:19 +00:00
|
|
|
{
|
|
|
|
/* Note! m_instance[sdl_event.jaxis.which]
|
|
|
|
* will segfault if over JOYINDEX_MAX, not too nice but what are the chances? */
|
2009-05-28 13:44:32 +00:00
|
|
|
|
|
|
|
/* Note!, with buttons, this wont care which button is pressed,
|
|
|
|
* only to set 'm_istrig_button', actual pressed buttons are detected by SDL_JoystickGetButton */
|
|
|
|
|
|
|
|
/* Note!, if you manage to press and release a button within 1 logic tick
|
|
|
|
* it wont work as it should */
|
|
|
|
|
2008-09-02 06:12:19 +00:00
|
|
|
switch(sdl_event.type)
|
|
|
|
{
|
|
|
|
case SDL_JOYAXISMOTION:
|
|
|
|
SCA_Joystick::m_instance[sdl_event.jaxis.which]->OnAxisMotion(&sdl_event);
|
|
|
|
break;
|
|
|
|
case SDL_JOYHATMOTION:
|
|
|
|
SCA_Joystick::m_instance[sdl_event.jhat.which]->OnHatMotion(&sdl_event);
|
|
|
|
break;
|
|
|
|
case SDL_JOYBUTTONUP:
|
|
|
|
SCA_Joystick::m_instance[sdl_event.jbutton.which]->OnButtonUp(&sdl_event);
|
|
|
|
break;
|
|
|
|
case SDL_JOYBUTTONDOWN:
|
|
|
|
SCA_Joystick::m_instance[sdl_event.jbutton.which]->OnButtonDown(&sdl_event);
|
|
|
|
break;
|
2009-04-07 06:23:45 +00:00
|
|
|
#if 0 /* Not used yet */
|
2008-09-02 06:12:19 +00:00
|
|
|
case SDL_JOYBALLMOTION:
|
|
|
|
SCA_Joystick::m_instance[sdl_event.jball.which]->OnBallMotion(&sdl_event);
|
|
|
|
break;
|
2009-04-07 06:23:45 +00:00
|
|
|
#endif
|
2008-09-02 06:12:19 +00:00
|
|
|
default:
|
|
|
|
printf("SCA_Joystick::HandleEvents, Unknown SDL event, this should not happen\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-10-20 00:19:21 +00:00
|
|
|
#endif /* WITH_SDL */
|