Blender V4.3
view3d_navigate_view_pan.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 "MEM_guardedalloc.h"
10
11#include "WM_api.hh"
12
13#include "RNA_access.hh"
14#include "RNA_define.hh"
15
16#include "view3d_intern.hh"
17
18#include "view3d_navigate.hh" /* own include */
19
20/* -------------------------------------------------------------------- */
26enum {
31};
32
34 {V3D_VIEW_PANLEFT, "PANLEFT", 0, "Pan Left", "Pan the view to the left"},
35 {V3D_VIEW_PANRIGHT, "PANRIGHT", 0, "Pan Right", "Pan the view to the right"},
36 {V3D_VIEW_PANUP, "PANUP", 0, "Pan Up", "Pan the view up"},
37 {V3D_VIEW_PANDOWN, "PANDOWN", 0, "Pan Down", "Pan the view down"},
38 {0, nullptr, 0, nullptr, nullptr},
39};
40
41static int viewpan_invoke_impl(bContext * /*C*/,
42 ViewOpsData *vod,
43 const wmEvent * /*event*/,
45{
46 int x = 0, y = 0;
47 int pandir = RNA_enum_get(ptr, "type");
48
49 if (pandir == V3D_VIEW_PANRIGHT) {
50 x = -32;
51 }
52 else if (pandir == V3D_VIEW_PANLEFT) {
53 x = 32;
54 }
55 else if (pandir == V3D_VIEW_PANUP) {
56 y = -25;
57 }
58 else if (pandir == V3D_VIEW_PANDOWN) {
59 y = 25;
60 }
61
62 viewmove_apply(vod, vod->prev.event_xy[0] + x, vod->prev.event_xy[1] + y);
63
64 return OPERATOR_FINISHED;
65}
66
67static int viewpan_invoke(bContext *C, wmOperator *op, const wmEvent *event)
68{
69 return view3d_navigate_invoke_impl(C, op, event, &ViewOpsType_pan);
70}
71
73{
74 /* identifiers */
75 ot->name = "Pan View Direction";
76 ot->description = "Pan the view in a given direction";
78
79 /* api callbacks */
82
83 /* flags */
84 ot->flag = 0;
85
86 /* Properties */
88 ot->srna, "type", prop_view_pan_items, 0, "Pan", "Direction of View Pan");
89}
90
95 /*idname*/ "VIEW3D_OT_view_pan",
96 /*poll_fn*/ view3d_location_poll,
97 /*init_fn*/ viewpan_invoke_impl,
98 /*apply_fn*/ nullptr,
99};
Read Guarded memory(de)allocation.
int RNA_enum_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
struct ViewOpsData::@544 prev
const char * idname
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(* 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
PropertyRNA * prop
Definition WM_types.hh:1092
StructRNA * srna
Definition WM_types.hh:1080
bool view3d_location_poll(bContext *C)
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
const ViewOpsType ViewOpsType_pan
static int viewpan_invoke_impl(bContext *, ViewOpsData *vod, const wmEvent *, PointerRNA *ptr)
static int viewpan_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void VIEW3D_OT_view_pan(wmOperatorType *ot)
static const EnumPropertyItem prop_view_pan_items[]
PointerRNA * ptr
Definition wm_files.cc:4126
wmOperatorType * ot
Definition wm_files.cc:4125