|
From: knittl <kn...@us...> - 2009-08-03 08:40:39
|
Module: performous
Branch: master
Commit: f1a97897ece494bb563679560250ea10f8f81227
Author: Vincent Le Ligeour <yo...@us...>
Date: Sat Aug 1 17:27:17 2009 +0200
Added pick events
---
game/joystick.cc | 28 ++++++++++++++++++++++++++--
game/joystick.hh | 6 ++++++
2 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/game/joystick.cc b/game/joystick.cc
index eb01fa5..e115e00 100644
--- a/game/joystick.cc
+++ b/game/joystick.cc
@@ -104,14 +104,38 @@ void input::init() {
bool input::pushEvent(SDL_Event _e) {
int joy_id;
using namespace input::Private;
+
+ Event event;
switch(_e.type) {
case SDL_JOYAXISMOTION:
joy_id = _e.jaxis.which;
- // do stuffs to devices[joy_id] events (PICK)
+
+ event.type = input::Event::PICK;
+ for( unsigned int i = 0 ; i < BUTTONS ; ++i ) {
+ event.pressed[i] = devices[joy_id].pressed(i);
+ }
+ if(_e.jaxis.value > 0 ) { // down
+ event.button = 0;
+ devices[joy_id].addEvent(event);
+ } else if(_e.jaxis.value < 0 ) { // up
+ event.button = 1;
+ devices[joy_id].addEvent(event);
+ }
break;
case SDL_JOYHATMOTION:
joy_id = _e.jhat.which;
- // do stuffs to devices[joy_id] events (PICK)
+
+ event.type = input::Event::PICK;
+ for( unsigned int i = 0 ; i < BUTTONS ; ++i ) {
+ event.pressed[i] = devices[joy_id].pressed(i);
+ }
+ if(_e.jhat.value == SDL_HAT_DOWN ) {
+ event.button = 0;
+ devices[joy_id].addEvent(event);
+ } else if(_e.jhat.value == SDL_HAT_UP ) {
+ event.button = 1;
+ devices[joy_id].addEvent(event);
+ }
break;
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
diff --git a/game/joystick.hh b/game/joystick.hh
index e65e7d4..6e2c004 100644
--- a/game/joystick.hh
+++ b/game/joystick.hh
@@ -35,6 +35,12 @@ namespace input {
void addEvent(Event _event) {
// only add event if the device is assigned
if( m_assigned ) m_events.push_back(_event);
+ if( _event.type == input::Event::PICK )
+ std::cout << "PICK event " << _event.button << std::endl;
+ if( _event.type == input::Event::PRESS )
+ std::cout << "PRESS event " << _event.button << std::endl;
+ if( _event.type == input::Event::RELEASE )
+ std::cout << "RELEASE event " << _event.button << std::endl;
// always keep track of button status
for( unsigned int i = 0 ; i < BUTTONS ; ++i ) {
m_pressed[i] = _event.pressed[i];
|