[Bf-blender-cvs] [e7afb8140ba] PSketch-279: Cleanup/Fix: Move keypress event handling into a separate function
Joshua Leung
noreply at git.blender.org
Tue May 8 18:03:31 CEST 2018
Commit: e7afb8140ba7ba7e3c399f9d8e38bbe58f5b9798
Author: Joshua Leung
Date: Tue Jan 2 05:06:08 2018 +1300
Branches: PSketch-279
https://developer.blender.org/rBe7afb8140ba7ba7e3c399f9d8e38bbe58f5b9798
Cleanup/Fix: Move keypress event handling into a separate function
This way, we can filter out the "release" events, preventing all of the
double-press bugs.
===================================================================
M source/blender/editors/armature/pose_sculpt.c
===================================================================
diff --git a/source/blender/editors/armature/pose_sculpt.c b/source/blender/editors/armature/pose_sculpt.c
index 93ed3938c6c..30193f17557 100644
--- a/source/blender/editors/armature/pose_sculpt.c
+++ b/source/blender/editors/armature/pose_sculpt.c
@@ -1496,6 +1496,7 @@ static void psculpt_brush_restore_apply(tPoseSculptingOp *pso, bPoseChannel *pch
pchan->size[2] = interpf(tab->oldscale[2], pchan->size[2], fac);
/* bendy bones */
+ // TODO: 1) Blend, 2) Head/Tail control
pchan->curveInX = tab->bbcurvein[0];
pchan->curveInY = tab->bbcurvein[1];
pchan->curveOutX = tab->bbcurveout[0];
@@ -2111,41 +2112,20 @@ static int psculpt_brush_invoke(bContext *C, wmOperator *op, const wmEvent *even
return OPERATOR_RUNNING_MODAL;
}
-/* painting - handle events */
-static int psculpt_brush_modal(bContext *C, wmOperator *op, const wmEvent *event)
+/* painting - handle key events */
+static void psculpt_brush_handle_key_event(
+ tPoseSculptingOp *pso, const wmEvent *event,
+ bool *redraw_region, bool *redraw_toolsettings)
{
- tPoseSculptingOp *pso = op->customdata;
-
const float STRENGTH_DELTA = 0.05f;
- bool redraw_region = false;
- bool redraw_toolsettings = false;
+ /* only accept 'press' event, and ignore 'release', so that we don't get double actions */
+ if (ELEM(event->val, KM_PRESS, KM_NOTHING) == 0) {
+ return;
+ }
+ /* The following events should just be key-presses */
switch (event->type) {
- /* mouse release or some other mbut click = abort! */
- case LEFTMOUSE:
- case MIDDLEMOUSE:
- case RIGHTMOUSE:
- psculpt_brush_exit(C, op);
- return OPERATOR_FINISHED;
-
- /* timer tick - only if this was our own timer */
- case TIMER:
- if (event->customdata == pso->timer) {
- pso->is_timer_tick = true;
- psculpt_brush_apply_event(C, op, event);
- pso->is_timer_tick = false;
- }
- break;
-
- /* mouse move = apply somewhere else */
- case MOUSEMOVE:
- case INBETWEEN_MOUSEMOVE:
- psculpt_brush_apply_event(C, op, event);
- break;
-
-
- /* Adjust brush settings */
/* FIXME: Step increments and modifier keys are hardcoded here! */
case WHEELUPMOUSE:
case PAGEUPKEY:
@@ -2160,8 +2140,8 @@ static int psculpt_brush_modal(bContext *C, wmOperator *op, const wmEvent *event
CLAMP_MAX(pso->brush->size, 300);
}
- redraw_region = true;
- redraw_toolsettings = true;
+ *redraw_region = true;
+ *redraw_toolsettings = true;
break;
case WHEELDOWNMOUSE:
@@ -2177,8 +2157,8 @@ static int psculpt_brush_modal(bContext *C, wmOperator *op, const wmEvent *event
CLAMP_MIN(pso->brush->size, 1);
}
- redraw_region = true;
- redraw_toolsettings = true;
+ *redraw_region = true;
+ *redraw_toolsettings = true;
break;
case PADPLUSKEY:
@@ -2186,8 +2166,8 @@ static int psculpt_brush_modal(bContext *C, wmOperator *op, const wmEvent *event
/* increase strength */
pso->brush->strength += STRENGTH_DELTA;
- redraw_region = true;
- redraw_toolsettings = true;
+ *redraw_region = true;
+ *redraw_toolsettings = true;
break;
case PADMINUS:
@@ -2195,8 +2175,8 @@ static int psculpt_brush_modal(bContext *C, wmOperator *op, const wmEvent *event
/* decrease strength */
pso->brush->strength -= STRENGTH_DELTA;
- redraw_region = true;
- redraw_toolsettings = true;
+ *redraw_region = true;
+ *redraw_toolsettings = true;
break;
/* Dynamically toggle XZ locks */
@@ -2215,7 +2195,7 @@ static int psculpt_brush_modal(bContext *C, wmOperator *op, const wmEvent *event
}
// TODO: recalc immediately
- redraw_toolsettings = true;
+ *redraw_toolsettings = true;
break;
case ZKEY:
@@ -2233,7 +2213,46 @@ static int psculpt_brush_modal(bContext *C, wmOperator *op, const wmEvent *event
}
// TODO: recalc immediately
- redraw_toolsettings = true;
+ *redraw_toolsettings = true;
+ break;
+ }
+}
+
+/* painting - handle events */
+static int psculpt_brush_modal(bContext *C, wmOperator *op, const wmEvent *event)
+{
+ tPoseSculptingOp *pso = op->customdata;
+
+ bool redraw_region = false;
+ bool redraw_toolsettings = false;
+
+ switch (event->type) {
+ /* mouse release or some other mbut click = abort! */
+ case LEFTMOUSE:
+ case MIDDLEMOUSE:
+ case RIGHTMOUSE:
+ psculpt_brush_exit(C, op);
+ return OPERATOR_FINISHED;
+
+ /* timer tick - only if this was our own timer */
+ case TIMER:
+ if (event->customdata == pso->timer) {
+ pso->is_timer_tick = true;
+ psculpt_brush_apply_event(C, op, event);
+ pso->is_timer_tick = false;
+ }
+ break;
+
+ /* mouse move = apply somewhere else */
+ case MOUSEMOVE:
+ case INBETWEEN_MOUSEMOVE:
+ psculpt_brush_apply_event(C, op, event);
+ break;
+
+
+ /* handle key presses used to adjust brush settings */
+ default:
+ psculpt_brush_handle_key_event(pso, event, &redraw_region, &redraw_toolsettings);
break;
}
More information about the Bf-blender-cvs
mailing list