Public Types | |
enum | Direction { Left = 0, Right = 1, Up = 2, Down = 3 } |
Public Member Functions | |
uJoystick (int id_) | |
uInput * | GetAxis (int index, int dir) |
uInput * | GetButton (int index) |
uInput * | GetBall (int index, Direction dir) |
uInput * | GetHat (int index, Direction dir) |
int & | GetHatDirection (int index, int axis) |
Public Attributes | |
int | id |
tString | name |
tString | internalName |
int | numAxes |
int | numButtons |
int | numBalls |
int | numHats |
Private Member Functions | |
tString | GetPersistentID (char const *type, int subID, char const *suffix=NULL) const |
tString | GetName (char const *type, int subID, char const *suffix=NULL) const |
tString | GetName (char const *type) const |
Private Attributes | |
uInputs | axes [2] |
uInputs | buttons |
uInputs | balls [4] |
uInputs | hats [4] |
std::vector< HatDirections > | hatDirection |
Classes | |
struct | HatDirections |
Definition at line 441 of file uInput.cpp.
enum uJoystick::Direction |
uJoystick::uJoystick | ( | int | id_ | ) | [inline] |
Definition at line 460 of file uInput.cpp.
References axes, c, uAction::internalName, isblank(), su_NewInput(), and tASSERT.
00461 : id( id_ ) 00462 { 00463 tASSERT( id >= 0 && id < SDL_NumJoysticks() ); 00464 00465 name = SDL_JoystickName( id ); 00466 00467 std::ostringstream iName; 00468 iName << "JOYSTICK_"; 00469 for ( char const * c = name.c_str(); *c; ++c ) 00470 { 00471 if ( isblank( *c ) ) 00472 { 00473 iName << "_"; 00474 } 00475 else 00476 { 00477 iName << char(toupper( *c )); 00478 } 00479 } 00480 00481 internalName = iName.str(); 00482 00483 SDL_Joystick * stick = SDL_JoystickOpen( id ); 00484 numAxes = SDL_JoystickNumAxes( stick ); 00485 numButtons = SDL_JoystickNumButtons( stick ); 00486 numBalls = SDL_JoystickNumBalls( stick ); 00487 numHats = SDL_JoystickNumHats( stick ); 00488 00489 // populate input types 00490 if ( numAxes >= 1 ) 00491 { 00492 axes[0].push_back( su_NewInput( GetPersistentID( "AXIS", 0, "-" ), GetName( "left" ) ) ); 00493 axes[1].push_back( su_NewInput( GetPersistentID( "AXIS", 0, "+" ), GetName( "right" ) ) ); 00494 } 00495 00496 if ( numAxes >= 2 ) 00497 { 00498 axes[0].push_back( su_NewInput( GetPersistentID( "AXIS", 1, "-" ), GetName( "up" ) ) ); 00499 axes[1].push_back( su_NewInput( GetPersistentID( "AXIS", 1, "+" ), GetName( "down" ) ) ); 00500 } 00501 00502 for ( int axis = 2; axis < numAxes; ++axis ) 00503 { 00504 axes[0].push_back( su_NewInput( GetPersistentID( "AXIS", axis, "-" ), GetName( "axis", axis, "-" ) ) ); 00505 axes[1].push_back( su_NewInput( GetPersistentID( "AXIS", axis, "+" ), GetName( "axis", axis, "+" ) ) ); 00506 } 00507 00508 for ( int button = 0; button < numButtons; ++button ) 00509 { 00510 buttons.push_back( su_NewInput( GetPersistentID( "BUTTON", button ), GetName( "button", button ) ) ); 00511 } 00512 00513 char const * directionInternal[] = { "LEFT", "RIGHT", "UP", "DOWN" }; 00514 char const * directionHuman[] = { "left", "right", "up", "down" }; 00515 00516 for ( int dir = 0; dir < 4; ++dir ) 00517 { 00518 char const * internal = directionInternal[dir]; 00519 char const * human = directionHuman[dir]; 00520 00521 for ( int ball = 0; ball < numBalls; ++ball ) 00522 { 00523 balls[dir].push_back( su_NewInput( GetPersistentID( "BALL", ball, internal ), GetName( "ball", ball, human ) ) ); 00524 } 00525 00526 for ( int hat = 0; hat < numHats; ++hat ) 00527 { 00528 hats[dir].push_back( su_NewInput( GetPersistentID( "HAT", hat, internal ), GetName( "hat", hat, human ) ) ); 00529 } 00530 } 00531 00532 hatDirection.resize( numHats );
uInput* uJoystick::GetAxis | ( | int | index, | |
int | dir | |||
) | [inline] |
Definition at line 534 of file uInput.cpp.
Referenced by su_TransformEvent().
00536 { 00537 tASSERT( index >= 0 && index < numAxes ); 00538 tASSERT( 0 == dir || 1 == dir ); 00539 00540 axes[1-dir][index]->SetPressed(0); 00541 return axes[dir][index];
uInput* uJoystick::GetButton | ( | int | index | ) | [inline] |
Definition at line 543 of file uInput.cpp.
References tASSERT.
Referenced by su_TransformEvent().
00545 { 00546 tASSERT( index >= 0 && index < numButtons ); 00547 00548 return buttons[index];
Definition at line 550 of file uInput.cpp.
References tASSERT.
Referenced by su_TransformEvent().
00552 { 00553 tASSERT( index >= 0 && index < numBalls ); 00554 00555 balls[dir ^ 1][index]->SetPressed(0); 00556 return balls[dir][index];
Definition at line 558 of file uInput.cpp.
References tASSERT.
Referenced by su_TransformEvent().
00560 { 00561 tASSERT( index >= 0 && index < numHats ); 00562 00563 hats[dir ^ 1][index]->SetPressed(0); 00564 return hats[dir][index];
int& uJoystick::GetHatDirection | ( | int | index, | |
int | axis | |||
) | [inline] |
Definition at line 566 of file uInput.cpp.
References tASSERT.
Referenced by su_TransformEvent().
00568 { 00569 tASSERT( index >= 0 && index < numHats ); 00570 tASSERT( 0 == axis || 1 == axis ); 00571 00572 return hatDirection[index].dir[axis];
tString uJoystick::GetPersistentID | ( | char const * | type, | |
int | subID, | |||
char const * | suffix = NULL | |||
) | const [inline, private] |
Definition at line 588 of file uInput.cpp.
References uAction::internalName.
00590 { 00591 std::ostringstream o; 00592 o << internalName << "_" << type << "_" << subID; 00593 if ( suffix ) 00594 { 00595 o << "_" << suffix; 00596 } 00597 return o.str();
tString uJoystick::GetName | ( | char const * | type, | |
int | subID, | |||
char const * | suffix = NULL | |||
) | const [inline, private] |
Definition at line 600 of file uInput.cpp.
00602 { 00603 std::ostringstream o; 00604 o << "Joystick " << id+1 << " " << type << " " << subID+1; 00605 if ( suffix ) 00606 { 00607 o << " " << suffix; 00608 } 00609 return o.str();
tString uJoystick::GetName | ( | char const * | type | ) | const [inline, private] |
Definition at line 612 of file uInput.cpp.
00612 : x and y 00613 tString GetName( char const * type ) const 00614 { 00615 std::ostringstream o; 00616 o << "Joystick " << id+1 << " " << type; 00617 return o.str();
int uJoystick::id |
Definition at line 444 of file uInput.cpp.
Definition at line 447 of file uInput.cpp.
Definition at line 447 of file uInput.cpp.
Definition at line 450 of file uInput.cpp.
Definition at line 450 of file uInput.cpp.
Definition at line 450 of file uInput.cpp.
Definition at line 450 of file uInput.cpp.
uInputs uJoystick::axes[2] [private] |
Definition at line 575 of file uInput.cpp.
uInputs uJoystick::buttons [private] |
Definition at line 575 of file uInput.cpp.
uInputs uJoystick::balls[4] [private] |
Definition at line 575 of file uInput.cpp.
uInputs uJoystick::hats[4] [private] |
Definition at line 575 of file uInput.cpp.
std::vector< HatDirections > uJoystick::hatDirection [private] |
Definition at line 585 of file uInput.cpp.