Blender V2.61 - r43446

UI_view2d.h

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version. 
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2008 Blender Foundation.
00019  * All rights reserved.
00020  *
00021  * 
00022  * Contributor(s): Blender Foundation, Joshua Leung
00023  *
00024  *
00025  * Generic 2d view with should allow drawing grids,
00026  * panning, zooming, scrolling, .. 
00027  * ***** END GPL LICENSE BLOCK *****
00028  */
00029 
00034 #ifndef UI_VIEW2D_H
00035 #define UI_VIEW2D_H
00036 
00037 /* ------------------------------------------ */
00038 /* Settings and Defines:                    */
00039 
00040 /* ---- General Defines ---- */
00041 
00042 /* generic value to use when coordinate lies out of view when converting */
00043 #define V2D_IS_CLIPPED  12000
00044 
00045 /* Common View2D view types 
00046  * NOTE: only define a type here if it completely sets all (+/- a few) of the relevant flags 
00047  *      and settings for a View2D region, and that set of settings is used in more
00048  *      than one specific place
00049  */
00050 enum {
00051         /* custom view type (region has defined all necessary flags already) */
00052     V2D_COMMONVIEW_CUSTOM = -1,
00053         /* standard (only use this when setting up a new view, as a sensible base for most settings) */
00054     V2D_COMMONVIEW_STANDARD,
00055         /* listview (i.e. Outliner) */
00056     V2D_COMMONVIEW_LIST,
00057         /* stackview (this is basically a list where new items are added at the top) */
00058     V2D_COMMONVIEW_STACK,
00059         /* headers (this is basically the same as listview, but no y-panning) */
00060     V2D_COMMONVIEW_HEADER,
00061         /* ui region containing panels */
00062     V2D_COMMONVIEW_PANELS_UI
00063 } eView2D_CommonViewTypes;
00064 
00065 /* ---- Defines for Scroller/Grid Arguments ----- */
00066 
00067 /* 'dummy' argument to pass when argument is irrelevant */
00068 #define V2D_ARG_DUMMY       -1
00069 
00070 /* Grid units */
00071 enum {
00072     /* for drawing time */
00073     V2D_UNIT_SECONDS = 0,
00074     V2D_UNIT_FRAMES,
00075     V2D_UNIT_FRAMESCALE,
00076     
00077     /* for drawing values */
00078     V2D_UNIT_VALUES,
00079     V2D_UNIT_DEGREES,
00080     V2D_UNIT_TIME,
00081     V2D_UNIT_SECONDSSEQ
00082 } eView2D_Units;
00083 
00084 /* clamping of grid values to whole numbers */
00085 enum {
00086     V2D_GRID_NOCLAMP = 0,
00087     V2D_GRID_CLAMP
00088 } eView2D_Clamp;
00089 
00090 /* flags for grid-lines to draw */
00091 enum {
00092     V2D_HORIZONTAL_LINES        = (1<<0),
00093     V2D_VERTICAL_LINES          = (1<<1),
00094     V2D_HORIZONTAL_AXIS         = (1<<2),
00095     V2D_VERTICAL_AXIS           = (1<<3),
00096     V2D_HORIZONTAL_FINELINES    = (1<<4),
00097     
00098     V2D_GRIDLINES_MAJOR         = (V2D_VERTICAL_LINES|V2D_VERTICAL_AXIS|V2D_HORIZONTAL_LINES|V2D_HORIZONTAL_AXIS),
00099     V2D_GRIDLINES_ALL           = (V2D_GRIDLINES_MAJOR|V2D_HORIZONTAL_FINELINES),
00100 } eView2D_Gridlines;
00101 
00102 /* ------ Defines for Scrollers ----- */
00103 
00104 /* scroller area */
00105 #define V2D_SCROLL_HEIGHT   17
00106 #define V2D_SCROLL_WIDTH    17
00107 
00108 /* scroller 'handles' hotspot radius for mouse */
00109 #define V2D_SCROLLER_HANDLE_SIZE    12
00110 
00111 /* ------ Define for UI_view2d_sync ----- */
00112 
00113 /* means copy it from another v2d */
00114 #define V2D_LOCK_SET    0
00115 /* means copy it to the other v2ds */
00116 #define V2D_LOCK_COPY   1
00117 
00118 
00119 /* ------------------------------------------ */
00120 /* Macros:                              */
00121 
00122 /* test if mouse in a scrollbar (assume that scroller availability has been tested) */
00123 #define IN_2D_VERT_SCROLL(v2d, co) (BLI_in_rcti(&v2d->vert, co[0], co[1]))
00124 #define IN_2D_HORIZ_SCROLL(v2d, co) (BLI_in_rcti(&v2d->hor, co[0], co[1]))
00125 
00126 /* ------------------------------------------ */
00127 /* Type definitions:                        */
00128 
00129 struct View2D;
00130 struct View2DGrid;
00131 struct View2DScrollers;
00132 
00133 struct wmKeyConfig;
00134 struct bScreen;
00135 struct ScrArea;
00136 struct ARegion;
00137 struct bContext;
00138 struct rctf;
00139 
00140 typedef struct View2DGrid View2DGrid;
00141 typedef struct View2DScrollers View2DScrollers;
00142 
00143 /* ----------------------------------------- */
00144 /* Prototypes:                          */
00145 
00146 /* refresh and validation (of view rects) */
00147 void UI_view2d_region_reinit(struct View2D *v2d, short type, int winx, int winy);
00148 
00149 void UI_view2d_curRect_validate(struct View2D *v2d);
00150 void UI_view2d_curRect_validate_resize(struct View2D *v2d, int resize);
00151 void UI_view2d_curRect_reset(struct View2D *v2d);
00152 void UI_view2d_sync(struct bScreen *screen, struct ScrArea *sa, struct View2D *v2dcur, int flag);
00153 
00154 void UI_view2d_totRect_set(struct View2D *v2d, int width, int height);
00155 void UI_view2d_totRect_set_resize(struct View2D *v2d, int width, int height, int resize);
00156 
00157 /* per tab offsets, returns 1 if tab changed */
00158 int UI_view2d_tab_set(struct View2D *v2d, int tab);
00159 
00160 /* view matrix operations */
00161 void UI_view2d_view_ortho(struct View2D *v2d);
00162 void UI_view2d_view_orthoSpecial(struct ARegion *ar, struct View2D *v2d, short xaxis);
00163 void UI_view2d_view_restore(const struct bContext *C);
00164 
00165 /* grid drawing */
00166 View2DGrid *UI_view2d_grid_calc(struct Scene *scene, struct View2D *v2d, short xunits, short xclamp, short yunits, short yclamp, int winx, int winy);
00167 void UI_view2d_grid_draw(struct View2D *v2d, View2DGrid *grid, int flag);
00168 void UI_view2d_constant_grid_draw(struct View2D *v2d);
00169 void UI_view2d_grid_size(View2DGrid *grid, float *r_dx, float *r_dy);
00170 void UI_view2d_grid_free(View2DGrid *grid);
00171 
00172 /* scrollbar drawing */
00173 View2DScrollers *UI_view2d_scrollers_calc(const struct bContext *C, struct View2D *v2d, short xunits, short xclamp, short yunits, short yclamp);
00174 void UI_view2d_scrollers_draw(const struct bContext *C, struct View2D *v2d, View2DScrollers *scrollers);
00175 void UI_view2d_scrollers_free(View2DScrollers *scrollers);
00176 
00177 /* list view tools */
00178 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);
00179 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);
00180 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);
00181 
00182 /* coordinate conversion */
00183 void UI_view2d_region_to_view(struct View2D *v2d, int x, int y, float *viewx, float *viewy);
00184 void UI_view2d_view_to_region(struct View2D *v2d, float x, float y, int *regionx, int *regiony);
00185 void UI_view2d_to_region_no_clip(struct View2D *v2d, float x, float y, int *regionx, int *region_y);
00186 
00187 /* utilities */
00188 struct View2D *UI_view2d_fromcontext(const struct bContext *C);
00189 struct View2D *UI_view2d_fromcontext_rwin(const struct bContext *C);
00190 
00191 void UI_view2d_getscale(struct View2D *v2d, float *x, float *y);
00192 
00193 short UI_view2d_mouse_in_scrollers(const struct bContext *C, struct View2D *v2d, int x, int y);
00194 
00195 /* cached text drawing in v2d, to allow pixel-aligned draw as post process */
00196 void UI_view2d_text_cache_add(struct View2D *v2d, float x, float y, const char *str, const char col[4]);
00197 void UI_view2d_text_cache_rectf(struct View2D *v2d, struct rctf *rect, const char *str, const char col[4]);
00198 void UI_view2d_text_cache_draw(struct ARegion *ar);
00199 
00200 /* operators */
00201 void UI_view2d_operatortypes(void);
00202 void UI_view2d_keymap(struct wmKeyConfig *keyconf);
00203 
00204 #endif /* UI_VIEW2D_H */
00205