View2D: Cleanup of presets and fixed errors in various views

Now, preset view configurations are only to be used if they define all (scrollers not included) relevant settings for the view they are set for. This should be less confusing than in the previous situation with V2D_COMMONVIEW_TIMELINE stuff.

One implication of this though, is that all Animation Editors (for example), will have to define their own version of the relatively commonly shared info. However, given the great diversity in the range of settings each have, this should not be too much of an issue.

Also, added a 'standard' view config for main 'window' regions. At this stage, it is recommended that this view config should be used only as a placeholder template on which a set of custom settings could be based. I've put it into use for the buttons window/scripts window/info window so far.
This commit is contained in:
Joshua Leung 2008-12-17 10:25:02 +00:00
parent c1379f6613
commit 616edcca12
16 changed files with 166 additions and 137 deletions

View File

@ -5196,7 +5196,6 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb)
SpaceButs *sbuts= (SpaceButs *)sl;
memcpy(&ar->v2d, &sbuts->v2d, sizeof(View2D));
ar->v2d.keepzoom |= V2D_KEEPASPECT;
ar->v2d.flag |= V2D_IS_INITIALISED;
break;
}
//case SPACE_XXX: // FIXME... add other ones

View File

@ -40,18 +40,20 @@
/* generic value to use when coordinate lies out of view when converting */
#define V2D_IS_CLIPPED 12000
/* common View2D view types */
/* Common View2D view types
* NOTE: only define a type here if it completely sets all (+/- a few) of the relevant flags
* and settings for a View2D region, and that set of settings is used in more
* than one specific place
*/
enum {
/* custom view type (region has defined all necessary flags already) */
V2D_COMMONVIEW_CUSTOM = 0,
/* view canvas ('standard' view, view limits/restrictions still need to be set first!) */
V2D_COMMONVIEW_VIEWCANVAS,
V2D_COMMONVIEW_CUSTOM = -1,
/* standard (only use this when setting up a new view, as a sensible base for most settings) */
V2D_COMMONVIEW_STANDARD,
/* listview (i.e. Outliner) */
V2D_COMMONVIEW_LIST,
/* headers (this is basically the same as listview, but no y-panning) */
V2D_COMMONVIEW_HEADER,
/* timegrid (this sets the settings for x/horizontal, but y/vertical settings still need to be set first!) */
V2D_COMMONVIEW_TIMELINE,
} eView2D_CommonViewTypes;
/* ---- Defines for Scroller/Grid Arguments ----- */

View File

