diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index fd56709c822..b49ebe3a775 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -5054,7 +5054,36 @@ static void do_versions_windowmanager_2_50(bScreen *screen) ar->alignment= RGN_ALIGN_BOTTOM; else ar->alignment= RGN_ALIGN_TOP; - // TODO: add conversion stuff for header scrolling to v2d of header region + + /* initialise view2d data for header region, to allow panning */ + ar->v2d.keepaspect= 1; + ar->v2d.keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_KEEPZOOM); + ar->v2d.keepofs = V2D_LOCKOFS_Y; + ar->v2d.keeptot = 2; // this keeps the view in place when region size changes... + ar->v2d.align = V2D_ALIGN_NO_NEG_X; + + ar->v2d.minzoom= ar->v2d.maxzoom= 1.0f; + + ar->v2d.mask.xmin= ar->v2d.mask.ymin= 0; + ar->v2d.mask.xmax= sa->winx; + ar->v2d.mask.ymax= HEADERY; + + ar->v2d.cur.xmin= sa->headbutofs; + ar->v2d.cur.xmax= sa->winx + sa->headbutofs; + ar->v2d.tot.xmin= 0.0f; + ar->v2d.tot.xmax= sa->headbutlen; + + if (ar->alignment == RGN_ALIGN_BOTTOM) { + ar->v2d.align = V2D_ALIGN_NO_NEG_Y; + ar->v2d.tot.ymin= ar->v2d.cur.ymin= 0.0f; // what was area->headrct.ymin? + ar->v2d.tot.ymax= ar->v2d.cur.ymax= HEADERY; + } + else { + // XXX what were the extents of the old headers? + ar->v2d.align = V2D_ALIGN_NO_NEG_Y; + ar->v2d.tot.ymin= ar->v2d.cur.ymin= 0.0f; // what was area->headrct.ymin? + ar->v2d.tot.ymax= ar->v2d.cur.ymax= HEADERY; + } } ar= MEM_callocN(sizeof(ARegion), "area region from do_versions"); diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c index c3544f20a15..bdbda0087b0 100644 --- a/source/blender/editors/interface/view2d.c +++ b/source/blender/editors/interface/view2d.c @@ -53,8 +53,8 @@ /* Refresh and Validation */ /* Adjust mask size in response to view size changes - * - When drawing a region, this should be called before - * any other drawing using View2D happens. + * - This should only be called in region init() callbacks, which are + * called when the region is resized or area changes... */ // XXX pre2.5 -> this used to be called calc_scrollrcts() void UI_view2d_size_update(View2D *v2d, int winx, int winy) @@ -96,6 +96,9 @@ void UI_view2d_size_update(View2D *v2d, int winx, int winy) v2d->mask.ymax= v2d->hor.ymin; } } + + /* make sure that 'cur' rect is in a valid state as a result of these changes */ + UI_view2d_curRect_validate(v2d); } /* Ensure View2D rects remain in a viable configuration @@ -104,7 +107,6 @@ void UI_view2d_size_update(View2D *v2d, int winx, int winy) // XXX pre2.5 -> this used to be called test_view2d() void UI_view2d_curRect_validate(View2D *v2d) { - /* cur is not allowed to be larger than max, smaller than min, or outside of tot */ float totwidth, totheight, curwidth, curheight, width, height; float winx, winy; rctf *cur, *tot; @@ -146,17 +148,21 @@ void UI_view2d_curRect_validate(View2D *v2d) float zoom, fac; /* check if excessive zoom on x-axis */ - zoom= winx / width; - if ((zoom < v2d->minzoom) || (zoom > v2d->maxzoom)) { - fac= (zoom < v2d->minzoom) ? (zoom / v2d->minzoom) : (zoom / v2d->maxzoom); - width *= fac; + if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0) { + zoom= winx / width; + if ((zoom < v2d->minzoom) || (zoom > v2d->maxzoom)) { + fac= (zoom < v2d->minzoom) ? (zoom / v2d->minzoom) : (zoom / v2d->maxzoom); + width *= fac; + } } /* check if excessive zoom on y-axis */ - zoom= winy / height; - if ((zoom < v2d->minzoom) || (zoom > v2d->maxzoom)) { - fac= (zoom < v2d->minzoom) ? (zoom / v2d->minzoom) : (zoom / v2d->maxzoom); - height *= fac; + if ((v2d->keepzoom & V2D_LOCKZOOM_Y)==0) { + zoom= winy / height; + if ((zoom < v2d->minzoom) || (zoom > v2d->maxzoom)) { + fac= (zoom < v2d->minzoom) ? (zoom / v2d->minzoom) : (zoom / v2d->maxzoom); + height *= fac; + } } } else { @@ -248,14 +254,14 @@ void UI_view2d_curRect_validate(View2D *v2d) /* Step 3: adjust so that it doesn't fall outside of bounds of tot */ if (v2d->keeptot) { - float temp; + float temp, diff; /* recalculate extents of cur */ curwidth= cur->xmax - cur->xmin; curheight= cur->ymax - cur->ymin; /* width */ - if ((curwidth > totwidth) && (v2d->keepzoom == 0)) { + if ( (curwidth > totwidth) && !(v2d->keepzoom & (V2D_KEEPZOOM|V2D_LOCKZOOM_X)) ) { /* 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; @@ -301,7 +307,15 @@ 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->xmin > tot->xmin) { + if ((cur->ymin < tot->ymin) && (cur->ymax > tot->ymax)) { + /* outside boundaries on both sides, so take middle-point of tot, and place in balanced way */ + temp= (tot->ymax + tot->ymin) * 0.5f; + diff= curheight * 0.5f; + + cur->ymin= temp - diff; + cur->ymax= temp + diff; + } + else if (cur->xmin > tot->xmin) { /* there's still space remaining, so shift left */ temp= cur->xmin - tot->xmin; @@ -318,7 +332,7 @@ void UI_view2d_curRect_validate(View2D *v2d) } /* height */ - if ((curheight > totheight) && (v2d->keepzoom == 0)) { + if ( (curheight > totheight) && !(v2d->keepzoom & (V2D_KEEPZOOM|V2D_LOCKZOOM_Y)) ) { /* 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; @@ -331,7 +345,15 @@ void UI_view2d_curRect_validate(View2D *v2d) * So, resolution is to just shift view by the gap between the extremities. * We favour moving the 'minimum' across, as that's origin for most things */ - if (cur->ymin < tot->ymin) { + if ((cur->ymin < tot->ymin) && (cur->ymax > tot->ymax)) { + /* outside boundaries on both sides, so take middle-point of tot, and place in balanced way */ + temp= (tot->ymax + tot->ymin) * 0.5f; + diff= curheight * 0.5f; + + cur->ymin= temp - diff; + cur->ymax= temp + diff; + } + else if (cur->ymin < tot->ymin) { /* there's still space remaining, so shift up */ temp= tot->ymin - cur->ymin; @@ -460,6 +482,9 @@ void UI_view2d_view_ortho(const bContext *C, View2D *v2d) * as they were causing some unwanted offsets when drawing */ wmOrtho2(C->window, v2d->cur.xmin, v2d->cur.xmax, v2d->cur.ymin, v2d->cur.ymax); + + /* XXX is this necessary? */ + wmLoadIdentity(C->window); } /* Set view matrices to only use one axis of 'cur' only @@ -469,20 +494,18 @@ void UI_view2d_view_ortho(const bContext *C, View2D *v2d) */ void UI_view2d_view_orthoSpecial(const bContext *C, View2D *v2d, short xaxis) { - ARegion *region= C->region; - int winx, winy; - - /* calculate extents of region */ - winx= region->winrct.xmax - region->winrct.xmin + 1; - winy= region->winrct.ymax - region->winrct.ymin + 1; + ARegion *ar= C->region; /* set the matrix - pixel offsets (-0.375) for 1:1 correspondance are not applied, * as they were causing some unwanted offsets when drawing */ if (xaxis) - wmOrtho2(C->window, v2d->cur.xmin, v2d->cur.xmax, 0, winy); + wmOrtho2(C->window, v2d->cur.xmin, v2d->cur.xmax, 0, ar->winy); else - wmOrtho2(C->window, 0, winx, v2d->cur.ymin, v2d->cur.ymax); + wmOrtho2(C->window, 0, ar->winx, v2d->cur.ymin, v2d->cur.ymax); + + /* XXX is this necessary? */ + wmLoadIdentity(C->window); } diff --git a/source/blender/editors/space_time/space_time.c b/source/blender/editors/space_time/space_time.c index 78afe75d013..de7573892aa 100644 --- a/source/blender/editors/space_time/space_time.c +++ b/source/blender/editors/space_time/space_time.c @@ -166,6 +166,12 @@ static void time_main_area_listener(ARegion *ar, wmNotifier *wmn) /* ************************ header time area region *********************** */ +/* add handlers, stuff you only do once or on area/region changes */ +static void time_header_area_init(wmWindowManager *wm, ARegion *ar) +{ + UI_view2d_size_update(&ar->v2d, ar->winx, ar->winy); +} + static void time_header_area_draw(const bContext *C, ARegion *ar) { float col[3]; @@ -178,8 +184,14 @@ static void time_header_area_draw(const bContext *C, ARegion *ar) glClearColor(col[0], col[1], col[2], 0.0); glClear(GL_COLOR_BUFFER_BIT); - + + /* set view2d view matrix for scrolling (without scrollers) */ + UI_view2d_view_ortho(C, &ar->v2d); + time_header_buttons(C, ar); + + /* restore view matrix? */ + UI_view2d_view_restore(C); } static void time_header_area_free(ARegion *ar) @@ -279,8 +291,9 @@ void ED_spacetype_time(void) art= MEM_callocN(sizeof(ARegionType), "spacetype time region"); art->regionid = RGN_TYPE_HEADER; art->minsizey= HEADERY; - art->keymapflag= ED_KEYMAP_UI; + art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D; + art->init= time_header_area_init; art->draw= time_header_area_draw; art->free= time_header_area_free; BLI_addhead(&st->regiontypes, art);