Correction for recent commit clearing font cache
[blender.git] / source / blender / editors / interface / view2d.c
index 559602b04c04314c5abb405e6d9e8bb4987ae4f9..aadb1b30f5ba600a8ceb2b13f4eb3411e7a1abcc 100644 (file)
@@ -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 */
  */
 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,167 @@ 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;
+       bool tot_changed = false, 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! */
                        }
+                       /* 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... */
-                       }
+                       /* 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 = 1;
-                               
-                               /* scroller settings are currently not set here... that is left for regions... */
-                       }
+               }
+               /* '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;
-                               
                        }
+                       /* 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;
+                       
+                       /* 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;
                        
-                       /* panels view, with horizontal/vertical align */
-                       case V2D_COMMONVIEW_PANELS_UI:
-                       {
+                       /* 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;
                }
+               /* 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;
@@ -391,23 +404,26 @@ void UI_view2d_curRect_validate_resize(View2D *v2d, int resize)
         * NOTE: in general, it is not expected that the lock-zoom will be used in conjunction with this
         */
        else if (v2d->keepzoom & V2D_LIMITZOOM) {
-               float zoom, fac;
                
                /* check if excessive zoom on x-axis */
                if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0) {
-                       zoom = winx / width;
-                       if ((zoom < v2d->minzoom) || (zoom > v2d->maxzoom)) {
-                               fac = (zoom < v2d->minzoom) ? (zoom / v2d->minzoom) : (zoom / v2d->maxzoom);
-                               width *= fac;
+                       const float zoom = winx / width;
+                       if (zoom < v2d->minzoom) {
+                               width = winx / v2d->minzoom;
+                       }
+                       else if (zoom > v2d->maxzoom) {
+                               width = winx / v2d->maxzoom;
                        }
                }
                
                /* check if excessive zoom on y-axis */
                if ((v2d->keepzoom & V2D_LOCKZOOM_Y) == 0) {
-                       zoom = winy / height;
-                       if ((zoom < v2d->minzoom) || (zoom > v2d->maxzoom)) {
-                               fac = (zoom < v2d->minzoom) ? (zoom / v2d->minzoom) : (zoom / v2d->maxzoom);
-                               height *= fac;
+                       const float zoom = winy / height;
+                       if (zoom < v2d->minzoom) {
+                               height = winy / v2d->minzoom;
+                       }
+                       else if (zoom > v2d->maxzoom) {
+                               height = winy / v2d->maxzoom;
                        }
                }
        }
@@ -419,14 +435,14 @@ void UI_view2d_curRect_validate_resize(View2D *v2d, int resize)
        
        /* check if we should restore aspect ratio (if view size changed) */
        if (v2d->keepzoom & V2D_KEEPASPECT) {
-               short do_x = FALSE, do_y = FALSE, do_cur /* , do_win */ /* UNUSED */;
+               bool do_x = false, do_y = false, do_cur /* , do_win */ /* UNUSED */;
                float /* curRatio, */ /* UNUSED */ winRatio;
                
                /* when a window edge changes, the aspect ratio can't be used to
                 * find which is the best new 'cur' rect. thats why it stores 'old' 
                 */
-               if (winx != v2d->oldwinx) do_x = TRUE;
-               if (winy != v2d->oldwiny) do_y = TRUE;
+               if (winx != v2d->oldwinx) do_x = true;
+               if (winy != v2d->oldwiny) do_y = true;
                
                /* curRatio = height / width; */ /* UNUSED */
                winRatio = winy / winx;
@@ -435,11 +451,15 @@ void UI_view2d_curRect_validate_resize(View2D *v2d, int resize)
                if (do_x == do_y) {
                        if (do_x && do_y) {
                                /* here is 1,1 case, so all others must be 0,0 */
-                               if (ABS(winx - v2d->oldwinx) > ABS(winy - v2d->oldwiny)) do_y = FALSE;
-                               else do_x = FALSE;
+                               if (fabsf(winx - v2d->oldwinx) > fabsf(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 */
@@ -476,8 +496,14 @@ void UI_view2d_curRect_validate_resize(View2D *v2d, int resize)
                                if (winy < v2d->oldwiny) {
                                        float temp = v2d->oldwiny - winy;
                                        
-                                       cur->ymin += temp;
-                                       cur->ymax += temp;
+                                       if (v2d->align & V2D_ALIGN_NO_NEG_Y) {
+                                               cur->ymin -= temp;
+                                               cur->ymax -= temp;
+                                       }
+                                       else { /* Assume V2D_ALIGN_NO_POS_Y or combination */
+                                               cur->ymin += temp;
+                                               cur->ymax += temp;
+                                       }
                                }
 
                        }
@@ -593,7 +619,7 @@ void UI_view2d_curRect_validate_resize(View2D *v2d, int resize)
                        if ((cur->xmin < tot->xmin) && (cur->xmax > tot->xmax)) {
                                /* outside boundaries on both sides, so take middle-point of tot, and place in balanced way */
                                temp = BLI_rctf_cent_x(tot);
-                               diff = curheight * 0.5f;
+                               diff = curwidth * 0.5f;
                                
                                cur->xmin = temp - diff;
                                cur->xmax = temp + diff;
@@ -709,12 +735,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);
 }
 
 /* ------------------ */
@@ -797,17 +823,17 @@ void UI_view2d_curRect_reset(View2D *v2d)
        /* handle width - posx and negx flags are mutually exclusive, so watch out */
        if ((v2d->align & V2D_ALIGN_NO_POS_X) && !(v2d->align & V2D_ALIGN_NO_NEG_X)) {
                /* width is in negative-x half */
-               v2d->cur.xmin = (float)-width;
+               v2d->cur.xmin = -width;
                v2d->cur.xmax = 0.0f;
        }
        else if ((v2d->align & V2D_ALIGN_NO_NEG_X) && !(v2d->align & V2D_ALIGN_NO_POS_X)) {
                /* width is in positive-x half */
                v2d->cur.xmin = 0.0f;
-               v2d->cur.xmax = (float)width;
+               v2d->cur.xmax = width;
        }
        else {
                /* width is centered around (x == 0) */
-               const float dx = (float)width / 2.0f;
+               const float dx = width / 2.0f;
                
                v2d->cur.xmin = -dx;
                v2d->cur.xmax = dx;
@@ -816,17 +842,17 @@ void UI_view2d_curRect_reset(View2D *v2d)
        /* handle height - posx and negx flags are mutually exclusive, so watch out */
        if ((v2d->align & V2D_ALIGN_NO_POS_Y) && !(v2d->align & V2D_ALIGN_NO_NEG_Y)) {
                /* height is in negative-y half */
-               v2d->cur.ymin = (float)-height;
+               v2d->cur.ymin = -height;
                v2d->cur.ymax = 0.0f;
        }
        else if ((v2d->align & V2D_ALIGN_NO_NEG_Y) && !(v2d->align & V2D_ALIGN_NO_POS_Y)) {
                /* height is in positive-y half */
                v2d->cur.ymin = 0.0f;
-               v2d->cur.ymax = (float)height;
+               v2d->cur.ymax = height;
        }
        else {
                /* height is centered around (y == 0) */
-               const float dy = (float)height / 2.0f;
+               const float dy = height / 2.0f;
                
                v2d->cur.ymin = -dy;
                v2d->cur.ymax = dy;
@@ -838,7 +864,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);
@@ -846,10 +872,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)
@@ -896,19 +923,28 @@ 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)
+bool UI_view2d_tab_set(View2D *v2d, int tab)
 {
        float default_offset[2] = {0.0f, 0.0f};
        float *offset, *new_offset;
-       int changed = 0;
+       bool changed = false;
 
        /* if tab changed, change offset */
        if (tab != v2d->tab_cur && v2d->tab_offset) {
@@ -925,7 +961,7 @@ int UI_view2d_tab_set(View2D *v2d, int tab)
 
                /* validation should happen in subsequent totRect_set */
 
-               changed = 1;
+               changed = true;
        }
 
        /* resize array if needed */
@@ -949,6 +985,15 @@ int UI_view2d_tab_set(View2D *v2d, int tab)
        return changed;
 }
 
+void UI_view2d_zoom_cache_reset(void)
+{
+       /* While scaling we can accumulate fonts at many sizes (~20 or so).
+        * Not an issue with embedded font, but can use over 500Mb with i18n ones! See [#38244]. */
+
+       /* note: only some views draw text, we could check for this case to avoid clearning cache */
+       BLF_cache_clear();
+}
+
 /* *********************************************************************** */
 /* View Matrix Setup */
 
@@ -958,19 +1003,24 @@ static void view2d_map_cur_using_mask(View2D *v2d, rctf *curmasked)
        *curmasked = v2d->cur;
        
        if (view2d_scroll_mapped(v2d->scroll)) {
-               float dx = BLI_rctf_size_x(&v2d->cur) / ((float)(BLI_rcti_size_x(&v2d->mask) + 1));
-               float dy = BLI_rctf_size_y(&v2d->cur) / ((float)(BLI_rcti_size_y(&v2d->mask) + 1));
-               
-               if (v2d->mask.xmin != 0)
-                       curmasked->xmin -= dx * (float)v2d->mask.xmin;
-               if (v2d->mask.xmax + 1 != v2d->winx)
-                       curmasked->xmax += dx * (float)(v2d->winx - v2d->mask.xmax - 1);
-               
-               if (v2d->mask.ymin != 0)
-                       curmasked->ymin -= dy * (float)v2d->mask.ymin;
-               if (v2d->mask.ymax + 1 != v2d->winy)
-                       curmasked->ymax += dy * (float)(v2d->winy - v2d->mask.ymax - 1);
+               float sizex = BLI_rcti_size_x(&v2d->mask);
+               float sizey = BLI_rcti_size_y(&v2d->mask);
                
+               /* prevent tiny or narrow regions to get invalid coordinates - mask can get negative even... */
+               if (sizex > 0.0f && sizey > 0.0f) {
+                       float dx = BLI_rctf_size_x(&v2d->cur) / (sizex + 1);
+                       float dy = BLI_rctf_size_y(&v2d->cur) / (sizey + 1);
+                       
+                       if (v2d->mask.xmin != 0)
+                               curmasked->xmin -= dx * (float)v2d->mask.xmin;
+                       if (v2d->mask.xmax + 1 != v2d->winx)
+                               curmasked->xmax += dx * (float)(v2d->winx - v2d->mask.xmax - 1);
+                       
+                       if (v2d->mask.ymin != 0)
+                               curmasked->ymin -= dy * (float)v2d->mask.ymin;
+                       if (v2d->mask.ymax + 1 != v2d->winy)
+                               curmasked->ymax += dy * (float)(v2d->winy - v2d->mask.ymax - 1);
+               }
        }
 }
 
@@ -978,15 +1028,20 @@ static void view2d_map_cur_using_mask(View2D *v2d, rctf *curmasked)
 void UI_view2d_view_ortho(View2D *v2d)
 {
        rctf curmasked;
-       float xofs, yofs;
+       const int sizex = BLI_rcti_size_x(&v2d->mask);
+       const int sizey = BLI_rcti_size_y(&v2d->mask);
+       const float eps = 0.001f;
+       float xofs = 0.0f, yofs = 0.0f;
        
        /* pixel offsets (-GLA_PIXEL_OFS) are needed to get 1:1 correspondence with pixels for smooth UI drawing,
         * but only applied where requested
         */
        /* XXX brecht: instead of zero at least use a tiny offset, otherwise
         * pixel rounding is effectively random due to float inaccuracy */
-       xofs = 0.001f * BLI_rctf_size_x(&v2d->cur) / BLI_rcti_size_x(&v2d->mask);
-       yofs = 0.001f * BLI_rctf_size_y(&v2d->cur) / BLI_rcti_size_y(&v2d->mask);
+       if (sizex > 0)
+               xofs = eps * BLI_rctf_size_x(&v2d->cur) / sizex;
+       if (sizey > 0)
+               yofs = eps * BLI_rctf_size_y(&v2d->cur) / sizey;
        
        /* apply mask-based adjustments to cur rect (due to scrollers), to eliminate scaling artifacts */
        view2d_map_cur_using_mask(v2d, &curmasked);
@@ -995,16 +1050,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) - (eps + xofs);
+               curmasked.xmax = floorf(curmasked.xmax) - (eps + 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) - (eps + yofs);
+               curmasked.ymax = floorf(curmasked.ymax) - (eps + 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();
@@ -1144,7 +1199,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;
                }
@@ -1161,7 +1216,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) {
@@ -1206,7 +1261,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++) {
@@ -1240,7 +1295,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++) {
@@ -1329,7 +1384,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;
@@ -1339,7 +1394,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;
@@ -1363,7 +1418,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);
@@ -1421,6 +1476,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");
@@ -1429,19 +1485,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);
@@ -1485,15 +1542,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 */
@@ -1527,15 +1575,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 */
@@ -1609,40 +1648,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;
@@ -1674,12 +1715,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) {
@@ -1705,9 +1746,8 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v
                                                        fac2 = fac2 - time;
                                                        
                                                        scroll_printstr(scene, fac, h, time + (float)FPS * fac2 / 100.0f, grid->powerx, V2D_UNIT_SECONDSSEQ, 'h');
+                                                       break;
                                                }
