diff options
author | Pablo Dobarro <pablodp606> | 2020-09-26 22:59:30 +0300 |
---|---|---|
committer | Pablo Dobarro <pablodp606@gmail.com> | 2020-09-26 23:04:45 +0300 |
commit | 8c81b3fb8b9c857626c037fe0c95c5d48a3ca20f (patch) | |
tree | 8837430bbea204b3e22fbbe59f2e328f0fbe663a /source/blender/windowmanager/intern/wm_gesture_ops.c | |
parent | 4c74980e7bd19164a715ee5141d5364bbea242bf (diff) |
Sculpt: Line gestures and Mask Line tool
This adds support for line gesture to SculptGestureContext and
implements a Mask Line tool, which affects everything to the right of a plane
defined by the straightline gesture.
For this to work, a new WM_gesture_straightline_oneshot_modal is needed
which only runs exec when the gesture is over.
Added as experimental as it does not have icon.
Reviewed By: Severin
Differential Revision: https://developer.blender.org/D8722
Diffstat (limited to 'source/blender/windowmanager/intern/wm_gesture_ops.c')
-rw-r--r-- | source/blender/windowmanager/intern/wm_gesture_ops.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/source/blender/windowmanager/intern/wm_gesture_ops.c b/source/blender/windowmanager/intern/wm_gesture_ops.c index a38cbb920c4..25de76d4428 100644 --- a/source/blender/windowmanager/intern/wm_gesture_ops.c +++ b/source/blender/windowmanager/intern/wm_gesture_ops.c @@ -792,6 +792,16 @@ void WM_OT_lasso_gesture(wmOperatorType *ot) /* -------------------------------------------------------------------- */ /** \name Straight Line Gesture + * + * Gesture defined by the start and end points of a line that is created between the posistion of + * the initial event and the position of the current event. + * + * Straight Line Gesture has two modal callbacks depending on the tool that is being implemented: a + * regular modal callback intended to update the data during the execution of the gesture and a + * oneshot callback that only updates the data once when the gesture finishes. + * + * It stores 4 values (xstart, ystart, xend, yend). + * * \{ */ static bool gesture_straightline_apply(bContext *C, wmOperator *op) @@ -841,6 +851,11 @@ int WM_gesture_straightline_invoke(bContext *C, wmOperator *op, const wmEvent *e return OPERATOR_RUNNING_MODAL; } +/** + * This modal callback calls exec once per mouse move event while the gesture is active with the + * updated line start and end values, so it can be used for tools that have a real time preview + * (like a gradient updating in real time over the mesh). + */ int WM_gesture_straightline_modal(bContext *C, wmOperator *op, const wmEvent *event) { wmGesture *gesture = op->customdata; @@ -886,6 +901,63 @@ int WM_gesture_straightline_modal(bContext *C, wmOperator *op, const wmEvent *ev return OPERATOR_RUNNING_MODAL; } +/** + * This modal oneshot callback only calls exec once after the gesture finishes without any updates + * during the gesture execution. Should be used for operations that are intended to be applied once + * without real time preview (like a trimming tool that only applies the bisect operation once + * after finishing the gesture as the bisect operation is too heavy to be computed in real time for + * a preview). + */ +int WM_gesture_straightline_oneshot_modal(bContext *C, wmOperator *op, const wmEvent *event) +{ + wmGesture *gesture = op->customdata; + wmWindow *win = CTX_wm_window(C); + rcti *rect = gesture->customdata; + + if (event->type == MOUSEMOVE) { + if (gesture->is_active == false) { + rect->xmin = rect->xmax = event->x - gesture->winrct.xmin; + rect->ymin = rect->ymax = event->y - gesture->winrct.ymin; + } + else { + rect->xmax = event->x - gesture->winrct.xmin; + rect->ymax = event->y - gesture->winrct.ymin; + } + + wm_gesture_tag_redraw(win); + } + else if (event->type == EVT_MODAL_MAP) { + switch (event->val) { + case GESTURE_MODAL_BEGIN: + if (gesture->is_active == false) { + gesture->is_active = true; + wm_gesture_tag_redraw(win); + } + break; + case GESTURE_MODAL_SELECT: + case GESTURE_MODAL_DESELECT: + case GESTURE_MODAL_IN: + case GESTURE_MODAL_OUT: + if (gesture->wait_for_input) { + gesture->modal_state = event->val; + } + if (gesture_straightline_apply(C, op)) { + gesture_modal_end(C, op); + return OPERATOR_FINISHED; + } + gesture_modal_end(C, op); + return OPERATOR_CANCELLED; + + case GESTURE_MODAL_CANCEL: + gesture_modal_end(C, op); + return OPERATOR_CANCELLED; + } + } + + gesture->is_active_prev = gesture->is_active; + return OPERATOR_RUNNING_MODAL; +} + void WM_gesture_straightline_cancel(bContext *C, wmOperator *op) { gesture_modal_end(C, op); |