diff options
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 2 | ||||
-rw-r--r-- | source/blender/editors/include/UI_view2d.h | 15 | ||||
-rw-r--r-- | source/blender/editors/interface/view2d.c | 146 | ||||
-rw-r--r-- | source/blender/editors/space_outliner/space_outliner.c | 12 | ||||
-rw-r--r-- | source/blender/editors/space_time/space_time.c | 4 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_view2d_types.h | 62 |
6 files changed, 178 insertions, 63 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 89fe51b0069..c79e7ea53ca 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -5076,6 +5076,7 @@ static void do_versions_windowmanager_2_50(bScreen *screen) memcpy(&ar->v2d, &soops->v2d, sizeof(View2D)); ar->v2d.scroll &= ~V2D_SCROLL_LEFT; ar->v2d.scroll |= V2D_SCROLL_RIGHT; + ar->v2d.align = (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_POS_Y); } break; case SPACE_TIME: @@ -5084,6 +5085,7 @@ static void do_versions_windowmanager_2_50(bScreen *screen) memcpy(&ar->v2d, &stime->v2d, sizeof(View2D)); ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_BOTTOM); + ar->v2d.align |= V2D_ALIGN_NO_NEG_Y; ar->v2d.keepofs |= V2D_LOCKOFS_Y; } break; 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 */ diff --git a/source/blender/makesdna/DNA_view2d_types.h b/source/blender/makesdna/DNA_view2d_types.h index b2086533b30..9af50f7dd60 100644 --- a/source/blender/makesdna/DNA_view2d_types.h +++ b/source/blender/makesdna/DNA_view2d_types.h @@ -50,56 +50,66 @@ typedef struct View2D { short keepofs; /* keepofs - axes that translation is not allowed to occur on */ short flag; /* settings */ + short align; /* alignment of content in totrect */ short oldwinx, oldwiny; /* storage of previous winx/winy values encountered by UI_view2d_enforce_status(), for keepaspect */ - float cursor[2]; /* only used in the UV view for now (for 2D-cursor) */ short around; /* pivot point for transforms (rotate and scale) */ - char pad[6]; + float cursor[2]; /* only used in the UV view for now (for 2D-cursor) */ + char pad[4]; } View2D; /* ---------------------------------- */ -/* v2d->keepzoom */ -#define V2D_KEEPZOOM 0x0001 -#define V2D_LOCKZOOM_X 0x0100 -#define V2D_LOCKZOOM_Y 0x0200 +/* view zooming restrictions, per axis (v2d->keepzoom) */ +#define V2D_LOCKZOOM_X 0x0100 +#define V2D_LOCKZOOM_Y 0x0200 -/* v2d->keepofs */ +/* view panning restrictions, per axis (v2d->keepofs) */ #define V2D_LOCKOFS_X (1<<1) #define V2D_LOCKOFS_Y (1<<2) -/* event codes for locking function */ -#define V2D_LOCK_COPY 1 -#define V2D_LOCK_REDRAW 2 - -/* v2d->flag */ -#define V2D_VIEWLOCK (1<<0) +/* general refresh settings (v2d->flag) */ + /* global view2d horizontal locking (for showing same time interval) */ +#define V2D_VIEWSYNC_X (1<<0) + /* within region view2d vertical locking */ +#define V2D_VIEWSYNC_Y (1<<1) /* scrollbar thickness */ #define V2D_SCROLL_HEIGHT 16 #define V2D_SCROLL_WIDTH 16 -/* scrollbar flags for View2D */ +/* scrollbar flags for View2D (v2d->scroll) */ /* left scrollbar */ -#define V2D_SCROLL_LEFT (1<<0) -#define V2D_SCROLL_RIGHT (1<<1) -#define V2D_SCROLL_VERTICAL (V2D_SCROLL_LEFT|V2D_SCROLL_RIGHT) +#define V2D_SCROLL_LEFT (1<<0) +#define V2D_SCROLL_RIGHT (1<<1) +#define V2D_SCROLL_VERTICAL (V2D_SCROLL_LEFT|V2D_SCROLL_RIGHT) /* horizontal scrollbar */ -#define V2D_SCROLL_TOP (1<<2) -#define V2D_SCROLL_BOTTOM (1<<3) -#define V2D_SCROLL_HORIZONTAL (V2D_SCROLL_TOP|V2D_SCROLL_BOTTOM) +#define V2D_SCROLL_TOP (1<<2) +#define V2D_SCROLL_BOTTOM (1<<3) +#define V2D_SCROLL_HORIZONTAL (V2D_SCROLL_TOP|V2D_SCROLL_BOTTOM) /* special hacks for outliner hscroll - prevent hanging older versions of Blender */ -#define V2D_SCROLL_BOTTOM_O (1<<4) -#define V2D_SCROLL_HORIZONTAL_O (V2D_SCROLL_BOTTOM|V2D_SCROLL_BOTTOM_O) +#define V2D_SCROLL_BOTTOM_O (1<<4) +#define V2D_SCROLL_HORIZONTAL_O (V2D_SCROLL_TOP|V2D_SCROLL_BOTTOM_O) /* scale markings - vertical */ -#define V2D_SCROLL_SCALE_LEFT (1<<5) -#define V2D_SCROLL_SCALE_RIGHT (1<<6) +#define V2D_SCROLL_SCALE_LEFT (1<<5) +#define V2D_SCROLL_SCALE_RIGHT (1<<6) #define V2D_SCROLL_SCALE_VERTICAL (V2D_SCROLL_SCALE_LEFT|V2D_SCROLL_SCALE_RIGHT) /* scale markings - horizontal */ -#define V2D_SCROLL_SCALE_BOTTOM (1<<7) -#define V2D_SCROLL_SCALE_TOP (1<<8) +#define V2D_SCROLL_SCALE_BOTTOM (1<<7) +#define V2D_SCROLL_SCALE_TOP (1<<8) #define V2D_SCROLL_SCALE_HORIZONTAL (V2D_SCROLL_SCALE_BOTTOM|V2D_SCROLL_SCALE_TOP) +/* alignment flags for totrect, flags use 'shading-out' convention (v2d->align) */ + /* all quadrants free */ +#define V2D_ALIGN_FREE 0 + /* horizontal restrictions */ +#define V2D_ALIGN_NO_POS_X (1<<0) +#define V2D_ALIGN_NO_NEG_X (1<<1) + /* vertical restrictions */ +#define V2D_ALIGN_NO_POS_Y (1<<2) +#define V2D_ALIGN_NO_NEG_Y (1<<3) + + #endif |