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) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
20 /** \file
21  * \ingroup DNA
22  */
23 
24 #pragma once
25 
26 #include "DNA_vec_types.h"
27 
28 /* ---------------------------------- */
29 
30 /* View 2D data - stored per region */
31 typedef struct View2D {
32   /** Tot - area that data can be drawn in; cur - region of tot that is visible in viewport. */
33   rctf tot, cur;
34   /** Vert - vertical scrollbar region; hor - horizontal scrollbar region. */
35   rcti vert, hor;
36   /** Mask - region (in screenspace) within which 'cur' can be viewed. */
37   rcti mask;
38 
39   /** Min/max sizes of 'cur' rect (only when keepzoom not set). */
40   float min[2], max[2];
41   /** Allowable zoom factor range (only when (keepzoom & V2D_LIMITZOOM)) is set. */
42   float minzoom, maxzoom;
43 
44   /** Scroll - scrollbars to display (bitflag). */
45   short scroll;
46   /** Scroll_ui - temp settings used for UI drawing of scrollers. */
47   short scroll_ui;
48 
49   /** Keeptot - 'cur' rect cannot move outside the 'tot' rect?. */
50   short keeptot;
51   /** Keepzoom - axes that zooming cannot occur on, and also clamp within zoom-limits. */
52   short keepzoom;
53   /** Keepofs - axes that translation is not allowed to occur on. */
54   short keepofs;
55 
56   /** Settings. */
57   short flag;
58   /** Alignment of content in totrect. */
59   short align;
60 
61   /** Storage of current winx/winy values, set in UI_view2d_size_update. */
62   short winx, winy;
63   /** Storage of previous winx/winy values encountered by UI_view2d_curRect_validate(),
64    * for keepaspect. */
65   short oldwinx, oldwiny;
66 
67   /** Pivot point for transforms (rotate and scale). */
68   short around;
69 
70   /* Usually set externally (as in, not in view2d files). */
71   /** Alpha of vertical and horizontal scrollbars (range is [0, 255]). */
72   char alpha_vert, alpha_hor;
73   char _pad[6];
74 
75   /* animated smooth view */
76   struct SmoothView2DStore *sms;
77   struct wmTimer *smooth_timer;
78 } View2D;
79 
80 /* ---------------------------------- */
81 
82 /* view zooming restrictions, per axis (v2d->keepzoom) */
83 enum {
84   /* zoom is clamped to lie within limits set by minzoom and maxzoom */
85   V2D_LIMITZOOM = (1 << 0),
86   /* aspect ratio is maintained on view resize */
87   V2D_KEEPASPECT = (1 << 1),
88   /* zoom is kept when the window resizes */
89   V2D_KEEPZOOM = (1 << 2),
90   /* zooming on x-axis is not allowed */
91   V2D_LOCKZOOM_X = (1 << 8),
92   /* zooming on y-axis is not allowed */
93   V2D_LOCKZOOM_Y = (1 << 9),
94 };
95 
96 /* view panning restrictions, per axis (v2d->keepofs) */
97 enum {
98   /* panning on x-axis is not allowed */
99   V2D_LOCKOFS_X = (1 << 1),
100   /* panning on y-axis is not allowed */
101   V2D_LOCKOFS_Y = (1 << 2),
102   /* on resize, keep the x offset */
103   V2D_KEEPOFS_X = (1 << 3),
104   /* on resize, keep the y offset */
105   V2D_KEEPOFS_Y = (1 << 4),
106 };
107 
108 /* view extent restrictions (v2d->keeptot) */
109 enum {
110   /** 'cur' view can be out of extents of 'tot' */
111   V2D_KEEPTOT_FREE = 0,
112   /** 'cur' rect is adjusted so that it satisfies the extents of 'tot', with some compromises */
113   V2D_KEEPTOT_BOUNDS = 1,
114   /** 'cur' rect is moved so that the 'minimum' bounds of the 'tot' rect are always respected
115    * (particularly in x-axis) */
116   V2D_KEEPTOT_STRICT = 2,
117 };
118 
119 /* general refresh settings (v2d->flag) */
120 enum {
121   /* global view2d horizontal locking (for showing same time interval) */
122   /* TODO: this flag may be set in old files but is not accessible currently,
123    * should be exposed from RNA - Campbell */
124   V2D_VIEWSYNC_SCREEN_TIME = (1 << 0),
125   /* within area (i.e. between regions) view2d vertical locking */
126   V2D_VIEWSYNC_AREA_VERTICAL = (1 << 1),
127   /* apply pixel offsets on x-axis when setting view matrices */
128   V2D_PIXELOFS_X = (1 << 2),
129   /* apply pixel offsets on y-axis when setting view matrices */
130   V2D_PIXELOFS_Y = (1 << 3),
131   /* view settings need to be set still... */
132   V2D_IS_INIT = (1 << 10),
133 };
134 
135 /* scroller flags for View2D (v2d->scroll) */
136 enum {
137   /* left scrollbar */
138   V2D_SCROLL_LEFT = (1 << 0),
139   V2D_SCROLL_RIGHT = (1 << 1),
140   V2D_SCROLL_VERTICAL = (V2D_SCROLL_LEFT | V2D_SCROLL_RIGHT),
141   /* horizontal scrollbar */
142   V2D_SCROLL_TOP = (1 << 2),
143   V2D_SCROLL_BOTTOM = (1 << 3),
144   /* UNUSED                    = (1 << 4), */
145   V2D_SCROLL_HORIZONTAL = (V2D_SCROLL_TOP | V2D_SCROLL_BOTTOM),
146   /* display vertical scale handles */
147   V2D_SCROLL_VERTICAL_HANDLES = (1 << 5),
148   /* display horizontal scale handles */
149   V2D_SCROLL_HORIZONTAL_HANDLES = (1 << 6),
150   /* induce hiding of scrollbars - set by region drawing in response to size of region */
151   V2D_SCROLL_VERTICAL_HIDE = (1 << 7),
152   V2D_SCROLL_HORIZONTAL_HIDE = (1 << 8),
153   /* scrollbar extends beyond its available window -
154    * set when calculating scrollbars for drawing */
155   V2D_SCROLL_VERTICAL_FULLR = (1 << 9),
156   V2D_SCROLL_HORIZONTAL_FULLR = (1 << 10),
157 };
158 
159 /* scroll_ui, activate flag for drawing */
160 enum {
161   V2D_SCROLL_H_ACTIVE = (1 << 0),
162   V2D_SCROLL_V_ACTIVE = (1 << 1),
163 };
164 
165 /* alignment flags for totrect, flags use 'shading-out' convention (v2d->align) */
166 enum {
167   /* all quadrants free */
168   V2D_ALIGN_FREE = 0,
169   /* horizontal restrictions */
170   V2D_ALIGN_NO_POS_X = (1 << 0),
171   V2D_ALIGN_NO_NEG_X = (1 << 1),
172   /* vertical restrictions */
173   V2D_ALIGN_NO_POS_Y = (1 << 2),
174   V2D_ALIGN_NO_NEG_Y = (1 << 3),
175 };
176