Blender V4.3
view2d_gizmo_navigate.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 "BLI_utildefines.h"
10
11#include "BKE_context.hh"
12
13#include "ED_gizmo_library.hh"
14#include "ED_screen.hh"
15
16#include "UI_resources.hh"
17
18#include "MEM_guardedalloc.h"
19
20#include "RNA_access.hh"
21
22#include "WM_api.hh"
23#include "WM_types.hh"
24
25#include "UI_view2d.hh"
26
27/* -------------------------------------------------------------------- */
35/* Size of main icon. */
36#define GIZMO_SIZE 80
37/* Factor for size of smaller button. */
38#define GIZMO_MINI_FAC 0.35f
39/* How much mini buttons offset from the primary. */
40#define GIZMO_MINI_OFFSET_FAC 0.38f
41
42enum {
45
47};
48
50 const char *opname;
51 const char *gizmo;
53};
54
56 {
57 "IMAGE_OT_view_pan",
58 "GIZMO_GT_button_2d",
59 ICON_VIEW_PAN,
60 },
61 {
62 "IMAGE_OT_view_zoom",
63 "GIZMO_GT_button_2d",
64 ICON_VIEW_ZOOM,
65 },
66};
67
69 {
70 "CLIP_OT_view_pan",
71 "GIZMO_GT_button_2d",
72 ICON_VIEW_PAN,
73 },
74 {
75 "CLIP_OT_view_zoom",
76 "GIZMO_GT_button_2d",
77 ICON_VIEW_ZOOM,
78 },
79};
80
82 {
83 "VIEW2D_OT_pan",
84 "GIZMO_GT_button_2d",
85 ICON_VIEW_PAN,
86 },
87 {
88 "VIEW2D_OT_zoom",
89 "GIZMO_GT_button_2d",
90 ICON_VIEW_ZOOM,
91 },
92};
93
95{
96 switch (space_type) {
97 case SPACE_IMAGE:
99 case SPACE_CLIP:
101 default:
102 /* Used for sequencer. */
104 }
105}
106
109 /* Store the view state to check for changes. */
110 struct {
113};
114
115static bool WIDGETGROUP_navigate_poll(const bContext *C, wmGizmoGroupType * /*gzgt*/)
116{
117 if ((U.uiflag & USER_SHOW_GIZMO_NAVIGATE) == 0) {
118 return false;
119 }
120 ScrArea *area = CTX_wm_area(C);
121 if (area == nullptr) {
122 return false;
123 }
124 switch (area->spacetype) {
125 case SPACE_SEQ: {
126 const SpaceSeq *sseq = static_cast<const SpaceSeq *>(area->spacedata.first);
128 return false;
129 }
130 break;
131 }
132 case SPACE_IMAGE: {
133 const SpaceImage *sima = static_cast<const SpaceImage *>(area->spacedata.first);
135 return false;
136 }
137 break;
138 }
139 case SPACE_CLIP: {
140 const SpaceClip *sc = static_cast<const SpaceClip *>(area->spacedata.first);
142 return false;
143 }
144 break;
145 }
146 }
147 return true;
148}
149
150static void WIDGETGROUP_navigate_setup(const bContext * /*C*/, wmGizmoGroup *gzgroup)
151{
152 NavigateWidgetGroup *navgroup = MEM_cnew<NavigateWidgetGroup>(__func__);
153
154 const NavigateGizmoInfo *navigate_params = navigate_params_from_space_type(
155 gzgroup->type->gzmap_params.spaceid);
156
157 for (int i = 0; i < GZ_INDEX_TOTAL; i++) {
158 const NavigateGizmoInfo *info = &navigate_params[i];
159 navgroup->gz_array[i] = WM_gizmo_new(info->gizmo, gzgroup, nullptr);
160 wmGizmo *gz = navgroup->gz_array[i];
162
163 {
164 uchar icon_color[3];
165 UI_GetThemeColor3ubv(TH_TEXT, icon_color);
166 int color_tint, color_tint_hi;
167 if (icon_color[0] > 128) {
168 color_tint = -40;
169 color_tint_hi = 60;
170 gz->color[3] = 0.5f;
171 gz->color_hi[3] = 0.5f;
172 }
173 else {
174 color_tint = 60;
175 color_tint_hi = 60;
176 gz->color[3] = 0.5f;
177 gz->color_hi[3] = 0.75f;
178 }
179 UI_GetThemeColorShade3fv(TH_HEADER, color_tint, gz->color);
180 UI_GetThemeColorShade3fv(TH_HEADER, color_tint_hi, gz->color_hi);
181 }
182
183 /* may be overwritten later */
185 if (info->icon != 0) {
186 PropertyRNA *prop = RNA_struct_find_property(gz->ptr, "icon");
187 RNA_property_enum_set(gz->ptr, prop, info->icon);
190 }
191
193 WM_gizmo_operator_set(gz, 0, ot, nullptr);
194 }
195
196 /* Modal operators, don't use initial mouse location since we're clicking on a button. */
197 {
198 int gz_ids[] = {GZ_INDEX_ZOOM};
199 for (int i = 0; i < ARRAY_SIZE(gz_ids); i++) {
200 wmGizmo *gz = navgroup->gz_array[gz_ids[i]];
202 RNA_boolean_set(&gzop->ptr, "use_cursor_init", false);
203 }
204 }
205
206 gzgroup->customdata = navgroup;
207}
208
210{
211 NavigateWidgetGroup *navgroup = static_cast<NavigateWidgetGroup *>(gzgroup->customdata);
212 ARegion *region = CTX_wm_region(C);
213
214 const rcti *rect_visible = ED_region_visible_rect(region);
215
216 if ((navgroup->state.rect_visible.xmax == rect_visible->xmax) &&
217 (navgroup->state.rect_visible.ymax == rect_visible->ymax))
218 {
219 return;
220 }
221
222 navgroup->state.rect_visible = *rect_visible;
223
224 const float icon_size = GIZMO_SIZE;
225 const float icon_offset_mini = icon_size * GIZMO_MINI_OFFSET_FAC * UI_SCALE_FAC;
226 const float co[2] = {
227 roundf(rect_visible->xmax - (icon_offset_mini * 0.75f)),
228 roundf(rect_visible->ymax - (icon_offset_mini * 0.75f)),
229 };
230
231 wmGizmo *gz;
232
233 for (uint i = 0; i < ARRAY_SIZE(navgroup->gz_array); i++) {
234 gz = navgroup->gz_array[i];
236 }
237
238 int icon_mini_slot = 0;
239
240 gz = navgroup->gz_array[GZ_INDEX_ZOOM];
241 gz->matrix_basis[3][0] = roundf(co[0]);
242 gz->matrix_basis[3][1] = roundf(co[1] - (icon_offset_mini * icon_mini_slot++));
244
245 gz = navgroup->gz_array[GZ_INDEX_MOVE];
246 gz->matrix_basis[3][0] = roundf(co[0]);
247 gz->matrix_basis[3][1] = roundf(co[1] - (icon_offset_mini * icon_mini_slot++));
249}
250
251void VIEW2D_GGT_navigate_impl(wmGizmoGroupType *gzgt, const char *idname)
252{
253 gzgt->name = "View2D Navigate";
254 gzgt->idname = idname;
255
258
262}
263
ScrArea * CTX_wm_area(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
unsigned char uchar
unsigned int uint
#define ARRAY_SIZE(arr)
@ SPACE_CLIP
@ SPACE_SEQ
@ SPACE_IMAGE
@ SCLIP_GIZMO_HIDE
@ SCLIP_GIZMO_HIDE_NAVIGATE
@ SI_GIZMO_HIDE
@ SI_GIZMO_HIDE_NAVIGATE
@ SEQ_GIZMO_HIDE
@ SEQ_GIZMO_HIDE_NAVIGATE
@ USER_SHOW_GIZMO_NAVIGATE
#define UI_SCALE_FAC
@ ED_GIZMO_BUTTON_SHOW_BACKDROP
@ ED_GIZMO_BUTTON_SHOW_OUTLINE
const rcti * ED_region_visible_rect(ARegion *region)
Definition area.cc:4010
Read Guarded memory(de)allocation.
@ TH_HEADER
@ TH_TEXT
void UI_GetThemeColorShade3fv(int colorid, int offset, float col[3])
void UI_GetThemeColor3ubv(int colorid, unsigned char col[3])
@ WM_GIZMO_HIDDEN
@ WM_GIZMO_MOVE_CURSOR
@ WM_GIZMO_DRAW_MODAL
@ WM_GIZMOGROUPTYPE_SCALE
@ WM_GIZMOGROUPTYPE_DRAW_MODAL_ALL
@ WM_GIZMOGROUPTYPE_PERSISTENT
unsigned int U
Definition btGjkEpa3.h:78
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value)
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
struct NavigateWidgetGroup::@407 state
wmGizmo * gz_array[GZ_INDEX_TOTAL]
int ymax
int xmax
wmGizmoGroupFnInit setup
const char * idname
wmGizmoMapType_Params gzmap_params
eWM_GizmoFlagGroupTypeFlag flag
wmGizmoGroupFnPoll poll
wmGizmoGroupFnDrawPrepare draw_prepare
wmGizmoGroupType * type
float matrix_basis[4][4]
float color_hi[4]
float color[4]
PointerRNA * ptr
float scale_basis
eWM_GizmoFlag flag
static void WIDGETGROUP_navigate_setup(const bContext *, wmGizmoGroup *gzgroup)
#define GIZMO_MINI_FAC
static NavigateGizmoInfo g_navigate_params_for_view2d[GZ_INDEX_TOTAL]
static NavigateGizmoInfo g_navigate_params_for_space_clip[GZ_INDEX_TOTAL]
static bool WIDGETGROUP_navigate_poll(const bContext *C, wmGizmoGroupType *)
#define GIZMO_SIZE
static NavigateGizmoInfo g_navigate_params_for_space_image[GZ_INDEX_TOTAL]
void VIEW2D_GGT_navigate_impl(wmGizmoGroupType *gzgt, const char *idname)
#define GIZMO_MINI_OFFSET_FAC
static void WIDGETGROUP_navigate_draw_prepare(const bContext *C, wmGizmoGroup *gzgroup)
static NavigateGizmoInfo * navigate_params_from_space_type(short space_type)
wmOperatorType * ot
Definition wm_files.cc:4125
wmGizmoOpElem * WM_gizmo_operator_get(wmGizmo *gz, int part_index)
Definition wm_gizmo.cc:195
wmGizmo * WM_gizmo_new(const char *idname, wmGizmoGroup *gzgroup, PointerRNA *properties)
Definition wm_gizmo.cc:94
void WM_gizmo_set_flag(wmGizmo *gz, const int flag, const bool enable)
Definition wm_gizmo.cc:303
PointerRNA * WM_gizmo_operator_set(wmGizmo *gz, int part_index, wmOperatorType *ot, IDProperty *properties)
Definition wm_gizmo.cc:203
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)