-                                               break;
-                                                       
                                                case V2D_UNIT_DEGREES:      /* Graph Editor for rotation Drivers */
                                                        /* HACK: although we're drawing horizontal, we make this draw as 'vertical', just to get degree signs */
                                                        scroll_printstr(scene, fac, h, val, grid->powerx, V2D_UNIT_DEGREES, 'v');
@@ -1720,40 +1760,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)) {
@@ -1783,7 +1825,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) {
@@ -1824,7 +1866,7 @@ void UI_view2d_scrollers_free(View2DScrollers *scrollers)
  *     - column, row                           = the 2d-coordinates (in 2D-view / 'tot' rect space) the cell exists at
  *     - rect                                  = coordinates of the cell (passed as single var instead of 4 separate, as it's more useful this way)
  */
-void UI_view2d_listview_cell_to_view(View2D *v2d, short columnwidth, short rowheight,
+void UI_view2d_listview_cell_to_view(View2D *v2d, float columnwidth, float rowheight,
                                      float startx, float starty,
                                      int column, int row, rctf *rect)
 {
@@ -1869,7 +1911,7 @@ void UI_view2d_listview_cell_to_view(View2D *v2d, short columnwidth, short rowhe
  *     - viewx, viewy                  = 2D-coordinates (in 2D-view / 'tot' rect space) to get the cell for
  *     - column, row                           = the 'coordinates' of the relevant 'cell'
  */
-void UI_view2d_listview_view_to_cell(View2D *v2d, short columnwidth, short rowheight, float startx, float starty, 
+void UI_view2d_listview_view_to_cell(View2D *v2d, float columnwidth, float rowheight, float startx, float starty,
                                      float viewx, float viewy, int *column, int *row)
 {
        /* adjust view coordinates to be all positive ints, corrected for the start offset */
@@ -1902,7 +1944,7 @@ void UI_view2d_listview_view_to_cell(View2D *v2d, short columnwidth, short rowhe
  *     - startx, starty                        = coordinates that the list starts from, which should be (0,0) for most views
  *     - column/row_min/max            = the starting and ending column/row indices
  */
-void UI_view2d_listview_visible_cells(View2D *v2d, short columnwidth, short rowheight, float startx, float starty, 
+void UI_view2d_listview_visible_cells(View2D *v2d, float columnwidth, float rowheight, float startx, float starty,
                                       int *column_min, int *column_max, int *row_min, int *row_max)
 {
        /* using 'cur' rect coordinates, call the cell-getting function to get the cells for this */
@@ -1925,7 +1967,7 @@ void UI_view2d_listview_visible_cells(View2D *v2d, short columnwidth, short rowh
  *     - x,y           = coordinates to convert
  *     - viewx,viewy           = resultant coordinates
  */
-void UI_view2d_region_to_view(View2D *v2d, int x, int y, float *r_viewx, float *r_viewy)
+void UI_view2d_region_to_view(View2D *v2d, float x, float y, float *r_viewx, float *r_viewy)
 {
        float div, ofs;
 
@@ -2000,6 +2042,17 @@ void UI_view2d_to_region_no_clip(View2D *v2d, float x, float y, int *regionx, in
        }
 }
 
+void UI_view2d_to_region_float(View2D *v2d, float x, float y, float *regionx, float *regiony)
+{
+       /* express given coordinates as proportional values */
+       x = -v2d->cur.xmin / BLI_rctf_size_x(&v2d->cur);
+       y = -v2d->cur.ymin / BLI_rctf_size_y(&v2d->cur);
+
+       /* convert proportional distances to screen coordinates */
+       *regionx = v2d->mask.xmin + x * BLI_rcti_size_x(&v2d->mask);
+       *regiony = v2d->mask.ymin + y * BLI_rcti_size_y(&v2d->mask);
+}
+
 /* *********************************************************************** */
 /* Utilities */
 
@@ -2041,6 +2094,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
@@ -2109,7 +2185,7 @@ void UI_view2d_text_cache_add(View2D *v2d, float x, float y, const char *str, co
 }
 
 /* no clip (yet) */
-void UI_view2d_text_cache_rectf(View2D *v2d, rctf *rect, const char *str, const char col[4])
+void UI_view2d_text_cache_rectf(View2D *v2d, const rctf *rect, const char *str, const char col[4])
 {
        int len = strlen(str) + 1;
        View2DString *v2s = MEM_callocN(sizeof(View2DString) + len, "View2DString");
@@ -2133,7 +2209,7 @@ void UI_view2d_text_cache_draw(ARegion *ar)
        int col_pack_prev = 0;
 
        /* investigate using BLF_ascender() */
-       const float default_height = strings.first ? BLF_height_default("28") : 0.0f;
+       const float default_height = strings.first ? BLF_height_default("28", 3) : 0.0f;
        
        // glMatrixMode(GL_PROJECTION);
        // glPushMatrix();