Fixes in view2d:

- mask/slider rects were calculated wrong 1 pixel (was overlapping)
- found bug with outliner stretching on area-edge-dragging. It required
  an extra mapping of the 'cur view' via mask to actual region.
- added v2d sanity check for uninitialized v2d's
- removed cruft in do_versions for headers (gets catched with above)
- added header-view2d-initialize function, for new-space calls

Fixes in areamanager:

- fixes in 'new space' for time/outliner/view2d
  (unfinished)

For Joshua:

- Making time window higher shows it doesn't update 'cur'. Not sure
  what kind of v2d flag should be checked or set?
This commit is contained in:
Ton Roosendaal 2008-12-12 16:29:33 +00:00
parent 05e5e00bc9
commit 2fa23a0594
8 changed files with 111 additions and 46 deletions

@ -5051,34 +5051,13 @@ static void area_add_header_region(ScrArea *sa, ListBase *lb)
ar->alignment= RGN_ALIGN_TOP;
/* initialise view2d data for header region, to allow panning */
/* is copy from ui_view2d.c */
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;
}
}
/* 2.50 patch */

@ -117,7 +117,7 @@ void UI_view2d_to_region_no_clip(struct View2D *v2d, float x, float y, short *re
struct View2D *UI_view2d_fromcontext(const struct bContext *C);
struct View2D *UI_view2d_fromcontext_rwin(const struct bContext *C);
void UI_view2d_getscale(struct View2D *v2d, float *x, float *y);
void UI_view2d_header_default(struct View2D *v2d);
/* operators */
void ui_view2d_operatortypes(void);

@ -35,6 +35,8 @@
#include "DNA_space_types.h"
#include "DNA_view2d_types.h"
#include "BLI_blenlib.h"
#include "BKE_global.h"
#include "BKE_utildefines.h"
@ -62,10 +64,13 @@
// XXX pre2.5 -> this used to be called calc_scrollrcts()
void UI_view2d_size_update(View2D *v2d, int winx, int winy)
{
v2d->winx= winx;
v2d->winy= winy;
/* mask - view frame */
v2d->mask.xmin= v2d->mask.ymin= 0;
v2d->mask.xmax= winx;
v2d->mask.ymax= winy;
v2d->mask.xmax= winx - 1; /* -1 yes! masks are pixels */
v2d->mask.ymax= winy - 1;
/* scrollbars shrink mask area, but should be based off regionsize
* - they can only be on one edge of the region they define
@ -76,13 +81,13 @@ void UI_view2d_size_update(View2D *v2d, int winx, int winy)
/* on left-hand edge of region */
v2d->vert= v2d->mask;
v2d->vert.xmax= V2D_SCROLL_WIDTH;
v2d->mask.xmin= V2D_SCROLL_WIDTH;
v2d->mask.xmin= v2d->vert.xmax + 1;
}
else if (v2d->scroll & V2D_SCROLL_RIGHT) {
/* on right-hand edge of region */
v2d->vert= v2d->mask;
v2d->vert.xmin= v2d->vert.xmax - V2D_SCROLL_WIDTH;
v2d->mask.xmax= v2d->vert.xmin;
v2d->mask.xmax= v2d->vert.xmin - 1;
}
/* horizontal scrollbar */
@ -90,13 +95,26 @@ void UI_view2d_size_update(View2D *v2d, int winx, int winy)
/* on bottom edge of region (V2D_SCROLL_BOTTOM_O is outliner, the ohter is for standard) */
v2d->hor= v2d->mask;
v2d->hor.ymax= V2D_SCROLL_HEIGHT;
v2d->mask.ymin= V2D_SCROLL_HEIGHT;
v2d->mask.ymin= v2d->hor.ymax + 1;
}
else if (v2d->scroll & V2D_SCROLL_TOP) {
/* on upper edge of region */
v2d->hor= v2d->mask;
v2d->hor.ymin= v2d->hor.ymax - V2D_SCROLL_HEIGHT;
v2d->mask.ymax= v2d->hor.ymin;
v2d->mask.ymax= v2d->hor.ymin - 1;
}
}
/* cope with unitialized veriables for simple cases, like header or outliner */
if(v2d->tot.xmin==v2d->tot.xmax || v2d->cur.xmin==v2d->cur.xmax) {
if(v2d->keepzoom) {
BLI_init_rctf(&v2d->tot, v2d->mask.xmin, v2d->mask.xmax, v2d->mask.ymin, v2d->mask.ymax);
BLI_init_rctf(&v2d->cur, v2d->mask.xmin, v2d->mask.xmax, v2d->mask.ymin, v2d->mask.ymax);
v2d->min[0]= v2d->max[0]= winx;
v2d->min[1]= v2d->max[1]= winy;
v2d->minzoom= 1.0f;
v2d->maxzoom= 1.0f;
}
}
@ -372,6 +390,7 @@ void UI_view2d_curRect_validate(View2D *v2d)
}
}
}
}
/* ------------------ */
@ -476,15 +495,41 @@ void UI_view2d_totRect_set (View2D *v2d, int width, int height)
/* *********************************************************************** */
/* View Matrix Setup */
/* mapping function to ensure 'cur' draws extended over the area were sliders are */
static void view2d_map_cur_using_mask(View2D *v2d, rctf *curmasked)
{
*curmasked= v2d->cur;
if (v2d->scroll) {
float dx= ((float)(v2d->mask.xmax-v2d->mask.xmin+1))/(v2d->cur.xmax-v2d->cur.xmin);
float dy= ((float)(v2d->mask.ymax-v2d->mask.ymin+1))/(v2d->cur.ymax-v2d->cur.ymin);
if (v2d->mask.xmin != 0)
curmasked->xmin -= dx*(float)v2d->mask.xmin;
if (v2d->mask.xmax+1 != v2d->winx)
curmasked->xmax += dx*(float)(v2d->winx - v2d->mask.xmax-1);
if (v2d->mask.ymin != 0)
curmasked->ymin -= dy*(float)v2d->mask.ymin;
if (v2d->mask.ymax+1 != v2d->winy)
curmasked->ymax += dy*(float)(v2d->winy - v2d->mask.ymax-1);
}
}
/* Set view matrices to use 'cur' rect as viewing frame for View2D drawing
* - this assumes viewport/scissor been set for the region, taking scrollbars into account
*/
* - this assumes viewport/scissor been set for the region, taking scrollbars into account
*/
void UI_view2d_view_ortho(const bContext *C, View2D *v2d)
{
rctf curmasked;
/* set the matrix - pixel offsets (-0.375) for 1:1 correspondance are not applied,
* as they were causing some unwanted offsets when drawing
*/
wmOrtho2(C->window, v2d->cur.xmin, v2d->cur.xmax, v2d->cur.ymin, v2d->cur.ymax);
view2d_map_cur_using_mask(v2d, &curmasked);
wmOrtho2(C->window, curmasked.xmin, curmasked.xmax, curmasked.ymin, curmasked.ymax);
/* XXX is this necessary? */
wmLoadIdentity(C->window);
@ -498,14 +543,16 @@ void UI_view2d_view_ortho(const bContext *C, View2D *v2d)
void UI_view2d_view_orthoSpecial(const bContext *C, View2D *v2d, short xaxis)
{
ARegion *ar= C->region;
rctf curmasked;
/* set the matrix - pixel offsets (-0.375) for 1:1 correspondance are not applied,
* as they were causing some unwanted offsets when drawing
*/
view2d_map_cur_using_mask(v2d, &curmasked);
if (xaxis)
wmOrtho2(C->window, v2d->cur.xmin, v2d->cur.xmax, 0, ar->winy);
wmOrtho2(C->window, curmasked.xmin, curmasked.xmax, 0, ar->winy);
else
wmOrtho2(C->window, 0, ar->winx, v2d->cur.ymin, v2d->cur.ymax);
wmOrtho2(C->window, 0, ar->winx, curmasked.ymin, curmasked.ymax);
/* XXX is this necessary? */
wmLoadIdentity(C->window);
@ -518,6 +565,17 @@ void UI_view2d_view_restore(const bContext *C)
ED_region_pixelspace(C, C->region);
}
/* allowing horizontal pan */
void UI_view2d_header_default(View2D *v2d)
{
v2d->keepaspect= 1;
v2d->keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_KEEPZOOM);
v2d->keepofs = V2D_LOCKOFS_Y;
v2d->keeptot = 2; // this keeps the view in place when region size changes...
v2d->align = V2D_ALIGN_NO_NEG_X;
}
/* *********************************************************************** */
/* Gridlines */

