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:
Diffstat (limited to 'source/blender/windowmanager/intern/wm_gesture_ops.c')
-rw-r--r--source/blender/windowmanager/intern/wm_gesture_ops.c72
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);