Blender  V3.3
view3d_navigate_move.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "BKE_context.h"
8 
9 #include "WM_api.h"
10 
11 #include "RNA_access.h"
12 #include "RNA_define.h"
13 
14 #include "ED_screen.h"
15 
16 #include "view3d_intern.h"
17 #include "view3d_navigate.h" /* own include */
18 
19 /* -------------------------------------------------------------------- */
23 /* NOTE: these defines are saved in keymap files, do not change values but just add new ones */
24 
26 {
27  static const EnumPropertyItem modal_items[] = {
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, NULL, 0, NULL, NULL},
34  };
35 
36  wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "View3D Move Modal");
37 
38  /* this function is called for each spacetype, 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  /* items for modal map */
46 
48  &(const KeyMapItem_Params){
49  .type = MIDDLEMOUSE,
50  .value = KM_RELEASE,
51  .modifier = KM_ANY,
52  .direction = KM_ANY,
53  },
56  &(const KeyMapItem_Params){
57  .type = EVT_ESCKEY,
58  .value = KM_PRESS,
59  .modifier = KM_ANY,
60  .direction = KM_ANY,
61  },
63 
64  /* disabled mode switching for now, can re-implement better, later on */
65 #if 0
67  &(const KeyMapItem_Params){
68  .type = LEFTMOUSE,
69  .value = KM_PRESS,
70  .modifier = KM_ANY,
71  .direction = KM_ANY,
72  },
75  &(const KeyMapItem_Params){
76  .type = EVT_LEFTCTRLKEY,
77  .value = KM_PRESS,
78  .modifier = KM_ANY,
79  .direction = KM_ANY,
80  },
83  &(const KeyMapItem_Params){
84  .type = EVT_LEFTSHIFTKEY,
85  .value = KM_RELEASE,
86  .modifier = KM_ANY,
87  .direction = KM_ANY,
88  },
90 #endif
91 
92  /* assign map to operators */
93  WM_modalkeymap_assign(keymap, "VIEW3D_OT_move");
94 }
95 
96 static int viewmove_modal(bContext *C, wmOperator *op, const wmEvent *event)
97 {
98 
99  ViewOpsData *vod = op->customdata;
100  short event_code = VIEW_PASS;
101  bool use_autokey = false;
103 
104  /* execute the events */
105  if (event->type == MOUSEMOVE) {
106  event_code = VIEW_APPLY;
107  }
108  else if (event->type == EVT_MODAL_MAP) {
109  switch (event->val) {
110  case VIEW_MODAL_CONFIRM:
111  event_code = VIEW_CONFIRM;
112  break;
114  WM_operator_name_call(C, "VIEW3D_OT_zoom", WM_OP_INVOKE_DEFAULT, NULL, event);
115  event_code = VIEW_CONFIRM;
116  break;
118  WM_operator_name_call(C, "VIEW3D_OT_rotate", WM_OP_INVOKE_DEFAULT, NULL, event);
119  event_code = VIEW_CONFIRM;
120  break;
121  }
122  }
123  else if (event->type == vod->init.event_type && event->val == KM_RELEASE) {
124  event_code = VIEW_CONFIRM;
125  }
126 
127  if (event_code == VIEW_APPLY) {
128  viewmove_apply(vod, event->xy[0], event->xy[1]);
130  use_autokey = true;
131  }
132  }
133  else if (event_code == VIEW_CONFIRM) {
134  use_autokey = true;
136  }
137 
138  if (use_autokey) {
139  ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true);
140  }
141 
142  if (ret & OPERATOR_FINISHED) {
143  ED_view3d_camera_lock_undo_push(op->type->name, vod->v3d, vod->rv3d, C);
145  op->customdata = NULL;
146  }
147 
148  return ret;
149 }
150 
151 static int viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event)
152 {
153  ViewOpsData *vod;
154 
155  const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init");
156 
157  vod = op->customdata = viewops_data_create(
158  C,
159  event,
161  (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0));
162  vod = op->customdata;
163 
165 
166  if (event->type == MOUSEPAN) {
167  /* invert it, trackpad scroll follows same principle as 2d windows this way */
169  vod, 2 * event->xy[0] - event->prev_xy[0], 2 * event->xy[1] - event->prev_xy[1]);
170 
172  op->customdata = NULL;
173 
174  return OPERATOR_FINISHED;
175  }
176 
177  /* add temp handler */
179 
180  return OPERATOR_RUNNING_MODAL;
181 }
182 
184 {
186  op->customdata = NULL;
187 }
188 
190 {
191 
192  /* identifiers */
193  ot->name = "Pan View";
194  ot->description = "Move the view";
195  ot->idname = "VIEW3D_OT_move";
196 
197  /* api callbacks */
202 
203  /* flags */
205 
206  /* properties */
208 }
209 
struct wmWindowManager * CTX_wm_manager(const bContext *C)
Definition: context.c:713
@ OPERATOR_FINISHED
@ OPERATOR_RUNNING_MODAL
bScreen * ED_screen_animation_playing(const struct wmWindowManager *wm)
bool ED_view3d_camera_lock_autokey(struct View3D *v3d, struct RegionView3D *rv3d, struct bContext *C, bool do_rotate, bool do_translate)
Definition: view3d_utils.c:665
bool ED_view3d_camera_lock_undo_push(const char *str, View3D *v3d, struct RegionView3D *rv3d, struct bContext *C)
Definition: view3d_utils.c:726
#define C
Definition: RandGen.cpp:25
@ KM_ANY
Definition: WM_types.h:265
@ KM_PRESS
Definition: WM_types.h:267
@ KM_RELEASE
Definition: WM_types.h:268
@ OPTYPE_BLOCKING
Definition: WM_types.h:150
@ OPTYPE_GRAB_CURSOR_XY
Definition: WM_types.h:154
@ WM_OP_INVOKE_DEFAULT
Definition: WM_types.h:201
@ VIEW_CONFIRM
Definition: image_ops.c:583
@ VIEW_PASS
Definition: image_ops.c:581
@ VIEW_APPLY
Definition: image_ops.c:582
return ret
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:4863
struct RegionView3D * rv3d
struct ARegion * region
struct ViewOpsData::@576 init
struct View3D * v3d
short val
Definition: WM_types.h:680
int xy[2]
Definition: WM_types.h:682
int prev_xy[2]
Definition: WM_types.h:728
short type
Definition: WM_types.h:678
const void * modal_items
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:919
const char * name
Definition: WM_types.h:888
int(* modal)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:935
const char * idname
Definition: WM_types.h:890
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:943
void(* cancel)(struct bContext *, struct wmOperator *)
Definition: WM_types.h:927
const char * description
Definition: WM_types.h:893
struct wmOperatorType * type
struct PointerRNA * ptr
void view3d_operator_properties_common(wmOperatorType *ot, const enum eV3D_OpPropFlag flag)
void viewops_data_free(bContext *C, ViewOpsData *vod)
ViewOpsData * viewops_data_create(bContext *C, const wmEvent *event, enum eViewOpsFlag viewops_flag)
bool view3d_location_poll(bContext *C)
enum eViewOpsFlag viewops_flag_from_prefs(void)
void viewmove_apply(ViewOpsData *vod, int x, int y)
@ VIEWROT_MODAL_SWITCH_ROTATE
@ VIEW_MODAL_CONFIRM
@ VIEWROT_MODAL_SWITCH_ZOOM
@ VIEWOPS_FLAG_USE_MOUSE_INIT
@ VIEWOPS_FLAG_ORBIT_SELECT
void ED_view3d_smooth_view_force_finish(struct bContext *C, struct View3D *v3d, struct ARegion *region)
@ V3D_OP_PROP_USE_MOUSE_INIT
void viewmove_modal_keymap(wmKeyConfig *keyconf)
static void viewmove_cancel(bContext *C, wmOperator *op)
static int viewmove_modal(bContext *C, wmOperator *op, const wmEvent *event)
static int viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void VIEW3D_OT_move(wmOperatorType *ot)
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
int WM_operator_name_call(bContext *C, const char *opstring, wmOperatorCallContext context, PointerRNA *properties, const wmEvent *event)
@ MOUSEPAN
@ EVT_MODAL_MAP
@ EVT_LEFTCTRLKEY
@ MOUSEMOVE
@ LEFTMOUSE
@ MIDDLEMOUSE
@ EVT_ESCKEY
@ EVT_LEFTSHIFTKEY
wmOperatorType * ot
Definition: wm_files.c:3479
wmKeyMap * WM_modalkeymap_find(wmKeyConfig *keyconf, const char *idname)
Definition: wm_keymap.c:914
void WM_modalkeymap_assign(wmKeyMap *km, const char *opname)
Definition: wm_keymap.c:985
wmKeyMapItem * WM_modalkeymap_add_item(wmKeyMap *km, const KeyMapItem_Params *params, int value)
Definition: wm_keymap.c:927
wmKeyMap * WM_modalkeymap_ensure(wmKeyConfig *keyconf, const char *idname, const EnumPropertyItem *items)
Definition: wm_keymap.c:888