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