[Bf-blender-cvs] [dcd4eb4c250] master: Cleanup: minor refactor to view operator event handling
Campbell Barton
noreply at git.blender.org
Wed Dec 7 07:46:38 CET 2022
Commit: dcd4eb4c2508e4149885f464251c295ddb9859b3
Author: Campbell Barton
Date: Wed Dec 7 16:23:03 2022 +1100
Branches: master
https://developer.blender.org/rBdcd4eb4c2508e4149885f464251c295ddb9859b3
Cleanup: minor refactor to view operator event handling
- Add VIEW_CANCEL event_code.
- De-duplicate operator freeing logic for the roll operator.
- Structure checks so adding cancel is is simplified.
- Split event checks into two blocks, one for model events, another
for all other events.
===================================================================
M source/blender/editors/space_image/image_ops.c
M source/blender/editors/space_view3d/view3d_navigate.h
M source/blender/editors/space_view3d/view3d_navigate_dolly.c
M source/blender/editors/space_view3d/view3d_navigate_move.c
M source/blender/editors/space_view3d/view3d_navigate_roll.c
M source/blender/editors/space_view3d/view3d_navigate_rotate.c
M source/blender/editors/space_view3d/view3d_navigate_zoom.c
===================================================================
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index 3503c4c8168..f6d21633bb3 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -667,35 +667,47 @@ static int image_view_zoom_modal(bContext *C, wmOperator *op, const wmEvent *eve
{
ViewZoomData *vpd = op->customdata;
short event_code = VIEW_PASS;
+ int ret = OPERATOR_RUNNING_MODAL;
- /* execute the events */
- if (event->type == TIMER && event->customdata == vpd->timer) {
- /* continuous zoom */
+ /* Execute the events. */
+ if (event->type == MOUSEMOVE) {
event_code = VIEW_APPLY;
}
- else if (event->type == MOUSEMOVE) {
- event_code = VIEW_APPLY;
+ else if (event->type == TIMER) {
+ /* Continuous zoom. */
+ if (event->customdata == vpd->timer) {
+ event_code = VIEW_APPLY;
+ }
}
- else if (event->type == vpd->launch_event && event->val == KM_RELEASE) {
- event_code = VIEW_CONFIRM;
+ else if (event->type == vpd->launch_event) {
+ if (event->val == KM_RELEASE) {
+ event_code = VIEW_CONFIRM;
+ }
}
- if (event_code == VIEW_APPLY) {
- const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init");
- image_zoom_apply(vpd,
- op,
- event->xy[0],
- event->xy[1],
- U.viewzoom,
- (U.uiflag & USER_ZOOM_INVERT) != 0,
- (use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)));
- }
- else if (event_code == VIEW_CONFIRM) {
+ switch (event_code) {
+ case VIEW_APPLY: {
+ const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init");
+ image_zoom_apply(vpd,
+ op,
+ event->xy[0],
+ event->xy[1],
+ U.viewzoom,
+ (U.uiflag & USER_ZOOM_INVERT) != 0,
+ (use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)));
+ break;
+ }
+ case VIEW_CONFIRM: {
+ ret = OPERATOR_FINISHED;
+ break;
+ }
+ }
+
+ if ((ret & OPERATOR_RUNNING_MODAL) == 0) {
image_view_zoom_exit(C, op, false);
- return OPERATOR_FINISHED;
}
- return OPERATOR_RUNNING_MODAL;
+ return ret;
}
static void image_view_zoom_cancel(bContext *C, wmOperator *op)
diff --git a/source/blender/editors/space_view3d/view3d_navigate.h b/source/blender/editors/space_view3d/view3d_navigate.h
index 792357ae134..b40c878f1fd 100644
--- a/source/blender/editors/space_view3d/view3d_navigate.h
+++ b/source/blender/editors/space_view3d/view3d_navigate.h
@@ -41,6 +41,8 @@ enum {
VIEW_PASS = 0,
VIEW_APPLY,
VIEW_CONFIRM,
+ /** Only supported by some viewport operators. */
+ VIEW_CANCEL,
};
/* NOTE: these defines are saved in keymap files, do not change values but just add new ones */
diff --git a/source/blender/editors/space_view3d/view3d_navigate_dolly.c b/source/blender/editors/space_view3d/view3d_navigate_dolly.c
index df0f4e6e94b..9e4c0f90839 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_dolly.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_dolly.c
@@ -142,11 +142,8 @@ static int viewdolly_modal(bContext *C, wmOperator *op, const wmEvent *event)
bool use_autokey = false;
int ret = OPERATOR_RUNNING_MODAL;
- /* execute the events */
- if (event->type == MOUSEMOVE) {
- event_code = VIEW_APPLY;
- }
- else if (event->type == EVT_MODAL_MAP) {
+ /* Execute the events. */
+ if (event->type == EVT_MODAL_MAP) {
switch (event->val) {
case VIEW_MODAL_CONFIRM:
event_code = VIEW_CONFIRM;
@@ -161,27 +158,40 @@ static int viewdolly_modal(bContext *C, wmOperator *op, const wmEvent *event)
break;
}
}
- else if (event->type == vod->init.event_type && event->val == KM_RELEASE) {
- event_code = VIEW_CONFIRM;
+ else {
+ if (event->type == MOUSEMOVE) {
+ event_code = VIEW_APPLY;
+ }
+ else if (event->type == vod->init.event_type) {
+ if (event->val == KM_RELEASE) {
+ event_code = VIEW_CONFIRM;
+ }
+ }
}
- if (event_code == VIEW_APPLY) {
- viewdolly_apply(vod, event->xy, (U.uiflag & USER_ZOOM_INVERT) != 0);
- if (ED_screen_animation_playing(CTX_wm_manager(C))) {
+ switch (event_code) {
+ case VIEW_APPLY: {
+ viewdolly_apply(vod, event->xy, (U.uiflag & USER_ZOOM_INVERT) != 0);
+ if (ED_screen_animation_playing(CTX_wm_manager(C))) {
+ use_autokey = true;
+ }
+ break;
+ }
+ case VIEW_CONFIRM: {
use_autokey = true;
+ ret = OPERATOR_FINISHED;
+ break;
}
}
- else if (event_code == VIEW_CONFIRM) {
- use_autokey = true;
- ret = OPERATOR_FINISHED;
- }
if (use_autokey) {
ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true);
}
- if (ret & OPERATOR_FINISHED) {
- ED_view3d_camera_lock_undo_push(op->type->name, vod->v3d, vod->rv3d, C);
+ if ((ret & OPERATOR_RUNNING_MODAL) == 0) {
+ if (ret & OPERATOR_FINISHED) {
+ ED_view3d_camera_lock_undo_push(op->type->name, vod->v3d, vod->rv3d, C);
+ }
viewops_data_free(C, vod);
op->customdata = NULL;
}
diff --git a/source/blender/editors/space_view3d/view3d_navigate_move.c b/source/blender/editors/space_view3d/view3d_navigate_move.c
index 9de0a2ae4c2..5de407f2a9b 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_move.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_move.c
@@ -101,11 +101,8 @@ static int viewmove_modal(bContext *C, wmOperator *op, const wmEvent *event)
bool use_autokey = false;
int ret = OPERATOR_RUNNING_MODAL;
- /* execute the events */
- if (event->type == MOUSEMOVE) {
- event_code = VIEW_APPLY;
- }
- else if (event->type == EVT_MODAL_MAP) {
+ /* Execute the events. */
+ if (event->type == EVT_MODAL_MAP) {
switch (event->val) {
case VIEW_MODAL_CONFIRM:
event_code = VIEW_CONFIRM;
@@ -120,27 +117,40 @@ static int viewmove_modal(bContext *C, wmOperator *op, const wmEvent *event)
break;
}
}
- else if (event->type == vod->init.event_type && event->val == KM_RELEASE) {
- event_code = VIEW_CONFIRM;
+ else {
+ if (event->type == MOUSEMOVE) {
+ event_code = VIEW_APPLY;
+ }
+ else if (event->type == vod->init.event_type) {
+ if (event->val == KM_RELEASE) {
+ event_code = VIEW_CONFIRM;
+ }
+ }
}
- if (event_code == VIEW_APPLY) {
- viewmove_apply(vod, event->xy[0], event->xy[1]);
- if (ED_screen_animation_playing(CTX_wm_manager(C))) {
+ switch (event_code) {
+ case VIEW_APPLY: {
+ viewmove_apply(vod, event->xy[0], event->xy[1]);
+ if (ED_screen_animation_playing(CTX_wm_manager(C))) {
+ use_autokey = true;
+ }
+ break;
+ }
+ case VIEW_CONFIRM: {
use_autokey = true;
+ ret = OPERATOR_FINISHED;
+ break;
}
}
- else if (event_code == VIEW_CONFIRM) {
- use_autokey = true;
- ret = OPERATOR_FINISHED;
- }
if (use_autokey) {
ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true);
}
- if (ret & OPERATOR_FINISHED) {
- ED_view3d_camera_lock_undo_push(op->type->name, vod->v3d, vod->rv3d, C);
+ if ((ret & OPERATOR_RUNNING_MODAL) == 0) {
+ if (ret & OPERATOR_FINISHED) {
+ ED_view3d_camera_lock_undo_push(op->type->name, vod->v3d, vod->rv3d, C);
+ }
viewops_data_free(C, op->customdata);
op->customdata = NULL;
}
diff --git a/source/blender/editors/space_view3d/view3d_navigate_roll.c b/source/blender/editors/space_view3d/view3d_navigate_roll.c
index 5a6a3ef1fa6..51b92cb23b3 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_roll.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_roll.c
@@ -87,11 +87,8 @@ static int viewroll_modal(bContext *C, wmOperator *op, const wmEvent *event)
bool use_autokey = false;
int ret = OPERATOR_RUNNING_MODAL;
- /* execute the events */
- if (event->type == MOUSEMOVE) {
- event_code = VIEW_APPLY;
- }
- else if (event->type == EVT_MODAL_MAP) {
+ /* Execute the events. */
+ if (event->type == EVT_MODAL_MAP) {
switch (event->val) {
case VIEW_MODAL_CONFIRM:
event_code = VIEW_CONFIRM;
@@ -106,40 +103,51 @@ static int viewroll_modal(bContext *C, wmOperator *op, const wmEvent *event)
break;
}
}
- else if (event->type == vod->init.event_type) {
- /* Check `vod->init.event_type` first in case RMB was used to invoke.
- * in this case confirming takes precedence over canceling, see: T102937. */
- if (event->val == KM_RELEASE) {
- event_code = VIEW_CONFIRM;
+ else {
+ if (event->type == MOUSEMOVE) {
+ event_code = VIEW_APPLY;
}
- }
- else if (ELEM(event->type, EVT_ESCKEY, RIGHTMOUSE)) {
- if (event->val == KM_PRESS) {
- /* Note this does not remove auto-keys on locked cameras. */
- copy_qt_qt(vod->rv3d->viewquat, vod->init.quat);
- ED_view3d_camera_lock_sync(vod->depsgraph, vod->v3d, vod->rv3d);
- viewops_data_free(C, op->customdata);
- op->customdata = NULL;
- return OPERATOR_CANCELLED;
+ else if (event->type == vod->init.event_type) {
+ /* Check `vod->init.event_type` first in case RMB was used to invoke.
+ * in this case confirming takes precedence over canceling, see: T102937. */
+ if (event->val == KM_RELEASE) {
+ event_code = VIEW_CONFIRM;
+ }
+ }
+ else if (ELEM(event->type, EVT_ESCKEY, RIGHTMOUSE)) {
+ if (event->val == KM_PRESS) {
+ event_code = VIEW_CANCEL;
+ }
}
}
- if (event_code == VIEW_APPLY) {
- viewroll_apply(vod, event->xy[0], event->xy[1]);
- if (ED_screen_animation_playing(CTX_wm_manager(C))) {
+ switch (event_code) {
+ case VIEW_APPLY: {
+ viewroll_apply(vod, event->xy[0], event->xy[1]);
+ if (ED_screen_animation_playing(CTX_wm_manager(C))) {
+ use_autokey = true;
+ }
+ break;
+ }
+ case VIEW_CONFIRM: {
use_autokey = true;
+ ret = OPERATOR_FINISHED;
+ break;
+ }
+ case VIEW_CANCEL: {
+ /* Note this does not remove auto-keys on locked cam
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list