@ -229,12 +229,12 @@ static void region_rect_recursive(ARegion *ar, rcti *remainder)
ar->winrct= *remainder;
if(ar->alignment==RGN_ALIGN_TOP) {
ar->winrct.ymin= ar->winrct.ymax - prefsizey;
remainder->ymax= ar->winrct.ymin-1;
ar->winrct.ymin= ar->winrct.ymax - prefsizey + 1;
remainder->ymax= ar->winrct.ymin - 1;
}
else {
ar->winrct.ymax= ar->winrct.ymin + prefsizey;
remainder->ymin= ar->winrct.ymax+1;
ar->winrct.ymax= ar->winrct.ymin + prefsizey - 1;
remainder->ymin= ar->winrct.ymax + 1;
}
}
}
@ -252,12 +252,12 @@ static void region_rect_recursive(ARegion *ar, rcti *remainder)
ar->winrct= *remainder;
if(ar->alignment==RGN_ALIGN_RIGHT) {
ar->winrct.xmin= ar->winrct.xmax - prefsizex;
remainder->xmax= ar->winrct.xmin-1;
ar->winrct.xmin= ar->winrct.xmax - prefsizex + 1;
remainder->xmax= ar->winrct.xmin - 1;
}
else {
ar->winrct.xmax= ar->winrct.xmin + prefsizex;
remainder->xmin= ar->winrct.xmax+1;
ar->winrct.xmax= ar->winrct.xmin + prefsizex - 1;
remainder->xmin= ar->winrct.xmax + 1;
}
}
}
@ -545,8 +545,8 @@ void ED_newspace(ScrArea *sa, int type)
sl->regionbase.first= sl->regionbase.last= NULL;
}
}
}
}
}

