4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2008 Blender Foundation.
21 * All rights reserved.
24 * Contributor(s): Blender Foundation, Joshua Leung
27 * Generic 2d view with should allow drawing grids,
28 * panning, zooming, scrolling, ..
29 * ***** END GPL LICENSE BLOCK *****
35 /* ------------------------------------------ */
36 /* Settings and Defines: */
38 /* ---- General Defines ---- */
40 /* generic value to use when coordinate lies out of view when converting */
41 #define V2D_IS_CLIPPED 12000
43 /* Common View2D view types
44 * NOTE: only define a type here if it completely sets all (+/- a few) of the relevant flags
45 * and settings for a View2D region, and that set of settings is used in more
46 * than one specific place
49 /* custom view type (region has defined all necessary flags already) */
50 V2D_COMMONVIEW_CUSTOM = -1,
51 /* standard (only use this when setting up a new view, as a sensible base for most settings) */
52 V2D_COMMONVIEW_STANDARD,
53 /* listview (i.e. Outliner) */
55 /* headers (this is basically the same as listview, but no y-panning) */
56 V2D_COMMONVIEW_HEADER,
57 /* ui region containing panels */
58 V2D_COMMONVIEW_PANELS_UI,
59 } eView2D_CommonViewTypes;
61 /* ---- Defines for Scroller/Grid Arguments ----- */
63 /* 'dummy' argument to pass when argument is irrelevant */
64 #define V2D_ARG_DUMMY -1
68 /* for drawing time */
73 /* for drawing values */
80 /* clamping of grid values to whole numbers */
86 /* flags for grid-lines to draw */
88 V2D_HORIZONTAL_LINES = (1<<0),
89 V2D_VERTICAL_LINES = (1<<1),
90 V2D_HORIZONTAL_AXIS = (1<<2),
91 V2D_VERTICAL_AXIS = (1<<3),
92 V2D_HORIZONTAL_FINELINES = (1<<4),
94 V2D_GRIDLINES_MAJOR = (V2D_VERTICAL_LINES|V2D_VERTICAL_AXIS|V2D_HORIZONTAL_LINES|V2D_HORIZONTAL_AXIS),
95 V2D_GRIDLINES_ALL = (V2D_GRIDLINES_MAJOR|V2D_HORIZONTAL_FINELINES),
98 /* ------ Defines for Scrollers ----- */
100 /* scroller thickness */
101 #define V2D_SCROLL_HEIGHT 16
102 #define V2D_SCROLL_WIDTH 16
104 /* half the size (in pixels) of scroller 'handles' */
105 #define V2D_SCROLLER_HANDLE_SIZE 5
107 /* ------ Define for UI_view2d_sync ----- */
109 /* means copy it from another v2d */
110 #define V2D_LOCK_SET 0
111 /* means copy it to the other v2ds */
112 #define V2D_LOCK_COPY 1
115 /* ------------------------------------------ */
118 /* test if mouse in a scrollbar (assume that scroller availability has been tested) */
119 #define IN_2D_VERT_SCROLL(v2d, co) (BLI_in_rcti(&v2d->vert, co[0], co[1]))
120 #define IN_2D_HORIZ_SCROLL(v2d, co) (BLI_in_rcti(&v2d->hor, co[0], co[1]))
122 /* ------------------------------------------ */
123 /* Type definitions: */
127 struct View2DScrollers;
129 struct wmWindowManager;
136 typedef struct View2DGrid View2DGrid;
137 typedef struct View2DScrollers View2DScrollers;
139 /* ----------------------------------------- */
142 /* refresh and validation (of view rects) */
143 void UI_view2d_region_reinit(struct View2D *v2d, short type, int winx, int winy);
145 void UI_view2d_curRect_validate(struct View2D *v2d);
146 void UI_view2d_curRect_reset(struct View2D *v2d);
147 void UI_view2d_sync(struct bScreen *screen, struct ScrArea *sa, struct View2D *v2dcur, int flag);
149 void UI_view2d_totRect_set(struct View2D *v2d, int width, int height);
151 /* view matrix operations */
152 void UI_view2d_view_ortho(const struct bContext *C, struct View2D *v2d);
153 void UI_view2d_view_orthoSpecial(const struct bContext *C, struct View2D *v2d, short xaxis);
154 void UI_view2d_view_restore(const struct bContext *C);
157 View2DGrid *UI_view2d_grid_calc(const struct bContext *C, struct View2D *v2d, short xunits, short xclamp, short yunits, short yclamp, int winx, int winy);
158 void UI_view2d_grid_draw(const struct bContext *C, struct View2D *v2d, View2DGrid *grid, int flag);
159 void UI_view2d_constant_grid_draw(const struct bContext *C, struct View2D *v2d);
160 void UI_view2d_grid_free(View2DGrid *grid);
162 /* scrollbar drawing */
163 View2DScrollers *UI_view2d_scrollers_calc(const struct bContext *C, struct View2D *v2d, short xunits, short xclamp, short yunits, short yclamp);
164 void UI_view2d_scrollers_draw(const struct bContext *C, struct View2D *v2d, View2DScrollers *scrollers);
165 void UI_view2d_scrollers_free(View2DScrollers *scrollers);
167 /* list view tools */
168 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);
169 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);
170 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);
172 /* coordinate conversion */
173 void UI_view2d_region_to_view(struct View2D *v2d, int x, int y, float *viewx, float *viewy);
174 void UI_view2d_view_to_region(struct View2D *v2d, float x, float y, int *regionx, int *regiony);
175 void UI_view2d_to_region_no_clip(struct View2D *v2d, float x, float y, int *regionx, int *region_y);
178 struct View2D *UI_view2d_fromcontext(const struct bContext *C);
179 struct View2D *UI_view2d_fromcontext_rwin(const struct bContext *C);
181 void UI_view2d_getscale(struct View2D *v2d, float *x, float *y);
183 short UI_view2d_mouse_in_scrollers(const struct bContext *C, struct View2D *v2d, int x, int y);
185 /* cached text drawing in v2d, to allow pixel-aligned draw as post process */
186 void UI_view2d_text_cache_add(struct View2D *v2d, float x, float y, char *str);
187 void UI_view2d_text_cache_draw(struct ARegion *ar);
190 void ui_view2d_operatortypes(void);
191 void UI_view2d_keymap(struct wmWindowManager *wm);
193 #endif /* UI_VIEW2D_H */