@ -68,6 +68,88 @@ void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy)
{
short tot_changed= 0;
/* 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;
/* see eView2D_CommonViewTypes in UI_view2d.h for available view presets */
switch (type) {
/* 'standard view' - optimum setup for 'standard' view behaviour, that should be used new views as basis for their
* own unique View2D settings, which should be used instead of this in most cases...
*/
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->minzoom= 0.01f;
v2d->maxzoom= 1000.0f;
/* tot rect and cur should be same size, and aligned using 'standard' OpenGL coordinates for now
* - region can resize 'tot' later to fit other data
* - keeptot is only within bounds, as strict locking is not that critical
* - view is aligned for (0,0) -> (winx-1, winy-1) setup
*/
v2d->align= (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_NEG_Y);
v2d->keeptot= V2D_KEEPTOT_BOUNDS;
v2d->tot.xmin= v2d->tot.ymin= 0.0f;
v2d->tot.xmax= (float)(winx - 1);
v2d->tot.ymax= (float)(winy - 1);
v2d->cur= v2d->tot;
/* scrollers - should we have these by default? */
// XXX for now, we don't override this, or set it either!
}
break;
/* 'list/channel view' - zoom, aspect ratio, and alignment restrictions are set here */
case V2D_COMMONVIEW_LIST:
{
/* zoom + aspect ratio are locked */
v2d->keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_KEEPZOOM|V2D_KEEPASPECT);
v2d->minzoom= v2d->maxzoom= 1.0f;
/* tot rect has strictly regulated placement, and must only occur in +/- quadrant */
v2d->align = (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_POS_Y);
v2d->keeptot = V2D_KEEPTOT_STRICT;
tot_changed= 1;
/* scroller settings are currently not set here... that is left for regions... */
}
break;
/* 'header' regions - zoom, aspect ratio, alignment, and panning restrictions are set here */
case V2D_COMMONVIEW_HEADER:
{
/* zoom + aspect ratio are locked */
v2d->keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_KEEPZOOM|V2D_KEEPASPECT);
v2d->minzoom= v2d->maxzoom= 1.0f;
v2d->min[0]= v2d->max[0]= winx;
v2d->min[1]= v2d->max[1]= winy;
/* tot rect has strictly regulated placement, and must only occur in +/+ quadrant */
v2d->align = (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_NEG_Y);
v2d->keeptot = V2D_KEEPTOT_STRICT;
tot_changed= 1;
/* panning in y-axis is prohibited */
v2d->keepofs= V2D_LOCKOFS_Y;
/* absolutely no scrollers allowed */
v2d->scroll= 0;
}
break;
/* other view types are completely defined using their own settings already */
default:
/* we don't do anything here, as settings should be fine, but just make sure that rect */
break;
}
}
/* store view size */
v2d->winx= winx;
v2d->winy= winy;
@ -124,91 +206,6 @@ void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy)
}
}
/* initialise data if there is a need for such */
if ((v2d->flag & V2D_IS_INITIALISED) == 0) {
v2d->flag |= V2D_IS_INITIALISED;
/* see eView2D_CommonViewTypes in UI_view2d.h for available view presets */
switch (type) {
/* 'standard view' - from (0,0) to (winx,winy), with other restrictions defined by region already */
case V2D_COMMONVIEW_VIEWCANVAS:
{
/* just set 'tot' rect alignment restictions for now */
v2d->align= V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_NEG_Y;
tot_changed= 1;
// XXX... should we set min/max here too? probably not essential yet
}
break;
/* 'list/channel view' - zoom, aspect ratio, and alignment restrictions are set here */
case V2D_COMMONVIEW_LIST:
{
/* zoom + aspect ratio are locked */
v2d->keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_KEEPZOOM|V2D_KEEPASPECT);
v2d->minzoom= v2d->maxzoom= 1.0f;
/* tot rect has strictly regulated placement, and must only occur in +/- quadrant */
v2d->align = (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_POS_Y);
v2d->keeptot = V2D_KEEPTOT_STRICT;
tot_changed= 1;
/* scroller settings are currently not set here... that is left for regions... */
}
break;
/* 'header' regions - zoom, aspect ratio, alignment, and panning restrictions are set here */
case V2D_COMMONVIEW_HEADER:
{
/* zoom + aspect ratio are locked */
v2d->keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_KEEPZOOM|V2D_KEEPASPECT);
v2d->minzoom= v2d->maxzoom= 1.0f;
v2d->min[0]= v2d->max[0]= winx;
v2d->min[1]= v2d->max[1]= winy;
/* tot rect has strictly regulated placement, and must only occur in +/+ quadrant */
v2d->align = (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_NEG_Y);
v2d->keeptot = V2D_KEEPTOT_STRICT;
tot_changed= 1;
/* panning in y-axis is prohibited */
v2d->keepofs= V2D_LOCKOFS_Y;
/* absolutely no scrollers allowed */
v2d->scroll= 0;
}
break;
/* 'timeline/animeditors' - only set x-axis settings (y axis settings have already been set by regions, so don't overwrite! */
case V2D_COMMONVIEW_TIMELINE:
{
/* zoom on x-axis is free, but zoom factors are usually standard */
v2d->minzoom= 0.5f;
v2d->maxzoom= 10.0f;
/* size limits on x-axis are also standard */
v2d->min[0]= 0.0f; // XXX... would 1.0f be better?
v2d->max[0]= MAXFRAMEF;
/* scrollers for x-axis must be shown, and with scales */
v2d->scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
/* 'tot' rect x-axis size */
v2d->tot.xmin= (float)(SFRA - 10);
v2d->tot.xmax= (float)(EFRA + 10);
v2d->cur.xmin= v2d->mask.xmin;
v2d->cur.xmax= v2d->mask.xmax;
tot_changed= 0; // er..
}
break;
/* other view types are completely defined using their own settings already */
default:
/* we don't do anything here, as settings should be fine, but just make sure that rect */
break;
}
}
/* set 'tot' rect before setting cur? */
if (tot_changed)
UI_view2d_totRect_set(v2d, winx, winy);

View File

@ -91,13 +91,23 @@ static SpaceLink *action_new(void)
ar->v2d.tot.xmax= 1000.0f;
ar->v2d.tot.ymax= 0.0f;
ar->v2d.min[1]= 0.0f;
ar->v2d.max[1]= 1000.0f;
ar->v2d.cur.xmin= -5.0f;
ar->v2d.cur.ymin= -75.0f;
ar->v2d.cur.xmax= 65.0f;
ar->v2d.cur.ymax= 5.0f;
ar->v2d.scroll = V2D_SCROLL_RIGHT;
ar->v2d.min[0]= 0.0f;
ar->v2d.min[1]= 0.0f;
ar->v2d.align= saction->v2d.align= V2D_ALIGN_NO_POS_Y;
ar->v2d.keepzoom= saction->v2d.keepzoom= V2D_LOCKZOOM_Y;
ar->v2d.max[0]= MAXFRAMEF;
ar->v2d.max[1]= 1000.0f;
ar->v2d.minzoom= 0.01f;
ar->v2d.maxzoom= 50;
ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
ar->v2d.scroll |= (V2D_SCROLL_RIGHT);
ar->v2d.keepzoom= V2D_LOCKZOOM_Y;
ar->v2d.align= V2D_ALIGN_NO_POS_X;
/* channel list region XXX */
ar= MEM_callocN(sizeof(ARegion), "area region from do_versions");
@ -139,7 +149,7 @@ static void action_main_area_init(wmWindowManager *wm, ARegion *ar)
{
ListBase *keymap;
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_TIMELINE, ar->winx, ar->winy);
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
/* own keymap */
keymap= WM_keymap_listbase(wm, "Action", SPACE_ACTION, 0); /* XXX weak? */

View File

@ -84,27 +84,29 @@ static SpaceLink *buttons_new(void)
BLI_addtail(&sbuts->regionbase, ar);
ar->regiontype= RGN_TYPE_WINDOW;
#if 0 // disabled, as this currently draws badly in new system
/* buts space goes from (0,0) to (1280, 228) */
ar->v2d.tot.xmin= 0.0f;
ar->v2d.tot.ymin= 0.0f;
ar->v2d.tot.xmax= 1279.0f;
ar->v2d.tot.ymax= 228.0f;
sbuts->v2d.tot.xmin= 0.0f;
sbuts->v2d.tot.ymin= 0.0f;
sbuts->v2d.tot.xmax= 1279.0f;
sbuts->v2d.tot.ymax= 228.0f;
ar->v2d.cur= sbuts->v2d.tot;
sbuts->v2d.min[0]= 256.0f;
sbuts->v2d.min[1]= 42.0f;
ar->v2d.min[0]= 256.0f;
ar->v2d.min[1]= 42.0f;
sbuts->v2d.max[0]= 2048.0f;
sbuts->v2d.max[1]= 450.0f;
ar->v2d.max[0]= 2048.0f;
ar->v2d.max[1]= 450.0f;
sbuts->v2d.minzoom= 0.5f;
sbuts->v2d.maxzoom= 1.21f;
ar->v2d.minzoom= 0.5f;
ar->v2d.maxzoom= 1.21f;
sbuts->v2d.scroll= 0; // TODO: will we need scrollbars?
sbuts->v2d.align= V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_NEG_Y;
sbuts->v2d.keepzoom= V2D_KEEPZOOM|V2D_KEEPASPECT;
sbuts->v2d.keeptot= 1;
sbuts->v2d.cur= sbuts->v2d.tot;
ar->v2d.scroll= 0; // TODO: will we need scrollbars?
ar->v2d.align= V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_NEG_Y;
ar->v2d.keepzoom= V2D_KEEPZOOM|V2D_KEEPASPECT;
ar->v2d.keeptot= V2D_KEEPTOT_BOUNDS;
#endif
return (SpaceLink *)sbuts;
@ -146,7 +148,7 @@ static void buttons_main_area_init(wmWindowManager *wm, ARegion *ar)
{
ListBase *keymap;
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy);
/* own keymap */
keymap= WM_keymap_listbase(wm, "Buttons", SPACE_BUTS, 0); /* XXX weak? */

View File

@ -232,6 +232,7 @@ void ED_spacetype_file(void)
/* regions: header */
art= MEM_callocN(sizeof(ARegionType), "spacetype file region");
art->regionid = RGN_TYPE_HEADER;
art->minsizey= HEADERY;
art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
art->init= file_header_area_init;
@ -242,6 +243,7 @@ void ED_spacetype_file(void)
/* regions: channels */
art= MEM_callocN(sizeof(ARegionType), "spacetype file region");
art->regionid = RGN_TYPE_CHANNELS;
art->minsizex= 80;
art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
// art->init= file_channel_area_init;

View File

@ -131,7 +131,7 @@ static void image_main_area_init(wmWindowManager *wm, ARegion *ar)
{
ListBase *keymap;
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_VIEWCANVAS, ar->winx, ar->winy);
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy);
/* own keymap */
keymap= WM_keymap_listbase(wm, "Image", SPACE_IMAGE, 0); /* XXX weak? */

View File

@ -119,7 +119,7 @@ static void info_main_area_init(wmWindowManager *wm, ARegion *ar)
{
ListBase *keymap;
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_VIEWCANVAS, ar->winx, ar->winy);
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy);
/* own keymap */
keymap= WM_keymap_listbase(wm, "info", SPACE_INFO, 0); /* XXX weak? */

View File

@ -104,7 +104,7 @@ static SpaceLink *ipo_new(void)
ar->v2d.min[1]= 0.01f;
ar->v2d.max[0]= MAXFRAMEF;
ar->v2d.max[1]= 10000.0f;
ar->v2d.max[1]= 50000.0f;
ar->v2d.scroll= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
ar->v2d.scroll |= (V2D_SCROLL_LEFT|V2D_SCROLL_SCALE_VERTICAL);
@ -194,7 +194,7 @@ static void ipo_main_area_init(wmWindowManager *wm, ARegion *ar)
{
ListBase *keymap;
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_TIMELINE, ar->winx, ar->winy);
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
/* own keymap */
keymap= WM_keymap_listbase(wm, "Ipo", SPACE_IPO, 0); /* XXX weak? */

View File

@ -113,7 +113,7 @@ static SpaceLink *nla_new(void)
BLI_addtail(&snla->regionbase, ar);
ar->regiontype= RGN_TYPE_CHANNELS;
ar->alignment= RGN_ALIGN_LEFT;
return (SpaceLink *)snla;
}
@ -148,7 +148,7 @@ static void nla_main_area_init(wmWindowManager *wm, ARegion *ar)
{
ListBase *keymap;
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_TIMELINE, ar->winx, ar->winy);
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
/* own keymap */
keymap= WM_keymap_listbase(wm, "NLA", SPACE_NLA, 0); /* XXX weak? */

View File

@ -142,7 +142,7 @@ static void node_main_area_init(wmWindowManager *wm, ARegion *ar)
{
ListBase *keymap;
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_VIEWCANVAS, ar->winx, ar->winy);
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
/* own keymap */
keymap= WM_keymap_listbase(wm, "Node", SPACE_NODE, 0); /* XXX weak? */
@ -154,6 +154,7 @@ static void node_main_area_draw(const bContext *C, ARegion *ar)
/* draw entirely, view changes should be handled here */
// SpaceNode *snode= C->area->spacedata.first;
View2D *v2d= &ar->v2d;
//View2DGrid *grid;
float col[3];
/* clear and setup matrix */
@ -162,7 +163,14 @@ static void node_main_area_draw(const bContext *C, ARegion *ar)
glClear(GL_COLOR_BUFFER_BIT);
UI_view2d_view_ortho(C, v2d);
#if 0
/* grid */
grid= UI_view2d_grid_calc(C, v2d, V2D_UNIT_VALUES, V2D_GRID_CLAMP, V2D_UNIT_VALUES, V2D_GRID_CLAMP, ar->winx, ar->winy);
UI_view2d_grid_draw(C, v2d, grid, V2D_GRIDLINES_ALL);
UI_view2d_grid_free(grid);
#endif
/* data... */

