Blender V5.3
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
18namespace blender {
19
20/* -------------------------------------------------------------------- */
23
24/* NOTE: these defines are saved in keymap files, do not change values but just add new ones */
25
27{
28 static const EnumPropertyItem modal_items[] = {
29 {VIEW_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
30 {VIEW_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
31
32 {VIEWROT_MODAL_SWITCH_ZOOM, "SWITCH_TO_ZOOM", 0, "Switch to Zoom"},
33 {VIEWROT_MODAL_SWITCH_ROTATE, "SWITCH_TO_ROTATE", 0, "Switch to Rotate"},
34
35 {0, nullptr, 0, nullptr, nullptr},
36 };
37
38 wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "View3D Move Modal");
39
40 /* This function is called for each space-type, only needs to add map once. */
41 if (keymap && keymap->modal_items) {
42 return;
43 }
44
45 keymap = WM_modalkeymap_ensure(keyconf, "View3D Move Modal", modal_items);
46
47 /* assign map to operators */
48 WM_modalkeymap_assign(keymap, "VIEW3D_OT_move");
49}
50
52 ViewOpsData *vod,
53 const eV3D_OpEvent event_code,
54 const int xy[2])
55{
56 bool use_autokey = false;
58
59 switch (event_code) {
60 case VIEW_APPLY: {
61 viewmove_apply(vod, xy[0], xy[1]);
63 use_autokey = true;
64 }
65 break;
66 }
67 case VIEW_CONFIRM: {
68 use_autokey = true;
70 break;
71 }
72 case VIEW_CANCEL: {
73 vod->state_restore();
75 break;
76 }
77 case VIEW_PASS:
78 break;
79 }
80
81 if (use_autokey) {
82 ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true);
83 }
84
85 return ret;
86}
87
89 ViewOpsData *vod,
90 const wmEvent *event,
91 PointerRNA * /*ptr*/)
92{
93 eV3D_OpEvent event_code = event->type == MOUSEPAN ? VIEW_CONFIRM : VIEW_PASS;
94
95 if (event_code == VIEW_CONFIRM) {
96 /* Invert it, trackpad scroll follows same principle as 2d windows this way. */
97 int mx = 2 * event->xy[0] - event->prev_xy[0];
98 int my = 2 * event->xy[1] - event->prev_xy[1];
99 viewmove_apply(vod, mx, my);
100
101 ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true);
102 return OPERATOR_FINISHED;
103 }
104
106}
107
109{
111}
112
114{
115 /* identifiers */
116 ot->name = "Pan View";
117 ot->description = "Move the view";
119
120 /* API callbacks. */
125
126 /* flags */
128
129 /* properties */
131}
132
134
137 /*idname*/ "VIEW3D_OT_move",
138 /*poll_fn*/ view3d_location_poll,
139 /*init_fn*/ viewmove_invoke_impl,
140 /*apply_fn*/ viewmove_modal_impl,
141};
142
143} // namespace blender
#define C
Definition RandGen.cpp:29
BMesh Iterators.
bool ED_view3d_camera_lock_autokey(View3D *v3d, RegionView3D *rv3d, bContext *C, bool do_rotate, bool do_translate)
wmKeyMap * WM_modalkeymap_find(wmKeyConfig *keyconf, const char *idname)
Definition wm_keymap.cc:999
static wmOperatorStatus viewmove_modal_impl(bContext *C, ViewOpsData *vod, const eV3D_OpEvent event_code, const int xy[2])
void viewmove_modal_keymap(wmKeyConfig *keyconf)
void view3d_operator_properties_common(wmOperatorType *ot, const enum eV3D_OpPropFlag flag)
void VIEW3D_OT_move(wmOperatorType *ot)
static wmOperatorStatus viewmove_invoke_impl(bContext *C, ViewOpsData *vod, const wmEvent *event, PointerRNA *)
const ViewOpsType ViewOpsType_move
wmOperatorStatus view3d_navigate_invoke_impl(bContext *C, wmOperator *op, const wmEvent *event, const ViewOpsType *nav_type)
wmWindowManager * CTX_wm_manager(const bContext *C)
bool view3d_location_poll(bContext *C)
@ VIEW_CONFIRM
Definition image_ops.cc:652
@ VIEWOPS_FLAG_DEPTH_NAVIGATE
@ VIEWOPS_FLAG_INIT_ZFAC
@ VIEWROT_MODAL_SWITCH_ZOOM
@ VIEWROT_MODAL_SWITCH_ROTATE
void viewmove_apply(ViewOpsData *vod, int x, int y)
void view3d_navigate_cancel_fn(bContext *C, wmOperator *op)
static wmOperatorStatus viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void WM_modalkeymap_assign(wmKeyMap *km, const char *opname)
@ V3D_OP_PROP_USE_MOUSE_INIT
wmKeyMap * WM_modalkeymap_ensure(wmKeyConfig *keyconf, const char *idname, const EnumPropertyItem *items)
Definition wm_keymap.cc:972
@ OPTYPE_BLOCKING
Definition WM_types.hh:192
@ OPTYPE_GRAB_CURSOR_XY
Definition WM_types.hh:196
bScreen * ED_screen_animation_playing(const wmWindowManager *wm)
wmOperatorStatus view3d_navigate_modal_fn(bContext *C, wmOperator *op, const wmEvent *event)
const char * description
Definition WM_types.hh:1115
void(*) cancel(bContext *C, wmOperator *op)
Definition WM_types.hh:1149
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1157