Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Leung <aligorith@gmail.com>2008-12-05 05:03:37 +0300
committerJoshua Leung <aligorith@gmail.com>2008-12-05 05:03:37 +0300
commit5e6041496174904e1745b39517b63b0dff78326b (patch)
tree204d9735a8abb407d03a4e7a09acfdc9268f6ca0 /source/blender/editors
parente4a8a39f9d649a2fc022959ef8bbee147422a38e (diff)
View2D API: Cleaning up API + New Methods
* Cleaned up flags defined for View2D, and added some for defining the alignment of the view's data in the 'tot' rect (i.e. which quadrant(s) the view data is allowed to reside in). * These flags are used in the new UI_view2d_totRect_set() function, which sets the new size of the 'tot' rect (i.e. the maximum viewable area). Currently, is only used for Outliner, but channel-lists also require this. * Added API method to reset 'cur' (current viewing region) to 'default' viewing region - UI_view2d_curRect_reset(). Currently, 'keepzoom' is not respected. I'll check on whether this is needed when I recode UI_view2d_status_enforce(), which is badly in need of a cleanup.
Diffstat (limited to 'source/blender/editors')
-rw-r--r--source/blender/editors/include/UI_view2d.h15
-rw-r--r--source/blender/editors/interface/view2d.c146
-rw-r--r--source/blender/editors/space_outliner/space_outliner.c12
-rw-r--r--source/blender/editors/space_time/space_time.c4
4 files changed, 140 insertions, 37 deletions
diff --git a/source/blender/editors/include/UI_view2d.h b/source/blender/editors/include/UI_view2d.h
index 07fc4e98519..02cf4b1f4cc 100644
--- a/source/blender/editors/include/UI_view2d.h
+++ b/source/blender/editors/include/UI_view2d.h
@@ -82,14 +82,19 @@ typedef struct View2DScrollers View2DScrollers;
/* ----------------------------------------- */
/* Prototypes: */
-/* setup */
+/* refresh and validation (of view rects) */
+ // XXX rename these...
+void UI_view2d_size_update(struct View2D *v2d, int winx, int winy);
+void UI_view2d_status_enforce(struct View2D *v2d, int winx, int winy);
+
+void UI_view2d_totRect_set(struct View2D *v2d, int width, int height);
+void UI_view2d_curRect_reset(struct View2D *v2d);
+
+/* view matrix operations */
void UI_view2d_view_ortho(const struct bContext *C, struct View2D *v2d);
-void UI_view2d_view_orthospecial(const struct bContext *C, struct View2D *v2d, short xaxis);
+void UI_view2d_view_orthoSpecial(const struct bContext *C, struct View2D *v2d, short xaxis);
void UI_view2d_view_restore(const struct bContext *C);
-void UI_view2d_update_size(struct View2D *v2d, int winx, int winy);
-void UI_view2d_enforce_status(struct View2D *v2d, int winx, int winy);
-
/* grid drawing */
View2DGrid *UI_view2d_calc_grid(const struct bContext *C, struct View2D *v2d, short unit, short clamp, int winx, int winy);
void UI_view2d_draw_grid(const struct bContext *C, struct View2D *v2d, View2DGrid *grid, int flag);
diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c
index e6ef33f3ddc..0b4ad56628f 100644
--- a/source/blender/editors/interface/view2d.c
+++ b/source/blender/editors/interface/view2d.c
@@ -52,9 +52,12 @@
/* *********************************************************************** */
/* Refresh and Validation */
-/* Adjust mask size in response to view size changes */
+/* Adjust mask size in response to view size changes
+ * - When drawing a region, this should be called before
+ * any other drawing using View2D happens.
+ */
// XXX pre2.5 -> this used to be called calc_scrollrcts()
-void UI_view2d_update_size(View2D *v2d, int winx, int winy)
+void UI_view2d_size_update(View2D *v2d, int winx, int winy)
{
/* mask - view frame */
v2d->mask.xmin= v2d->mask.ymin= 0;
@@ -99,8 +102,8 @@ void UI_view2d_update_size(View2D *v2d, int winx, int winy)
* - cur is not allowed to be: larger than max, smaller than min, or outside of tot
*/
// XXX pre2.5 -> this used to be called test_view2d()
-// XXX FIXME - still need to go through this and figure out what it all parts of it do
-void UI_view2d_enforce_status(View2D *v2d, int winx, int winy)
+// XXX FIXME - this is an old mess function... let's rewrite!
+void UI_view2d_status_enforce(View2D *v2d, int winx, int winy)
{
/* cur is not allowed to be larger than max, smaller than min, or outside of tot */
rctf *cur, *tot;
@@ -115,7 +118,7 @@ void UI_view2d_enforce_status(View2D *v2d, int winx, int winy)
/* get pointers */
cur= &v2d->cur;
- tot= &v2d->tot;
+ tot= &v2d->cur;
/* dx, dy are width and height of v2d->cur, respectively */
dx= cur->xmax - cur->xmin;
@@ -216,14 +219,14 @@ void UI_view2d_enforce_status(View2D *v2d, int winx, int winy)
}
if (do_x) {
- if ((v2d->keeptot == 2) && (winx < v2d->oldwinx)) {
+ if ((v2d->keeptot == 2) && (winx != v2d->oldwinx)) {
/* This is a special hack for the outliner, to ensure that the
- * outliner contents will not eventually get pushed out of view
- * when shrinking the view.
+ * outliner contents will stay in their relative place in the view
+ * when the view is resized
*/
cur->xmax -= cur->xmin;
cur->xmin= 0.0f;
- }
+ }
else {
/* portrait window: correct for x */
dx= cur->ymax - cur->ymin;
@@ -326,6 +329,105 @@ void UI_view2d_enforce_status(View2D *v2d, int winx, int winy)
}
}
+/* ------------------ */
+
+/* Change the size of the maximum viewable area (i.e. 'tot' rect)
+ * - Currently, caller will need to call UI_status_enforce() after this,
+ * with the region width+height to make sure that 'cur' rect is still valid
+ */
+void UI_view2d_totRect_set(View2D *v2d, int width, int height)
+{
+ /* don't do anything if either value is 0 */
+ if (ELEM3(0, v2d, width, height))
+ return;
+
+ /* handle width - posx and negx flags are mutually exclusive, so watch out */
+ if ((v2d->align & V2D_ALIGN_NO_POS_X) && !(v2d->align & V2D_ALIGN_NO_NEG_X)) {
+ /* width is in negative-x half */
+ v2d->cur.xmin= (float)-width;
+ v2d->cur.xmax= 0.0f;
+ }
+ else if ((v2d->align & V2D_ALIGN_NO_NEG_X) && !(v2d->align & V2D_ALIGN_NO_POS_X)) {
+ /* width is in positive-x half */
+ v2d->cur.xmin= 0.0f;
+ v2d->cur.xmax= (float)width;
+ }
+ else {
+ /* width is centered around x==0 */
+ const float dx= (float)width / 2.0f;
+
+ v2d->cur.xmin= -dx;
+ v2d->cur.xmax= dx;
+ }
+
+ /* handle height - posx and negx flags are mutually exclusive, so watch out */
+ if ((v2d->align & V2D_ALIGN_NO_POS_Y) && !(v2d->align & V2D_ALIGN_NO_NEG_Y)) {
+ /* height is in negative-y half */
+ v2d->cur.ymin= (float)-height;
+ v2d->cur.ymax= 0.0f;
+ }
+ else if ((v2d->align & V2D_ALIGN_NO_NEG_Y) && !(v2d->align & V2D_ALIGN_NO_POS_Y)) {
+ /* height is in positive-y half */
+ v2d->cur.ymin= 0.0f;
+ v2d->cur.ymax= (float)height;
+ }
+ else {
+ /* height is centered around y==0 */
+ const float dy= (float)height / 2.0f;
+
+ v2d->cur.ymin= -dy;
+ v2d->cur.ymax= dy;
+ }
+}
+
+/* Restore 'cur' rect to standard orientation (i.e. optimal maximum view of tot) */
+void UI_view2d_curRect_reset (View2D *v2d)
+{
+ float width, height;
+
+ /* assume width and height of 'cur' rect by default, should be same size as mask */
+ width= (float)(v2d->mask.xmax - v2d->mask.xmin + 1);
+ height= (float)(v2d->mask.ymax - v2d->mask.ymin + 1);
+
+ /* handle width - posx and negx flags are mutually exclusive, so watch out */
+ if ((v2d->align & V2D_ALIGN_NO_POS_X) && !(v2d->align & V2D_ALIGN_NO_NEG_X)) {
+ /* width is in negative-x half */
+ v2d->cur.xmin= (float)-width;
+ v2d->cur.xmax= 0.0f;
+ }
+ else if ((v2d->align & V2D_ALIGN_NO_NEG_X) && !(v2d->align & V2D_ALIGN_NO_POS_X)) {
+ /* width is in positive-x half */
+ v2d->cur.xmin= 0.0f;
+ v2d->cur.xmax= (float)width;
+ }
+ else {
+ /* width is centered around x==0 */
+ const float dx= (float)width / 2.0f;
+
+ v2d->cur.xmin= -dx;
+ v2d->cur.xmax= dx;
+ }
+
+ /* handle height - posx and negx flags are mutually exclusive, so watch out */
+ if ((v2d->align & V2D_ALIGN_NO_POS_Y) && !(v2d->align & V2D_ALIGN_NO_NEG_Y)) {
+ /* height is in negative-y half */
+ v2d->cur.ymin= (float)-height;
+ v2d->cur.ymax= 0.0f;
+ }
+ else if ((v2d->align & V2D_ALIGN_NO_NEG_Y) && !(v2d->align & V2D_ALIGN_NO_POS_Y)) {
+ /* height is in positive-y half */
+ v2d->cur.ymin= 0.0f;
+ v2d->cur.ymax= (float)height;
+ }
+ else {
+ /* height is centered around y==0 */
+ const float dy= (float)height / 2.0f;
+
+ v2d->cur.ymin= -dy;
+ v2d->cur.ymax= dy;
+ }
+}
+
/* *********************************************************************** */
/* View Matrix Setup */
@@ -345,7 +447,7 @@ void UI_view2d_view_ortho(const bContext *C, View2D *v2d)
*
* - xaxis = if non-zero, only use cur x-axis, otherwise use cur-yaxis (mostly this will be used for x)
*/
-void UI_view2d_view_orthospecial(const bContext *C, View2D *v2d, short xaxis)
+void UI_view2d_view_orthoSpecial(const bContext *C, View2D *v2d, short xaxis)
{
ARegion *region= C->region;
int winx, winy;
@@ -640,14 +742,14 @@ View2DScrollers *UI_view2d_calc_scrollers(const bContext *C, View2D *v2d, short
/* horizontal scrollers */
if (v2d->scroll & (V2D_SCROLL_HORIZONTAL|V2D_SCROLL_HORIZONTAL_O)) {
/* slider 'button' extents */
- totsize= v2d->tot.xmax - v2d->tot.xmin;
+ totsize= v2d->cur.xmax - v2d->cur.xmin;
scrollsize= hor.xmax - hor.xmin;
- fac= (v2d->cur.xmin- v2d->tot.xmin) / totsize;
+ fac= (v2d->cur.xmin- v2d->cur.xmin) / totsize;
//if (fac < 0.0f) fac= 0.0f;
scrollers->hor_min= hor.xmin + (fac * scrollsize);
- fac= (v2d->cur.xmax - v2d->tot.xmin) / totsize;
+ fac= (v2d->cur.xmax - v2d->cur.xmin) / totsize;
//if (fac > 1.0f) fac= 1.0f;
scrollers->hor_max= hor.xmin + (fac * scrollsize);
@@ -658,14 +760,14 @@ View2DScrollers *UI_view2d_calc_scrollers(const bContext *C, View2D *v2d, short
/* vertical scrollers */
if (v2d->scroll & V2D_SCROLL_VERTICAL) {
/* slider 'button' extents */
- totsize= v2d->tot.ymax - v2d->tot.ymin;
+ totsize= v2d->cur.ymax - v2d->cur.ymin;
scrollsize= vert.ymax - vert.ymin;
- fac= (v2d->cur.ymin- v2d->tot.ymin) / totsize;
+ fac= (v2d->cur.ymin- v2d->cur.ymin) / totsize;
//if (fac < 0.0f) fac= 0.0f;
scrollers->vert_min= vert.ymin + (fac * scrollsize);
- fac= (v2d->cur.ymax - v2d->tot.ymin) / totsize;
+ fac= (v2d->cur.ymax - v2d->cur.ymin) / totsize;
//if (fac > 1.0f) fac= 1.0f;
scrollers->vert_max= vert.ymin + (fac * scrollsize);
@@ -752,13 +854,13 @@ void UI_view2d_draw_scrollers(const bContext *C, View2D *v2d, View2DScrollers *s
// FIXME: implement fancy one... but only when we get this working first!
{
UI_ThemeColorShade(TH_SHADE1, dark);
- glRecti(scrollers->hor_min, hor.ymin, scrollers->hor_max, hor.ymax);
+ glRecti(scrollers->hor_min, hor.ymin+2, scrollers->hor_max, hor.ymax-2);
/* draw lines on either end of 'box' */
glLineWidth(2.0);
UI_ThemeColorShade(TH_SHADE1, darker);
- sdrawline(scrollers->hor_min, hor.ymin, scrollers->hor_min, hor.ymax);
- sdrawline(scrollers->hor_max, hor.ymin, scrollers->hor_max, hor.ymax);
+ sdrawline(scrollers->hor_min, hor.ymin+2, scrollers->hor_min, hor.ymax-2);
+ sdrawline(scrollers->hor_max, hor.ymin+2, scrollers->hor_max, hor.ymax-2);
glLineWidth(1.0);
}
@@ -844,13 +946,13 @@ void UI_view2d_draw_scrollers(const bContext *C, View2D *v2d, View2DScrollers *s
// FIXME: implement fancy one... but only when we get this working first!
{
UI_ThemeColorShade(TH_SHADE1, dark);
- glRecti(vert.xmin, scrollers->vert_min, vert.xmax, scrollers->vert_max);
+ glRecti(vert.xmin+2, scrollers->vert_min, vert.xmax-2, scrollers->vert_max);
/* draw lines on either end of 'box' */
glLineWidth(2.0);
UI_ThemeColorShade(TH_SHADE1, darker);
- sdrawline(vert.xmin, scrollers->vert_min, vert.xmax, scrollers->vert_min);
- sdrawline(vert.xmin, scrollers->vert_max, vert.xmax, scrollers->vert_max);
+ sdrawline(vert.xmin+2, scrollers->vert_min, vert.xmax-2, scrollers->vert_min);
+ sdrawline(vert.xmin+2, scrollers->vert_max, vert.xmax-2, scrollers->vert_max);
glLineWidth(1.0);
}
diff --git a/source/blender/editors/space_outliner/space_outliner.c b/source/blender/editors/space_outliner/space_outliner.c
index 2518d809d29..b00572cc7b0 100644
--- a/source/blender/editors/space_outliner/space_outliner.c
+++ b/source/blender/editors/space_outliner/space_outliner.c
@@ -346,12 +346,11 @@ static void outliner_main_area_draw(const bContext *C, ARegion *ar)
UI_GetThemeColor3fv(TH_BACK, col);
glClearColor(col[0], col[1], col[2], 0.0);
glClear(GL_COLOR_BUFFER_BIT);
-
- // XXX width should be depend on max length of items (like height)...
+
awidth= width= ar->winrct.xmax - ar->winrct.xmin + 1;
aheight= height= ar->winrct.ymax - ar->winrct.ymin + 1;
- UI_view2d_update_size(v2d, awidth, aheight);
+ UI_view2d_size_update(v2d, awidth, aheight);
/* create table */
cell.space= soutliner;
@@ -397,11 +396,8 @@ static void outliner_main_area_draw(const bContext *C, ARegion *ar)
width= (cols + 1) * COLUMN_WIDTH;
/* need to validate view2d after updating size of tot */
- v2d->tot.xmin= 0;
- v2d->tot.xmax= width;
- v2d->tot.ymax= 0;
- v2d->tot.ymin= -height;
- UI_view2d_enforce_status(v2d, awidth, aheight);
+ UI_view2d_totRect_set(v2d, width, height);
+ UI_view2d_status_enforce(v2d, awidth, aheight);
rct.xmin= 0;
rct.ymin= -height;
diff --git a/source/blender/editors/space_time/space_time.c b/source/blender/editors/space_time/space_time.c
index b4d5986ba69..9e0b06b1e9e 100644
--- a/source/blender/editors/space_time/space_time.c
+++ b/source/blender/editors/space_time/space_time.c
@@ -124,7 +124,7 @@ static void time_main_area_draw(const bContext *C, ARegion *ar)
winx= ar->winrct.xmax - ar->winrct.xmin + 1;
winy= ar->winrct.ymax - ar->winrct.ymin + 1;
- UI_view2d_update_size(v2d, winx, winy);
+ UI_view2d_size_update(v2d, winx, winy);
/* clear and setup matrix */
UI_GetThemeColor3fv(TH_BACK, col);
@@ -146,7 +146,7 @@ static void time_main_area_draw(const bContext *C, ARegion *ar)
time_draw_cfra_time(C, stime, ar);
/* markers */
- UI_view2d_view_orthospecial(C, v2d, 1);
+ UI_view2d_view_orthoSpecial(C, v2d, 1);
draw_markers_time(C, 0);
/* reset view matrix */