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:
authorKester Maddock <Christopher.Maddock.1@uni.massey.ac.nz>2005-01-23 04:36:29 +0300
committerKester Maddock <Christopher.Maddock.1@uni.massey.ac.nz>2005-01-23 04:36:29 +0300
commita1f0f165e42982fb5ef45dea54f3ebc48cbca892 (patch)
tree09d843f18ce514a76779d90767145dba7c8c8ad6 /source/blender
parenta572d196e655e60c68c622adcb28cf45138c4d15 (diff)
Added Joystick sensor (from snailrose)
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenkernel/intern/sca.c3
-rw-r--r--source/blender/blenloader/intern/writefile.c3
-rw-r--r--source/blender/makesdna/DNA_sensor_types.h31
-rw-r--r--source/blender/src/buttons_logic.c65
4 files changed, 99 insertions, 3 deletions
diff --git a/source/blender/blenkernel/intern/sca.c b/source/blender/blenkernel/intern/sca.c
index fdcf998d1d3..e772a3bcdb4 100644
--- a/source/blender/blenkernel/intern/sca.c
+++ b/source/blender/blenkernel/intern/sca.c
@@ -172,6 +172,9 @@ void init_sensor(bSensor *sens)
case SENS_MESSAGE:
sens->data= MEM_callocN(sizeof(bMessageSensor), "messagesens");
break;
+ case SENS_JOYSTICK:
+ sens->data= MEM_callocN(sizeof(bJoystickSensor), "joysticksens");
+ break;
default:
; /* this is very severe... I cannot make any memory for this */
/* logic brick... */
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 3232f12f13e..e5b6177aea4 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -474,6 +474,9 @@ static void write_sensors(WriteData *wd, ListBase *lb)
case SENS_MESSAGE:
writestruct(wd, DATA, "bMessageSensor", 1, sens->data);
break;
+ case SENS_JOYSTICK:
+ writestruct(wd, DATA, "bJoystickSensor", 1, sens->data);
+ break;
default:
; /* error: don't know how to write this file */
}
diff --git a/source/blender/makesdna/DNA_sensor_types.h b/source/blender/makesdna/DNA_sensor_types.h
index 9c4d3c1ca20..c56fe81ca19 100644
--- a/source/blender/makesdna/DNA_sensor_types.h
+++ b/source/blender/makesdna/DNA_sensor_types.h
@@ -151,6 +151,19 @@ typedef struct bSensor {
int pad;
} bSensor;
+typedef struct bJoystickSensor {
+ char name[32];
+ short type;
+ short pad;
+ int axis;
+ int axisf;
+ int button;
+ int buttonf;
+ int hat;
+ int hatf;
+ int precision;
+} bJoystickSensor;
+
/* bMouseSensor->type: uses blender event defines */
/* propertysensor->type */
@@ -186,7 +199,7 @@ typedef struct bSensor {
#define SENS_RANDOM 8
#define SENS_RAY 9
#define SENS_MESSAGE 10
-
+#define SENS_JOYSTICK 11
/* sensor->flag */
#define SENS_SHOW 1
#define SENS_DEL 2
@@ -196,7 +209,7 @@ typedef struct bSensor {
/* sensor->pulse */
#define SENS_PULSE_CONT 0
#define SENS_PULSE_REPEAT 1
-#define SENS_PULSE_ONCE 2
+//#define SENS_PULSE_ONCE 2
#define SENS_NEG_PULSE_MODE 4
/* sensor->suppress */
@@ -224,5 +237,19 @@ typedef struct bSensor {
#define BL_SENS_MOUSE_MOVEMENT 8
#define BL_SENS_MOUSE_MOUSEOVER 16
+#define SENS_JOY_BUTTON 0
+#define SENS_JOY_BUTTON_PRESSED 0
+#define SENS_JOY_BUTTON_RELEASED 1
+
+#define SENS_JOY_AXIS 1
+#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_DIR 0
+
#endif
diff --git a/source/blender/src/buttons_logic.c b/source/blender/src/buttons_logic.c
index d70f4cd9fd6..61c57ea8596 100644
--- a/source/blender/src/buttons_logic.c
+++ b/source/blender/src/buttons_logic.c
@@ -640,6 +640,8 @@ static char *sensor_name(int type)
return "Ray";
case SENS_MESSAGE:
return "Message";
+ case SENS_JOYSTICK:
+ return "Joystick";
}
return "unknown";
}
@@ -649,7 +651,7 @@ static char *sensor_pup(void)
/* the number needs to match defines in game.h */
return "Sensors %t|Always %x0|Keyboard %x3|Mouse %x5|"
"Touch %x1|Collision %x6|Near %x2|Radar %x7|"
- "Property %x4|Random %x8|Ray %x9|Message %x10";
+ "Property %x4|Random %x8|Ray %x9|Message %x10|Joystick %x11";
}
static char *controller_name(int type)
@@ -928,6 +930,7 @@ static int get_col_sensor(int type)
case SENS_RANDOM: return TH_BUT_NEUTRAL;
case SENS_RAY: return TH_BUT_SETTING1;
case SENS_MESSAGE: return TH_BUT_SETTING2;
+ case SENS_JOYSTICK: return TH_BUT_NEUTRAL;
default: return TH_BUT_NEUTRAL;
}
}
@@ -980,6 +983,8 @@ static short draw_sensorbuttons(bSensor *sens, uiBlock *block, short xco, short
bRandomSensor *randomSensor = NULL;
bRaySensor *raySens = NULL;
bMessageSensor *mes = NULL;
+ bJoystickSensor *joy = NULL;
+
short ysize;
char *str;
@@ -1299,6 +1304,64 @@ static short draw_sensorbuttons(bSensor *sens, uiBlock *block, short xco, short
yco -= ysize;
break;
}
+ case SENS_JOYSTICK:
+ {
+
+ ysize = 72;
+
+ glRects(xco, yco-ysize, xco+width, yco);
+ uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
+
+ /* line 1: header */
+ draw_default_sensor_header(sens, block, xco, yco, width);
+
+ joy= sens->data;
+
+
+ str= "Type %t|Button %x0|Axis %x1|Hat%x2";
+ uiDefButS(block, MENU, B_REDR, str, xco+10, yco-44, 0.6 * (width-20), 19,
+ &joy->type, 0, 31, 0, 0,
+ "The type of event this joystick sensor is triggered on.");
+
+ if(joy->type == SENS_JOY_BUTTON)
+ {
+ uiDefButI(block, NUM, 1, "Number:", xco+10, yco-68, 0.6 * (width-20), 19,
+ &joy->button, 0, 18, 100, 0,
+ "Specify which button to use");
+
+ str = "Type %t|Pressed %x0|Released %x1";
+ uiDefButI(block, MENU, B_REDR, str, xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
+ &joy->buttonf, 2.0, 31, 0, 0,
+ "Button pressed or released.");
+ }
+ else if(joy->type == SENS_JOY_AXIS)
+ {
+ uiDefButI(block, NUM, 1, "Number:", xco+10, yco-68, 0.6 * (width-20), 19,
+ &joy->axis, 1, 2.0, 100, 0,
+ "Specify which axis to use");
+
+ 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");
+
+ str = "Type %t|Up Axis %x1 |Down Axis %x3|Left Axis %x2|Right Axis %x0";
+ uiDefButI(block, MENU, B_REDR, str, xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
+ &joy->axisf, 2.0, 31, 0, 0,
+ "The direction of the axis");
+ }
+ else
+ {
+ uiDefButI(block, NUM, 1, "Number:", xco+10, yco-68, 0.6 * (width-20), 19,
+ &joy->hat, 1, 2.0, 100, 0,
+ "Specify which hat to use");
+
+ uiDefButI(block, NUM, 1, "Direction:", xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
+ &joy->hatf, 0, 12, 100, 0,
+ "Specify hat direction");
+ }
+ yco-= ysize;
+ break;
+ }
}
uiBlockSetEmboss(block, UI_EMBOSSM);