Blender V4.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
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/* -------------------------------------------------------------------- */
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
86static int viewmove_invoke_impl(bContext * /*C*/,
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 return OPERATOR_FINISHED;
99 }
100
102}
103
104static int viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event)
105{
106 return view3d_navigate_invoke_impl(C, op, event, &ViewOpsType_move);
107}
108
110{
111 /* identifiers */
112 ot->name = "Pan View";
113 ot->description = "Move the view";
115
116 /* api callbacks */
121
122 /* flags */
124
125 /* properties */
127}
128
133 /*idname*/ "VIEW3D_OT_move",
134 /*poll_fn*/ view3d_location_poll,
135 /*init_fn*/ viewmove_invoke_impl,
136 /*apply_fn*/ viewmove_modal_impl,
137};
wmWindowManager * CTX_wm_manager(const bContext *C)
@ 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)
@ OPTYPE_BLOCKING
Definition WM_types.hh:164
@ OPTYPE_GRAB_CURSOR_XY
Definition WM_types.hh:168
@ VIEW_CONFIRM
Definition image_ops.cc:587
@ VIEW_PASS
Definition image_ops.cc:585
@ VIEW_APPLY
Definition image_ops.cc:586
return ret
RegionView3D * rv3d
const char * idname
const void * modal_items
const char * name
Definition WM_types.hh:990
bool(* poll)(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1042
const char * idname
Definition WM_types.hh:992
int(* modal)(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1036
int(* invoke)(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1022
const char * description
Definition WM_types.hh:996
void(* cancel)(bContext *C, wmOperator *op)
Definition WM_types.hh:1028
void view3d_navigate_cancel_fn(bContext *C, wmOperator *op)
void view3d_operator_properties_common(wmOperatorType *ot, const enum eV3D_OpPropFlag flag)
bool view3d_location_poll(bContext *C)
int view3d_navigate_modal_fn(bContext *C, wmOperator *op, const wmEvent *event)
void viewmove_apply(ViewOpsData *vod, int x, int y)
int view3d_navigate_invoke_impl(bContext *C, wmOperator *op, const wmEvent *event, const ViewOpsType *nav_type)
@ VIEWOPS_FLAG_DEPTH_NAVIGATE
@ VIEWOPS_FLAG_INIT_ZFAC
eV3D_OpEvent
@ VIEW_CANCEL
@ VIEWROT_MODAL_SWITCH_ROTATE
@ VIEW_MODAL_CANCEL
@ VIEW_MODAL_CONFIRM
@ VIEWROT_MODAL_SWITCH_ZOOM
@ V3D_OP_PROP_USE_MOUSE_INIT
void viewmove_modal_keymap(wmKeyConfig *keyconf)
static int viewmove_modal_impl(bContext *C, ViewOpsData *vod, const eV3D_OpEvent event_code, const int xy[2])
static int viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static int viewmove_invoke_impl(bContext *, ViewOpsData *vod, const wmEvent *event, PointerRNA *)
const ViewOpsType ViewOpsType_move
void VIEW3D_OT_move(wmOperatorType *ot)
int xy[2]
Definition wm_draw.cc:170
@ MOUSEPAN
wmOperatorType * ot
Definition wm_files.cc:4125
wmKeyMap * WM_modalkeymap_ensure(wmKeyConfig *keyconf, const char *idname, const EnumPropertyItem *items)
Definition wm_keymap.cc:933
void WM_modalkeymap_assign(wmKeyMap *km, const char *opname)
wmKeyMap * WM_modalkeymap_find(wmKeyConfig *keyconf, const char *idname)
Definition wm_keymap.cc:960