@ -480,10 +480,32 @@ static void outliner_header_area_free(ARegion *ar)
static SpaceLink *outliner_new(void)
{
ARegion *ar;
SpaceOops *soutliner;
soutliner= MEM_callocN(sizeof(SpaceOops), "initoutliner");
/* header */
ar= MEM_callocN(sizeof(ARegion), "header for outliner");
BLI_addtail(&soutliner->regionbase, ar);
ar->regiontype= RGN_TYPE_HEADER;
ar->alignment= RGN_ALIGN_BOTTOM;
UI_view2d_header_default(&ar->v2d);
/* main area */
ar= MEM_callocN(sizeof(ARegion), "main area for outliner");
BLI_addtail(&soutliner->regionbase, ar);
ar->regiontype= RGN_TYPE_WINDOW;
ar->v2d.scroll |= V2D_SCROLL_RIGHT;
ar->v2d.align = (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_POS_Y);
ar->v2d.keepzoom |= (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y);
ar->v2d.keepaspect= 1;
ar->v2d.keepzoom= 1;
ar->v2d.keeptot= 2; /* XXX make define */
return (SpaceLink*)soutliner;
}
@ -515,7 +537,7 @@ static SpaceLink *outliner_duplicate(SpaceLink *sl)
return (SpaceLink *)soutlinern;
}
/* only called once, from screen/spacetypes.c */
/* only called once, from space_api/spacetypes.c */
void ED_spacetype_outliner(void)
{
SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype time");

@ -216,6 +216,8 @@ static SpaceLink *time_new(void)
BLI_addtail(&stime->regionbase, ar);
ar->regiontype= RGN_TYPE_HEADER;
ar->alignment= RGN_ALIGN_BOTTOM;
UI_view2d_header_default(&ar->v2d);
/* main area */
ar= MEM_callocN(sizeof(ARegion), "main area for time");
@ -268,7 +270,7 @@ static SpaceLink *time_duplicate(SpaceLink *sl)
return (SpaceLink *)stimen;
}
/* only called once, from screen/spacetypes.c */
/* only called once, from space_api/spacetypes.c */
/* it defines all callbacks to maintain spaces */
void ED_spacetype_time(void)
{

@ -49,6 +49,8 @@
#include "BIF_gl.h"
#include "UI_view2d.h"
#include "view3d_intern.h" // own include
/* ******************** default callbacks for view3d space ***************** */
@ -94,6 +96,8 @@ static SpaceLink *view3d_new(void)
BLI_addtail(&vd->regionbase, ar);
ar->regiontype= RGN_TYPE_HEADER;
ar->alignment= RGN_ALIGN_BOTTOM;
UI_view2d_header_default(&ar->v2d);
/* main area */
ar= MEM_callocN(sizeof(ARegion), "main area for view3d");

@ -53,11 +53,11 @@ typedef struct View2D {
short flag; /* settings */
short align; /* alignment of content in totrect */
short winx, winy; /* storage of current winx/winy values, set in UI_view2d_size_update */
short oldwinx, oldwiny; /* storage of previous winx/winy values encountered by UI_view2d_curRect_validate(), for keepaspect */
short around; /* pivot point for transforms (rotate and scale) */
float cursor[2]; /* only used in the UV view for now (for 2D-cursor) */
char pad[4];
} View2D;
/* ---------------------------------- */