Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-04-07 10:23:45 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-04-07 10:23:45 +0400
commit885fa49aa4cd49a552bfe6210e3cb4701c4a5d04 (patch)
treea92028138d51c136190dceaaaf600a58246c823c /source/blender
parent816a9f3acb47f97d5bf92ae7ae8803e31f4a9f0a (diff)
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.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/makesdna/DNA_sensor_types.h11
-rw-r--r--source/blender/src/buttons_logic.c56
2 files changed, 40 insertions, 27 deletions
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;
}