Follow up to previous commit.

* Expose is_tablet property to events to determine if event contains
tablet data.
* Expose tablet tilt for events as a 2D vector in python
This commit is contained in:
Antonis Ryakiotakis 2014-07-14 17:49:00 +03:00
parent 45f0bd6eb1
commit 48eececdba
5 changed files with 46 additions and 6 deletions

View File

@ -715,7 +715,7 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event)
float pressure;
/* see if tablet affects event */
pressure = WM_event_tablet_data(event, &stroke->pen_flip);
pressure = WM_event_tablet_data(event, &stroke->pen_flip, NULL);
paint_stroke_add_sample(p, stroke, event->mval[0], event->mval[1], pressure);
paint_stroke_sample_average(stroke, &sample_average);

View File

@ -568,7 +568,19 @@ static int rna_Event_unicode_length(PointerRNA *ptr)
static float rna_Event_pressure_get(PointerRNA *ptr)
{
wmEvent *event = ptr->data;
return WM_event_tablet_data(event, NULL);
return WM_event_tablet_data(event, NULL, NULL);
}
static int rna_Event_is_tablet_get(PointerRNA *ptr)
{
wmEvent *event = ptr->data;
return WM_event_is_tablet(event);
}
static void rna_Event_tilt_get(PointerRNA *ptr, float *values)
{
wmEvent *event = ptr->data;
WM_event_tablet_data(event, NULL, values);
}
static PointerRNA rna_PopupMenu_layout_get(PointerRNA *ptr)
@ -1619,6 +1631,17 @@ static void rna_def_event(BlenderRNA *brna)
RNA_def_property_float_funcs(prop, "rna_Event_pressure_get", NULL, NULL);
RNA_def_property_ui_text(prop, "Tablet Pressure", "The pressure of the tablet or 1.0 if no tablet present");
prop = RNA_def_property(srna, "tilt", PROP_FLOAT, PROP_XYZ_LENGTH);
RNA_def_property_array(prop, 2);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_float_funcs(prop, "rna_Event_tilt_get", NULL, NULL);
RNA_def_property_ui_text(prop, "Tablet Tilt", "The pressure of the tablet or zeroes if no tablet present");
prop = RNA_def_property(srna, "is_tablet", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_boolean_funcs(prop, "rna_Event_is_tablet_get", NULL);
RNA_def_property_ui_text(prop, "Tablet Pressure", "The pressure of the tablet or 1.0 if no tablet present");
/* modifiers */
prop = RNA_def_property(srna, "shift", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "shift", 1);

View File

@ -449,7 +449,8 @@ void WM_event_ndof_rotate_get(const struct wmNDOFMotionData *ndof, float
float WM_event_ndof_to_axis_angle(const struct wmNDOFMotionData *ndof, float axis[3]);
void WM_event_ndof_to_quat(const struct wmNDOFMotionData *ndof, float q[4]);
float WM_event_tablet_data(const struct wmEvent *event, int *pen_flip);
float WM_event_tablet_data(const struct wmEvent *event, int *pen_flip, float tilt[2]);
bool WM_event_is_tablet(const struct wmEvent *event);
#ifdef __cplusplus
}

View File

@ -3406,16 +3406,25 @@ void WM_event_ndof_to_quat(const struct wmNDOFMotionData *ndof, float q[4])
/* if this is a tablet event, return tablet pressure and set *pen_flip
* to 1 if the eraser tool is being used, 0 otherwise */
float WM_event_tablet_data(const wmEvent *event, int *pen_flip)
float WM_event_tablet_data(const wmEvent *event, int *pen_flip, float tilt[2])
{
int erasor = 0;
float pressure = 1;
if (tilt)
zero_v2(tilt);
if (event->tablet_data) {
wmTabletData *wmtab = event->tablet_data;
erasor = (wmtab->Active == EVT_TABLET_ERASER);
pressure = (wmtab->Active != EVT_TABLET_NONE) ? wmtab->Pressure : 1;
if (wmtab->Active != EVT_TABLET_NONE) {
pressure = wmtab->Pressure;
if (tilt) {
tilt[0] = wmtab->Xtilt;
tilt[1] = wmtab->Ytilt;
}
}
}
if (pen_flip)
@ -3424,4 +3433,10 @@ float WM_event_tablet_data(const wmEvent *event, int *pen_flip)
return pressure;
}
bool WM_event_is_tablet(const struct wmEvent *event)
{
return (event->tablet_data) ? true : false;
}
/** \} */

View File

@ -301,7 +301,8 @@ void ED_armature_transform(struct bArmature *arm, float mat[4][4]) RET_NONE
struct wmEventHandler *WM_event_add_modal_handler(struct bContext *C, struct wmOperator *op) RET_NULL
struct wmTimer *WM_event_add_timer(struct wmWindowManager *wm, struct wmWindow *win, int event_type, double timestep) RET_NULL
void WM_event_remove_timer(struct wmWindowManager *wm, struct wmWindow *win, struct wmTimer *timer) RET_NONE
float WM_event_tablet_data(const struct wmEvent *event, int *pen_flip) RET_ZERO
float WM_event_tablet_data(const struct wmEvent *event, int *pen_flip, float tilt[2]) RET_ZERO
bool WM_event_is_tablet(const struct wmEvent *event) RET_ZERO
void ED_armature_edit_bone_remove(struct bArmature *arm, struct EditBone *exBone) RET_NONE
void object_test_constraints(struct Object *owner) RET_NONE
void ED_armature_ebone_to_mat4(struct EditBone *ebone, float mat[4][4]) RET_NONE