diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-07-30 02:57:53 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-07-30 02:57:53 +0400 |
commit | 408ba429e6aa392f769aac4a442a7a06c1740326 (patch) | |
tree | 63ae81d4fd4799cf3d6e4afd444681c6fc5ea1d3 /source/blender/editors/interface | |
parent | 2df1eeba0e212fe551f2e4cbfe222bd36026670f (diff) |
2.5: Buttons View
* When resizing the window, the top position is now preserved,
instead of the center position.
* Fix zoom level not being preserved in various cases, when
changing both with and height. This replaces some earlier code
which did this at screen level but wasn't very reliable.
* Different tabs now each preserve their own scroll.
* When switching between tabs, it now scrolls to show as many
buttons as possible, instead of possibly showing empty space.
There is a trade-off here between doing that keeping the
buttons in the same place, no ideal solution exists I think.
* Change zooming in/out to be symmetric, for example doing
numpad + then - did not give the original zoom level back.
* Added some calls to avoid hanging tooltips when manipulating
the view.
Internals:
* Added V2D_KEEPOFS_X and V2D_KEEPOFS_Y to keep the top/bottom
rather than the center.
* Renamed V2D_KEEPZOOM to V2D_LIMITZOOM (seems more appropriate),
and make V2D_KEEPZOOM preserve the zoom level.
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r-- | source/blender/editors/interface/view2d.c | 131 | ||||
-rw-r--r-- | source/blender/editors/interface/view2d_ops.c | 52 |
2 files changed, 150 insertions, 33 deletions
diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c index c76110ac440..f9fb7a9306f 100644 --- a/source/blender/editors/interface/view2d.c +++ b/source/blender/editors/interface/view2d.c @@ -154,13 +154,15 @@ static void view2d_masks(View2D *v2d) */ void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy) { - short tot_changed= 0; + short tot_changed= 0, init= 0; uiStyle *style= U.uistyles.first; /* initialise data if there is a need for such */ if ((v2d->flag & V2D_IS_INITIALISED) == 0) { /* set initialised flag so that View2D doesn't get reinitialised next time again */ v2d->flag |= V2D_IS_INITIALISED; + + init= 1; /* see eView2D_CommonViewTypes in UI_view2d.h for available view presets */ switch (type) { @@ -170,7 +172,7 @@ void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy) case V2D_COMMONVIEW_STANDARD: { /* for now, aspect ratio should be maintained, and zoom is clamped within sane default limits */ - v2d->keepzoom= (V2D_KEEPASPECT|V2D_KEEPZOOM); + v2d->keepzoom= (V2D_KEEPASPECT|V2D_LIMITZOOM); v2d->minzoom= 0.01f; v2d->maxzoom= 1000.0f; @@ -197,7 +199,7 @@ void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy) case V2D_COMMONVIEW_LIST: { /* zoom + aspect ratio are locked */ - v2d->keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_KEEPZOOM|V2D_KEEPASPECT); + v2d->keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_LIMITZOOM|V2D_KEEPASPECT); v2d->minzoom= v2d->maxzoom= 1.0f; /* tot rect has strictly regulated placement, and must only occur in +/- quadrant */ @@ -214,7 +216,7 @@ void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy) case V2D_COMMONVIEW_STACK: { /* zoom + aspect ratio are locked */ - v2d->keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_KEEPZOOM|V2D_KEEPASPECT); + v2d->keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_LIMITZOOM|V2D_KEEPASPECT); v2d->minzoom= v2d->maxzoom= 1.0f; /* tot rect has strictly regulated placement, and must only occur in +/+ quadrant */ @@ -230,7 +232,7 @@ void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy) case V2D_COMMONVIEW_HEADER: { /* zoom + aspect ratio are locked */ - v2d->keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_KEEPZOOM|V2D_KEEPASPECT); + v2d->keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_LIMITZOOM|V2D_KEEPASPECT); v2d->minzoom= v2d->maxzoom= 1.0f; v2d->min[0]= v2d->max[0]= (float)(winx-1); v2d->min[1]= v2d->max[1]= (float)(winy-1); @@ -257,9 +259,10 @@ void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy) float panelzoom= (style) ? style->panelzoom : 1.0f; /* for now, aspect ratio should be maintained, and zoom is clamped within sane default limits */ - v2d->keepzoom= (V2D_KEEPASPECT|V2D_KEEPZOOM); + v2d->keepzoom= (V2D_KEEPASPECT|V2D_LIMITZOOM|V2D_KEEPZOOM); v2d->minzoom= 0.5f; v2d->maxzoom= 2.0f; + //tot_changed= 1; v2d->align= (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_POS_Y); v2d->keeptot= V2D_KEEPTOT_BOUNDS; @@ -298,17 +301,16 @@ void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy) /* set 'tot' rect before setting cur? */ if (tot_changed) - UI_view2d_totRect_set(v2d, winx, winy); + UI_view2d_totRect_set_resize(v2d, winx, winy, !init); else - UI_view2d_curRect_validate(v2d); - + UI_view2d_curRect_validate_resize(v2d, !init); } /* Ensure View2D rects remain in a viable configuration * - 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() -void UI_view2d_curRect_validate(View2D *v2d) +void UI_view2d_curRect_validate_resize(View2D *v2d, int resize) { float totwidth, totheight, curwidth, curheight, width, height; float winx, winy; @@ -351,10 +353,30 @@ void UI_view2d_curRect_validate(View2D *v2d) if(winx<1) winx= 1; if(winy<1) winy= 1; - /* keepzoom (V2D_KEEPZOOM set), indicates that zoom level on each axis must not exceed limits + /* V2D_LIMITZOOM indicates that zoom level should be preserved when the window size changes */ + if (resize && (v2d->keepzoom & V2D_KEEPZOOM)) { + float zoom, oldzoom; + + if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0) { + zoom= winx / width; + oldzoom= v2d->oldwinx / curwidth; + + if(oldzoom != zoom) + width *= zoom/oldzoom; + } + + if ((v2d->keepzoom & V2D_LOCKZOOM_Y)==0) { + zoom= winy / height; + oldzoom= v2d->oldwiny / curheight; + + if(oldzoom != zoom) + height *= zoom/oldzoom; + } + } + /* keepzoom (V2D_LIMITZOOM set), indicates that zoom level on each axis must not exceed limits * NOTE: in general, it is not expected that the lock-zoom will be used in conjunction with this */ - if (v2d->keepzoom & V2D_KEEPZOOM) { + else if (v2d->keepzoom & V2D_LIMITZOOM) { float zoom, fac; /* check if excessive zoom on x-axis */ @@ -460,11 +482,17 @@ void UI_view2d_curRect_validate(View2D *v2d) if ((width != curwidth) || (height != curheight)) { float temp, dh; - /* resize from centerpoint */ + /* resize from centerpoint, unless otherwise specified */ if (width != curwidth) { if (v2d->keepofs & V2D_LOCKOFS_X) { cur->xmax += width - (cur->xmax - cur->xmin); } + else if (v2d->keepofs & V2D_KEEPOFS_X) { + if(v2d->align & V2D_ALIGN_NO_POS_X) + cur->xmin -= width - (cur->xmax - cur->xmin); + else + cur->xmax += width - (cur->xmax - cur->xmin); + } else { temp= (cur->xmax + cur->xmin) * 0.5f; dh= width * 0.5f; @@ -477,6 +505,12 @@ void UI_view2d_curRect_validate(View2D *v2d) if (v2d->keepofs & V2D_LOCKOFS_Y) { cur->ymax += height - (cur->ymax - cur->ymin); } + else if (v2d->keepofs & V2D_KEEPOFS_Y) { + if(v2d->align & V2D_ALIGN_NO_POS_Y) + cur->ymin -= height - (cur->ymax - cur->ymin); + else + cur->ymax += height - (cur->ymax - cur->ymin); + } else { temp= (cur->ymax + cur->ymin) * 0.5f; dh= height * 0.5f; @@ -496,7 +530,7 @@ void UI_view2d_curRect_validate(View2D *v2d) curheight= cur->ymax - cur->ymin; /* width */ - if ( (curwidth > totwidth) && !(v2d->keepzoom & (V2D_KEEPZOOM|V2D_LOCKZOOM_X)) ) { + if ( (curwidth > totwidth) && !(v2d->keepzoom & (V2D_KEEPZOOM|V2D_LOCKZOOM_X|V2D_LIMITZOOM)) ) { /* if zoom doesn't have to be maintained, just clamp edges */ if (cur->xmin < tot->xmin) cur->xmin= tot->xmin; if (cur->xmax > tot->xmax) cur->xmax= tot->xmax; @@ -542,13 +576,13 @@ void UI_view2d_curRect_validate(View2D *v2d) * We favour moving the 'minimum' across, as that's origin for most things * (XXX - in the past, max was favoured... if there are bugs, swap!) */ - if ((cur->ymin < tot->ymin) && (cur->ymax > tot->ymax)) { + if ((cur->xmin < tot->xmin) && (cur->xmax > tot->xmax)) { /* outside boundaries on both sides, so take middle-point of tot, and place in balanced way */ - temp= (tot->ymax + tot->ymin) * 0.5f; + temp= (tot->xmax + tot->xmin) * 0.5f; diff= curheight * 0.5f; - cur->ymin= temp - diff; - cur->ymax= temp + diff; + cur->xmin= temp - diff; + cur->xmax= temp + diff; } else if (cur->xmin < tot->xmin) { /* move cur across so that it sits at minimum of tot */ @@ -579,7 +613,7 @@ void UI_view2d_curRect_validate(View2D *v2d) } /* height */ - if ( (curheight > totheight) && !(v2d->keepzoom & (V2D_KEEPZOOM|V2D_LOCKZOOM_Y)) ) { + if ( (curheight > totheight) && !(v2d->keepzoom & (V2D_KEEPZOOM|V2D_LOCKZOOM_Y|V2D_LIMITZOOM)) ) { /* if zoom doesn't have to be maintained, just clamp edges */ if (cur->ymin < tot->ymin) cur->ymin= tot->ymin; if (cur->ymax > tot->ymax) cur->ymax= tot->ymax; @@ -664,6 +698,11 @@ void UI_view2d_curRect_validate(View2D *v2d) view2d_masks(v2d); } +void UI_view2d_curRect_validate(View2D *v2d) +{ + return UI_view2d_curRect_validate_resize(v2d, 0); +} + /* ------------------ */ /* Called by menus to activate it, or by view2d operators to make sure 'related' views stay in synchrony */ @@ -783,7 +822,7 @@ void UI_view2d_curRect_reset (View2D *v2d) /* ------------------ */ /* Change the size of the maximum viewable area (i.e. 'tot' rect) */ -void UI_view2d_totRect_set (View2D *v2d, int width, int height) +void UI_view2d_totRect_set_resize (View2D *v2d, int width, int height, int resize) { int scroll= view2d_scroll_mapped(v2d->scroll); @@ -841,7 +880,57 @@ void UI_view2d_totRect_set (View2D *v2d, int width, int height) } /* make sure that 'cur' rect is in a valid state as a result of these changes */ - UI_view2d_curRect_validate(v2d); + UI_view2d_curRect_validate_resize(v2d, resize); +} + +void UI_view2d_totRect_set(View2D *v2d, int width, int height) +{ + UI_view2d_totRect_set_resize(v2d, width, height, 0); +} + +int UI_view2d_tab_set(View2D *v2d, int tab) +{ + float default_offset[2]= {0.0f, 0.0f}; + float *offset, *new_offset; + int changed= 0; + + /* if tab changed, change offset */ + if(tab != v2d->tab_cur && v2d->tab_offset) { + if(tab < v2d->tab_num) + offset= &v2d->tab_offset[tab*2]; + else + offset= default_offset; + + v2d->cur.xmax += offset[0] - v2d->cur.xmin; + v2d->cur.xmin= offset[0]; + + v2d->cur.ymin += offset[1] - v2d->cur.ymax; + v2d->cur.ymax= offset[1]; + + /* validation should happen in subsequent totRect_set */ + + changed= 1; + } + + /* resize array if needed */ + if(tab >= v2d->tab_num) { + new_offset= MEM_callocN(sizeof(float)*(tab+1)*2, "view2d tab offset"); + + if(v2d->tab_offset) { + memcpy(new_offset, v2d->tab_offset, sizeof(float)*v2d->tab_num*2); + MEM_freeN(v2d->tab_offset); + } + + v2d->tab_offset= new_offset; + v2d->tab_num= tab+1; + } + + /* set current tab and offset */ + v2d->tab_cur= tab; + v2d->tab_offset[2*tab+0]= v2d->cur.xmin; + v2d->tab_offset[2*tab+1]= v2d->cur.ymax; + + return changed; } /* *********************************************************************** */ diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c index ee2a50d12a9..1e8cda68e6d 100644 --- a/source/blender/editors/interface/view2d_ops.c +++ b/source/blender/editors/interface/view2d_ops.c @@ -151,6 +151,7 @@ static void view_pan_apply(bContext *C, wmOperator *op) /* request updates to be done... */ ED_area_tag_redraw(vpd->sa); UI_view2d_sync(vpd->sc, vpd->sa, v2d, V2D_LOCK_COPY); + WM_event_add_mousemove(C); /* exceptions */ if(vpd->sa->spacetype==SPACE_OUTLINER) { @@ -493,17 +494,33 @@ static void view_zoomstep_apply(bContext *C, wmOperator *op) { ARegion *ar= CTX_wm_region(C); View2D *v2d= &ar->v2d; - float dx, dy; - - /* calculate amount to move view by */ - dx= (v2d->cur.xmax - v2d->cur.xmin) * (float)RNA_float_get(op->ptr, "zoomfacx"); - dy= (v2d->cur.ymax - v2d->cur.ymin) * (float)RNA_float_get(op->ptr, "zoomfacy"); + float dx, dy, facx, facy; + /* calculate amount to move view by, ensuring symmetry so the + * old zoom level is restored after zooming back the same amount */ + facx= RNA_float_get(op->ptr, "zoomfacx"); + facy= RNA_float_get(op->ptr, "zoomfacy"); + + if(facx >= 0.0f) { + dx= (v2d->cur.xmax - v2d->cur.xmin) * facx; + dy= (v2d->cur.ymax - v2d->cur.ymin) * facy; + } + else { + dx= ((v2d->cur.xmax - v2d->cur.xmin)/(1.0f + 2.0f*facx)) * facx; + dy= ((v2d->cur.ymax - v2d->cur.ymin)/(1.0f + 2.0f*facy)) * facy; + } + /* only resize view on an axis if change is allowed */ if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0) { if (v2d->keepofs & V2D_LOCKOFS_X) { v2d->cur.xmax -= 2*dx; } + else if (v2d->keepofs & V2D_KEEPOFS_X) { + if(v2d->align & V2D_ALIGN_NO_POS_X) + v2d->cur.xmin += 2*dx; + else + v2d->cur.xmax -= 2*dx; + } else { v2d->cur.xmin += dx; v2d->cur.xmax -= dx; @@ -513,18 +530,25 @@ static void view_zoomstep_apply(bContext *C, wmOperator *op) if (v2d->keepofs & V2D_LOCKOFS_Y) { v2d->cur.ymax -= 2*dy; } + else if (v2d->keepofs & V2D_KEEPOFS_Y) { + if(v2d->align & V2D_ALIGN_NO_POS_Y) + v2d->cur.ymin += 2*dy; + else + v2d->cur.ymax -= 2*dy; + } else { v2d->cur.ymin += dy; v2d->cur.ymax -= dy; } } - + /* validate that view is in valid configuration after this operation */ UI_view2d_curRect_validate(v2d); - + /* request updates to be done... */ ED_area_tag_redraw(CTX_wm_area(C)); UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY); + WM_event_add_mousemove(C); } /* --------------- Individual Operators ------------------- */ @@ -681,6 +705,7 @@ static void view_zoomdrag_apply(bContext *C, wmOperator *op) /* request updates to be done... */ ED_area_tag_redraw(CTX_wm_area(C)); UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY); + WM_event_add_mousemove(C); } /* cleanup temp customdata */ @@ -922,6 +947,7 @@ static int view_borderzoom_exec(bContext *C, wmOperator *op) /* request updates to be done... */ ED_area_tag_redraw(CTX_wm_area(C)); UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY); + WM_event_add_mousemove(C); return OPERATOR_FINISHED; } @@ -1162,6 +1188,7 @@ static void scroller_activate_apply(bContext *C, wmOperator *op) /* request updates to be done... */ ED_area_tag_redraw(CTX_wm_area(C)); UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY); + WM_event_add_mousemove(C); } /* handle user input for scrollers - calculations of mouse-movement need to be done here, not in the apply callback! */ @@ -1301,20 +1328,20 @@ static int reset_exec(bContext *C, wmOperator *op) /* 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)) { v2d->cur.xmax= 0.0f; - v2d->cur.xmin= v2d->winx*style->panelzoom; + v2d->cur.xmin= -winx*style->panelzoom; } else if ((v2d->align & V2D_ALIGN_NO_NEG_X) && !(v2d->align & V2D_ALIGN_NO_POS_X)) { - v2d->cur.xmax= (v2d->cur.xmax - v2d->cur.xmin)*style->panelzoom; + v2d->cur.xmax= winx*style->panelzoom; v2d->cur.xmin= 0.0f; } /* - 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)) { v2d->cur.ymax= 0.0f; - v2d->cur.ymin= -v2d->winy*style->panelzoom; + v2d->cur.ymin= -winy*style->panelzoom; } else if ((v2d->align & V2D_ALIGN_NO_NEG_Y) && !(v2d->align & V2D_ALIGN_NO_POS_Y)) { - v2d->cur.ymax= (v2d->cur.ymax - v2d->cur.ymin)*style->panelzoom; + v2d->cur.ymax= winy*style->panelzoom; v2d->cur.ymin= 0.0f; } } @@ -1325,6 +1352,7 @@ static int reset_exec(bContext *C, wmOperator *op) /* request updates to be done... */ ED_area_tag_redraw(CTX_wm_area(C)); UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY); + WM_event_add_mousemove(C); return OPERATOR_FINISHED; } @@ -1340,7 +1368,7 @@ void VIEW2D_OT_reset(wmOperatorType *ot) ot->poll= view2d_poll; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + // ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } /* ********************************************************* */ |