本文整理汇总了C++中SDL_JoystickNumButtons函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_JoystickNumButtons函数的具体用法?C++ SDL_JoystickNumButtons怎么用?C++ SDL_JoystickNumButtons使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_JoystickNumButtons函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SDL_JoystickOpen
void
JoystickManager::on_joystick_added(int joystick_index)
{
log_debug << "on_joystick_added(): " << joystick_index << std::endl;
SDL_Joystick* joystick = SDL_JoystickOpen(joystick_index);
if (!joystick)
{
log_warning << "failed to open joystick: " << joystick_index
<< ": " << SDL_GetError() << std::endl;
}
else
{
joysticks.push_back(joystick);
}
if(min_joybuttons < 0 || SDL_JoystickNumButtons(joystick) < min_joybuttons)
min_joybuttons = SDL_JoystickNumButtons(joystick);
if(SDL_JoystickNumButtons(joystick) > max_joybuttons)
max_joybuttons = SDL_JoystickNumButtons(joystick);
if(SDL_JoystickNumAxes(joystick) > max_joyaxis)
max_joyaxis = SDL_JoystickNumAxes(joystick);
if(SDL_JoystickNumHats(joystick) > max_joyhats)
max_joyhats = SDL_JoystickNumHats(joystick);
}
示例2: SDL_JoystickClose
void
JoystickKeyboardController::updateAvailableJoysticks()
{
for(std::vector<SDL_Joystick*>::iterator i = joysticks.begin();
i != joysticks.end(); ++i) {
if(*i != 0)
SDL_JoystickClose(*i);
}
joysticks.clear();
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
SDL_InitSubSystem(SDL_INIT_JOYSTICK);
int joystick_count = SDL_NumJoysticks();
min_joybuttons = -1;
max_joybuttons = -1;
max_joyaxis = -1;
max_joyhats = -1;
if( joystick_count > 0 ){
for(int i = 0; i < joystick_count; ++i) {
SDL_Joystick* joystick = SDL_JoystickOpen(i);
bool good = true;
if(SDL_JoystickNumButtons(joystick) < 2) {
log_info << "Joystick " << i << ": " << SDL_JoystickName(i) << " has less than 2 buttons" << std::endl;
good = false;
}
if(SDL_JoystickNumAxes(joystick) < 2
&& SDL_JoystickNumHats(joystick) == 0) {
log_info << "Joystick " << i << ": " << SDL_JoystickName(i) << " has less than 2 axes and no hat" << std::endl;
good = false;
}
if(!good) {
SDL_JoystickClose(joystick);
continue;
}
if(min_joybuttons < 0 || SDL_JoystickNumButtons(joystick) < min_joybuttons)
min_joybuttons = SDL_JoystickNumButtons(joystick);
if(SDL_JoystickNumButtons(joystick) > max_joybuttons)
max_joybuttons = SDL_JoystickNumButtons(joystick);
if(SDL_JoystickNumAxes(joystick) > max_joyaxis)
max_joyaxis = SDL_JoystickNumAxes(joystick);
if(SDL_JoystickNumHats(joystick) > max_joyhats)
max_joyhats = SDL_JoystickNumHats(joystick);
joysticks.push_back(joystick);
}
}
// some joysticks or SDL seem to produce some bogus events after being opened
Uint32 ticks = SDL_GetTicks();
while(SDL_GetTicks() - ticks < 200) {
SDL_Event event;
SDL_PollEvent(&event);
}
}
示例3: SDL_InitSubSystem
void ControladorJoystick::initialiseJoysticks(
std::map<string, int>* correspondenciaTeclasJ1,
std::map<string, int>* correspondenciaEjesJ1,
std::map<string, int>* correspondenciaTeclasJ2,
std::map<string, int>* correspondenciaEjesJ2) {
if(SDL_WasInit(SDL_INIT_JOYSTICK) == 0)
SDL_InitSubSystem(SDL_INIT_JOYSTICK);
if (correspondenciaTeclasJ1)
this->correspondenciaTeclas = correspondenciaTeclasJ1;
else
this->correspondenciaTeclas = correspondenciaTeclasPorDefecto();
if (correspondenciaEjesJ1)
this->correspondenciaEjes = correspondenciaEjesJ1;
else
this->correspondenciaEjes = correspondenciaEjesPorDefecto();
this->estadoJoystick1 = new std::map<string, bool>;
this->estadoJoystick2 = new std::map<string, bool>;
this->estadoJoystickNulo = new std::map<string, bool>;
if(SDL_NumJoysticks() > 0) {
for(int i = 0; i < SDL_NumJoysticks(); i++) {
SDL_Joystick* joy = SDL_JoystickOpen(i);
if(joy) {
// INICIA JOYSTICKS
m_joysticks.push_back(joy);
// SETEO DIRECCIONES EN CERO
m_joystickValues.push_back(std::make_pair(new Vector2D(0,0), new Vector2D(0,0)));
// SETEA ESTADO DE TECLAS ACTUALES EN FALSE
//cout << "CANTIDAD BOTONES[" << i << "]:" << SDL_JoystickNumButtons(joy) << endl;
std::vector<bool> tempButtons_actual;
for(int j = 0; j < SDL_JoystickNumButtons(joy); j++)
tempButtons_actual.push_back(false);
m_buttonStates_actual.push_back(tempButtons_actual);
// SETEA ESTADO DE TECLAS ANTERIORES EN FALSE
//cout << "CANTIDAD BOTONES[" << i << "]:" << SDL_JoystickNumButtons(joy) << endl;
std::vector<int> tempButtons_anterior;
for(int j = 0; j < SDL_JoystickNumButtons(joy); j++)
tempButtons_anterior.push_back(0);
m_cantidad_de_pulsaciones.push_back(tempButtons_anterior);
}
else
std::cout << SDL_GetError();
}
SDL_JoystickEventState(SDL_ENABLE);
m_bJoysticksInitialised = true;
//std::cout << "Initialised "<< m_joysticks.size() << " joystick(s)";
}
else
m_bJoysticksInitialised = false;
}
示例4: ui_joystick_init
int
ui_joystick_init( void )
{
int error, retval;
#ifdef UI_SDL
error = SDL_InitSubSystem( SDL_INIT_JOYSTICK );
#else
/* Other UIs could handle joysticks by the SDL library */
error = SDL_Init(SDL_INIT_JOYSTICK|SDL_INIT_VIDEO);
#endif
if ( error ) {
ui_error( UI_ERROR_ERROR, "failed to initialise joystick subsystem" );
return 0;
}
retval = SDL_NumJoysticks();
if( retval >= 2 ) {
retval = 2;
if( ( joystick2 = SDL_JoystickOpen( 1 ) ) == NULL ) {
ui_error( UI_ERROR_ERROR, "failed to initialise joystick 2" );
return 0;
}
if( SDL_JoystickNumAxes( joystick2 ) < 2 ||
SDL_JoystickNumButtons( joystick2 ) < 1 ) {
ui_error( UI_ERROR_ERROR, "sorry, joystick 2 is inadequate!" );
return 0;
}
}
if( retval > 0 ) {
if( ( joystick1 = SDL_JoystickOpen( 0 ) ) == NULL ) {
ui_error( UI_ERROR_ERROR, "failed to initialise joystick 1" );
return 0;
}
if( SDL_JoystickNumAxes( joystick1 ) < 2 ||
SDL_JoystickNumButtons( joystick1 ) < 1 ) {
ui_error( UI_ERROR_ERROR, "sorry, joystick 1 is inadequate!" );
return 0;
}
}
SDL_JoystickEventState( SDL_ENABLE );
return retval;
}
示例5: libjoy_get_button_specific
int libjoy_get_button_specific( int joy, int button )
{
if ( joy >= 0 && joy < _max_joys )
{
#ifdef TARGET_CAANOO
if ( button >= 0 && ( ( joy == 0 && button <= 21 ) || ( joy != 0 && SDL_JoystickNumButtons( _joysticks[ joy ] ) ) ) )
#else
if ( button >= 0 && button <= SDL_JoystickNumButtons( _joysticks[ joy ] ) )
#endif
{
#ifdef TARGET_CAANOO
if ( joy == 0 )
{
int vax;
switch ( button )
{
case 1: /* UPLF */ return ( SDL_JoystickGetAxis( _joysticks[ 0 ], 1 ) < -16384 && SDL_JoystickGetAxis( _joysticks[ 0 ], 0 ) < -16384 );
case 3: /* DWLF */ return ( SDL_JoystickGetAxis( _joysticks[ 0 ], 1 ) > 16384 && SDL_JoystickGetAxis( _joysticks[ 0 ], 0 ) < -16384 );
case 5: /* DWRT */ return ( SDL_JoystickGetAxis( _joysticks[ 0 ], 1 ) > 16384 && SDL_JoystickGetAxis( _joysticks[ 0 ], 0 ) > 16384 );
case 7: /* UPRT */ return ( SDL_JoystickGetAxis( _joysticks[ 0 ], 1 ) < -16384 && SDL_JoystickGetAxis( _joysticks[ 0 ], 0 ) > 16384 );
case 0: /* UP */ vax = SDL_JoystickGetAxis( _joysticks[ 0 ], 0 ) ; return ( SDL_JoystickGetAxis( _joysticks[ 0 ], 1 ) < -16384 && ABS( vax ) < 16384 );
case 4: /* DW */ vax = SDL_JoystickGetAxis( _joysticks[ 0 ], 0 ) ; return ( SDL_JoystickGetAxis( _joysticks[ 0 ], 1 ) > 16384 && ABS( vax ) < 16384 );
case 2: /* LF */ vax = SDL_JoystickGetAxis( _joysticks[ 0 ], 1 ) ; return ( SDL_JoystickGetAxis( _joysticks[ 0 ], 0 ) < -16384 && ABS( vax ) < 16384 );
case 6: /* RT */ vax = SDL_JoystickGetAxis( _joysticks[ 0 ], 1 ) ; return ( SDL_JoystickGetAxis( _joysticks[ 0 ], 0 ) > 16384 && ABS( vax ) < 16384 );
case 8: /* MENU->HOME */ return ( SDL_JoystickGetButton( _joysticks[ 0 ], 6 ) );
case 9: /* SELECT->HELP-II */ return ( SDL_JoystickGetButton( _joysticks[ 0 ], 9 ) );
case 10: /* L */ return ( SDL_JoystickGetButton( _joysticks[ 0 ], 4 ) );
case 11: /* R */ return ( SDL_JoystickGetButton( _joysticks[ 0 ], 5 ) );
case 12: /* A */ return ( SDL_JoystickGetButton( _joysticks[ 0 ], 0 ) );
case 13: /* B */ return ( SDL_JoystickGetButton( _joysticks[ 0 ], 2 ) );
case 14: /* X */ return ( SDL_JoystickGetButton( _joysticks[ 0 ], 1 ) );
case 15: /* Y */ return ( SDL_JoystickGetButton( _joysticks[ 0 ], 3 ) );
case 16: /* VOLUP */ return ( 0 );
case 17: /* VOLDOWN */ return ( 0 );
case 18: /* CLICK */ return ( SDL_JoystickGetButton( _joysticks[ 0 ], 10 ) );
case 19: /* POWER-LOCK (CAANOO) */ return ( SDL_JoystickGetButton( _joysticks[ 0 ], 7 ) ); /* Only Caanoo */
case 20: /* HELP-I (CAANOO) */ return ( SDL_JoystickGetButton( _joysticks[ 0 ], 8 ) ); /* Only Caanoo */
default: return ( 0 );
}
}
#endif
return SDL_JoystickGetButton( _joysticks[ joy ], button ) ;
}
}
return 0 ;
}
示例6: ui_joystick_init
int
ui_joystick_init( void )
{
int error, retval;
error = SDL_InitSubSystem( SDL_INIT_JOYSTICK );
if ( error ) {
ui_error( UI_ERROR_ERROR, "failed to initialise joystick subsystem" );
return 0;
}
retval = SDL_NumJoysticks();
if( retval >= 2 ) {
retval = 2;
if( ( joystick2 = SDL_JoystickOpen( 1 ) ) == NULL ) {
ui_error( UI_ERROR_ERROR, "failed to initialise joystick 2" );
return 0;
}
if( SDL_JoystickNumAxes( joystick2 ) < 2 ||
SDL_JoystickNumButtons( joystick2 ) < 1 ) {
ui_error( UI_ERROR_ERROR, "sorry, joystick 2 is inadequate!" );
return 0;
}
}
if( retval > 0 ) {
if( ( joystick1 = SDL_JoystickOpen( 0 ) ) == NULL ) {
ui_error( UI_ERROR_ERROR, "failed to initialise joystick 1" );
return 0;
}
if( SDL_JoystickNumAxes( joystick1 ) < 2 ||
SDL_JoystickNumButtons( joystick1 ) < 1 ) {
ui_error( UI_ERROR_ERROR, "sorry, joystick 1 is inadequate!" );
return 0;
}
}
SDL_JoystickEventState( SDL_ENABLE );
return retval;
}
示例7: joystick_use
/**
* @brief Makes the game use a joystick by index.
*
* @param indjoystick Index of the joystick to use.
* @return 0 on success.
*/
int joystick_use( int indjoystick )
{
/* Check to see if it exists. */
if ((indjoystick < 0) || (indjoystick >= SDL_NumJoysticks())) {
WARN("Joystick of index number %d does not existing, switching to default 0",
indjoystick);
indjoystick = 0;
}
/* Close if already open. */
if (joystick != NULL) {
SDL_JoystickClose(joystick);
joystick = NULL;
}
/* Start using joystick. */
joystick = SDL_JoystickOpen(indjoystick);
if (joystick == NULL) {
WARN("Error opening joystick %d [%s]", indjoystick, SDL_JoystickName(indjoystick));
return -1;
}
LOG("Using joystick %d - %s", indjoystick, SDL_JoystickName(indjoystick));
DEBUG(" with %d axes, %d buttons, %d balls and %d hats",
SDL_JoystickNumAxes(joystick), SDL_JoystickNumButtons(joystick),
SDL_JoystickNumBalls(joystick), SDL_JoystickNumHats(joystick));
/* Initialize the haptic if possible. */
joystick_initHaptic();
/* For style purposes. */
DEBUG();
return 0;
}
示例8: st_joystick_setup
void st_joystick_setup(void)
{
/* Init Joystick: */
use_joystick = true;
if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
{
fprintf(stderr, "Warning: I could not initialize joystick!\n"
"The Simple DirectMedia error that occured was:\n"
"%s\n\n", SDL_GetError());
use_joystick = false;
}
else
{
/* Open joystick: */
if (SDL_NumJoysticks() <= 0)
{
fprintf(stderr, "Warning: No joysticks are available.\n");
use_joystick = false;
}
else
{
js = SDL_JoystickOpen(joystick_num);
if (js == NULL)
{
fprintf(stderr, "Warning: Could not open joystick %d.\n"
"The Simple DirectMedia error that occured was:\n"
"%s\n\n", joystick_num, SDL_GetError());
use_joystick = false;
}
else
{
if (SDL_JoystickNumAxes(js) < 2)
{
fprintf(stderr,
"Warning: Joystick does not have enough axes!\n");
use_joystick = false;
}
else
{
if (SDL_JoystickNumButtons(js) < 2)
{
fprintf(stderr,
"Warning: "
"Joystick does not have enough buttons!\n");
use_joystick = false;
}
}
}
}
}
}
示例9: Log
INLINE BOOL Input::Initialize()
{
Log(TAG "Initializing...");
BOOL r = this->Reset();
#if defined(WIN32) && defined(DEBUG)
SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE);
#endif
MEMSET(parJoy, '\0', sizeof(parJoy));
SDL_InitSubSystem(SDL_INIT_JOYSTICK);
iJoystickCount = SDL_NumJoysticks();
if (iJoystickCount)
{
SDL_JoystickEventState(SDL_ENABLE);
Log(TAG "Joystick(s): ");
for (u32 i = 0; i < iJoystickCount; i++)
{
parJoy[i] = SDL_JoystickOpen(i);
if (parJoy[i])
{
Log("Opened Joystick %d:", i);
Log(TAG "\tName: %s", SDL_JoystickName(i));
Log(TAG "\t\tAxes: %d", SDL_JoystickNumAxes(parJoy[i]));
Log(TAG "\t\tButtons: %d", SDL_JoystickNumButtons(parJoy[i]));
Log(TAG "\t\tHats: %d", SDL_JoystickNumHats(parJoy[i]));
Log(TAG "\t\tBalls: %d", SDL_JoystickNumBalls(parJoy[i]));
}
}
}
Log(TAG "Initialization completed.");
return r;
}
示例10: JOYSTICKGetNumButtons
void JOYSTICKGetNumButtons(int nlhs, mxArray *plhs[], int nrhs, CONSTmxArray *prhs[])
{
ProjectTable *joystickTable=GetProjectTable();
int numSticks;
CONSTmxArray *numArg;
double stickNum;
SDL_Joystick *pStick;
prhs;
if(joystickTable->giveHelp){GiveHelp(useGetNumButtons,synopsisGetNumButtons);return;}
numArg = joystickTable->joystickNumberArgument;
if(numArg == NULL || nlhs > 1 || nrhs > 0 || !mxIsDouble(numArg) || (mxGetM(numArg) * mxGetN(numArg) != 1))
GiveUsageExit(useGetNumButtons);
numSticks = SDL_NumJoysticks();
stickNum = mxGetPr(numArg)[0];
if(stickNum > numSticks)
PrintfExit("The joystick number %d passed to JOYSTICK 'GetNumButtons' exceeds the number of joysticks, %d",stickNum,numSticks);
if(stickNum < 1)
PrintfExit("The joystick number passed to JOYSTICK 'GetNumButtons' must be greater than 0");
pStick = GetJoystickObjFromNum((int)stickNum-1);
if(pStick == NULL)
PrintfExit("JOYSTICK 'GetNumButtons' can not open joystick number %d",stickNum);
plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL);
mxGetPr(plhs[0])[0] = SDL_JoystickNumButtons(pStick);
}
示例11: SDL_JoystickNumButtons
uint8_t Joystick::getNumberOfButtons() const {
uint8_t number = 0;
if (isConnected()) {
number = SDL_JoystickNumButtons(m_joystickHandle);
}
return number;
}
示例12: mScreen
//-------------------------------------------------------------------------------------------------------------------//
Application::Application(): mScreen(NULL), mEvent(), mIsItTimeToClose(false), mJoystick(NULL)
{
// On initialise la SDL.
MTest_T_MSG (SDL_Init(SDL_INIT_EVERYTHING) == -1, "SDL Initialization Error : " << SDL_GetError());
// Log pour les Joysticks.
MOut(SDL_NumJoysticks() << " joysticks connected");
for (int i = 0; i < SDL_NumJoysticks() ; ++i)
{
MOut("Joystick_" << i << " : " << SDL_JoystickName(i));
}
if (SDL_NumJoysticks() > 0)
{
// On active la gestion des evenements des Joysticks.
SDL_JoystickEventState(SDL_ENABLE);
// On charge le premier Joystick connecté.
mJoystick = SDL_JoystickOpen(0);
MOut("----> " << SDL_JoystickNumButtons(mJoystick) << " buttons");
MOut("----> " << SDL_JoystickNumAxes(mJoystick) << " axes");
MOut("----> " << SDL_JoystickNumBalls(mJoystick) << " trackballs");
MOut("----> " << SDL_JoystickNumHats(mJoystick) << " hats");
}
}
示例13: controller_joystick_attach
void controller_joystick_attach( Tank *t ) {
JoystickPrivateData *data;
/* Make sure that this is even a joystick to connect to: */
if(SDL_NumJoysticks() == 0) {
/* TODO: exiting isn't all that friendly... we need a better controller API... */
gamelib_debug("No joysticks connected.\n");
exit(1);
}
data = get_object(JoystickPrivateData);
data->joystick = SDL_JoystickOpen(0);
if(data->joystick) {
gamelib_debug("Using Joystick #0:\n");
gamelib_debug(" Name: %s\n", SDL_JoystickName(0));
gamelib_debug(" Axes: %d\n", SDL_JoystickNumAxes(data->joystick));
gamelib_debug(" Buttons: %d\n", SDL_JoystickNumButtons(data->joystick));
gamelib_debug(" Balls: %d\n", SDL_JoystickNumBalls(data->joystick));
} else {
gamelib_debug("Failed to open Joystick #0.\n");
exit(1);
}
tank_set_controller(t, joystick_controller, data);
}
示例14: Init_Joy
void Init_Joy (void)
{
int num_joy;
if (SDL_InitSubSystem (SDL_INIT_JOYSTICK) == -1)
{
fprintf(stderr, "Couldn't initialize SDL-Joystick: %s\n", SDL_GetError());
Terminate(ERR);
} else
DebugPrintf(1, "\nSDL Joystick initialisation successful.\n");
DebugPrintf (1, " %d Joysticks found!\n", num_joy = SDL_NumJoysticks ());
if (num_joy > 0)
joy = SDL_JoystickOpen (0);
if (joy)
{
DebugPrintf (1, "Identifier: %s\n", SDL_JoystickName (0));
DebugPrintf (1, "Number of Axes: %d\n", joy_num_axes = SDL_JoystickNumAxes(joy));
DebugPrintf (1, "Number of Buttons: %d\n", SDL_JoystickNumButtons(joy));
/* aktivate Joystick event handling */
SDL_JoystickEventState (SDL_ENABLE);
}
else
joy = NULL; /* signals that no yoystick is present */
return;
}
示例15: SDL_JoystickNumButtons
//------------------------------------------------------------
int ofxSDLAppWindow::getControllerNumButtons(int num) {
if (num >= numJoys || !joys[num]) {
return 0;
}
return SDL_JoystickNumButtons(joys[num]);
}