本文整理汇总了C++中SDL_JoystickName函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_JoystickName函数的具体用法?C++ SDL_JoystickName怎么用?C++ SDL_JoystickName使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_JoystickName函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SDL_GameControllerNameForIndex
static const char *sdl_joypad_name(unsigned pad)
{
if (pad >= MAX_USERS)
return NULL;
#ifdef HAVE_SDL2
if (sdl_pads[pad].controller)
return SDL_GameControllerNameForIndex(pad);
return SDL_JoystickNameForIndex(pad);
#else
return SDL_JoystickName(pad);
#endif
}
示例2: inputinit
void inputinit()
{
int i, numjoysticks;
if( (numjoysticks=SDL_NumJoysticks())>0 ) {
joysticks = malloc(sizeof(*joysticks)*numjoysticks);
SDL_JoystickEventState(SDL_ENABLE);
SJC_Write("%d controller/joystick%s detected:",numjoysticks,(numjoysticks>1?"s":""));
for( i=0; i<numjoysticks; i++ ) {
joysticks[i] = SDL_JoystickOpen(i);
SJC_Write(" #%i: %.20s",i,SDL_JoystickName(i));
}
}
}
示例3: IN_JoystickInitMenu
/**
* @brief Adds joysticks to the options menu
*/
void IN_JoystickInitMenu (void)
{
uiNode_t* joystickOptions = nullptr;
const int total = SDL_NumJoysticks();
if (total == 0) {
UI_AddOption(&joystickOptions, "", _("None"), "0");
} else {
for (int i = 0; i < total; i++)
UI_AddOption(&joystickOptions, "", SDL_JoystickName(i), va("%i", i));
}
UI_RegisterOption(OPTION_JOYSTICKS, joystickOptions);
}
示例4: Q_ASSERT
bool Joystick::attachJoystick(int which)
{
Q_ASSERT(device_attached != true);
joystick = SDL_JoystickOpen(which);
if (joystick == nullptr) {
qCWarning(phxInput, "Joystick: Unable to open sdl joystick: %s",
SDL_GetError());
return false;
}
setDeviceName(SDL_JoystickName(joystick));
device_attached = true;
return true;
}
示例5: _SaveMappings
static int _SaveMappings()
{
char bind[2056];
const char* name;
if (_this->controller != NULL) {
name = SDL_GameControllerName(_this->controller);
} else {
name = SDL_JoystickName(_this->joystick);
}
SDL_JoystickGUID guid = SDL_JoystickGetGUID(_this->joystick);
char guid_string[33];
SDL_JoystickGetGUIDString(guid, guid_string, 33);
guid_string[32] = 0;
snprintf(bind, 2056, "%s,%s,platform:%s,", guid_string, name, SDL_GetPlatform());
int index = strlen(bind);
for (int i = 0; i < NUM_MAPPINGS; ++i) {
const char* to = NULL;
if (_this->mappings[i].type == SDL_CONTROLLER_BINDTYPE_AXIS) {
to = SDL_GameControllerGetStringForAxis(_this->mappings[i].value.axis);
} else if (_this->mappings[i].type != SDL_CONTROLLER_BINDTYPE_BUTTON){
to = SDL_GameControllerGetStringForButton(_this->mappings[i].value.button);
}
if (to == NULL) {
continue;
}
char from[10];
if (_this->mappings[i].bind.bindType == SDL_CONTROLLER_BINDTYPE_AXIS) {
snprintf(from, 10, "a%d", _this->mappings[i].bind.value.axis);
} else if (_this->mappings[i].bind.bindType
== SDL_CONTROLLER_BINDTYPE_BUTTON) {
snprintf(from, 10, "b%d", _this->mappings[i].bind.value.button);
} if (_this->mappings[i].bind.bindType == SDL_CONTROLLER_BINDTYPE_HAT) {
snprintf(from, 10, "h%d.%d", _this->mappings[i].bind.value.hat.hat,
_this->mappings[i].bind.value.hat.hat_mask);
} else {
continue;
}
snprintf(bind, 2056 - index, "%s:%s,", to, from);
index += strlen(to) + strlen(from);
}
SDL_GameControllerAddMapping(bind);
// TODO Save to file
SDL_Log("Mapping: %s\n", bind);
}
示例6: SetJoystickButtonLabel
static void SetJoystickButtonLabel(void)
{
char *name;
name = "None set";
if (joystick_initted
&& joystick_index >= 0 && joystick_index < SDL_NumJoysticks())
{
name = (char *) SDL_JoystickName(joystick_index);
}
TXT_SetButtonLabel(joystick_button, name);
}
示例7: SDL_JoystickName
const char *GameJoystick::getName( long n )
{
if( n < 0 )
return NULL;
#ifdef HAVE_SDL_SDL_H
if( n >= SDL_NumJoysticks() )
return NULL;
return SDL_JoystickName( n );
#endif
return NULL;
}
示例8: send_joystick_info
void send_joystick_info(int joy_idx)
{
SDL_Joystick * joy = joysticks.find( joy_idx )->second;
lo_message m1 = lo_message_new();
lo_message_add_string( m1, SDL_JoystickName(joy_idx) );
lo_message_add_int32( m1, joy_idx );
lo_message_add_int32( m1, SDL_JoystickNumAxes(joy) );
lo_message_add_int32( m1, SDL_JoystickNumButtons(joy) );
lo_message_add_int32( m1, SDL_JoystickNumHats(joy) );
lo_message_add_int32( m1, SDL_JoystickNumBalls(joy) );
lo_send_message_from( t, s, "/joystick/info", m1 );
}
示例9: I_GetJoystickNameFromIndex
//
// I_GetJoystickNameFromIndex
//
std::string I_GetJoystickNameFromIndex (int index)
{
const char *joyname = NULL;
std::string ret;
joyname = SDL_JoystickName(index);
if(!joyname)
return "";
ret = joyname;
return ret;
}
示例10: InputDevice
void InputHandler_SDL::GetDevicesAndDescriptions(vector<InputDevice>& vDevicesOut, vector<CString>& vDescriptionsOut)
{
vDevicesOut.push_back( DEVICE_KEYBOARD );
vDescriptionsOut.push_back( "Keyboard" );
for( int i=0; i<SDL_NumJoysticks(); i++ )
{
if( SDL_JoystickOpened(i) )
{
vDevicesOut.push_back( InputDevice(DEVICE_JOY1+i) );
vDescriptionsOut.push_back( SDL_JoystickName(i) );
}
}
}
示例11: joystickb_sdl_device_desc_get
int joystickb_sdl_device_desc_get(unsigned joystick, char* desc)
{
#if SDL_MAJOR_VERSION == 1
const char* joy_name = SDL_JoystickName(joystick);
if (!joy_name)
return -1;
log_std(("joystickb:sdl: desc:\"%s\"\n", joy_name));
sncpy(desc, DEVICE_NAME_MAX, joy_name);
#else
const char* joy_name = SDL_JoystickName(sdl_state.map[joystick]);
if (!joy_name)
return -1;
log_std(("joystickb:sdl: desc:\"%s\"\n", joy_name));
sncpy(desc, DEVICE_NAME_MAX, joy_name);
#endif
return 0;
}
示例12: Get_Names
vector<std::string> cJoystick :: Get_Names( void ) const
{
vector<std::string> names;
// get joy count
int joy_count = SDL_NumJoysticks();
// joystick names
for( int i = 0; i < joy_count; i++ )
{
names.push_back( SDL_JoystickName( i ) );
}
return names;
}
示例13: deinit_joysticks
void md::init_joysticks()
{
int n;
unsigned int i;
SDL_Joystick *(*tmp)[];
deinit_joysticks();
// Initialize the joystick support
// Thanks to Cameron Moore <[email protected]>
if(SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0)
{
fprintf(stderr, "joystick: Unable to initialize joystick system\n");
return;
}
n = SDL_NumJoysticks();
if (n <= 0) {
fprintf(stderr, "joystick: no joystick found\n");
return;
}
fprintf(stderr, "joystick: %d joystick(s) found\n", n);
tmp = (SDL_Joystick *(*)[])malloc(sizeof((*tmp)[0]) * n);
if (tmp == NULL) {
fprintf(stderr, "joystick: unable to allocate memory\n");
return;
}
// Open all of them.
for (i = 0; (i != (unsigned int)n); ++i) {
SDL_Joystick *handle = SDL_JoystickOpen(i);
if (handle == NULL)
fprintf(stderr, "joystick: can't open joystick %u: %s",
i, SDL_GetError());
else
fprintf(stderr,
"joystick #%u:, %d %s, %d button(s),"
" %d hat(s), name: \"%s\"\n",
i,
SDL_JoystickNumAxes(handle),
((SDL_JoystickNumAxes(handle) == 1) ?
"axis" : "axes"),
SDL_JoystickNumButtons(handle),
SDL_JoystickNumHats(handle),
SDL_JoystickName(i));
(*tmp)[i] = handle;
}
handles = tmp;
handles_n = i;
// Enable joystick events
SDL_JoystickEventState(SDL_ENABLE);
}
示例14: S2D_OpenControllers
/*
* Open controllers and joysticks
*/
void S2D_OpenControllers() {
char guid_str[33];
// Enumerate joysticks
for (int device_index = 0; device_index < SDL_NumJoysticks(); ++device_index) {
// Check if joystick supports SDL's game controller interface (a mapping is available)
if (SDL_IsGameController(device_index)) {
SDL_GameController *controller = SDL_GameControllerOpen(device_index);
SDL_JoystickID intance_id = SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(controller));
SDL_JoystickGetGUIDString(
SDL_JoystickGetGUID(SDL_GameControllerGetJoystick(controller)),
guid_str, 33
);
if (intance_id > last_intance_id) {
if (controller) {
S2D_Log(S2D_INFO, "Controller #%i: %s\n GUID: %s", intance_id, SDL_GameControllerName(controller), guid_str);
} else {
S2D_Log(S2D_ERROR, "Could not open controller #%i: %s", intance_id, SDL_GetError());
}
last_intance_id = intance_id;
}
// Controller interface not supported, try to open as joystick
} else {
SDL_Joystick *joy = SDL_JoystickOpen(device_index);
SDL_JoystickID intance_id = SDL_JoystickInstanceID(joy);
if (!joy) {
S2D_Log(S2D_ERROR, "Could not open controller");
} else if(intance_id > last_intance_id) {
SDL_JoystickGetGUIDString(
SDL_JoystickGetGUID(joy),
guid_str, 33
);
S2D_Log(S2D_INFO,
"Controller #%i: %s\n GUID: %s\n Axes: %d\n Buttons: %d\n Balls: %d",
intance_id, SDL_JoystickName(joy), guid_str, SDL_JoystickNumAxes(joy),
SDL_JoystickNumButtons(joy), SDL_JoystickNumBalls(joy)
);
S2D_Log(S2D_WARN, "Controller #%i does not have a mapping available", intance_id);
last_intance_id = intance_id;
}
}
}
}
示例15: WatchJoystick
static SDL_bool
WatchJoystick(SDL_Joystick * joystick)
{
SDL_Window *window = NULL;
const char *name = NULL;
/* Create a window to display joystick axis position */
window = SDL_CreateWindow("Joystick Test", SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
SCREEN_HEIGHT, 0);
if (window == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError());
return SDL_FALSE;
}
screen = SDL_CreateRenderer(window, -1, 0);
if (screen == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
SDL_DestroyWindow(window);
return SDL_FALSE;
}
SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE);
SDL_RenderClear(screen);
SDL_RenderPresent(screen);
SDL_RaiseWindow(window);
/* Print info about the joystick we are watching */
name = SDL_JoystickName(joystick);
SDL_Log("Watching joystick %d: (%s)\n", SDL_JoystickInstanceID(joystick),
name ? name : "Unknown Joystick");
SDL_Log("Joystick has %d axes, %d hats, %d balls, and %d buttons\n",
SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
/* Loop, getting joystick events! */
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop_arg(loop, joystick, 0, 1);
#else
while (!done) {
loop(joystick);
}
#endif
SDL_DestroyRenderer(screen);
SDL_DestroyWindow(window);
return retval;
}