本文整理汇总了C++中SDL_JoystickGetButton函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_JoystickGetButton函数的具体用法?C++ SDL_JoystickGetButton怎么用?C++ SDL_JoystickGetButton使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_JoystickGetButton函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sdl_pad_get_button
static uint8_t sdl_pad_get_button(sdl_joypad_t *pad, unsigned button)
{
#ifdef HAVE_SDL2
/* TODO: see if a LUT like xinput_joypad.c's button_index_to_bitmap_code is needed. */
if (pad->controller)
return SDL_GameControllerGetButton(pad->controller, (SDL_GameControllerButton)button);
#endif
return SDL_JoystickGetButton(pad->joypad, button);
}
示例2: SetButtonState
void JoystickInfo::SaveState()
{
for (int i = 0; i < numbuttons; ++i)
SetButtonState(i, SDL_JoystickGetButton(joy, i));
for (int i = 0; i < numaxes; ++i)
SetAxisState(i, SDL_JoystickGetAxis(joy, i));
for (int i = 0; i < numhats; ++i)
SetHatState(i, SDL_JoystickGetHat(joy, i));
}
示例3: GfctrlSDL2JoyGetCurrentStates
int
GfctrlSDL2JoyGetCurrentStates(tCtrlJoyInfo *joyInfo)
{
int ind;
int i,j;
unsigned int b;
unsigned int mask;
if (gfctrlJoyPresent == GFCTRL_JOY_PRESENT)
{
// Update all the joysticks
SDL_JoystickUpdate();
for (ind = 0; ind < gfctrlJoyPresent; ind++)
{
if (Joysticks[ind])
{
j = SDL_JoystickNumAxes(Joysticks[ind]);
if (j > GFCTRL_JOY_MAX_AXES) j = GFCTRL_JOY_MAX_AXES;
for (i=0; i < j;i++)
joyInfo->ax[GFCTRL_JOY_MAX_AXES * ind + i] = ((float) SDL_JoystickGetAxis(Joysticks[ind],i)) / 32768;
b = 0;
for (i=0; i < GFCTRL_JOY_MAX_BUTTONS;i++)
{
mask = (unsigned int)SDL_JoystickGetButton(Joysticks[ind], i);
b |= (mask << i);
}
/* Joystick buttons */
for (i = 0, mask = 1; i < GFCTRL_JOY_MAX_BUTTONS; i++, mask *= 2)
{
if (((b & mask) != 0) && ((joyInfo->oldb[ind] & mask) == 0)) {
joyInfo->edgeup[i + GFCTRL_JOY_MAX_BUTTONS * ind] = 1;
} else {
joyInfo->edgeup[i + GFCTRL_JOY_MAX_BUTTONS * ind] = 0;
}
if (((b & mask) == 0) && ((joyInfo->oldb[ind] & mask) != 0)) {
joyInfo->edgedn[i + GFCTRL_JOY_MAX_BUTTONS * ind] = 1;
} else {
joyInfo->edgedn[i + GFCTRL_JOY_MAX_BUTTONS * ind] = 0;
}
if ((b & mask) != 0) {
joyInfo->levelup[i + GFCTRL_JOY_MAX_BUTTONS * ind] = 1;
} else {
joyInfo->levelup[i + GFCTRL_JOY_MAX_BUTTONS * ind] = 0;
}
}
joyInfo->oldb[ind] = b;
}
}
}
else
{
return -1;
}
return 0;
}
示例4: getbuttonjoystick
//getbuttonjoystick(i,a) : Get the current state of a given button on a given joystick
int getbuttonjoystick(int index,int button)
{
int ret;
SDL_JoystickUpdate();
if (SDLjoy[index])
ret= SDL_JoystickGetButton(SDLjoy[index],button);
else
ret=-1;
return ret;
}
示例5: ClearStates
void cJoystickSDL::Update() {
if ( NULL != mJoystick ) {
ClearStates();
for ( Int32 i = 0; i < mButtons; i++ ) {
UpdateButton( i, 0 != SDL_JoystickGetButton( mJoystick, i ) );
}
}
}
示例6: SDL_JoystickUpdate
bool JoystickController::bindJoystickKey(SDL_Joystick *joy, KM_Key &k)
{
int val=0, dx=0, dy=0;
//SDL_PumpEvents();
SDL_JoystickUpdate();
for(int i=0; i<SDL_JoystickNumBalls(joy);i++)
{
dx=0; dy=0;
SDL_JoystickGetBall(joy, i, &dx, &dy);
if(dx!=0)
{
k.val=dx;
k.id=i;
k.type=(int)KeyMapJoyCtrls::JoyBallX;
return true;
}else if(dy!=0)
{
k.val=dy;
k.id=i;
k.type=(int)KeyMapJoyCtrls::JoyBallY;
return true;
}
}
for(int i=0; i<SDL_JoystickNumHats(joy);i++)
{
val=0;
val=SDL_JoystickGetHat(joy, i);
if(val!=0)
{
k.val=val;
k.id=i;
k.type=(int)KeyMapJoyCtrls::JoyHat;
return true;
}
}
for(int i=0; i<SDL_JoystickNumButtons(joy);i++)
{
val=0;
val=SDL_JoystickGetButton(joy, i);
if(val==1)
{
k.val=val;
k.id=i;
k.type=(int)KeyMapJoyCtrls::JoyButton;
return true;
}
}
k.val=0;
k.id=0;
k.type=(int)KeyMapJoyCtrls::NoControl;
return false;
}
示例7: get_joystick_state
Sint16 get_joystick_state (Sint16 *mx, Sint16 *my, Sint16 *button, Sint16 check_button)
{
SDL_PumpEvents ();
*mx = SDL_JoystickGetAxis (joystick, 0);
*my = SDL_JoystickGetAxis (joystick, 1);
*button = SDL_JoystickGetButton (joystick, check_button);
return (0);
}
示例8: mrb_sdl2_joystick_joystick_get_button
static mrb_value
mrb_sdl2_joystick_joystick_get_button(mrb_state *mrb, mrb_value self)
{
Uint8 result;
mrb_int button;
SDL_Joystick * joystick_p = mrb_sdl2_joystick_joystick_get_ptr(mrb, self);
mrb_get_args(mrb, "i", &button);
result = SDL_JoystickGetButton(joystick_p, button);
return (0 == result) ? mrb_false_value() : mrb_true_value();
}
示例9: IN_JoyButtons
int IN_JoyButtons()
{
if(!Joystick) return 0;
SDL_JoystickUpdate();
int res = 0;
for(int i = 0; i < JoyNumButtons && i < 32; i++)
res |= SDL_JoystickGetButton(Joystick, i) << i;
return res;
}
示例10: getJoy
Controller::Button Controller::Peripheral::retJoyButton()
{
SDL_Joystick * joy = getJoy();
for (register int i = static_cast<int>(BUTTON_MAX); i >= 0 ; i--)
{
if (SDL_JoystickGetButton(joy, static_cast<SDL_GameControllerButton>(i)))
return (static_cast<Button>(i));
}
return (BUTTON_INVALID);
}
示例11: SDL_PushEvent
/** Updates the state info in CApplication and on change, creates SDL events and pushes them to SDL event queue.
This way, the events get handled properly in the main event loop and besides, SDL_PushEvent() ensures thread-safety. */
void CApplication::UpdateJoystick()
{
if (! m_joystickEnabled)
return;
SDL_JoystickUpdate();
for (int axis = 0; axis < static_cast<int>( m_joyAxeState.size() ); ++axis)
{
int newValue = SDL_JoystickGetAxis(m_private->joystick, axis);
if (m_joyAxeState[axis] != newValue)
{
m_joyAxeState[axis] = newValue;
SDL_Event joyAxisEvent;
joyAxisEvent.jaxis.type = SDL_JOYAXISMOTION;
joyAxisEvent.jaxis.which = 0;
joyAxisEvent.jaxis.axis = axis;
joyAxisEvent.jaxis.value = newValue;
SDL_PushEvent(&joyAxisEvent);
}
}
for (int button = 0; button < static_cast<int>( m_joyButtonState.size() ); ++button)
{
bool newValue = SDL_JoystickGetButton(m_private->joystick, button) == 1;
if (m_joyButtonState[button] != newValue)
{
m_joyButtonState[button] = newValue;
SDL_Event joyButtonEvent;
if (newValue)
{
joyButtonEvent.jbutton.type = SDL_JOYBUTTONDOWN;
joyButtonEvent.jbutton.state = SDL_PRESSED;
}
else
{
joyButtonEvent.jbutton.type = SDL_JOYBUTTONUP;
joyButtonEvent.jbutton.state = SDL_RELEASED;
}
joyButtonEvent.jbutton.which = 0;
joyButtonEvent.jbutton.button = button;
SDL_PushEvent(&joyButtonEvent);
}
}
}
示例12: ndof_update
void ndof_update(NDOF_Device *in_dev)
{
int i;
LinJoystickPrivate *priv = (LinJoystickPrivate *) in_dev->private_data;
assert(priv != NULL);
if(priv->USE_SDL)
{
SDL_JoystickUpdate();
SDL_Joystick *j = priv->j;
for(i = 0; i < in_dev->axes_count; i++)
{
in_dev->axes[i] = (int) (SDL_JoystickGetAxis(j, i));
}
for(i = 0; i < in_dev->btn_count; i++)
{
in_dev->buttons[i] = SDL_JoystickGetButton(j, i);
}
} else {
// update SpaceNavigator
struct input_event ev;
while(read(priv->fd, &ev, sizeof(struct input_event)) > 0)
{
switch (ev.type)
{
case EV_KEY:
// printf("Key %d pressed %d.\n", ev.code, ev.value);
priv->buttons[ev.code & 0xff] = ev.value;
break;
case EV_REL:
case EV_ABS: // 2.6.35 and up, maybe earlier kernels too send EV_ABS instead of EV_REL
// printf("%d %g\n", ev.code, ev.value);
// clean up small values
priv->axes[ev.code] = abs(ev.value) > SPACE_NAVIG_THRESHOLD ? ev.value : 0;
break;
default:
break;
}
}
memcpy(in_dev->axes, priv->axes, in_dev->axes_count * sizeof(long int));
memcpy(in_dev->buttons, priv->buttons, in_dev->btn_count * sizeof(long int));
}
}
示例13: stroke_timer
static void stroke_timer(int id, float dt)
{
float g[3] = { 0.f, 0.f, 0.f };
//senquack - allowed more flexible aim-speed control
#ifdef GCWZERO
float rot_dir = stroke_rotate;
float rot_speed = 0.0f;
if (l_pressed && r_pressed) {
rot_dir = 0.0f;
// k = 0.0f;
} else if (l_pressed) {
rot_dir = -1.0f;
rot_speed = 24.0f;
} else if (r_pressed) {
rot_dir = 1.0f;
rot_speed = 24.0f;
} else {
if (fast_aim) {
rot_speed = 24.0f;
} else {
rot_speed = 2.0f;
}
}
game_set_rot(rot_dir * rot_speed);
if (fast_aim) {
game_set_mag(stroke_mag * 24.0f);
} else {
game_set_mag(stroke_mag * 6.0f);
}
#else
float k;
if (SDL_GetModState() & KMOD_SHIFT ||
(joystick && SDL_JoystickGetButton(joystick,
config_get_d(CONFIG_JOYSTICK_BUTTON_X)))) {
k = 0.25f;
}
else
{
k = 1.0f;
}
game_set_rot(stroke_rotate * k);
game_set_mag(stroke_mag * k);
#endif //GCWZERO
game_update_view(dt);
game_step(g, dt);
}
示例14: SDL_JoystickUpdate
void JoystickReader::OnTimer(void* userdata){
JoystickReader* self = (JoystickReader*)userdata;
SDL_JoystickUpdate();
const int numButtons = SDL_JoystickNumButtons(self->js);
for (int i = 0; i < numButtons; i++) {
if (SDL_JoystickGetButton(self->js, i)){
if (self->callbackFunc)
if (self->callbackFunc(i, self->callbackUserdata))
return;
}
}
Fl::repeat_timeout(0.1, OnTimer, self);
}
示例15: joystick_event
void joystick_event( void )
{
int j;
T_JOY *joy = &joy_info;
int now = 0, chg;
Sint16 x, y;
Uint8 button;
if( enable_joystick ){
SDL_JoystickUpdate();
if( joy->dev ){
/* Uint8 pad = SDL_JoystickGetHat( joy->dev,
SDL_HAT_UP | SDL_HAT_RIGHT |
SDL_HAT_DOWN | SDL_HAT_LEFT ); */
x = SDL_JoystickGetAxis( joy->dev, 0 );
y = SDL_JoystickGetAxis( joy->dev, 1 );
if ( x < -0x4000 ) now |= AXIS_L;
else if( x > 0x4000 ) now |= AXIS_R;
if ( y < -0x4000 ) now |= AXIS_U;
else if( y > 0x4000 ) now |= AXIS_D;
chg = joy->axis ^ now;
if( chg & AXIS_L ) pc88_pad( KEY88_PAD_LEFT, (now & AXIS_L) );
if( chg & AXIS_R ) pc88_pad( KEY88_PAD_RIGHT, (now & AXIS_R) );
if( chg & AXIS_U ) pc88_pad( KEY88_PAD_UP, (now & AXIS_U) );
if( chg & AXIS_D ) pc88_pad( KEY88_PAD_DOWN, (now & AXIS_D) );
joy->axis = now;
for( j=0; j<joy->nr_button; j++ ){
button = SDL_JoystickGetButton( joy->dev, j );
if( joy->button[j] != button ){
pc88_pad( KEY88_PAD_A + j, ( button ) );
joy->button[j] = button;
}
}
}
}
}