2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2008 Blender Foundation.
19 * All rights reserved.
22 * Contributor(s): Blender Foundation, Joshua Leung
25 * Generic 2d view with should allow drawing grids,
26 * panning, zooming, scrolling, ..
27 * ***** END GPL LICENSE BLOCK *****
34 #ifndef __UI_VIEW2D_H__
35 #define __UI_VIEW2D_H__
37 /* ------------------------------------------ */
38 /* Settings and Defines: */
40 /* ---- General Defines ---- */
42 /* generic value to use when coordinate lies out of view when converting */
43 #define V2D_IS_CLIPPED 12000
45 /* Common View2D view types
46 * NOTE: only define a type here if it completely sets all (+/- a few) of the relevant flags
47 * and settings for a View2D region, and that set of settings is used in more
48 * than one specific place
51 /* custom view type (region has defined all necessary flags already) */
52 V2D_COMMONVIEW_CUSTOM = -1,
53 /* standard (only use this when setting up a new view, as a sensible base for most settings) */
54 V2D_COMMONVIEW_STANDARD,
55 /* listview (i.e. Outliner) */
57 /* stackview (this is basically a list where new items are added at the top) */
59 /* headers (this is basically the same as listview, but no y-panning) */
60 V2D_COMMONVIEW_HEADER,
61 /* ui region containing panels */
62 V2D_COMMONVIEW_PANELS_UI
63 } eView2D_CommonViewTypes;
65 /* ---- Defines for Scroller/Grid Arguments ----- */
67 /* 'dummy' argument to pass when argument is irrelevant */
68 #define V2D_ARG_DUMMY -1
72 /* for drawing time */
77 /* for drawing values */
84 /* clamping of grid values to whole numbers */
90 /* flags for grid-lines to draw */
92 V2D_HORIZONTAL_LINES = (1 << 0),
93 V2D_VERTICAL_LINES = (1 << 1),
94 V2D_HORIZONTAL_AXIS = (1 << 2),
95 V2D_VERTICAL_AXIS = (1 << 3),
96 V2D_HORIZONTAL_FINELINES = (1 << 4),
98 V2D_GRIDLINES_MAJOR = (V2D_VERTICAL_LINES | V2D_VERTICAL_AXIS | V2D_HORIZONTAL_LINES | V2D_HORIZONTAL_AXIS),
99 V2D_GRIDLINES_ALL = (V2D_GRIDLINES_MAJOR | V2D_HORIZONTAL_FINELINES),
102 /* ------ Defines for Scrollers ----- */
105 #define V2D_SCROLL_HEIGHT 17
106 #define V2D_SCROLL_WIDTH 17
108 /* scroller 'handles' hotspot radius for mouse */
109 #define V2D_SCROLLER_HANDLE_SIZE 12
111 /* ------ Define for UI_view2d_sync ----- */
113 /* means copy it from another v2d */
114 #define V2D_LOCK_SET 0
115 /* means copy it to the other v2ds */
116 #define V2D_LOCK_COPY 1
119 /* ------------------------------------------ */
122 /* test if mouse in a scrollbar (assume that scroller availability has been tested) */
123 #define IN_2D_VERT_SCROLL(v2d, co) (BLI_rcti_isect_pt_v(&v2d->vert, co))
124 #define IN_2D_HORIZ_SCROLL(v2d, co) (BLI_rcti_isect_pt_v(&v2d->hor, co))
126 /* ------------------------------------------ */
127 /* Type definitions: */
131 struct View2DScrollers;
140 typedef struct View2DGrid View2DGrid;
141 typedef struct View2DScrollers View2DScrollers;
143 /* ----------------------------------------- */
146 /* refresh and validation (of view rects) */
147 void UI_view2d_region_reinit(struct View2D *v2d, short type, int winx, int winy);
149 void UI_view2d_curRect_validate(struct View2D *v2d);
150 void UI_view2d_curRect_validate_resize(struct View2D *v2d, int resize);
151 void UI_view2d_curRect_reset(struct View2D *v2d);
152 void UI_view2d_sync(struct bScreen *screen, struct ScrArea *sa, struct View2D *v2dcur, int flag);
154 void UI_view2d_totRect_set(struct View2D *v2d, int width, int height);
155 void UI_view2d_totRect_set_resize(struct View2D *v2d, int width, int height, int resize);
157 /* per tab offsets, returns 1 if tab changed */
158 int UI_view2d_tab_set(struct View2D *v2d, int tab);
160 /* view matrix operations */
161 void UI_view2d_view_ortho(struct View2D *v2d);
162 void UI_view2d_view_orthoSpecial(struct ARegion *ar, struct View2D *v2d, short xaxis);
163 void UI_view2d_view_restore(const struct bContext *C);
166 View2DGrid *UI_view2d_grid_calc(struct Scene *scene, struct View2D *v2d, short xunits, short xclamp, short yunits, short yclamp, int winx, int winy);
167 void UI_view2d_grid_draw(struct View2D *v2d, View2DGrid *grid, int flag);
168 void UI_view2d_constant_grid_draw(struct View2D *v2d);
169 void UI_view2d_multi_grid_draw(struct View2D *v2d, float step, int level_size, int totlevels);
170 void UI_view2d_grid_size(View2DGrid *grid, float *r_dx, float *r_dy);
171 void UI_view2d_grid_free(View2DGrid *grid);
173 /* scrollbar drawing */
174 View2DScrollers *UI_view2d_scrollers_calc(const struct bContext *C, struct View2D *v2d, short xunits, short xclamp, short yunits, short yclamp);
175 void UI_view2d_scrollers_draw(const struct bContext *C, struct View2D *v2d, View2DScrollers *scrollers);
176 void UI_view2d_scrollers_free(View2DScrollers *scrollers);
178 /* list view tools */
179 void UI_view2d_listview_cell_to_view(struct View2D *v2d, short columnwidth, short rowheight, float startx, float starty, int column, int row, struct rctf *rect);
180 void UI_view2d_listview_view_to_cell(struct View2D *v2d, short columnwidth, short rowheight, float startx, float starty, float viewx, float viewy, int *column, int *row);
181 void UI_view2d_listview_visible_cells(struct View2D *v2d, short columnwidth, short rowheight, float startx, float starty, int *column_min, int *column_max, int *row_min, int *row_max);
183 /* coordinate conversion */
184 void UI_view2d_region_to_view(struct View2D *v2d, int x, int y, float *viewx, float *viewy);
185 void UI_view2d_view_to_region(struct View2D *v2d, float x, float y, int *regionx, int *regiony);
186 void UI_view2d_to_region_no_clip(struct View2D *v2d, float x, float y, int *regionx, int *region_y);
189 struct View2D *UI_view2d_fromcontext(const struct bContext *C);
190 struct View2D *UI_view2d_fromcontext_rwin(const struct bContext *C);
192 void UI_view2d_getscale(struct View2D *v2d, float *x, float *y);
194 short UI_view2d_mouse_in_scrollers(const struct bContext *C, struct View2D *v2d, int x, int y);
196 /* cached text drawing in v2d, to allow pixel-aligned draw as post process */
197 void UI_view2d_text_cache_add(struct View2D *v2d, float x, float y, const char *str, const char col[4]);
198 void UI_view2d_text_cache_rectf(struct View2D *v2d, struct rctf *rect, const char *str, const char col[4]);
199 void UI_view2d_text_cache_draw(struct ARegion *ar);
202 void UI_view2d_operatortypes(void);
203 void UI_view2d_keymap(struct wmKeyConfig *keyconf);
205 void UI_view2d_smooth_view(struct bContext *C, struct ARegion *ar,
206 const struct rctf *cur);
208 #endif /* __UI_VIEW2D_H__ */