mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-18 09:51:40 +00:00
[input] Allow button and axis inputs to be named
keyhelp provides the input name if it is known, and in_bind tries to use the provided input name if not a number. Case sensitivity for name lookups is dependent on the input driver.
This commit is contained in:
parent
f4c521d51d
commit
84f746dab2
3 changed files with 96 additions and 4 deletions
|
@ -77,6 +77,12 @@ typedef struct in_driver_s {
|
||||||
int *numaxes);
|
int *numaxes);
|
||||||
void (*button_info) (void *data, void *device, in_buttoninfo_t *buttons,
|
void (*button_info) (void *data, void *device, in_buttoninfo_t *buttons,
|
||||||
int *numbuttons);
|
int *numbuttons);
|
||||||
|
// null means either invalid number or the name is not known
|
||||||
|
const char *(*get_axis_name) (void *data, void *device, int axis_num);
|
||||||
|
const char *(*get_button_name) (void *data, void *device, int button_num);
|
||||||
|
// -1 for invalid name
|
||||||
|
int (*get_axis_num) (void *data, void *device, const char *axis_name);
|
||||||
|
int (*get_button_num) (void *data, void *device, const char *button_name);
|
||||||
} in_driver_t;
|
} in_driver_t;
|
||||||
|
|
||||||
typedef struct in_device_s {
|
typedef struct in_device_s {
|
||||||
|
@ -111,6 +117,10 @@ void IN_SetDeviceEventData (int devid, void *data);
|
||||||
void *IN_GetDeviceEventData (int devid);
|
void *IN_GetDeviceEventData (int devid);
|
||||||
int IN_AxisInfo (int devid, in_axisinfo_t *axes, int *numaxes);
|
int IN_AxisInfo (int devid, in_axisinfo_t *axes, int *numaxes);
|
||||||
int IN_ButtonInfo (int devid, in_buttoninfo_t *button, int *numbuttons);
|
int IN_ButtonInfo (int devid, in_buttoninfo_t *button, int *numbuttons);
|
||||||
|
const char *IN_GetAxisName (int devid, int axis_num);
|
||||||
|
const char *IN_GetButtonName (int devid, int button_num);
|
||||||
|
int IN_GetAxisNumber (int devid, const char *axis_name);
|
||||||
|
int IN_GetButtonNumber (int devid, const char *button_name);
|
||||||
|
|
||||||
void IN_ProcessEvents (void);
|
void IN_ProcessEvents (void);
|
||||||
|
|
||||||
|
|
|
@ -283,11 +283,12 @@ in_keyhelp_event_handler (const IE_event_t *ie_event, void *unused)
|
||||||
|
|
||||||
size_t devid = ie_event->button.devid;
|
size_t devid = ie_event->button.devid;
|
||||||
in_devbindings_t *db = ie_event->button.data;
|
in_devbindings_t *db = ie_event->button.data;
|
||||||
const char *name = db ? db->name : 0;
|
const char *bind_name = db ? db->name : 0;
|
||||||
const char *type = 0;
|
const char *type = 0;
|
||||||
int num = -1;
|
int num = -1;
|
||||||
const char *devname = IN_GetDeviceName (devid);
|
const char *devname = IN_GetDeviceName (devid);
|
||||||
const char *id = IN_GetDeviceId (devid);
|
const char *id = IN_GetDeviceId (devid);
|
||||||
|
const char *name = 0;
|
||||||
|
|
||||||
if (ie_event->type == ie_axis) {
|
if (ie_event->type == ie_axis) {
|
||||||
int axis = ie_event->axis.axis;
|
int axis = ie_event->axis.axis;
|
||||||
|
@ -317,17 +318,20 @@ in_keyhelp_event_handler (const IE_event_t *ie_event, void *unused)
|
||||||
type = "axis";
|
type = "axis";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
name = IN_GetAxisName (devid, num);
|
||||||
} else if (ie_event->type == ie_button) {
|
} else if (ie_event->type == ie_button) {
|
||||||
if (ie_event->button.state) {
|
if (ie_event->button.state) {
|
||||||
num = ie_event->button.button;
|
num = ie_event->button.button;
|
||||||
type = "button";
|
type = "button";
|
||||||
}
|
}
|
||||||
|
name = IN_GetButtonName (devid, num);
|
||||||
}
|
}
|
||||||
if (!type) {
|
if (!type) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
IE_Set_Focus (in_keyhelp_saved_handler);
|
IE_Set_Focus (in_keyhelp_saved_handler);
|
||||||
Sys_Printf ("%s (%s %s) %s %d\n", name, devname, id, type, num);
|
Sys_Printf ("%s (%s %s) %s %d (%s)\n", bind_name, devname, id, type, num,
|
||||||
|
name ? name : "");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -402,7 +406,10 @@ in_bind_f (void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (*type == 'a') {
|
if (*type == 'a') {
|
||||||
if (*end || num < 0 || num >= dev->num_axes) {
|
if (*end) {
|
||||||
|
num = IN_GetAxisNumber (dev->devid, number);
|
||||||
|
}
|
||||||
|
if (num < 0 || num >= dev->num_axes) {
|
||||||
Sys_Printf ("invalid axis number: %s\n", number);
|
Sys_Printf ("invalid axis number: %s\n", number);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -464,7 +471,10 @@ in_bind_f (void)
|
||||||
// the rest of the command line is the binding
|
// the rest of the command line is the binding
|
||||||
const char *binding = Cmd_Args (5);
|
const char *binding = Cmd_Args (5);
|
||||||
|
|
||||||
if (*end || num < 0 || num >= dev->num_buttons) {
|
if (*end) {
|
||||||
|
num = IN_GetButtonNumber (dev->devid, number);
|
||||||
|
}
|
||||||
|
if (num < 0 || num >= dev->num_buttons) {
|
||||||
Sys_Printf ("invalid button number: %s\n", number);
|
Sys_Printf ("invalid button number: %s\n", number);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -280,6 +280,78 @@ IN_ButtonInfo (int devid, in_buttoninfo_t *buttons, int *numbuttons)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
IN_GetAxisName (int devid, int axis_num)
|
||||||
|
{
|
||||||
|
if ((size_t) devid >= in_devices.size) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (!in_devices.a[devid].device || in_devices.a[devid].driverid == -1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int driver = in_devices.a[devid].driverid;
|
||||||
|
in_regdriver_t *rd = &in_drivers.a[driver];
|
||||||
|
if (!rd->driver.get_axis_name) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return rd->driver.get_axis_name (rd->data, in_devices.a[devid].device,
|
||||||
|
axis_num);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
IN_GetButtonName (int devid, int button_num)
|
||||||
|
{
|
||||||
|
if ((size_t) devid >= in_devices.size) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (!in_devices.a[devid].device || in_devices.a[devid].driverid == -1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int driver = in_devices.a[devid].driverid;
|
||||||
|
in_regdriver_t *rd = &in_drivers.a[driver];
|
||||||
|
if (!rd->driver.get_button_name) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return rd->driver.get_button_name (rd->data, in_devices.a[devid].device,
|
||||||
|
button_num);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
IN_GetAxisNumber (int devid, const char *axis_name)
|
||||||
|
{
|
||||||
|
if ((size_t) devid >= in_devices.size) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (!in_devices.a[devid].device || in_devices.a[devid].driverid == -1) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
int driver = in_devices.a[devid].driverid;
|
||||||
|
in_regdriver_t *rd = &in_drivers.a[driver];
|
||||||
|
if (!rd->driver.get_axis_num) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return rd->driver.get_axis_num (rd->data, in_devices.a[devid].device,
|
||||||
|
axis_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
IN_GetButtonNumber (int devid, const char *button_name)
|
||||||
|
{
|
||||||
|
if ((size_t) devid >= in_devices.size) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (!in_devices.a[devid].device || in_devices.a[devid].driverid == -1) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
int driver = in_devices.a[devid].driverid;
|
||||||
|
in_regdriver_t *rd = &in_drivers.a[driver];
|
||||||
|
if (!rd->driver.get_button_num) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return rd->driver.get_button_num (rd->data, in_devices.a[devid].device,
|
||||||
|
button_name);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
IN_UpdateGrab (cvar_t *var) // called from context_*.c
|
IN_UpdateGrab (cvar_t *var) // called from context_*.c
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue