* Grid calculation now takes separate args for x/y units and clamping
* Timeline now gets V2D_LOCKZOOM_Y flag to prevent zooming in y-axis
This commit is contained in:
2008-12-13 09:25:47 +00:00
parent 9f06ed1b36
commit 4de30b2304
5 changed files with 62 additions and 52 deletions

View File

@@ -5114,8 +5114,7 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb)
ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_BOTTOM);
ar->v2d.align |= V2D_ALIGN_NO_NEG_Y;
ar->v2d.keepofs |= V2D_LOCKOFS_Y;
/* XXX hrmf, force Y zoom to be fixed? */
ar->v2d.keepzoom |= V2D_LOCKZOOM_Y;
ar->v2d.min[1]= ar->v2d.max[1]= 500.0;
}
break;
@@ -5124,7 +5123,7 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb)
SpaceIpo *sipo= (SpaceIpo *)sl;
memcpy(&ar->v2d, &sipo->v2d, sizeof(View2D));
ar->v2d.scroll= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_BOTTOM);
ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_BOTTOM);
ar->v2d.scroll |= (V2D_SCROLL_LEFT|V2D_SCROLL_SCALE_LEFT);
}

View File

@@ -103,7 +103,7 @@ void UI_view2d_view_orthoSpecial(const struct bContext *C, struct View2D *v2d, s
void UI_view2d_view_restore(const struct bContext *C);
/* grid drawing */
View2DGrid *UI_view2d_grid_calc(const struct bContext *C, struct View2D *v2d, short unit, short clamp, int winx, int winy);
View2DGrid *UI_view2d_grid_calc(const struct bContext *C, struct View2D *v2d, short xunits, short xclamp, short yunits, short yclamp, int winx, int winy);
void UI_view2d_grid_draw(const struct bContext *C, struct View2D *v2d, View2DGrid *grid, int flag);
void UI_view2d_grid_free(View2DGrid *grid);

View File

@@ -640,23 +640,29 @@ static void step_to_grid(float *step, int *power, int unit)
* - Currently, will return pointer to View2DGrid struct that needs to
* be freed with UI_view2d_grid_free()
* - Is used for scrollbar drawing too (for units drawing)
* - Units + clamping args will be checked, to make sure they are valid values that can be used
* so it is very possible that we won't return grid at all!
*
* - unit = V2D_UNIT_* grid steps in seconds or frames
* - clamp = V2D_CLAMP_* only show whole-number intervals
* - winx = width of region we're drawing to
* - winy = height of region we're drawing into
* - xunits,yunits = V2D_UNIT_* grid steps in seconds or frames
* - xclamp,yclamp = V2D_CLAMP_* only show whole-number intervals
* - winx = width of region we're drawing to
* - winy = height of region we're drawing into
*/
View2DGrid *UI_view2d_grid_calc(const bContext *C, View2D *v2d, short unit, short clamp, int winx, int winy)
View2DGrid *UI_view2d_grid_calc(const bContext *C, View2D *v2d, short xunits, short xclamp, short yunits, short yclamp, int winx, int winy)
{
View2DGrid *grid;
float space, pixels, seconddiv;
int secondgrid;
/* check that there are at least some workable args */
if (ELEM(V2D_ARG_DUMMY, xunits, xclamp) && ELEM(V2D_ARG_DUMMY, yunits, yclamp))
return NULL;
/* grid here is allocated... */
grid= MEM_callocN(sizeof(View2DGrid), "View2DGrid");
/* rule: gridstep is minimal GRIDSTEP pixels */
if (unit == V2D_UNIT_SECONDS) {
if (xunits == V2D_UNIT_SECONDS) {
secondgrid= 1;
seconddiv= 0.01f * FPS;
}
@@ -665,39 +671,46 @@ View2DGrid *UI_view2d_grid_calc(const bContext *C, View2D *v2d, short unit, shor
seconddiv= 1.0f;
}
/* calculate x-axis grid scale */
space= v2d->cur.xmax - v2d->cur.xmin;
pixels= v2d->mask.xmax - v2d->mask.xmin;
grid->dx= (MINGRIDSTEP * space) / (seconddiv * pixels);
step_to_grid(&grid->dx, &grid->powerx, unit);
grid->dx *= seconddiv;
if (clamp == V2D_GRID_CLAMP) {
if (grid->dx < 0.1f) grid->dx= 0.1f;
grid->powerx-= 2;
if (grid->powerx < -2) grid->powerx= -2;
/* calculate x-axis grid scale (only if both args are valid) */
if (ELEM(V2D_ARG_DUMMY, xunits, xclamp) == 0) {
space= v2d->cur.xmax - v2d->cur.xmin;
pixels= v2d->mask.xmax - v2d->mask.xmin;
grid->dx= (MINGRIDSTEP * space) / (seconddiv * pixels);
step_to_grid(&grid->dx, &grid->powerx, xunits);
grid->dx *= seconddiv;
if (xclamp == V2D_GRID_CLAMP) {
if (grid->dx < 0.1f) grid->dx= 0.1f;
grid->powerx-= 2;
if (grid->powerx < -2) grid->powerx= -2;
}
}
/* calculate y-axis grid scale */
space= v2d->cur.ymax - v2d->cur.ymin;
pixels= winy;
grid->dy= MINGRIDSTEP * space / pixels;
step_to_grid(&grid->dy, &grid->powery, unit);
if (clamp == V2D_GRID_CLAMP) {
if (grid->dy < 1.0f) grid->dy= 1.0f;
if (grid->powery < 1) grid->powery= 1;
/* calculate y-axis grid scale (only if both args are valid) */
if (ELEM(V2D_ARG_DUMMY, yunits, yclamp) == 0) {
space= v2d->cur.ymax - v2d->cur.ymin;
pixels= winy;
grid->dy= MINGRIDSTEP * space / pixels;
step_to_grid(&grid->dy, &grid->powery, yunits);
if (yclamp == V2D_GRID_CLAMP) {
if (grid->dy < 1.0f) grid->dy= 1.0f;
if (grid->powery < 1) grid->powery= 1;
}
}
/* calculate start position */
grid->startx= seconddiv*(v2d->cur.xmin/seconddiv - fmod(v2d->cur.xmin/seconddiv, grid->dx/seconddiv));
if (v2d->cur.xmin < 0.0f) grid->startx-= grid->dx;
if (ELEM(V2D_ARG_DUMMY, xunits, xclamp) == 0) {
grid->startx= seconddiv*(v2d->cur.xmin/seconddiv - fmod(v2d->cur.xmin/seconddiv, grid->dx/seconddiv));
if (v2d->cur.xmin < 0.0f) grid->startx-= grid->dx;
}
if (ELEM(V2D_ARG_DUMMY, yunits, yclamp) == 0) {
grid->starty= (v2d->cur.ymin - fmod(v2d->cur.ymin, grid->dy));
if (v2d->cur.ymin < 0.0f) grid->starty-= grid->dy;
}
grid->starty= (v2d->cur.ymin - fmod(v2d->cur.ymin, grid->dy));
if (v2d->cur.ymin < 0.0f) grid->starty-= grid->dy;
return grid;
}
@@ -707,6 +720,10 @@ void UI_view2d_grid_draw(const bContext *C, View2D *v2d, View2DGrid *grid, int f
float vec1[2], vec2[2];
int a, step;
/* check for grid first, as it may not exist */
if (grid == NULL)
return;
/* vertical lines */
if (flag & V2D_VERTICAL_LINES) {
/* initialise initial settings */
@@ -809,7 +826,9 @@ void UI_view2d_grid_draw(const bContext *C, View2D *v2d, View2DGrid *grid, int f
/* free temporary memory used for drawing grid */
void UI_view2d_grid_free(View2DGrid *grid)
{
MEM_freeN(grid);
/* only free if there's a grid */
if (grid)
MEM_freeN(grid);
}
/* *********************************************************************** */
@@ -888,15 +907,7 @@ View2DScrollers *UI_view2d_scrollers_calc(const bContext *C, View2D *v2d, short
scrollers->yclamp= yclamp;
scrollers->yunits= yunits;
/* calculate grid only if clamping + units are valid arguments */
if ( !((xclamp == V2D_ARG_DUMMY) && (xunits == V2D_ARG_DUMMY) && (yclamp == V2D_ARG_DUMMY) && (yunits == V2D_ARG_DUMMY)) ) {
/* if both axes show scale, give priority to horizontal.. */
// FIXME: this doesn't do justice to the vertical scroller calculations...
if ((v2d->scroll & V2D_SCROLL_SCALE_HORIZONTAL) && ELEM(V2D_ARG_DUMMY, xclamp, xunits)==0)
scrollers->grid= UI_view2d_grid_calc(C, v2d, xunits, xclamp, (hor.xmax - hor.xmin), (vert.ymax - vert.ymin));
else if (v2d->scroll & V2D_SCROLL_SCALE_VERTICAL && ELEM(V2D_ARG_DUMMY, yclamp, yunits)==0)
scrollers->grid= UI_view2d_grid_calc(C, v2d, yunits, yclamp, (hor.xmax - hor.xmin), (vert.ymax - vert.ymin));
}
scrollers->grid= UI_view2d_grid_calc(C, v2d, xunits, xclamp, yunits, yclamp, (hor.xmax - hor.xmin), (vert.ymax - vert.ymin));
}
/* return scrollers */
@@ -1074,7 +1085,7 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v
/* scale indicators */
// XXX will need to update the font drawing when the new stuff comes in
if (v2d->scroll & V2D_SCROLL_SCALE_HORIZONTAL) {
if ((v2d->scroll & V2D_SCROLL_SCALE_HORIZONTAL) && (vs->grid)) {
View2DGrid *grid= vs->grid;
float fac, dfac, fac2, val;
@@ -1082,7 +1093,7 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v
* - fac is x-coordinate to draw to
* - dfac is gap between scale markings
*/
fac= (grid->startx- v2d->cur.xmin) / (v2d->cur.xmax - v2d->cur.xmin);
fac= (grid->startx - v2d->cur.xmin) / (v2d->cur.xmax - v2d->cur.xmin);
fac= hor.xmin + fac*(hor.xmax - hor.xmin);
dfac= (grid->dx) / (v2d->cur.xmax - v2d->cur.xmin);
@@ -1193,7 +1204,7 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v
/* scale indiators */
// XXX will need to update the font drawing when the new stuff comes in
if (v2d->scroll & V2D_SCROLL_SCALE_VERTICAL) {
if ((v2d->scroll & V2D_SCROLL_SCALE_VERTICAL) && (vs->grid)) {
View2DGrid *grid= vs->grid;
float fac, dfac, val;

View File

@@ -222,7 +222,7 @@ static void ipo_main_area_draw(const bContext *C, ARegion *ar)
/* grid */
unit= (sipo->flag & SIPO_DRAWTIME)? V2D_UNIT_SECONDS : V2D_UNIT_FRAMES;
grid= UI_view2d_grid_calc(C, v2d, unit, V2D_GRID_NOCLAMP, ar->winx, ar->winy);
grid= UI_view2d_grid_calc(C, v2d, unit, V2D_GRID_NOCLAMP, V2D_UNIT_VALUES/*unit-y*/, V2D_GRID_NOCLAMP, ar->winx, ar->winy);
UI_view2d_grid_draw(C, v2d, grid, V2D_GRIDLINES_ALL);
UI_view2d_grid_free(grid);

View File

@@ -139,7 +139,7 @@ static void time_main_area_draw(const bContext *C, ARegion *ar)
/* grid */
unit= (stime->flag & TIME_DRAWFRAMES)? V2D_UNIT_FRAMES: V2D_UNIT_SECONDS;
grid= UI_view2d_grid_calc(C, v2d, unit, V2D_GRID_CLAMP, ar->winx, ar->winy);
grid= UI_view2d_grid_calc(C, v2d, unit, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY, ar->winx, ar->winy);
UI_view2d_grid_draw(C, v2d, grid, (V2D_VERTICAL_LINES|V2D_VERTICAL_AXIS));
UI_view2d_grid_free(grid);