diff options
author | Matt Ebb <matt@mke3.net> | 2010-05-07 12:10:20 +0400 |
---|---|---|
committer | Matt Ebb <matt@mke3.net> | 2010-05-07 12:10:20 +0400 |
commit | fbb68188dfdc213cf6653fc1a4573c79abd85527 (patch) | |
tree | 1198597aac1add4be38020826fb6bb2979501553 /source/blender | |
parent | ba8b63fbd7a780224c68004664ba0ff156bc01f2 (diff) |
Restrict keyboard sensor stored events to only what's appropriate per property
(normal key, modifier key, etc)
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/makesrna/intern/rna_sensor.c | 39 | ||||
-rw-r--r-- | source/blender/windowmanager/wm_event_types.h | 3 |
2 files changed, 35 insertions, 7 deletions
diff --git a/source/blender/makesrna/intern/rna_sensor.c b/source/blender/makesrna/intern/rna_sensor.c index ef9a6b0bba3..edae9ab36b6 100644 --- a/source/blender/makesrna/intern/rna_sensor.c +++ b/source/blender/makesrna/intern/rna_sensor.c @@ -32,6 +32,8 @@ #include "DNA_object_types.h" #include "DNA_sensor_types.h" +#include "WM_types.h" + EnumPropertyItem sensor_type_items[] ={ {SENS_ACTUATOR, "ACTUATOR", 0, "Actuator", ""}, {SENS_ALWAYS, "ALWAYS", 0, "Always", ""}, @@ -151,6 +153,33 @@ EnumPropertyItem *rna_Sensor_type_itemf(bContext *C, PointerRNA *ptr, int *free) return item; } +static void rna_Sensor_keyboard_key_set(struct PointerRNA *ptr, int value) +{ + bSensor *sens= (bSensor *)ptr->data; + bKeyboardSensor *ks = sens->data; + + if (ISKEYBOARD(value) && !ISKEYMODIFIER(value)) + ks->key = value; +} + +static void rna_Sensor_keyboard_modifier_set(struct PointerRNA *ptr, int value) +{ + bSensor *sens= (bSensor *)ptr->data; + bKeyboardSensor *ks = sens->data; + + if (ISKEYMODIFIER(value)) + ks->qual = value; +} + +static void rna_Sensor_keyboard_modifier2_set(struct PointerRNA *ptr, int value) +{ + bSensor *sens= (bSensor *)ptr->data; + bKeyboardSensor *ks = sens->data; + + if (ISKEYMODIFIER(value)) + ks->qual2 = value; +} + #else static void rna_def_sensor(BlenderRNA *brna) @@ -284,26 +313,22 @@ static void rna_def_keyboard_sensor(BlenderRNA *brna) RNA_def_struct_ui_text(srna, "Keyboard Sensor", "Sensor to detect keyboard events"); RNA_def_struct_sdna_from(srna, "bKeyboardSensor", "data"); - /* - prop= RNA_def_property(srna, "key", PROP_INT, PROP_NONE);//XXX need to use another input template - //RNA_def_property_clear_flag(prop, PROP_EDITABLE); // need better range or enum check - RNA_def_property_ui_text(prop, "Key", "Input key code"); - RNA_def_property_range(prop, 0, 255); - */ - prop= RNA_def_property(srna, "key", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "key"); RNA_def_property_enum_items(prop, event_type_items); + RNA_def_property_enum_funcs(prop, NULL, "rna_Sensor_keyboard_key_set", NULL); RNA_def_property_ui_text(prop, "Key", ""); prop= RNA_def_property(srna, "modifier_key", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "qual"); RNA_def_property_enum_items(prop, event_type_items); + RNA_def_property_enum_funcs(prop, NULL, "rna_Sensor_keyboard_modifier_set", NULL); RNA_def_property_ui_text(prop, "Modifier Key", "Modifier key code"); prop= RNA_def_property(srna, "second_modifier_key", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "qual2"); RNA_def_property_enum_items(prop, event_type_items); + RNA_def_property_enum_funcs(prop, NULL, "rna_Sensor_keyboard_modifier2_set", NULL); RNA_def_property_ui_text(prop, "Second Modifier Key", "Modifier key code"); prop= RNA_def_property(srna, "target", PROP_STRING, PROP_NONE); diff --git a/source/blender/windowmanager/wm_event_types.h b/source/blender/windowmanager/wm_event_types.h index a38e433fe56..7b83e1d4179 100644 --- a/source/blender/windowmanager/wm_event_types.h +++ b/source/blender/windowmanager/wm_event_types.h @@ -213,6 +213,9 @@ /* test whether the event is a key on the keyboard */ #define ISKEYBOARD(event) (event >=' ' && event <=320) + /* test whether the event is a modifier key */ +#define ISKEYMODIFIER(event) ((event >= LEFTCTRLKEY && event <= LEFTSHIFTKEY) || event == COMMANDKEY) + /* test whether the event is a mouse button */ #define ISMOUSE(event) (event >= LEFTMOUSE && event <= MOUSEROTATE) |