From 885fa49aa4cd49a552bfe6210e3cb4701c4a5d04 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 7 Apr 2009 06:23:45 +0000 Subject: BGE Joystick Sensor - Raised limit of 2 axis to 4 axis pairs (4==8 joysticks axis pairs) - Added a new Joystick Sensor type "Single Axis", so you can detect horizontal or vertical movement, rather then just Up/Down/Left/Right - added Python attribute "axisSingle" so you can get the value from the selected axis (rather then getting it out of the axis list) - renamed Py attribute "axisPosition" to "axisValues" (was never in a release) If we need to increase the axis limit again just change JOYAXIS_MAX and the button limits. --- source/blender/makesdna/DNA_sensor_types.h | 11 +++--- source/blender/src/buttons_logic.c | 56 ++++++++++++++++++------------ 2 files changed, 40 insertions(+), 27 deletions(-) (limited to 'source/blender') diff --git a/source/blender/makesdna/DNA_sensor_types.h b/source/blender/makesdna/DNA_sensor_types.h index 2cae2cc8ccb..7a358ad0694 100644 --- a/source/blender/makesdna/DNA_sensor_types.h +++ b/source/blender/makesdna/DNA_sensor_types.h @@ -166,7 +166,8 @@ typedef struct bJoystickSensor { char type; char joyindex; short flag; - int axis; + short axis; + short axis_single; int axisf; int button; int hat; @@ -255,20 +256,22 @@ typedef struct bJoystickSensor { #define SENS_JOY_ANY_EVENT 1 -#define SENS_JOY_BUTTON 0 +#define SENS_JOY_BUTTON 0 /* axis type */ #define SENS_JOY_BUTTON_PRESSED 0 #define SENS_JOY_BUTTON_RELEASED 1 -#define SENS_JOY_AXIS 1 +#define SENS_JOY_AXIS 1 /* axis type */ #define SENS_JOY_X_AXIS 0 #define SENS_JOY_Y_AXIS 1 #define SENS_JOY_NEG_X_AXIS 2 #define SENS_JOY_NEG_Y_AXIS 3 #define SENS_JOY_PRECISION 4 -#define SENS_JOY_HAT 2 +#define SENS_JOY_HAT 2 /* axis type */ #define SENS_JOY_HAT_DIR 0 +#define SENS_JOY_AXIS_SINGLE 3 /* axis type */ + #define SENS_DELAY_REPEAT 1 // should match JOYINDEX_MAX in SCA_JoystickDefines.h */ diff --git a/source/blender/src/buttons_logic.c b/source/blender/src/buttons_logic.c index cf6d29da0d3..94790ac0f40 100644 --- a/source/blender/src/buttons_logic.c +++ b/source/blender/src/buttons_logic.c @@ -1457,32 +1457,33 @@ static short draw_sensorbuttons(bSensor *sens, uiBlock *block, short xco, short &joy->joyindex, 0, SENS_JOY_MAXINDEX-1, 100, 0, "Specify which joystick to use"); - str= "Type %t|Button %x0|Axis %x1|Hat%x2"; + str= "Type %t|Button %x0|Axis %x1|Single Axis %x3|Hat%x2"; uiDefButC(block, MENU, B_REDR, str, xco+87, yco-44, 0.26 * (width-20), 19, &joy->type, 0, 31, 0, 0, "The type of event this joystick sensor is triggered on."); - if (joy->flag & SENS_JOY_ANY_EVENT) { - switch (joy->type) { - case SENS_JOY_AXIS: - str = "All Axis Events"; - break; - case SENS_JOY_BUTTON: - str = "All Button Events"; - break; - default: - str = "All Hat Events"; - break; + if (joy->type != SENS_JOY_AXIS_SINGLE) { + if (joy->flag & SENS_JOY_ANY_EVENT) { + switch (joy->type) { + case SENS_JOY_AXIS: + str = "All Axis Events"; + break; + case SENS_JOY_BUTTON: + str = "All Button Events"; + break; + default: + str = "All Hat Events"; + break; + } + } else { + str = "All"; } - } else { - str = "All"; + + uiDefButBitS(block, TOG, SENS_JOY_ANY_EVENT, B_REDR, str, + xco+10 + 0.475 * (width-20), yco-68, ((joy->flag & SENS_JOY_ANY_EVENT) ? 0.525 : 0.12) * (width-20), 19, + &joy->flag, 0, 0, 0, 0, + "Triggered by all events on this joysticks current type (axis/button/hat)"); } - - uiDefButBitS(block, TOG, SENS_JOY_ANY_EVENT, B_REDR, str, - xco+10 + 0.475 * (width-20), yco-68, ((joy->flag & SENS_JOY_ANY_EVENT) ? 0.525 : 0.12) * (width-20), 19, - &joy->flag, 0, 0, 0, 0, - "Triggered by all events on this joysticks current type (axis/button/hat)"); - if(joy->type == SENS_JOY_BUTTON) { if ((joy->flag & SENS_JOY_ANY_EVENT)==0) { @@ -1493,8 +1494,8 @@ static short draw_sensorbuttons(bSensor *sens, uiBlock *block, short xco, short } else if(joy->type == SENS_JOY_AXIS) { - uiDefButI(block, NUM, 1, "Number:", xco+10, yco-68, 0.46 * (width-20), 19, - &joy->axis, 1, 2.0, 100, 0, + uiDefButS(block, NUM, 1, "Number:", xco+10, yco-68, 0.46 * (width-20), 19, + &joy->axis, 1, 4.0, 100, 0, "Specify which axis pair to use, 1 is useually the main direction input."); uiDefButI(block, NUM, 1, "Threshold:", xco+10 + 0.6 * (width-20),yco-44, 0.4 * (width-20), 19, @@ -1508,7 +1509,7 @@ static short draw_sensorbuttons(bSensor *sens, uiBlock *block, short xco, short "The direction of the axis, use 'All Events' to recieve events on any direction"); } } - else + else if (joy->type == SENS_JOY_HAT) { uiDefButI(block, NUM, 1, "Number:", xco+10, yco-68, 0.46 * (width-20), 19, &joy->hat, 1, 2.0, 100, 0, @@ -1520,6 +1521,15 @@ static short draw_sensorbuttons(bSensor *sens, uiBlock *block, short xco, short "Specify hat direction"); } } + else { /* (joy->type == SENS_JOY_AXIS_SINGLE)*/ + uiDefButS(block, NUM, 1, "Number:", xco+10, yco-68, 0.46 * (width-20), 19, + &joy->axis_single, 1, 8.0, 100, 0, + "Specify a single axis (verticle/horizontal/other) to detect"); + + uiDefButI(block, NUM, 1, "Threshold:", xco+10 + 0.6 * (width-20),yco-44, 0.4 * (width-20), 19, + &joy->precision, 0, 32768.0, 100, 0, + "Specify the precision of the axis"); + } yco-= ysize; break; } -- cgit v1.2.3