diff options
Diffstat (limited to 'source/blender/editors/interface/view2d.c')
-rw-r--r-- | source/blender/editors/interface/view2d.c | 540 |
1 files changed, 292 insertions, 248 deletions
diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c index f1a3f59bc22..a66169d54ae 100644 --- a/source/blender/editors/interface/view2d.c +++ b/source/blender/editors/interface/view2d.c @@ -39,6 +39,7 @@ #include "DNA_userdef_types.h" #include "BLI_blenlib.h" +#include "BLI_math.h" #include "BLI_utildefines.h" #include "BKE_context.h" @@ -60,6 +61,8 @@ #include "interface_intern.h" +static void ui_view2d_curRect_validate_resize(View2D *v2d, int resize, int mask_scrollers); + /* *********************************************************************** */ /* XXX still unresolved: scrolls hide/unhide vs region mask handling */ @@ -73,15 +76,15 @@ */ static int view2d_scroll_mapped(int scroll) { - if (scroll & V2D_SCROLL_HORIZONTAL_HIDE) + if (scroll & V2D_SCROLL_HORIZONTAL_FULLR) scroll &= ~(V2D_SCROLL_HORIZONTAL); - if (scroll & V2D_SCROLL_VERTICAL_HIDE) + if (scroll & V2D_SCROLL_VERTICAL_FULLR) scroll &= ~(V2D_SCROLL_VERTICAL); return scroll; } /* called each time cur changes, to dynamically update masks */ -static void view2d_masks(View2D *v2d) +static void view2d_masks(View2D *v2d, int check_scrollers) { int scroll; @@ -90,19 +93,26 @@ static void view2d_masks(View2D *v2d) v2d->mask.xmax = v2d->winx - 1; /* -1 yes! masks are pixels */ v2d->mask.ymax = v2d->winy - 1; -#if 0 - /* XXX see above */ - v2d->scroll &= ~(V2D_SCROLL_HORIZONTAL_HIDE | V2D_SCROLL_VERTICAL_HIDE); - /* check size if: */ - if (v2d->scroll & V2D_SCROLL_HORIZONTAL) - if (!(v2d->scroll & V2D_SCROLL_SCALE_HORIZONTAL)) - if (BLI_rctf_size_x(&v2d->tot) <= BLI_rcti_size_x(&v2d->cur)) - v2d->scroll |= V2D_SCROLL_HORIZONTAL_HIDE; - if (v2d->scroll & V2D_SCROLL_VERTICAL) - if (!(v2d->scroll & V2D_SCROLL_SCALE_VERTICAL)) - if (BLI_rctf_size_y(&v2d->tot) <= BLI_rctf_size_y(&v2d->cur)) - v2d->scroll |= V2D_SCROLL_VERTICAL_HIDE; -#endif + if (check_scrollers) { + /* check size if hiding flag is set: */ + if (v2d->scroll & V2D_SCROLL_HORIZONTAL_HIDE) { + if (!(v2d->scroll & V2D_SCROLL_SCALE_HORIZONTAL)) { + if (BLI_rctf_size_x(&v2d->tot) > BLI_rctf_size_x(&v2d->cur)) + v2d->scroll &= ~V2D_SCROLL_HORIZONTAL_FULLR; + else + v2d->scroll |= V2D_SCROLL_HORIZONTAL_FULLR; + } + } + if (v2d->scroll & V2D_SCROLL_VERTICAL_HIDE) { + if (!(v2d->scroll & V2D_SCROLL_SCALE_VERTICAL)) { + if (BLI_rctf_size_y(&v2d->tot) + 0.01f > BLI_rctf_size_y(&v2d->cur)) + v2d->scroll &= ~V2D_SCROLL_VERTICAL_FULLR; + else + v2d->scroll |= V2D_SCROLL_VERTICAL_FULLR; + } + } + } + scroll = view2d_scroll_mapped(v2d->scroll); /* scrollers shrink mask area, but should be based off regionsize @@ -126,8 +136,8 @@ static void view2d_masks(View2D *v2d) } /* horizontal scroller */ - if (scroll & (V2D_SCROLL_BOTTOM | V2D_SCROLL_BOTTOM_O)) { - /* on bottom edge of region (V2D_SCROLL_BOTTOM_O is outliner, the other is for standard) */ + if (scroll & (V2D_SCROLL_BOTTOM)) { + /* on bottom edge of region */ v2d->hor = v2d->mask; v2d->hor.ymax = V2D_SCROLL_HEIGHT; v2d->mask.ymin = v2d->hor.ymax + 1; @@ -142,8 +152,8 @@ static void view2d_masks(View2D *v2d) /* adjust vertical scroller if there's a horizontal scroller, to leave corner free */ if (scroll & V2D_SCROLL_VERTICAL) { /* just set y min/max for vertical scroller to y min/max of mask as appropriate */ - if (scroll & (V2D_SCROLL_BOTTOM | V2D_SCROLL_BOTTOM_O)) { - /* on bottom edge of region (V2D_SCROLL_BOTTOM_O is outliner, the other is for standard) */ + if (scroll & (V2D_SCROLL_BOTTOM)) { + /* on bottom edge of region */ v2d->vert.ymin = v2d->mask.ymin; } else if (scroll & V2D_SCROLL_TOP) { @@ -152,7 +162,6 @@ static void view2d_masks(View2D *v2d) } } } - } /* Refresh and Validation */ @@ -165,163 +174,173 @@ static void view2d_masks(View2D *v2d) */ void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy) { - short tot_changed = 0, init = 0; + short tot_changed = 0, do_init; uiStyle *style = UI_GetStyle(); - /* initialize data if there is a need for such */ - if ((v2d->flag & V2D_IS_INITIALISED) == 0) { - /* set initialized flag so that View2D doesn't get reinitialised next time again */ - v2d->flag |= V2D_IS_INITIALISED; - - init = 1; + do_init = (v2d->flag & V2D_IS_INITIALISED) == 0; - /* see eView2D_CommonViewTypes in UI_view2d.h for available view presets */ - switch (type) { - /* 'standard view' - optimum setup for 'standard' view behavior, - * that should be used new views as basis for their - * own unique View2D settings, which should be used instead of this in most cases... + /* see eView2D_CommonViewTypes in UI_view2d.h for available view presets */ + switch (type) { + /* 'standard view' - optimum setup for 'standard' view behavior, + * 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_LIMITZOOM); + 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 */ - case V2D_COMMONVIEW_STANDARD: - { - /* for now, aspect ratio should be maintained, and zoom is clamped within sane default limits */ - v2d->keepzoom = (V2D_KEEPASPECT | V2D_LIMITZOOM); - 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->align = (V2D_ALIGN_NO_NEG_X | V2D_ALIGN_NO_NEG_Y); + v2d->keeptot = V2D_KEEPTOT_BOUNDS; + + if (do_init) { 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; + /* 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_LIMITZOOM | V2D_KEEPASPECT); + v2d->minzoom = v2d->maxzoom = 1.0f; - /* '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_LIMITZOOM | 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; - - /* 'stack view' - practically the same as list/channel view, except is located in the pos y half instead. - * zoom, aspect ratio, and alignment restrictions are set here */ - case V2D_COMMONVIEW_STACK: - { - /* zoom + aspect ratio are locked */ - v2d->keepzoom = (V2D_LOCKZOOM_X | V2D_LOCKZOOM_Y | V2D_LIMITZOOM | 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_NEG_Y); - v2d->keeptot = V2D_KEEPTOT_STRICT; - tot_changed = 1; - - /* scroller settings are currently not set here... that is left for regions... */ - } - break; + /* 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 = do_init; + + /* scroller settings are currently not set here... that is left for regions... */ + } + break; + + /* 'stack view' - practically the same as list/channel view, except is located in the pos y half instead. + * zoom, aspect ratio, and alignment restrictions are set here */ + case V2D_COMMONVIEW_STACK: + { + /* zoom + aspect ratio are locked */ + v2d->keepzoom = (V2D_LOCKZOOM_X | V2D_LOCKZOOM_Y | V2D_LIMITZOOM | 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_NEG_Y); + v2d->keeptot = V2D_KEEPTOT_STRICT; + tot_changed = do_init; + + /* 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_LIMITZOOM | V2D_KEEPASPECT); + v2d->minzoom = v2d->maxzoom = 1.0f; + + if (do_init) { + v2d->tot.xmin = 0.0f; + v2d->tot.xmax = winx; + v2d->tot.ymin = 0.0f; + v2d->tot.ymax = winy; + v2d->cur = v2d->tot; - /* '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_LIMITZOOM | V2D_KEEPASPECT); - v2d->minzoom = v2d->maxzoom = 1.0f; v2d->min[0] = v2d->max[0] = (float)(winx - 1); v2d->min[1] = v2d->max[1] = (float)(winy - 1); - - /* 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; + /* 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 = do_init; + + /* panning in y-axis is prohibited */ + v2d->keepofs = V2D_LOCKOFS_Y; - /* panels view, with horizontal/vertical align */ - case V2D_COMMONVIEW_PANELS_UI: - { + /* absolutely no scrollers allowed */ + v2d->scroll = 0; + + } + break; + + /* panels view, with horizontal/vertical align */ + case V2D_COMMONVIEW_PANELS_UI: + { + + /* for now, aspect ratio should be maintained, and zoom is clamped within sane default limits */ + v2d->keepzoom = (V2D_KEEPASPECT | V2D_LIMITZOOM | V2D_KEEPZOOM); + v2d->minzoom = 0.5f; + v2d->maxzoom = 2.0f; + + v2d->align = (V2D_ALIGN_NO_NEG_X | V2D_ALIGN_NO_POS_Y); + v2d->keeptot = V2D_KEEPTOT_BOUNDS; + + /* note, scroll is being flipped in ED_region_panels() drawing */ + v2d->scroll |= V2D_SCROLL_HORIZONTAL_HIDE; + v2d->scroll |= V2D_SCROLL_VERTICAL_HIDE; + + if (do_init) { float panelzoom = (style) ? style->panelzoom : 1.0f; + float scrolw = v2d->scroll & V2D_SCROLL_RIGHT ? V2D_SCROLL_WIDTH : 0.0f; - /* for now, aspect ratio should be maintained, and zoom is clamped within sane default limits */ - v2d->keepzoom = (V2D_KEEPASPECT | V2D_LIMITZOOM | V2D_KEEPZOOM); - v2d->minzoom = 0.5f; - v2d->maxzoom = 2.0f; - //tot_changed = 1; - - v2d->align = (V2D_ALIGN_NO_NEG_X | V2D_ALIGN_NO_POS_Y); - v2d->keeptot = V2D_KEEPTOT_BOUNDS; - - v2d->scroll |= (V2D_SCROLL_RIGHT | V2D_SCROLL_BOTTOM); - v2d->scroll |= V2D_SCROLL_HORIZONTAL_HIDE; - v2d->scroll &= ~V2D_SCROLL_VERTICAL_HIDE; - v2d->tot.xmin = 0.0f; - v2d->tot.xmax = winx; + v2d->tot.xmax = winx - scrolw; v2d->tot.ymax = 0.0f; v2d->tot.ymin = -winy; v2d->cur.xmin = 0.0f; - /* bad workaround for keeping zoom level with scrollers */ - v2d->cur.xmax = (winx - V2D_SCROLL_WIDTH) * panelzoom; + v2d->cur.xmax = (winx) * panelzoom - scrolw; v2d->cur.ymax = 0.0f; v2d->cur.ymin = (-winy) * panelzoom; } - 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; } + 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 initialized flag so that View2D doesn't get reinitialised next time again */ + v2d->flag |= V2D_IS_INITIALISED; + /* store view size */ v2d->winx = winx; v2d->winy = winy; - /* set masks */ - view2d_masks(v2d); + /* set masks (always do), but leave scroller scheck to totrect_set */ + view2d_masks(v2d, 0); /* set 'tot' rect before setting cur? */ - if (tot_changed) - UI_view2d_totRect_set_resize(v2d, winx, winy, !init); + /* XXX confusing stuff here still - I made this function not check scroller hide - that happens in totrect_set */ + if (tot_changed) + UI_view2d_totRect_set_resize(v2d, winx, winy, !do_init); else - UI_view2d_curRect_validate_resize(v2d, !init); + ui_view2d_curRect_validate_resize(v2d, !do_init, 0); + } /* Ensure View2D rects remain in a viable configuration * - cur is not allowed to be: larger than max, smaller than min, or outside of tot */ // XXX pre2.5 -> this used to be called test_view2d() -void UI_view2d_curRect_validate_resize(View2D *v2d, int resize) +static void ui_view2d_curRect_validate_resize(View2D *v2d, int resize, int mask_scrollers) { float totwidth, totheight, curwidth, curheight, width, height; float winx, winy; @@ -438,8 +457,12 @@ void UI_view2d_curRect_validate_resize(View2D *v2d, int resize) if (ABS(winx - v2d->oldwinx) > ABS(winy - v2d->oldwiny)) do_y = FALSE; else do_x = FALSE; } - else if (winRatio > 1.0f) do_x = FALSE; - else do_x = TRUE; + else if (winRatio > 1.0f) { + do_x = FALSE; + } + else { + do_x = TRUE; + } } do_cur = do_x; /* do_win = do_y; */ /* UNUSED */ @@ -715,12 +738,12 @@ void UI_view2d_curRect_validate_resize(View2D *v2d, int resize) } /* set masks */ - view2d_masks(v2d); + view2d_masks(v2d, mask_scrollers); } void UI_view2d_curRect_validate(View2D *v2d) { - UI_view2d_curRect_validate_resize(v2d, 0); + ui_view2d_curRect_validate_resize(v2d, 0, 1); } /* ------------------ */ @@ -844,7 +867,7 @@ void UI_view2d_curRect_reset(View2D *v2d) /* Change the size of the maximum viewable area (i.e. 'tot' rect) */ void UI_view2d_totRect_set_resize(View2D *v2d, int width, int height, int resize) { - int scroll = view2d_scroll_mapped(v2d->scroll); +// int scroll = view2d_scroll_mapped(v2d->scroll); /* don't do anything if either value is 0 */ width = abs(width); @@ -852,10 +875,11 @@ void UI_view2d_totRect_set_resize(View2D *v2d, int width, int height, int resize /* hrumf! */ /* XXX: there are work arounds for this in the panel and file browse code. */ - if (scroll & V2D_SCROLL_HORIZONTAL) - width -= V2D_SCROLL_WIDTH; - if (scroll & V2D_SCROLL_VERTICAL) - height -= V2D_SCROLL_HEIGHT; + /* round to int, because this is called with width + V2D_SCROLL_WIDTH */ +// if (scroll & V2D_SCROLL_HORIZONTAL) +// width -= (int)V2D_SCROLL_WIDTH; +// if (scroll & V2D_SCROLL_VERTICAL) +// height -= (int)V2D_SCROLL_HEIGHT; if (ELEM(0, width, height)) { if (G.debug & G_DEBUG) @@ -902,12 +926,21 @@ void UI_view2d_totRect_set_resize(View2D *v2d, int width, int height, int resize } /* make sure that 'cur' rect is in a valid state as a result of these changes */ - UI_view2d_curRect_validate_resize(v2d, resize); + ui_view2d_curRect_validate_resize(v2d, resize, 1); + } void UI_view2d_totRect_set(View2D *v2d, int width, int height) { + int scroll = view2d_scroll_mapped(v2d->scroll); + UI_view2d_totRect_set_resize(v2d, width, height, 0); + + /* solve bad recursion... if scroller state changed, mask is different, so you get different rects */ + if (scroll != view2d_scroll_mapped(v2d->scroll)) { + UI_view2d_totRect_set_resize(v2d, width, height, 0); + } + } int UI_view2d_tab_set(View2D *v2d, int tab) @@ -1001,16 +1034,16 @@ void UI_view2d_view_ortho(View2D *v2d) /* XXX ton: this flag set by outliner, for icons */ if (v2d->flag & V2D_PIXELOFS_X) { - curmasked.xmin = floorf(curmasked.xmin) - 0.001f; - curmasked.xmax = floorf(curmasked.xmax) - 0.001f; + curmasked.xmin = floorf(curmasked.xmin) - (0.001f + xofs); + curmasked.xmax = floorf(curmasked.xmax) - (0.001f + xofs); } if (v2d->flag & V2D_PIXELOFS_Y) { - curmasked.ymin = floorf(curmasked.ymin) - 0.001f; - curmasked.ymax = floorf(curmasked.ymax) - 0.001f; + curmasked.ymin = floorf(curmasked.ymin) - (0.001f + yofs); + curmasked.ymax = floorf(curmasked.ymax) - (0.001f + yofs); } /* set matrix on all appropriate axes */ - wmOrtho2(curmasked.xmin - xofs, curmasked.xmax - xofs, curmasked.ymin - yofs, curmasked.ymax - yofs); + wmOrtho2(curmasked.xmin, curmasked.xmax, curmasked.ymin, curmasked.ymax); /* XXX is this necessary? */ glLoadIdentity(); @@ -1150,7 +1183,7 @@ View2DGrid *UI_view2d_grid_calc(Scene *scene, View2D *v2d, pixels = (float)BLI_rcti_size_x(&v2d->mask); if (pixels != 0.0f) { - grid->dx = (U.v2d_min_gridsize * space) / (seconddiv * pixels); + grid->dx = (U.v2d_min_gridsize * UI_DPI_FAC * space) / (seconddiv * pixels); step_to_grid(&grid->dx, &grid->powerx, xunits); grid->dx *= seconddiv; } @@ -1167,7 +1200,7 @@ View2DGrid *UI_view2d_grid_calc(Scene *scene, View2D *v2d, space = BLI_rctf_size_y(&v2d->cur); pixels = (float)winy; - grid->dy = U.v2d_min_gridsize * space / pixels; + grid->dy = U.v2d_min_gridsize * UI_DPI_FAC * space / pixels; step_to_grid(&grid->dy, &grid->powery, yunits); if (yclamp == V2D_GRID_CLAMP) { @@ -1212,7 +1245,7 @@ void UI_view2d_grid_draw(View2D *v2d, View2DGrid *grid, int flag) vec2[1] = v2d->cur.ymax; /* minor gridlines */ - step = (BLI_rcti_size_x(&v2d->mask) + 1) / U.v2d_min_gridsize; + step = (BLI_rcti_size_x(&v2d->mask) + 1) / (U.v2d_min_gridsize * UI_DPI_FAC); UI_ThemeColor(TH_GRID); for (a = 0; a < step; a++) { @@ -1246,7 +1279,7 @@ void UI_view2d_grid_draw(View2D *v2d, View2DGrid *grid, int flag) vec1[0] = grid->startx; vec2[0] = v2d->cur.xmax; - step = (BLI_rcti_size_y(&v2d->mask) + 1) / U.v2d_min_gridsize; + step = (BLI_rcti_size_y(&v2d->mask) + 1) / (U.v2d_min_gridsize * UI_DPI_FAC); UI_ThemeColor(TH_GRID); for (a = 0; a <= step; a++) { @@ -1335,7 +1368,7 @@ void UI_view2d_constant_grid_draw(View2D *v2d) } /* Draw a multi-level grid in given 2d-region */ -void UI_view2d_multi_grid_draw(View2D *v2d, float step, int level_size, int totlevels) +void UI_view2d_multi_grid_draw(View2D *v2d, int colorid, float step, int level_size, int totlevels) { int offset = -10; float lstep = step; @@ -1345,7 +1378,7 @@ void UI_view2d_multi_grid_draw(View2D *v2d, float step, int level_size, int totl int i; float start; - UI_ThemeColorShade(TH_BACK, offset); + UI_ThemeColorShade(colorid, offset); i = (v2d->cur.xmin >= 0.0f ? -(int)(-v2d->cur.xmin / lstep) : (int)(v2d->cur.xmin / lstep)); start = i * lstep; @@ -1369,7 +1402,7 @@ void UI_view2d_multi_grid_draw(View2D *v2d, float step, int level_size, int totl } /* X and Y axis */ - UI_ThemeColorShade(TH_BACK, offset - 8); + UI_ThemeColorShade(colorid, offset - 8); glVertex2f(0.0f, v2d->cur.ymin); glVertex2f(0.0f, v2d->cur.ymax); glVertex2f(v2d->cur.xmin, 0.0f); @@ -1427,6 +1460,7 @@ View2DScrollers *UI_view2d_scrollers_calc(const bContext *C, View2D *v2d, rcti vert, hor; float fac1, fac2, totsize, scrollsize; int scroll = view2d_scroll_mapped(v2d->scroll); + int smaller; /* scrollers is allocated here... */ scrollers = MEM_callocN(sizeof(View2DScrollers), "View2DScrollers"); @@ -1435,19 +1469,20 @@ View2DScrollers *UI_view2d_scrollers_calc(const bContext *C, View2D *v2d, hor = v2d->hor; /* slider rects need to be smaller than region */ - hor.xmin += 4; - hor.xmax -= 4; + smaller = (int)(0.2f * U.widget_unit); + hor.xmin += smaller; + hor.xmax -= smaller; if (scroll & V2D_SCROLL_BOTTOM) - hor.ymin += 4; + hor.ymin += smaller; else - hor.ymax -= 4; + hor.ymax -= smaller; if (scroll & V2D_SCROLL_LEFT) - vert.xmin += 4; + vert.xmin += smaller; else - vert.xmax -= 4; - vert.ymin += 4; - vert.ymax -= 4; + vert.xmax -= smaller; + vert.ymin += smaller; + vert.ymax -= smaller; CLAMP(vert.ymin, vert.ymin, vert.ymax - V2D_SCROLLER_HANDLE_SIZE); CLAMP(hor.xmin, hor.xmin, hor.xmax - V2D_SCROLLER_HANDLE_SIZE); @@ -1491,15 +1526,6 @@ View2DScrollers *UI_view2d_scrollers_calc(const bContext *C, View2D *v2d, CLAMP(scrollers->hor_min, hor.xmin, hor.xmax - V2D_SCROLLER_HANDLE_SIZE); } - /* check whether sliders can disappear due to the full-range being used */ - if (v2d->keeptot) { - if ((fac1 <= 0.0f) && (fac2 >= 1.0f)) { - v2d->scroll |= V2D_SCROLL_HORIZONTAL_FULLR; - scrollers->horfull = 1; - } - else - v2d->scroll &= ~V2D_SCROLL_HORIZONTAL_FULLR; - } } /* vertical scrollers */ @@ -1533,15 +1559,6 @@ View2DScrollers *UI_view2d_scrollers_calc(const bContext *C, View2D *v2d, CLAMP(scrollers->vert_min, vert.ymin, vert.ymax - V2D_SCROLLER_HANDLE_SIZE); } - /* check whether sliders can disappear due to the full-range being used */ - if (v2d->keeptot) { - if ((fac1 <= 0.0f) && (fac2 >= 1.0f)) { - v2d->scroll |= V2D_SCROLL_VERTICAL_FULLR; - scrollers->vertfull = 1; - } - else - v2d->scroll &= ~V2D_SCROLL_VERTICAL_FULLR; - } } /* grid markings on scrollbars */ @@ -1615,40 +1632,42 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v /* horizontal scrollbar */ if (scroll & V2D_SCROLL_HORIZONTAL) { - /* only draw scrollbar when it doesn't fill the entire space */ - if (vs->horfull == 0) { - bTheme *btheme = UI_GetTheme(); - uiWidgetColors wcol = btheme->tui.wcol_scroll; - rcti slider; - int state; - - slider.xmin = vs->hor_min; - slider.xmax = vs->hor_max; - slider.ymin = hor.ymin; - slider.ymax = hor.ymax; - - state = (v2d->scroll_ui & V2D_SCROLL_H_ACTIVE) ? UI_SCROLL_PRESSED : 0; - - /* show zoom handles if: - * - zooming on x-axis is allowed (no scroll otherwise) - * - slider bubble is large enough (no overdraw confusion) - * - scale is shown on the scroller - * (workaround to make sure that button windows don't show these, - * and only the time-grids with their zoomability can do so) - */ - if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0 && - (v2d->scroll & V2D_SCROLL_SCALE_HORIZONTAL) && - (BLI_rcti_size_x(&slider) > V2D_SCROLLER_HANDLE_SIZE)) - { - state |= UI_SCROLL_ARROWS; - } - - UI_ThemeColor(TH_BACK); + bTheme *btheme = UI_GetTheme(); + uiWidgetColors wcol = btheme->tui.wcol_scroll; + rcti slider; + int state; + unsigned char col[4]; + + slider.xmin = vs->hor_min; + slider.xmax = vs->hor_max; + slider.ymin = hor.ymin; + slider.ymax = hor.ymax; + + state = (v2d->scroll_ui & V2D_SCROLL_H_ACTIVE) ? UI_SCROLL_PRESSED : 0; + + /* show zoom handles if: + * - zooming on x-axis is allowed (no scroll otherwise) + * - slider bubble is large enough (no overdraw confusion) + * - scale is shown on the scroller + * (workaround to make sure that button windows don't show these, + * and only the time-grids with their zoomability can do so) + */ + if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0 && + (v2d->scroll & V2D_SCROLL_SCALE_HORIZONTAL) && + (BLI_rcti_size_x(&slider) > V2D_SCROLLER_HANDLE_SIZE)) + { + state |= UI_SCROLL_ARROWS; + } + + /* clean rect behind slider, but not with transparent background */ + UI_GetThemeColor4ubv(TH_BACK, col); + if (col[3] == 255) { + glColor3ub(col[0], col[1], col[2]); glRecti(v2d->hor.xmin, v2d->hor.ymin, v2d->hor.xmax, v2d->hor.ymax); - - uiWidgetScrollDraw(&wcol, &hor, &slider, state); } + uiWidgetScrollDraw(&wcol, &hor, &slider, state); + /* scale indicators */ if ((scroll & V2D_SCROLL_SCALE_HORIZONTAL) && (vs->grid)) { View2DGrid *grid = vs->grid; @@ -1680,12 +1699,12 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v /* draw numbers in the appropriate range */ if (dfac > 0.0f) { - float h = 2.0f + (float)(hor.ymin); + float h = 0.1f * UI_UNIT_Y + (float)(hor.ymin); - for (; fac < hor.xmax - 10; fac += dfac, val += grid->dx) { + for (; fac < hor.xmax - 0.5f * U.widget_unit; fac += dfac, val += grid->dx) { /* make prints look nicer for scrollers */ - if (fac < hor.xmin + 10) + if (fac < hor.xmin + 0.5f * U.widget_unit) continue; switch (vs->xunits) { @@ -1726,40 +1745,42 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v /* vertical scrollbar */ if (scroll & V2D_SCROLL_VERTICAL) { - /* only draw scrollbar when it doesn't fill the entire space */ - if (vs->vertfull == 0) { - bTheme *btheme = UI_GetTheme(); - uiWidgetColors wcol = btheme->tui.wcol_scroll; - rcti slider; - int state; - - slider.xmin = vert.xmin; - slider.xmax = vert.xmax; - slider.ymin = vs->vert_min; - slider.ymax = vs->vert_max; - - state = (v2d->scroll_ui & V2D_SCROLL_V_ACTIVE) ? UI_SCROLL_PRESSED : 0; - - /* show zoom handles if: - * - zooming on y-axis is allowed (no scroll otherwise) - * - slider bubble is large enough (no overdraw confusion) - * - scale is shown on the scroller - * (workaround to make sure that button windows don't show these, - * and only the time-grids with their zoomability can do so) - */ - if ((v2d->keepzoom & V2D_LOCKZOOM_Y) == 0 && - (v2d->scroll & V2D_SCROLL_SCALE_VERTICAL) && - (BLI_rcti_size_y(&slider) > V2D_SCROLLER_HANDLE_SIZE)) - { - state |= UI_SCROLL_ARROWS; - } - - UI_ThemeColor(TH_BACK); + bTheme *btheme = UI_GetTheme(); + uiWidgetColors wcol = btheme->tui.wcol_scroll; + rcti slider; + int state; + unsigned char col[4]; + + slider.xmin = vert.xmin; + slider.xmax = vert.xmax; + slider.ymin = vs->vert_min; + slider.ymax = vs->vert_max; + + state = (v2d->scroll_ui & V2D_SCROLL_V_ACTIVE) ? UI_SCROLL_PRESSED : 0; + + /* show zoom handles if: + * - zooming on y-axis is allowed (no scroll otherwise) + * - slider bubble is large enough (no overdraw confusion) + * - scale is shown on the scroller + * (workaround to make sure that button windows don't show these, + * and only the time-grids with their zoomability can do so) + */ + if ((v2d->keepzoom & V2D_LOCKZOOM_Y) == 0 && + (v2d->scroll & V2D_SCROLL_SCALE_VERTICAL) && + (BLI_rcti_size_y(&slider) > V2D_SCROLLER_HANDLE_SIZE)) + { + state |= UI_SCROLL_ARROWS; + } + + /* clean rect behind slider, but not with transparent background */ + UI_GetThemeColor4ubv(TH_BACK, col); + if (col[3] == 255) { + glColor3ub(col[0], col[1], col[2]); glRecti(v2d->vert.xmin, v2d->vert.ymin, v2d->vert.xmax, v2d->vert.ymax); - - uiWidgetScrollDraw(&wcol, &vert, &slider, state); } + uiWidgetScrollDraw(&wcol, &vert, &slider, state); + /* scale indiators */ if ((scroll & V2D_SCROLL_SCALE_VERTICAL) && (vs->grid)) { @@ -1789,7 +1810,7 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v /* draw vertical steps */ if (dfac > 0.0f) { - BLF_rotation_default(90.0f); + BLF_rotation_default(M_PI / 2); BLF_enable_default(BLF_ROTATION); for (; fac < vert.ymax - 10; fac += dfac, val += grid->dy) { @@ -2047,6 +2068,29 @@ void UI_view2d_getscale(View2D *v2d, float *x, float *y) if (x) *x = BLI_rcti_size_x(&v2d->mask) / BLI_rctf_size_x(&v2d->cur); if (y) *y = BLI_rcti_size_y(&v2d->mask) / BLI_rctf_size_y(&v2d->cur); } +/* Same as UI_view2d_getscale() - 1.0f / x, y */ +void UI_view2d_getscale_inverse(View2D *v2d, float *x, float *y) +{ + if (x) *x = BLI_rctf_size_x(&v2d->cur) / BLI_rcti_size_x(&v2d->mask); + if (y) *y = BLI_rctf_size_y(&v2d->cur) / BLI_rcti_size_y(&v2d->mask); +} + +/* Simple functions for consistent center offset access. + * Used by node editor to shift view center for each individual node tree. + */ +void UI_view2d_getcenter(struct View2D *v2d, float *x, float *y) +{ + /* get center */ + if (x) *x = BLI_rctf_cent_x(&v2d->cur); + if (y) *y = BLI_rctf_cent_y(&v2d->cur); +} +void UI_view2d_setcenter(struct View2D *v2d, float x, float y) +{ + BLI_rctf_recenter(&v2d->cur, x, y); + + /* make sure that 'cur' rect is in a valid state as a result of these changes */ + UI_view2d_curRect_validate(v2d); +} /* Check if mouse is within scrollers * - Returns appropriate code for match |