From 92cbb4b033ee236aafefbf22b2e2adfb363d36b1 Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Wed, 3 Dec 2008 09:06:30 +0000 Subject: [PATCH] View2D - assorted wip changes (nothing to see here) --- source/blender/editors/include/UI_view2d.h | 8 ++++-- source/blender/editors/interface/view2d.c | 11 +++++--- source/blender/editors/interface/view2d_ops.c | 28 +++++++++++++++++++ .../editors/space_outliner/space_outliner.c | 2 +- .../blender/editors/space_time/space_time.c | 2 +- 5 files changed, 42 insertions(+), 9 deletions(-) diff --git a/source/blender/editors/include/UI_view2d.h b/source/blender/editors/include/UI_view2d.h index 3e80b77cd29..cd2345bf247 100644 --- a/source/blender/editors/include/UI_view2d.h +++ b/source/blender/editors/include/UI_view2d.h @@ -38,11 +38,14 @@ /* generic value to use when coordinate lies out of view when converting */ #define V2D_IS_CLIPPED 12000 -/* --- Grids --- */ /* grid-units (for drawing time) */ #define V2D_UNIT_SECONDS 0 #define V2D_UNIT_FRAMES 1 +/* grid-units (for drawing values) */ +#define V2D_UNIT_VALUES 2 +#define V2D_UNIT_DEGREES 3 + /* clamping of grid values to whole numbers */ #define V2D_GRID_CLAMP 0 #define V2D_GRID_NOCLAMP 1 @@ -53,7 +56,6 @@ #define V2D_HORIZONTAL_AXIS (1<<2) #define V2D_VERTICAL_AXIS (1<<3) -/* --- Scrollers --- */ /* ------------------------------------------ */ /* Macros: */ @@ -92,7 +94,7 @@ void UI_view2d_draw_grid(const struct bContext *C, struct View2D *v2d, View2DGri void UI_view2d_free_grid(View2DGrid *grid); /* scrollbar drawing */ -View2DScrollers *UI_view2d_calc_scrollers(const struct bContext *C, struct View2D *v2d, short units, short clamp); +View2DScrollers *UI_view2d_calc_scrollers(const struct bContext *C, struct View2D *v2d, short xunits, short xclamp, short yunits, short yclamp); void UI_view2d_draw_scrollers(const struct bContext *C, struct View2D *v2d, View2DScrollers *scrollers, int flag); void UI_view2d_free_scrollers(View2DScrollers *scrollers); diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c index 0d10f37e400..d16b41f4f74 100644 --- a/source/blender/editors/interface/view2d.c +++ b/source/blender/editors/interface/view2d.c @@ -628,7 +628,7 @@ struct View2DScrollers { }; /* Calculate relevant scroller properties */ -View2DScrollers *UI_view2d_calc_scrollers(const bContext *C, View2D *v2d, short units, short clamp) +View2DScrollers *UI_view2d_calc_scrollers(const bContext *C, View2D *v2d, short xunits, short xclamp, short yunits, short yclamp) { View2DScrollers *scrollers; rcti vert, hor; @@ -640,12 +640,14 @@ View2DScrollers *UI_view2d_calc_scrollers(const bContext *C, View2D *v2d, short /* scrollers is allocated here... */ scrollers= MEM_callocN(sizeof(View2DScrollers), "View2DScrollers"); - /* slider 'buttons': + /* scroller 'buttons': * - These should always remain within the visible region of the scrollbar * - They represent the region of 'tot' that is visible in 'cur' */ - /* slider 'button' extents - horizontal */ + + /* horizontal scrollers */ if (v2d->scroll & (HOR_SCROLL|HOR_SCROLLO)) { + /* slider 'button' extents */ totsize= v2d->tot.xmax - v2d->tot.xmin; scrollsize= hor.xmax - hor.xmin; @@ -661,8 +663,9 @@ View2DScrollers *UI_view2d_calc_scrollers(const bContext *C, View2D *v2d, short scrollers->hor_min= scrollers->hor_max; } - /* slider 'button' extents - vertical */ + /* vertical scrollers */ if (v2d->scroll & VERT_SCROLL) { + /* slider 'button' extents */ totsize= v2d->tot.ymax - v2d->tot.ymin; scrollsize= vert.ymax - vert.ymin; diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c index 9e6a9a6dada..0fd01ea18ed 100644 --- a/source/blender/editors/interface/view2d_ops.c +++ b/source/blender/editors/interface/view2d_ops.c @@ -51,6 +51,32 @@ /* ********************************************************* */ /* General Polling Funcs */ +/* Check if mouse is within scrollbars + * - Returns true or false (1 or 0) + * + * - x,y = mouse coordinates in screen (not region) space + */ +static short mouse_in_v2d_scrollers (const bContext *C, View2D *v2d, int x, int y) +{ + ARegion *ar= C->region; + int co[2]; + + /* clamp x,y to region-coordinates first */ + // FIXME: is this needed? + co[0]= x - ar->winrct.xmin; + co[1]= y - ar->winrct.ymin; + + /* check if within scrollbars */ + if (v2d->scroll & (HOR_SCROLL|HOR_SCROLLO)) { + if (IN_2D_HORIZ_SCROLL(v2d, co)) return 1; + } + if (v2d->scroll & VERT_SCROLL) { + if (IN_2D_VERT_SCROLL(v2d, co)) return 1; + } + + /* not found */ + return 0; +} /* ********************************************************* */ @@ -76,6 +102,8 @@ typedef struct v2dViewPanData { /* options for version 1 */ int startx, starty; /* mouse x/y values in window when operator was initiated */ int lastx, lasty; /* previous x/y values of mouse in window */ + + short in_scroller; /* activated in scrollbar */ } v2dViewPanData; /* initialise panning customdata */ diff --git a/source/blender/editors/space_outliner/space_outliner.c b/source/blender/editors/space_outliner/space_outliner.c index 6362df7d26c..9c92e2320dd 100644 --- a/source/blender/editors/space_outliner/space_outliner.c +++ b/source/blender/editors/space_outliner/space_outliner.c @@ -423,7 +423,7 @@ static void outliner_main_area_draw(const bContext *C, ARegion *ar) UI_view2d_view_restore(C); /* scrollers */ - scrollers= UI_view2d_calc_scrollers(C, v2d, 0, 0); // XXX last two vars here are useless + scrollers= UI_view2d_calc_scrollers(C, v2d, 0, 0, 0, 0); // XXX last two vars here are useless UI_view2d_draw_scrollers(C, v2d, scrollers, (0)); UI_view2d_free_scrollers(scrollers); } diff --git a/source/blender/editors/space_time/space_time.c b/source/blender/editors/space_time/space_time.c index e391ac82c82..fffbbb5f1ab 100644 --- a/source/blender/editors/space_time/space_time.c +++ b/source/blender/editors/space_time/space_time.c @@ -152,7 +152,7 @@ static void time_main_area_draw(const bContext *C, ARegion *ar) UI_view2d_view_restore(C); /* scrollers */ - scrollers= UI_view2d_calc_scrollers(C, v2d, unit, V2D_GRID_CLAMP); + scrollers= UI_view2d_calc_scrollers(C, v2d, unit, V2D_GRID_CLAMP, 0, 0); UI_view2d_draw_scrollers(C, v2d, scrollers, (0)); UI_view2d_free_scrollers(scrollers); }