View File

@ -129,7 +129,7 @@ static void script_main_area_init(wmWindowManager *wm, ARegion *ar)
{
ListBase *keymap;
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_VIEWCANVAS, ar->winx, ar->winy);
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy);
/* own keymap */
keymap= WM_keymap_listbase(wm, "Script", SPACE_SCRIPT, 0); /* XXX weak? */

View File

@ -148,7 +148,7 @@ static void sequencer_main_area_init(wmWindowManager *wm, ARegion *ar)
{
ListBase *keymap;
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_TIMELINE, ar->winx, ar->winy);
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
/* own keymap */
keymap= WM_keymap_listbase(wm, "Sequencer", SPACE_SEQ, 0); /* XXX weak? */

View File

@ -144,7 +144,7 @@ static void sound_main_area_init(wmWindowManager *wm, ARegion *ar)
{
ListBase *keymap;
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_TIMELINE, ar->winx, ar->winy);
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
/* own keymap */
keymap= WM_keymap_listbase(wm, "Sound", SPACE_SOUND, 0); /* XXX weak? */

View File

@ -122,7 +122,7 @@ static void text_main_area_init(wmWindowManager *wm, ARegion *ar)
{
ListBase *keymap;
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_VIEWCANVAS, ar->winx, ar->winy);
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy);
/* own keymap */
keymap= WM_keymap_listbase(wm, "Text", SPACE_TEXT, 0); /* XXX weak? */

View File

@ -109,7 +109,7 @@ static void time_main_area_init(wmWindowManager *wm, ARegion *ar)
{
ListBase *keymap;
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_TIMELINE, ar->winx, ar->winy);
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
/* own keymap */
keymap= WM_keymap_listbase(wm, "TimeLine", SPACE_TIME, 0); /* XXX weak? */
@ -227,18 +227,27 @@ static SpaceLink *time_new(void)
BLI_addtail(&stime->regionbase, ar);
ar->regiontype= RGN_TYPE_WINDOW;
/* only need to set y-locks for view2d of main area,
* as the rest is taken care of by View2D preset for TimeGrids
*/
ar->v2d.min[1]= 20.0;
ar->v2d.max[1]= 20.0;
ar->v2d.tot.xmin= (float)(SFRA - 4);
ar->v2d.tot.ymin= 0.0f;
ar->v2d.tot.xmax= (float)(EFRA + 4);
ar->v2d.tot.ymax= 50.0f;
ar->v2d.cur.ymin= ar->v2d.tot.ymin= 0.0f;
ar->v2d.cur.ymax= ar->v2d.tot.ymax= 20.0f;
ar->v2d.cur= ar->v2d.tot;
ar->v2d.min[0]= 1.0f;
ar->v2d.min[1]= 50.0f;
ar->v2d.max[0]= MAXFRAMEF;
ar->v2d.max[1]= 50.0;
ar->v2d.minzoom= 0.1f;
ar->v2d.maxzoom= 10.0;
ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
ar->v2d.align |= V2D_ALIGN_NO_NEG_Y;
ar->v2d.keepofs |= V2D_LOCKOFS_Y;
ar->v2d.keepzoom |= V2D_LOCKZOOM_Y;
ar->v2d.align = V2D_ALIGN_NO_NEG_Y;
ar->v2d.keepofs = V2D_LOCKOFS_Y;
ar->v2d.keepzoom = V2D_LOCKZOOM_Y;
return (SpaceLink*)stime;
}