Blender  V2.93
UI_view2d.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2008 Blender Foundation.
17  * All rights reserved.
18  * Generic 2d view with should allow drawing grids,
19  * panning, zooming, scrolling, ..
20  */
21 
26 #pragma once
27 
28 #include "BLI_compiler_attrs.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /* ------------------------------------------ */
35 /* Settings and Defines: */
36 
37 /* ---- General Defines ---- */
38 
39 /* generic value to use when coordinate lies out of view when converting */
40 #define V2D_IS_CLIPPED 12000
41 
42 /* Common View2D view types
43  * NOTE: only define a type here if it completely sets all (+/- a few) of the relevant flags
44  * and settings for a View2D region, and that set of settings is used in more
45  * than one specific place
46  */
48  /* custom view type (region has defined all necessary flags already) */
50  /* standard (only use this when setting up a new view, as a sensible base for most settings) */
52  /* listview (i.e. Outliner) */
54  /* stackview (this is basically a list where new items are added at the top) */
56  /* headers (this is basically the same as listview, but no y-panning) */
58  /* ui region containing panels */
60 };
61 
62 /* ---- Defines for Scroller Arguments ----- */
63 
64 /* ------ Defines for Scrollers ----- */
65 
67 #define V2D_SCROLL_HEIGHT (0.45f * U.widget_unit)
68 #define V2D_SCROLL_WIDTH (0.45f * U.widget_unit)
70 #define V2D_SCROLL_HANDLE_HEIGHT (0.6f * U.widget_unit)
71 #define V2D_SCROLL_HANDLE_WIDTH (0.6f * U.widget_unit)
72 
74 #define V2D_SCROLL_HANDLE_SIZE_HOTSPOT (0.6f * U.widget_unit)
75 
77 #define V2D_SCROLL_THUMB_SIZE_MIN (30.0 * UI_DPI_FAC)
78 
79 /* ------ Define for UI_view2d_sync ----- */
80 
81 /* means copy it from another v2d */
82 #define V2D_LOCK_SET 0
83 /* means copy it to the other v2ds */
84 #define V2D_LOCK_COPY 1
85 
86 /* ------------------------------------------ */
87 /* Macros: */
88 
89 /* test if mouse in a scrollbar (assume that scroller availability has been tested) */
90 #define IN_2D_VERT_SCROLL(v2d, co) (BLI_rcti_isect_pt_v(&v2d->vert, co))
91 #define IN_2D_HORIZ_SCROLL(v2d, co) (BLI_rcti_isect_pt_v(&v2d->hor, co))
92 
93 #define IN_2D_VERT_SCROLL_RECT(v2d, rct) (BLI_rcti_isect(&v2d->vert, rct, NULL))
94 #define IN_2D_HORIZ_SCROLL_RECT(v2d, rct) (BLI_rcti_isect(&v2d->hor, rct, NULL))
95 
96 /* ------------------------------------------ */
97 /* Type definitions: */
98 
99 struct View2D;
100 struct View2DScrollers;
101 
102 struct ARegion;
103 struct Scene;
104 struct ScrArea;
105 struct bContext;
106 struct bScreen;
107 struct rctf;
108 struct wmGizmoGroupType;
109 struct wmKeyConfig;
110 
111 typedef struct View2DScrollers View2DScrollers;
112 
113 /* ----------------------------------------- */
114 /* Prototypes: */
115 
116 /* refresh and validation (of view rects) */
117 void UI_view2d_region_reinit(struct View2D *v2d, short type, int winx, int winy);
118 
119 void UI_view2d_curRect_validate(struct View2D *v2d);
120 void UI_view2d_curRect_reset(struct View2D *v2d);
122 void UI_view2d_sync(struct bScreen *screen, struct ScrArea *area, struct View2D *v2dcur, int flag);
123 
124 /* Perform all required updates after `v2d->cur` as been modified.
125  * This includes like validation view validation (#UI_view2d_curRect_validate).
126  *
127  * Current intent is to use it from user code, such as view navigation and zoom operations. */
128 void UI_view2d_curRect_changed(const struct bContext *C, struct View2D *v2d);
129 
130 void UI_view2d_totRect_set(struct View2D *v2d, int width, int height);
131 void UI_view2d_totRect_set_resize(struct View2D *v2d, int width, int height, bool resize);
132 
133 void UI_view2d_mask_from_win(const struct View2D *v2d, struct rcti *r_mask);
134 
135 void UI_view2d_zoom_cache_reset(void);
136 
137 /* view matrix operations */
138 void UI_view2d_view_ortho(const struct View2D *v2d);
139 void UI_view2d_view_orthoSpecial(struct ARegion *region, struct View2D *v2d, const bool xaxis);
140 void UI_view2d_view_restore(const struct bContext *C);
141 
142 /* grid drawing */
143 void UI_view2d_constant_grid_draw(const struct View2D *v2d, float step);
145  const struct View2D *v2d, int colorid, float step, int level_size, int totlevels);
146 
147 void UI_view2d_draw_lines_y__values(const struct View2D *v2d);
148 void UI_view2d_draw_lines_x__values(const struct View2D *v2d);
150 void UI_view2d_draw_lines_x__discrete_time(const struct View2D *v2d, const struct Scene *scene);
152  const struct Scene *scene,
153  bool display_seconds);
155  const struct Scene *scene,
156  bool display_seconds);
157 
159  const struct Scene *scene,
160  bool display_seconds);
161 float UI_view2d_grid_resolution_y__values(const struct View2D *v2d);
162 
163 /* scale indicator text drawing */
164 void UI_view2d_draw_scale_y__values(const struct ARegion *region,
165  const struct View2D *v2d,
166  const struct rcti *rect,
167  int colorid);
168 void UI_view2d_draw_scale_y__block(const struct ARegion *region,
169  const struct View2D *v2d,
170  const struct rcti *rect,
171  int colorid);
173  const struct View2D *v2d,
174  const struct rcti *rect,
175  const struct Scene *scene,
176  bool display_seconds,
177  int colorid);
178 void UI_view2d_draw_scale_x__frames_or_seconds(const struct ARegion *region,
179  const struct View2D *v2d,
180  const struct rcti *rect,
181  const struct Scene *scene,
182  bool display_seconds,
183  int colorid);
184 
185 /* scrollbar drawing */
187  const struct rcti *mask_custom,
188  struct View2DScrollers *r_scrollers);
189 void UI_view2d_scrollers_draw(struct View2D *v2d, const struct rcti *mask_custom);
190 
191 /* list view tools */
192 void UI_view2d_listview_view_to_cell(float columnwidth,
193  float rowheight,
194  float startx,
195  float starty,
196  float viewx,
197  float viewy,
198  int *column,
199  int *row);
200 
201 /* coordinate conversion */
202 float UI_view2d_region_to_view_x(const struct View2D *v2d, float x);
203 float UI_view2d_region_to_view_y(const struct View2D *v2d, float y);
205  const struct View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL();
206 void UI_view2d_region_to_view_rctf(const struct View2D *v2d,
207  const struct rctf *rect_src,
208  struct rctf *rect_dst) ATTR_NONNULL();
209 
210 float UI_view2d_view_to_region_x(const struct View2D *v2d, float x);
211 float UI_view2d_view_to_region_y(const struct View2D *v2d, float y);
213  const struct View2D *v2d, float x, float y, int *r_region_x, int *r_region_y) ATTR_NONNULL();
214 
216  const struct View2D *v2d, float x, float y, int *r_region_x, int *r_region_y) ATTR_NONNULL();
217 void UI_view2d_view_to_region_fl(const struct View2D *v2d,
218  float x,
219  float y,
220  float *r_region_x,
221  float *r_region_y) ATTR_NONNULL();
222 void UI_view2d_view_to_region_m4(const struct View2D *v2d, float matrix[4][4]) ATTR_NONNULL();
223 void UI_view2d_view_to_region_rcti(const struct View2D *v2d,
224  const struct rctf *rect_src,
225  struct rcti *rect_dst) ATTR_NONNULL();
227  const struct rctf *rect_src,
228  struct rcti *rect_dst) ATTR_NONNULL();
229 
230 /* utilities */
231 struct View2D *UI_view2d_fromcontext(const struct bContext *C);
233 
234 void UI_view2d_scroller_size_get(const struct View2D *v2d, float *r_x, float *r_y);
235 void UI_view2d_scale_get(const struct View2D *v2d, float *r_x, float *r_y);
236 float UI_view2d_scale_get_x(const struct View2D *v2d);
237 float UI_view2d_scale_get_y(const struct View2D *v2d);
238 void UI_view2d_scale_get_inverse(const struct View2D *v2d, float *r_x, float *r_y);
239 
240 void UI_view2d_center_get(const struct View2D *v2d, float *r_x, float *r_y);
241 void UI_view2d_center_set(struct View2D *v2d, float x, float y);
242 
243 void UI_view2d_offset(struct View2D *v2d, float xfac, float yfac);
244 
246  const struct ARegion *region, const struct View2D *v2d, int x, int y, int *r_scroll);
247 char UI_view2d_mouse_in_scrollers(const struct ARegion *region,
248  const struct View2D *v2d,
249  int x,
250  int y);
251 char UI_view2d_rect_in_scrollers_ex(const struct ARegion *region,
252  const struct View2D *v2d,
253  const struct rcti *rect,
254  int *r_scroll);
255 char UI_view2d_rect_in_scrollers(const struct ARegion *region,
256  const struct View2D *v2d,
257  const struct rcti *rect);
258 
259 /* cached text drawing in v2d, to allow pixel-aligned draw as post process */
260 void UI_view2d_text_cache_add(struct View2D *v2d,
261  float x,
262  float y,
263  const char *str,
264  size_t str_len,
265  const unsigned char col[4]);
267  const struct rctf *rect_view,
268  const char *str,
269  size_t str_len,
270  const unsigned char col[4]);
271 void UI_view2d_text_cache_draw(struct ARegion *region);
272 
273 /* operators */
274 void ED_operatortypes_view2d(void);
275 void ED_keymap_view2d(struct wmKeyConfig *keyconf);
276 
278  struct ARegion *region,
279  const struct rctf *cur,
280  const int smooth_viewtx);
281 
282 #define UI_MARKER_MARGIN_Y (42 * UI_DPI_FAC)
283 #define UI_TIME_SCRUB_MARGIN_Y (23 * UI_DPI_FAC)
284 
285 /* Gizmo Types */
286 
287 /* view2d_gizmo_navigate.c */
288 /* Caller passes in own idname. */
289 void VIEW2D_GGT_navigate_impl(struct wmGizmoGroupType *gzgt, const char *idname);
290 
291 #ifdef __cplusplus
292 }
293 #endif
#define ATTR_NONNULL(...)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
#define C
Definition: RandGen.cpp:39
void UI_view2d_draw_lines_y__values(const struct View2D *v2d)
void UI_view2d_constant_grid_draw(const struct View2D *v2d, float step)
bool UI_view2d_area_supports_sync(struct ScrArea *area)
Definition: view2d.c:869
void UI_view2d_center_set(struct View2D *v2d, float x, float y)
Definition: view2d.c:1950
void VIEW2D_GGT_navigate_impl(struct wmGizmoGroupType *gzgt, const char *idname)
void UI_view2d_smooth_view(struct bContext *C, struct ARegion *region, const struct rctf *cur, const int smooth_viewtx)
void UI_view2d_scale_get(const struct View2D *v2d, float *r_x, float *r_y)
void UI_view2d_region_reinit(struct View2D *v2d, short type, int winx, int winy)
Definition: view2d.c:240
char UI_view2d_mouse_in_scrollers(const struct ARegion *region, const struct View2D *v2d, int x, int y)
char UI_view2d_rect_in_scrollers(const struct ARegion *region, const struct View2D *v2d, const struct rcti *rect)
float UI_view2d_view_to_region_x(const struct View2D *v2d, float x)
void UI_view2d_view_to_region_rcti(const struct View2D *v2d, const struct rctf *rect_src, struct rcti *rect_dst) ATTR_NONNULL()
void UI_view2d_text_cache_add(struct View2D *v2d, float x, float y, const char *str, size_t str_len, const unsigned char col[4])
Definition: view2d.c:2087
void UI_view2d_totRect_set(struct View2D *v2d, int width, int height)
Definition: view2d.c:1052
struct View2D * UI_view2d_fromcontext(const struct bContext *C)
float UI_view2d_view_to_region_y(const struct View2D *v2d, float y)
void UI_view2d_draw_lines_x__discrete_time(const struct View2D *v2d, const struct Scene *scene)
void UI_view2d_view_to_region_fl(const struct View2D *v2d, float x, float y, float *r_region_x, float *r_region_y) ATTR_NONNULL()
void UI_view2d_draw_scale_y__block(const struct ARegion *region, const struct View2D *v2d, const struct rcti *rect, int colorid)
float UI_view2d_grid_resolution_x__frames_or_seconds(const struct View2D *v2d, const struct Scene *scene, bool display_seconds)
Definition: view2d_draw.c:445
float UI_view2d_grid_resolution_y__values(const struct View2D *v2d)
Definition: view2d_draw.c:455
void UI_view2d_view_restore(const struct bContext *C)
void UI_view2d_totRect_set_resize(struct View2D *v2d, int width, int height, bool resize)
Definition: view2d.c:994
void UI_view2d_curRect_reset(struct View2D *v2d)
Definition: view2d.c:944
void UI_view2d_draw_lines_x__values(const struct View2D *v2d)
void UI_view2d_listview_view_to_cell(float columnwidth, float rowheight, float startx, float starty, float viewx, float viewy, int *column, int *row)
Definition: view2d.c:1623
void UI_view2d_draw_scale_x__discrete_frames_or_seconds(const struct ARegion *region, const struct View2D *v2d, const struct rcti *rect, const struct Scene *scene, bool display_seconds, int colorid)
Definition: view2d_draw.c:560
void UI_view2d_multi_grid_draw(const struct View2D *v2d, int colorid, float step, int level_size, int totlevels)
char UI_view2d_mouse_in_scrollers_ex(const struct ARegion *region, const struct View2D *v2d, int x, int y, int *r_scroll)
void UI_view2d_scale_get_inverse(const struct View2D *v2d, float *r_x, float *r_y)
void UI_view2d_region_to_view_rctf(const struct View2D *v2d, const struct rctf *rect_src, struct rctf *rect_dst) ATTR_NONNULL()
void UI_view2d_view_to_region_m4(const struct View2D *v2d, float matrix[4][4]) ATTR_NONNULL()
bool UI_view2d_view_to_region_clip(const struct View2D *v2d, float x, float y, int *r_region_x, int *r_region_y) ATTR_NONNULL()
void UI_view2d_view_ortho(const struct View2D *v2d)
float UI_view2d_scale_get_y(const struct View2D *v2d)
void UI_view2d_region_to_view(const struct View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL()
void UI_view2d_zoom_cache_reset(void)
Definition: view2d.c:1057
void UI_view2d_draw_lines_x__frames_or_seconds(const struct View2D *v2d, const struct Scene *scene, bool display_seconds)
void UI_view2d_draw_scale_x__frames_or_seconds(const struct ARegion *region, const struct View2D *v2d, const struct rcti *rect, const struct Scene *scene, bool display_seconds, int colorid)
Definition: view2d_draw.c:575
char UI_view2d_rect_in_scrollers_ex(const struct ARegion *region, const struct View2D *v2d, const struct rcti *rect, int *r_scroll)
bool UI_view2d_view_to_region_rcti_clip(const struct View2D *v2d, const struct rctf *rect_src, struct rcti *rect_dst) ATTR_NONNULL()
void UI_view2d_text_cache_draw(struct ARegion *region)
Definition: view2d.c:2148
void UI_view2d_view_to_region(const struct View2D *v2d, float x, float y, int *r_region_x, int *r_region_y) ATTR_NONNULL()
void UI_view2d_mask_from_win(const struct View2D *v2d, struct rcti *r_mask)
void UI_view2d_sync(struct bScreen *screen, struct ScrArea *area, struct View2D *v2dcur, int flag)
Definition: view2d.c:876
void UI_view2d_curRect_changed(const struct bContext *C, struct View2D *v2d)
void UI_view2d_scrollers_draw(struct View2D *v2d, const struct rcti *mask_custom)
void ED_keymap_view2d(struct wmKeyConfig *keyconf)
Definition: view2d_ops.c:2420
void UI_view2d_draw_lines_x__discrete_values(const struct View2D *v2d)
float UI_view2d_region_to_view_x(const struct View2D *v2d, float x)
Definition: view2d.c:1659
float UI_view2d_scale_get_x(const struct View2D *v2d)
void ED_operatortypes_view2d(void)
Definition: view2d_ops.c:2393
void UI_view2d_view_orthoSpecial(struct ARegion *region, struct View2D *v2d, const bool xaxis)
Definition: view2d.c:1159
eView2D_CommonViewTypes
Definition: UI_view2d.h:47
@ V2D_COMMONVIEW_LIST
Definition: UI_view2d.h:53
@ V2D_COMMONVIEW_STACK
Definition: UI_view2d.h:55
@ V2D_COMMONVIEW_HEADER
Definition: UI_view2d.h:57
@ V2D_COMMONVIEW_CUSTOM
Definition: UI_view2d.h:49
@ V2D_COMMONVIEW_STANDARD
Definition: UI_view2d.h:51
@ V2D_COMMONVIEW_PANELS_UI
Definition: UI_view2d.h:59
void UI_view2d_center_get(const struct View2D *v2d, float *r_x, float *r_y)
Definition: view2d.c:1940
void UI_view2d_draw_scale_y__values(const struct ARegion *region, const struct View2D *v2d, const struct rcti *rect, int colorid)
float UI_view2d_region_to_view_y(const struct View2D *v2d, float y)
Definition: view2d.c:1664
struct View2D * UI_view2d_fromcontext_rwin(const struct bContext *C)
void UI_view2d_offset(struct View2D *v2d, float xfac, float yfac)
Definition: view2d.c:1964
void UI_view2d_draw_lines_x__discrete_frames_or_seconds(const struct View2D *v2d, const struct Scene *scene, bool display_seconds)
void UI_view2d_scrollers_calc(struct View2D *v2d, const struct rcti *mask_custom, struct View2DScrollers *r_scrollers)
void UI_view2d_text_cache_add_rectf(struct View2D *v2d, const struct rctf *rect_view, const char *str, size_t str_len, const unsigned char col[4])
void UI_view2d_curRect_validate(struct View2D *v2d)
Definition: view2d.c:851
void UI_view2d_scroller_size_get(const struct View2D *v2d, float *r_x, float *r_y)
Scene scene
#define str(s)
uint col
static void area(int d1, int d2, int e1, int e2, float weights[2])