Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Leung <aligorith@gmail.com>2008-12-13 12:25:47 +0300
committerJoshua Leung <aligorith@gmail.com>2008-12-13 12:25:47 +0300
commit4de30b2304025dc4a17b1d2bb0444040d5094e58 (patch)
treeacf8fd3ffa03cd4f5370d76eebf82eb2ced36727 /source/blender/editors
parent9f06ed1b367fed6cea55d829ea62ff613b902c87 (diff)
View2D:
* 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
Diffstat (limited to 'source/blender/editors')
-rw-r--r--source/blender/editors/include/UI_view2d.h2
-rw-r--r--source/blender/editors/interface/view2d.c103
-rw-r--r--source/blender/editors/space_ipo/space_ipo.c2
-rw-r--r--source/blender/editors/space_time/space_time.c2
4 files changed, 60 insertions, 49 deletions
diff --git a/source/blender/editors/include/UI_view2d.h b/source/blender/editors/include/UI_view2d.h
index 04537ed69b1..2705c5de4f6 100644
--- a/source/blender/editors/include/UI_view2d.h
+++ b/source/blender/editors/include/UI_view2d.h
@@ -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);
diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c
index 054f4c7f160..e6d9a86538c 100644
--- a/source/blender/editors/interface/view2d.c
+++ b/source/blender/editors/interface/view2d.c
@@ -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;
diff --git a/source/blender/editors/space_ipo/space_ipo.c b/source/blender/editors/space_ipo/space_ipo.c
index 675becb3308..700c2bbb225 100644
--- a/source/blender/editors/space_ipo/space_ipo.c
+++ b/source/blender/editors/space_ipo/space_ipo.c
@@ -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);
diff --git a/source/blender/editors/space_time/space_time.c b/source/blender/editors/space_time/space_time.c
index 7c6267f8071..728beae364e 100644
--- a/source/blender/editors/space_time/space_time.c
+++ b/source/blender/editors/space_time/space_time.c
@@ -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);