*/
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) {
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;
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 */
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 */
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);
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;
/* 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;
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 */
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;
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;
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;
* 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 */
}
/* 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;
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 */
/* ------------------ */
/* 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);
}
/* 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;
}
/* *********************************************************************** */