Blender V5.0
view3d_navigate_view_move.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BKE_context.hh"
10
11#include "WM_api.hh"
12
13#include "ED_screen.hh"
14
15#include "view3d_intern.hh"
16#include "view3d_navigate.hh" /* own include */
17
18/* -------------------------------------------------------------------- */
21
22/* NOTE: these defines are saved in keymap files, do not change values but just add new ones */
23
25{
26 static const EnumPropertyItem modal_items[] = {
27 {VIEW_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
28 {VIEW_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
29
30 {VIEWROT_MODAL_SWITCH_ZOOM, "SWITCH_TO_ZOOM", 0, "Switch to Zoom"},
31 {VIEWROT_MODAL_SWITCH_ROTATE, "SWITCH_TO_ROTATE", 0, "Switch to Rotate"},
32
33 {0, nullptr, 0, nullptr, nullptr},
34 };
35
36 wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "View3D Move Modal");
37
38 /* This function is called for each space-type, only needs to add map once. */
39 if (keymap && keymap->modal_items) {
40 return;
41 }
42
43 keymap = WM_modalkeymap_ensure(keyconf, "View3D Move Modal", modal_items);
44
45 /* assign map to operators */
46 WM_modalkeymap_assign(keymap, "VIEW3D_OT_move");
47}
48
50 ViewOpsData *vod,
51 const eV3D_OpEvent event_code,
52 const int xy[2])
53{
54 bool use_autokey = false;
56
57 switch (event_code) {
58 case VIEW_APPLY: {
59 viewmove_apply(vod, xy[0], xy[1]);
61 use_autokey = true;
62 }
63 break;
64 }
65 case VIEW_CONFIRM: {
66 use_autokey = true;
68 break;
69 }
70 case VIEW_CANCEL: {
71 vod->state_restore();
73 break;
74 }
75 case VIEW_PASS:
76 break;
77 }
78
79 if (use_autokey) {
80 ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true);
81 }
82
83 return ret;
84}
85
87 ViewOpsData *vod,
88 const wmEvent *event,
89 PointerRNA * /*ptr*/)
90{
91 eV3D_OpEvent event_code = event->type == MOUSEPAN ? VIEW_CONFIRM : VIEW_PASS;
92
93 if (event_code == VIEW_CONFIRM) {
94 /* Invert it, trackpad scroll follows same principle as 2d windows this way. */
95 int mx = 2 * event->xy[0] - event->prev_xy[0];
96 int my = 2 * event->xy[1] - event->prev_xy[1];
97 viewmove_apply(vod, mx, my);
98
99 ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true);
100 return OPERATOR_FINISHED;
101 }
102
104}
105
107{
109}
110
112{
113 /* identifiers */
114 ot->name = "Pan View";
115 ot->description = "Move the view";
116 ot->idname = ViewOpsType_move.idname;
117
118 /* API callbacks. */
119 ot->invoke = viewmove_invoke;
121 ot->poll = view3d_location_poll;
123
124 /* flags */
126
127 /* properties */
129}
130
132
135 /*idname*/ "VIEW3D_OT_move",
136 /*poll_fn*/ view3d_location_poll,
137 /*init_fn*/ viewmove_invoke_impl,
138 /*apply_fn*/ viewmove_modal_impl,
139};
wmWindowManager * CTX_wm_manager(const bContext *C)
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
@ OPERATOR_RUNNING_MODAL
bScreen * ED_screen_animation_playing(const wmWindowManager *wm)
bool ED_view3d_camera_lock_autokey(View3D *v3d, RegionView3D *rv3d, bContext *C, bool do_rotate, bool do_translate)
#define C
Definition RandGen.cpp:29
@ OPTYPE_BLOCKING
Definition WM_types.hh:184
@ OPTYPE_GRAB_CURSOR_XY
Definition WM_types.hh:188
@ VIEW_CONFIRM
Definition image_ops.cc:601
@ VIEW_PASS
Definition image_ops.cc:599
@ VIEW_APPLY
Definition image_ops.cc:600
return ret
RegionView3D * rv3d
const void * modal_items
void view3d_navigate_cancel_fn(bContext *C, wmOperator *op)
wmOperatorStatus view3d_navigate_invoke_impl(bContext *C, wmOperator *op, const wmEvent *event, const ViewOpsType *nav_type)
void view3d_operator_properties_common(wmOperatorType *ot, const enum eV3D_OpPropFlag flag)
wmOperatorStatus view3d_navigate_modal_fn(bContext *C, wmOperator *op, const wmEvent *event)
bool view3d_location_poll(bContext *C)
void viewmove_apply(ViewOpsData *vod, int x, int y)
@ VIEWOPS_FLAG_DEPTH_NAVIGATE
@ VIEWOPS_FLAG_INIT_ZFAC
eV3D_OpEvent
@ VIEW_CANCEL
@ V3D_OP_PROP_USE_MOUSE_INIT
const ViewOpsType ViewOpsType_move
@ VIEWROT_MODAL_SWITCH_ROTATE
@ VIEW_MODAL_CANCEL
@ VIEW_MODAL_CONFIRM
@ VIEWROT_MODAL_SWITCH_ZOOM
void viewmove_modal_keymap(wmKeyConfig *keyconf)
static wmOperatorStatus viewmove_modal_impl(bContext *C, ViewOpsData *vod, const eV3D_OpEvent event_code, const int xy[2])
static wmOperatorStatus viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus viewmove_invoke_impl(bContext *C, ViewOpsData *vod, const wmEvent *event, PointerRNA *)
void VIEW3D_OT_move(wmOperatorType *ot)
int xy[2]
Definition wm_draw.cc:178
@ MOUSEPAN
wmOperatorType * ot
Definition wm_files.cc:4237
wmKeyMap * WM_modalkeymap_ensure(wmKeyConfig *keyconf, const char *idname, const EnumPropertyItem *items)
Definition wm_keymap.cc:932
void WM_modalkeymap_assign(wmKeyMap *km, const char *opname)
wmKeyMap * WM_modalkeymap_find(wmKeyConfig *keyconf, const char *idname)
Definition wm_keymap.cc:959