soc-2008-mxcurioni: merged changes to revision 23516
[blender.git] / source / blender / editors / interface / view2d.c
index 3d8b4fa959addac879a178da91f2afe4a19f0e40..be58a78ca859908082b25af9418ccdf86e2e8b51 100644 (file)
  * ***** END GPL LICENSE BLOCK *****
  */
 
-#include <string.h>
+#include <limits.h>
 #include <math.h>
+#include <string.h>
 
 #include "MEM_guardedalloc.h"
 
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
 #include "DNA_space_types.h"
+#include "DNA_userdef_types.h"
 #include "DNA_view2d_types.h"
 
 #include "BLI_blenlib.h"
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
 
+#include "BLF_api.h"
+
 #include "ED_screen.h"
 
+#include "UI_interface.h"
 #include "UI_resources.h"
-#include "UI_text.h"
 #include "UI_view2d.h"
 
-#include "UI_interface.h"
-#include "interface.h"
+#include "interface_intern.h"
 
 /* *********************************************************************** */
+
+/* helper to allow scrollbars to dynamically hide */
+static int view2d_scroll_mapped(int scroll)
+{
+       if(scroll & V2D_SCROLL_HORIZONTAL_HIDE)
+               scroll &= ~(V2D_SCROLL_HORIZONTAL);
+       if(scroll & V2D_SCROLL_VERTICAL_HIDE)
+               scroll &= ~(V2D_SCROLL_VERTICAL);
+       return scroll;
+}
+
+/* called each time cur changes, to dynamically update masks */
+static void view2d_masks(View2D *v2d)
+{
+       int scroll;
+       
+       /* mask - view frame */
+       v2d->mask.xmin= v2d->mask.ymin= 0;
+       v2d->mask.xmax= v2d->winx - 1;  /* -1 yes! masks are pixels */
+       v2d->mask.ymax= v2d->winy - 1;
+
+#if 0
+       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 (v2d->tot.xmax-v2d->tot.xmin <= v2d->cur.xmax-v2d->cur.xmin)
+                               v2d->scroll |= V2D_SCROLL_HORIZONTAL_HIDE;
+       if (v2d->scroll & V2D_SCROLL_VERTICAL)
+               if(!(v2d->scroll & V2D_SCROLL_SCALE_VERTICAL))
+                       if (v2d->tot.ymax-v2d->tot.ymin <= v2d->cur.ymax-v2d->cur.ymin)
+                               v2d->scroll |= V2D_SCROLL_VERTICAL_HIDE;
+#endif
+       scroll= view2d_scroll_mapped(v2d->scroll);
+       
+       /* scrollers shrink mask area, but should be based off regionsize 
+        *      - they can only be on one to two edges of the region they define
+        *      - if they overlap, they must not occupy the corners (which are reserved for other widgets)
+        */
+       if (scroll) {
+               /* vertical scroller */
+               if (scroll & V2D_SCROLL_LEFT) {
+                       /* on left-hand edge of region */
+                       v2d->vert= v2d->mask;
+                       v2d->vert.xmax= V2D_SCROLL_WIDTH;
+                       v2d->mask.xmin= v2d->vert.xmax + 1;
+               }
+               else if (scroll & V2D_SCROLL_RIGHT) {
+                       /* on right-hand edge of region */
+                       v2d->vert= v2d->mask;
+                       v2d->vert.xmax++; /* one pixel extra... was leaving a minor gap... */
+                       v2d->vert.xmin= v2d->vert.xmax - V2D_SCROLL_WIDTH;
+                       v2d->mask.xmax= v2d->vert.xmin - 1;
+               }
+               
+               /* 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) */
+                       v2d->hor= v2d->mask;
+                       v2d->hor.ymax= V2D_SCROLL_HEIGHT;
+                       v2d->mask.ymin= v2d->hor.ymax + 1;
+               }
+               else if (scroll & V2D_SCROLL_TOP) {
+                       /* on upper edge of region */
+                       v2d->hor= v2d->mask;
+                       v2d->hor.ymin= v2d->hor.ymax - V2D_SCROLL_HEIGHT;
+                       v2d->mask.ymax= v2d->hor.ymin - 1;
+               }
+               
+               /* 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) */
+                               v2d->vert.ymin= v2d->mask.ymin;
+                       }
+                       else if (scroll & V2D_SCROLL_TOP) {
+                               /* on upper edge of region */
+                               v2d->vert.ymax= v2d->mask.ymax;
+                       }
+               }
+       }
+       
+}
+
 /* Refresh and Validation */
 
 /* Initialise all relevant View2D data (including view rects if first time) and/or refresh mask sizes after view resize
  */
 void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy)
 {
-       short tot_changed= 0;
-       
+       short tot_changed= 0, init= 0;
+       uiStyle *style= U.uistyles.first;
+
        /* initialise data if there is a need for such */
        if ((v2d->flag & V2D_IS_INITIALISED) == 0) {
                /* set initialised flag so that View2D doesn't get reinitialised next time again */
                v2d->flag |= V2D_IS_INITIALISED;
+
+               init= 1;
                
                /* see eView2D_CommonViewTypes in UI_view2d.h for available view presets */
                switch (type) {
@@ -81,7 +172,7 @@ void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy)
                        case V2D_COMMONVIEW_STANDARD:
                        {
                                /* for now, aspect ratio should be maintained, and zoom is clamped within sane default limits */
-                               v2d->keepzoom= (V2D_KEEPASPECT|V2D_KEEPZOOM);
+                               v2d->keepzoom= (V2D_KEEPASPECT|V2D_LIMITZOOM);
                                v2d->minzoom= 0.01f;
                                v2d->maxzoom= 1000.0f;
                                
@@ -108,7 +199,7 @@ void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy)
                        case V2D_COMMONVIEW_LIST:
                        {
                                /* zoom + aspect ratio are locked */
-                               v2d->keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_KEEPZOOM|V2D_KEEPASPECT);
+                               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 */
@@ -120,14 +211,31 @@ void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy)
                        }
                                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;
+                               
                        /* '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_KEEPZOOM|V2D_KEEPASPECT);
+                               v2d->keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_LIMITZOOM|V2D_KEEPASPECT);
                                v2d->minzoom= v2d->maxzoom= 1.0f;
-                               v2d->min[0]= v2d->max[0]= winx-1;
-                               v2d->min[1]= v2d->max[1]= winy-1;
+                               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);
@@ -145,82 +253,64 @@ void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy)
                        }
                                break;
                        
-                       /* other view types are completely defined using their own settings already */
+                       /* panels view, with horizontal/vertical align */
+                       case V2D_COMMONVIEW_PANELS_UI:
+                       {
+                               float panelzoom= (style) ? style->panelzoom : 1.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->tot.xmin= 0.0f;
+                               v2d->tot.xmax= winx;
+                               
+                               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.ymax= 0.0f;
+                               /* bad workaround for keeping zoom level with scrollers */
+                               v2d->cur.ymin= (-winy + V2D_SCROLL_HEIGHT)*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;  
                }
        }
        
-       
        /* store view size */
        v2d->winx= winx;
        v2d->winy= winy;
        
-       /* mask - view frame */
-       v2d->mask.xmin= v2d->mask.ymin= 0;
-       v2d->mask.xmax= winx - 1;       /* -1 yes! masks are pixels */
-       v2d->mask.ymax= winy - 1;
-       
-       /* scrollers shrink mask area, but should be based off regionsize 
-        *      - they can only be on one to two edges of the region they define
-        *      - if they overlap, they must not occupy the corners (which are reserved for other widgets)
-        */
-       if (v2d->scroll) {
-               /* vertical scroller */
-               if (v2d->scroll & V2D_SCROLL_LEFT) {
-                       /* on left-hand edge of region */
-                       v2d->vert= v2d->mask;
-                       v2d->vert.xmax= V2D_SCROLL_WIDTH;
-                       v2d->mask.xmin= v2d->vert.xmax + 1;
-               }
-               else if (v2d->scroll & V2D_SCROLL_RIGHT) {
-                       /* on right-hand edge of region */
-                       v2d->vert= v2d->mask;
-                       v2d->vert.xmin= v2d->vert.xmax - V2D_SCROLL_WIDTH;
-                       v2d->mask.xmax= v2d->vert.xmin - 1;
-               }
-               
-               /* horizontal scroller */
-               if (v2d->scroll & (V2D_SCROLL_BOTTOM|V2D_SCROLL_BOTTOM_O)) {
-                       /* on bottom edge of region (V2D_SCROLL_BOTTOM_O is outliner, the other is for standard) */
-                       v2d->hor= v2d->mask;
-                       v2d->hor.ymax= V2D_SCROLL_HEIGHT;
-                       v2d->mask.ymin= v2d->hor.ymax + 1;
-               }
-               else if (v2d->scroll & V2D_SCROLL_TOP) {
-                       /* on upper edge of region */
-                       v2d->hor= v2d->mask;
-                       v2d->hor.ymin= v2d->hor.ymax - V2D_SCROLL_HEIGHT;
-                       v2d->mask.ymax= v2d->hor.ymin - 1;
-               }
-               
-               /* adjust vertical scroller if there's a horizontal scroller, to leave corner free */
-               if (v2d->scroll & V2D_SCROLL_VERTICAL) {
-                       /* just set y min/max for vertical scroller to y min/max of mask as appropriate */
-                       if (v2d->scroll & (V2D_SCROLL_BOTTOM|V2D_SCROLL_BOTTOM_O)) {
-                               /* on bottom edge of region (V2D_SCROLL_BOTTOM_O is outliner, the other is for standard) */
-                               v2d->vert.ymin= v2d->mask.ymin;
-                       }
-                       else if (v2d->scroll & V2D_SCROLL_TOP) {
-                               /* on upper edge of region */
-                               v2d->vert.ymax= v2d->mask.ymax;
-                       }
-               }
-       }
+       /* set masks */
+       view2d_masks(v2d);
        
        /* set 'tot' rect before setting cur? */
        if (tot_changed) 
-               UI_view2d_totRect_set(v2d, winx, winy);
+               UI_view2d_totRect_set_resize(v2d, winx, winy, !init);
        else
-               UI_view2d_curRect_validate(v2d);
+               UI_view2d_curRect_validate_resize(v2d, !init);
 }
 
 /* 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(View2D *v2d)
+void UI_view2d_curRect_validate_resize(View2D *v2d, int resize)
 {
        float totwidth, totheight, curwidth, curheight, width, height;
        float winx, winy;
@@ -257,10 +347,36 @@ void UI_view2d_curRect_validate(View2D *v2d)
        if (v2d->keepzoom & V2D_LOCKZOOM_Y)
                height= winy;
                
-       /* keepzoom (V2D_KEEPZOOM set), indicates that zoom level on each axis must not exceed limits 
+       /* values used to divide, so make it safe */
+       if(width<1) width= 1;
+       if(height<1) height= 1;
+       if(winx<1) winx= 1;
+       if(winy<1) winy= 1;
+       
+       /* V2D_LIMITZOOM indicates that zoom level should be preserved when the window size changes */
+       if (resize && (v2d->keepzoom & V2D_KEEPZOOM)) {
+               float zoom, oldzoom;
+
+               if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0) {
+                       zoom= winx / width;
+                       oldzoom= v2d->oldwinx / curwidth;
+
+                       if(oldzoom != zoom)
+                               width *= zoom/oldzoom;
+               }
+
+               if ((v2d->keepzoom & V2D_LOCKZOOM_Y)==0) {
+                       zoom= winy / height;
+                       oldzoom= v2d->oldwiny / curheight;
+
+                       if(oldzoom != zoom)
+                               height *= zoom/oldzoom;
+               }
+       }
+       /* keepzoom (V2D_LIMITZOOM set), indicates that zoom level on each axis must not exceed limits 
         * NOTE: in general, it is not expected that the lock-zoom will be used in conjunction with this
         */
-       if (v2d->keepzoom & V2D_KEEPZOOM) {
+       else if (v2d->keepzoom & V2D_LIMITZOOM) {
                float zoom, fac;
                
                /* check if excessive zoom on x-axis */
@@ -342,6 +458,14 @@ void UI_view2d_curRect_validate(View2D *v2d)
                                /* special exception for Outliner (and later channel-lists):
                                 *      - Currently, no actions need to be taken here...
                                 */
+
+                               if (winy < v2d->oldwiny) {
+                                       float temp = v2d->oldwiny - winy;
+                                       
+                                       cur->ymin += temp;
+                                       cur->ymax += temp;
+                               }
+
                        }
                        else {
                                /* landscape window: correct for y */
@@ -350,28 +474,50 @@ void UI_view2d_curRect_validate(View2D *v2d)
                }
                
                /* store region size for next time */
-               v2d->oldwinx= winx; 
-               v2d->oldwiny= winy;
+               v2d->oldwinx= (short)winx; 
+               v2d->oldwiny= (short)winy;
        }
        
        /* Step 2: apply new sizes to cur rect, but need to take into account alignment settings here... */
        if ((width != curwidth) || (height != curheight)) {
                float temp, dh;
                
-               /* resize from centerpoint */
+               /* resize from centerpoint, unless otherwise specified */
                if (width != curwidth) {
-                       temp= (cur->xmax + cur->xmin) * 0.5f;
-                       dh= width * 0.5f;
-                       
-                       cur->xmin = temp - dh;
-                       cur->xmax = temp + dh;
+                       if (v2d->keepofs & V2D_LOCKOFS_X) {
+                               cur->xmax += width - (cur->xmax - cur->xmin);
+                       }
+                       else if (v2d->keepofs & V2D_KEEPOFS_X) {
+                               if(v2d->align & V2D_ALIGN_NO_POS_X)
+                                       cur->xmin -= width - (cur->xmax - cur->xmin);
+                               else
+                                       cur->xmax += width - (cur->xmax - cur->xmin);
+                       }
+                       else {
+                               temp= (cur->xmax + cur->xmin) * 0.5f;
+                               dh= width * 0.5f;
+                               
+                               cur->xmin = temp - dh;
+                               cur->xmax = temp + dh;
+                       }
                }
                if (height != curheight) {
-                       temp= (cur->ymax + cur->ymin) * 0.5f;
-                       dh= height * 0.5f;
-                       
-                       cur->ymin = temp - dh;
-                       cur->ymax = temp + dh;
+                       if (v2d->keepofs & V2D_LOCKOFS_Y) {
+                               cur->ymax += height - (cur->ymax - cur->ymin);
+                       }
+                       else if (v2d->keepofs & V2D_KEEPOFS_Y) {
+                               if(v2d->align & V2D_ALIGN_NO_POS_Y)
+                                       cur->ymin -= height - (cur->ymax - cur->ymin);
+                               else
+                                       cur->ymax += height - (cur->ymax - cur->ymin);
+                       }
+                       else {
+                               temp= (cur->ymax + cur->ymin) * 0.5f;
+                               dh= height * 0.5f;
+                               
+                               cur->ymin = temp - dh;
+                               cur->ymax = temp + dh;
+                       }
                }
        }
        
@@ -384,7 +530,7 @@ void UI_view2d_curRect_validate(View2D *v2d)
                curheight= cur->ymax - cur->ymin;
                
                /* width */
-               if ( (curwidth > totwidth) && !(v2d->keepzoom & (V2D_KEEPZOOM|V2D_LOCKZOOM_X)) ) {
+               if ( (curwidth > totwidth) && !(v2d->keepzoom & (V2D_KEEPZOOM|V2D_LOCKZOOM_X|V2D_LIMITZOOM)) ) {
                        /* if zoom doesn't have to be maintained, just clamp edges */
                        if (cur->xmin < tot->xmin) cur->xmin= tot->xmin;
                        if (cur->xmax > tot->xmax) cur->xmax= tot->xmax;
@@ -430,13 +576,13 @@ void UI_view2d_curRect_validate(View2D *v2d)
                         * We favour moving the 'minimum' across, as that's origin for most things
                         * (XXX - in the past, max was favoured... if there are bugs, swap!)
                         */
-                       if ((cur->ymin < tot->ymin) && (cur->ymax > tot->ymax)) {
+                       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= (tot->ymax + tot->ymin) * 0.5f;
+                               temp= (tot->xmax + tot->xmin) * 0.5f;
                                diff= curheight * 0.5f;
                                
-                               cur->ymin= temp - diff;
-                               cur->ymax= temp + diff;
+                               cur->xmin= temp - diff;
+                               cur->xmax= temp + diff;
                        }
                        else if (cur->xmin < tot->xmin) {
                                /* move cur across so that it sits at minimum of tot */
@@ -467,7 +613,7 @@ void UI_view2d_curRect_validate(View2D *v2d)
                }
                
                /* height */
-               if ( (curheight > totheight) && !(v2d->keepzoom & (V2D_KEEPZOOM|V2D_LOCKZOOM_Y)) ) {
+               if ( (curheight > totheight) && !(v2d->keepzoom & (V2D_KEEPZOOM|V2D_LOCKZOOM_Y|V2D_LIMITZOOM)) ) {
                        /* if zoom doesn't have to be maintained, just clamp edges */
                        if (cur->ymin < tot->ymin) cur->ymin= tot->ymin;
                        if (cur->ymax > tot->ymax) cur->ymax= tot->ymax;
@@ -547,6 +693,14 @@ void UI_view2d_curRect_validate(View2D *v2d)
                        }
                }
        }
+       
+       /* set masks */
+       view2d_masks(v2d);
+}
+
+void UI_view2d_curRect_validate(View2D *v2d)
+{
+       return UI_view2d_curRect_validate_resize(v2d, 0);
 }
 
 /* ------------------ */
@@ -562,7 +716,7 @@ void UI_view2d_sync(bScreen *screen, ScrArea *area, View2D *v2dcur, int flag)
                return;
                
        /* check if doing within area syncing (i.e. channels/vertical) */
-       if (v2dcur->flag & V2D_VIEWSYNC_AREA_VERTICAL) {
+       if ((v2dcur->flag & V2D_VIEWSYNC_AREA_VERTICAL) && (area)) {
                for (ar= area->regionbase.first; ar; ar= ar->next) {
                        /* don't operate on self */
                        if (v2dcur != &ar->v2d) {
@@ -587,7 +741,7 @@ void UI_view2d_sync(bScreen *screen, ScrArea *area, View2D *v2dcur, int flag)
        }
        
        /* check if doing whole screen syncing (i.e. time/horizontal) */
-       if (v2dcur->flag & V2D_VIEWSYNC_SCREEN_TIME) {
+       if ((v2dcur->flag & V2D_VIEWSYNC_SCREEN_TIME) && (screen)) {
                for (sa= screen->areabase.first; sa; sa= sa->next) {
                        for (ar= sa->regionbase.first; ar; ar= ar->next) {
                                /* don't operate on self */
@@ -668,11 +822,24 @@ void UI_view2d_curRect_reset (View2D *v2d)
 /* ------------------ */
 
 /* Change the size of the maximum viewable area (i.e. 'tot' rect) */
-void UI_view2d_totRect_set (View2D *v2d, int width, int height)
+void UI_view2d_totRect_set_resize (View2D *v2d, int width, int height, int resize)
 {
+       int scroll= view2d_scroll_mapped(v2d->scroll);
+       
        /* don't do anything if either value is 0 */
-       if (ELEM3(0, v2d, width, height))
+       width= abs(width);
+       height= abs(height);
+       
+       /* hrumf! */
+       if(scroll & V2D_SCROLL_HORIZONTAL) 
+               width -= V2D_SCROLL_WIDTH;
+       if(scroll & V2D_SCROLL_VERTICAL) 
+               height -= V2D_SCROLL_HEIGHT;
+       
+       if (ELEM3(0, v2d, width, height)) {
+               printf("Error: View2D totRect set exiting: v2d=%p width=%d height=%d \n", v2d, width, height); // XXX temp debug info
                return;
+       }
        
        /* 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)) {
@@ -713,7 +880,57 @@ void UI_view2d_totRect_set (View2D *v2d, int width, int height)
        }
        
        /* make sure that 'cur' rect is in a valid state as a result of these changes */
-       UI_view2d_curRect_validate(v2d);
+       UI_view2d_curRect_validate_resize(v2d, resize);
+}
+
+void UI_view2d_totRect_set(View2D *v2d, int width, int height)
+{
+       UI_view2d_totRect_set_resize(v2d, width, height, 0);
+}
+
+int UI_view2d_tab_set(View2D *v2d, int tab)
+{
+       float default_offset[2]= {0.0f, 0.0f};
+       float *offset, *new_offset;
+       int changed= 0;
+
+       /* if tab changed, change offset */
+       if(tab != v2d->tab_cur && v2d->tab_offset) {
+               if(tab < v2d->tab_num)
+                       offset= &v2d->tab_offset[tab*2];
+               else
+                       offset= default_offset;
+
+               v2d->cur.xmax += offset[0] - v2d->cur.xmin;
+               v2d->cur.xmin= offset[0];
+
+               v2d->cur.ymin += offset[1] - v2d->cur.ymax;
+               v2d->cur.ymax= offset[1];
+
+               /* validation should happen in subsequent totRect_set */
+
+               changed= 1;
+       }
+
+       /* resize array if needed */
+       if(tab >= v2d->tab_num) {
+               new_offset= MEM_callocN(sizeof(float)*(tab+1)*2, "view2d tab offset");
+
+               if(v2d->tab_offset) {
+                       memcpy(new_offset, v2d->tab_offset, sizeof(float)*v2d->tab_num*2);
+                       MEM_freeN(v2d->tab_offset);
+               }
+
+               v2d->tab_offset= new_offset;
+               v2d->tab_num= tab+1;
+       }
+
+       /* set current tab and offset */
+       v2d->tab_cur= tab;
+       v2d->tab_offset[2*tab+0]= v2d->cur.xmin;
+       v2d->tab_offset[2*tab+1]= v2d->cur.ymax;
+
+       return changed;
 }
 
 /* *********************************************************************** */
@@ -724,7 +941,7 @@ static void view2d_map_cur_using_mask(View2D *v2d, rctf *curmasked)
 {
        *curmasked= v2d->cur;
        
-       if ((v2d->scroll)) {
+       if (view2d_scroll_mapped(v2d->scroll)) {
                float dx= (v2d->cur.xmax-v2d->cur.xmin)/((float)(v2d->mask.xmax-v2d->mask.xmin+1));
                float dy= (v2d->cur.ymax-v2d->cur.ymin)/((float)(v2d->mask.ymax-v2d->mask.ymin+1));
                
@@ -750,8 +967,14 @@ void UI_view2d_view_ortho(const bContext *C, View2D *v2d)
        /* pixel offsets (-0.375f) are needed to get 1:1 correspondance with pixels for smooth UI drawing, 
         * but only applied where requsted
         */
-       xofs= (v2d->flag & V2D_PIXELOFS_X) ? 0.375f : 0.0f;
-       yofs= (v2d->flag & V2D_PIXELOFS_Y) ? 0.375f : 0.0f;
+       /* XXX ton: fix this! */
+       xofs= 0.0; // (v2d->flag & V2D_PIXELOFS_X) ? 0.375f : 0.0f;
+       yofs= 0.0; // (v2d->flag & V2D_PIXELOFS_Y) ? 0.375f : 0.0f;
+
+       /* XXX brecht: instead of zero at least use a tiny offset, otherwise
+        * pixel rounding is effectively random due to float inaccuracy */
+       xofs= 0.001f;
+       yofs= 0.001f;
        
        /* apply mask-based adjustments to cur rect (due to scrollers), to eliminate scaling artifacts */
        view2d_map_cur_using_mask(v2d, &curmasked);
@@ -775,8 +998,9 @@ void UI_view2d_view_orthoSpecial(const bContext *C, View2D *v2d, short xaxis)
        /* pixel offsets (-0.375f) are needed to get 1:1 correspondance with pixels for smooth UI drawing, 
         * but only applied where requsted
         */
-       xofs= (v2d->flag & V2D_PIXELOFS_X) ? 0.375f : 0.0f;
-       yofs= (v2d->flag & V2D_PIXELOFS_Y) ? 0.375f : 0.0f;
+       /* XXX temp (ton) */
+       xofs= 0.0f; // (v2d->flag & V2D_PIXELOFS_X) ? 0.375f : 0.0f;
+       yofs= 0.0f; // (v2d->flag & V2D_PIXELOFS_Y) ? 0.375f : 0.0f;
        
        /* apply mask-based adjustments to cur rect (due to scrollers), to eliminate scaling artifacts */
        view2d_map_cur_using_mask(v2d, &curmasked);
@@ -795,7 +1019,14 @@ void UI_view2d_view_orthoSpecial(const bContext *C, View2D *v2d, short xaxis)
 /* Restore view matrices after drawing */
 void UI_view2d_view_restore(const bContext *C)
 {
-       ED_region_pixelspace(CTX_wm_region(C));
+       ARegion *ar= CTX_wm_region(C);
+       int width= ar->winrct.xmax-ar->winrct.xmin+1;
+       int height= ar->winrct.ymax-ar->winrct.ymin+1;
+       
+       wmOrtho2(0.0f, (float)width, 0.0f, (float)height);
+       wmLoadIdentity();
+       
+       //      ED_region_pixelspace(CTX_wm_region(C));
 }
 
 /* *********************************************************************** */
@@ -816,40 +1047,40 @@ struct View2DGrid {
 /* try to write step as a power of 10 */
 static void step_to_grid(float *step, int *power, int unit)
 {
-       const float loga= log10(*step);
+       const float loga= (float)log10(*step);
        float rem;
        
        *power= (int)(loga);
        
        rem= loga - (*power);
-       rem= pow(10.0, rem);
+       rem= (float)pow(10.0, rem);
        
-       if (loga < 0.0) {
-               if (rem < 0.2) rem= 0.2;
-               else if(rem < 0.5) rem= 0.5;
-               else rem= 1.0;
+       if (loga < 0.0f) {
+               if (rem < 0.2f) rem= 0.2f;
+               else if(rem < 0.5f) rem= 0.5f;
+               else rem= 1.0f;
                
-               *step= rem * pow(10.0, (float)(*power));
+               *step= rem * (float)pow(10.0, (*power));
                
                /* for frames, we want 1.0 frame intervals only */
                if (unit == V2D_UNIT_FRAMES) {
-                       rem = 1.0;
-                       *step = 1.0;
+                       rem = 1.0f;
+                       *step = 1.0f;
                }
                
                /* prevents printing 1.0 2.0 3.0 etc */
-               if (rem == 1.0) (*power)++;     
+               if (rem == 1.0f) (*power)++;    
        }
        else {
-               if (rem < 2.0) rem= 2.0;
-               else if(rem < 5.0) rem= 5.0;
-               else rem= 10.0;
+               if (rem < 2.0f) rem= 2.0f;
+               else if(rem < 5.0f) rem= 5.0f;
+               else rem= 10.0f;
                
-               *step= rem * pow(10.0, (float)(*power));
+               *step= rem * (float)pow(10.0, (*power));
                
                (*power)++;
                /* prevents printing 1.0, 2.0, 3.0, etc. */
-               if (rem == 10.0) (*power)++;    
+               if (rem == 10.0f) (*power)++;   
        }
 }
 
@@ -882,7 +1113,7 @@ View2DGrid *UI_view2d_grid_calc(const bContext *C, View2D *v2d, short xunits, sh
        /* rule: gridstep is minimal GRIDSTEP pixels */
        if (xunits == V2D_UNIT_SECONDS) {
                secondgrid= 1;
-               seconddiv= 0.01f * FPS;
+               seconddiv= (float)(0.01 * FPS);
        }
        else {
                secondgrid= 0;
@@ -892,7 +1123,7 @@ View2DGrid *UI_view2d_grid_calc(const bContext *C, View2D *v2d, short xunits, sh
        /* 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;
+               pixels= (float)(v2d->mask.xmax - v2d->mask.xmin);
                
                grid->dx= (MINGRIDSTEP * space) / (seconddiv * pixels);
                step_to_grid(&grid->dx, &grid->powerx, xunits);
@@ -908,7 +1139,7 @@ View2DGrid *UI_view2d_grid_calc(const bContext *C, View2D *v2d, short xunits, sh
        /* 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;
+               pixels= (float)winy;
                
                grid->dy= MINGRIDSTEP * space / pixels;
                step_to_grid(&grid->dy, &grid->powery, yunits);
@@ -921,14 +1152,14 @@ View2DGrid *UI_view2d_grid_calc(const bContext *C, View2D *v2d, short xunits, sh
        
        /* calculate start position */
        if (ELEM(V2D_ARG_DUMMY, xunits, xclamp) == 0) {
-               grid->startx= seconddiv*(v2d->cur.xmin/seconddiv - fmod(v2d->cur.xmin/seconddiv, grid->dx/seconddiv));
+               grid->startx= seconddiv*(v2d->cur.xmin/seconddiv - (float)fmod(v2d->cur.xmin/seconddiv, grid->dx/seconddiv));
                if (v2d->cur.xmin < 0.0f) grid->startx-= grid->dx;
        }
        else
                grid->startx= v2d->cur.xmin;
                
        if (ELEM(V2D_ARG_DUMMY, yunits, yclamp) == 0) {
-               grid->starty= (v2d->cur.ymin - fmod(v2d->cur.ymin, grid->dy));
+               grid->starty= (v2d->cur.ymin - (float)fmod(v2d->cur.ymin, grid->dy));
                if (v2d->cur.ymin < 0.0f) grid->starty-= grid->dy;
        }
        else
@@ -1053,7 +1284,7 @@ void UI_view2d_constant_grid_draw(const bContext *C, View2D *v2d)
 
        UI_ThemeColorShade(TH_BACK, -10);
        
-       start= v2d->cur.xmin -fmod(v2d->cur.xmin, step);
+       start= v2d->cur.xmin - (float)fmod(v2d->cur.xmin, step);
        
        glBegin(GL_LINES);
        for(; start<v2d->cur.xmax; start+=step) {
@@ -1061,7 +1292,7 @@ void UI_view2d_constant_grid_draw(const bContext *C, View2D *v2d)
                glVertex2f(start, v2d->cur.ymax);
        }
 
-       start= v2d->cur.ymin -fmod(v2d->cur.ymin, step);
+       start= v2d->cur.ymin - (float)fmod(v2d->cur.ymin, step);
        for(; start<v2d->cur.ymax; start+=step) {
                glVertex2f(v2d->cur.xmin, start);
                glVertex2f(v2d->cur.xmax, start);
@@ -1086,18 +1317,21 @@ void UI_view2d_grid_free(View2DGrid *grid)
 }
 
 /* *********************************************************************** */
-/* Scrollbars */
+/* Scrollers */
 
 /* View2DScrollers is typedef'd in UI_view2d.h 
  * WARNING: the start of this struct must not change, as view2d_ops.c uses this too. 
  *                For now, we don't need to have a separate (internal) header for structs like this...
  */
-struct View2DScrollers {       
+struct View2DScrollers {
                /* focus bubbles */
        int vert_min, vert_max; /* vertical scrollbar */
        int hor_min, hor_max;   /* horizontal scrollbar */
        
-               /* scales */
+       rcti hor, vert;                 /* exact size of slider backdrop */
+       int horfull, vertfull;  /* set if sliders are full, we don't draw them */
+       
+       /* scales */
        View2DGrid *grid;               /* grid for coordinate drawing */
        short xunits, xclamp;   /* units and clamping options for x-axis */
        short yunits, yclamp;   /* units and clamping options for y-axis */
@@ -1108,13 +1342,33 @@ View2DScrollers *UI_view2d_scrollers_calc(const bContext *C, View2D *v2d, short
 {
        View2DScrollers *scrollers;
        rcti vert, hor;
-       float fac, totsize, scrollsize;
+       float fac1, fac2, totsize, scrollsize;
+       int scroll= view2d_scroll_mapped(v2d->scroll);
+       
+       /* scrollers is allocated here... */
+       scrollers= MEM_callocN(sizeof(View2DScrollers), "View2DScrollers");
        
        vert= v2d->vert;
        hor= v2d->hor;
        
-       /* scrollers is allocated here... */
-       scrollers= MEM_callocN(sizeof(View2DScrollers), "View2DScrollers");
+       /* slider rects need to be smaller than region */
+       hor.xmin+=4;
+       hor.xmax-=4;
+       if (scroll & V2D_SCROLL_BOTTOM)
+               hor.ymin+=4;
+       else
+               hor.ymax-=4;
+       
+       if (scroll & V2D_SCROLL_LEFT)
+               vert.xmin+=4;
+       else
+               vert.xmax-=4;
+       vert.ymin+=4;
+       vert.ymax-=4;
+       
+       /* store in scrollers, used for drawing */
+       scrollers->vert= vert;
+       scrollers->hor= hor;
        
        /* scroller 'buttons':
         *      - These should always remain within the visible region of the scrollbar
@@ -1122,39 +1376,71 @@ View2DScrollers *UI_view2d_scrollers_calc(const bContext *C, View2D *v2d, short
         */
        
        /* horizontal scrollers */
-       if (v2d->scroll & V2D_SCROLL_HORIZONTAL) {
+       if (scroll & V2D_SCROLL_HORIZONTAL) {
                /* scroller 'button' extents */
                totsize= v2d->tot.xmax - v2d->tot.xmin;
-               scrollsize= hor.xmax - hor.xmin;
+               scrollsize= (float)(hor.xmax - hor.xmin);
                
-               fac= (v2d->cur.xmin- v2d->tot.xmin) / totsize;
-               scrollers->hor_min= hor.xmin + (fac * scrollsize);
+               fac1= (v2d->cur.xmin - v2d->tot.xmin) / totsize;
+               if(fac1<=0.0f)
+                       scrollers->hor_min= hor.xmin;
+               else
+                       scrollers->hor_min= (int)(hor.xmin + (fac1 * scrollsize));
                
-               fac= (v2d->cur.xmax - v2d->tot.xmin) / totsize;
-               scrollers->hor_max= hor.xmin + (fac * scrollsize);
+               fac2= (v2d->cur.xmax - v2d->tot.xmin) / totsize;
+               if(fac2>=1.0f)
+                       scrollers->hor_max= hor.xmax;
+               else
+                       scrollers->hor_max= (int)(hor.xmin + (fac2 * scrollsize));
                
+               /* prevent inverted sliders */
                if (scrollers->hor_min > scrollers->hor_max) 
                        scrollers->hor_min= scrollers->hor_max;
+               /* prevent sliders from being too small, and disappearing */
+               if ((scrollers->hor_max - scrollers->hor_min) < V2D_SCROLLER_HANDLE_SIZE)
+                       scrollers->hor_max+= V2D_SCROLLER_HANDLE_SIZE;
+               
+               /* check whether sliders can disappear */
+               if(v2d->keeptot) {
+                       if(fac1 <= 0.0f && fac2 >= 1.0f) 
+                               scrollers->horfull= 1;
+               }
        }
        
        /* vertical scrollers */
-       if (v2d->scroll & V2D_SCROLL_VERTICAL) {
+       if (scroll & V2D_SCROLL_VERTICAL) {
                /* scroller 'button' extents */
                totsize= v2d->tot.ymax - v2d->tot.ymin;
-               scrollsize= vert.ymax - vert.ymin;
+               scrollsize= (float)(vert.ymax - vert.ymin);
                
-               fac= (v2d->cur.ymin- v2d->tot.ymin) / totsize;
-               scrollers->vert_min= vert.ymin + (fac * scrollsize);
+               fac1= (v2d->cur.ymin- v2d->tot.ymin) / totsize;
+               if(fac1<=0.0f)
+                       scrollers->vert_min= vert.ymin;
+               else
+                       scrollers->vert_min= (int)(vert.ymin + (fac1 * scrollsize));
                
-               fac= (v2d->cur.ymax - v2d->tot.ymin) / totsize;
-               scrollers->vert_max= vert.ymin + (fac * scrollsize);
+               fac2= (v2d->cur.ymax - v2d->tot.ymin) / totsize;
+               if(fac2>=1.0f)
+                       scrollers->vert_max= vert.ymax;
+               else
+                       scrollers->vert_max= (int)(vert.ymin + (fac2 * scrollsize));
                
+               /* prevent inverted sliders */
                if (scrollers->vert_min > scrollers->vert_max) 
                        scrollers->vert_min= scrollers->vert_max;
+               /* prevent sliders from being too small, and disappearing */
+               if ((scrollers->vert_max - scrollers->vert_min) < V2D_SCROLLER_HANDLE_SIZE)
+                       scrollers->vert_max+= V2D_SCROLLER_HANDLE_SIZE;
+               
+               /* check whether sliders can disappear */
+               if(v2d->keeptot) {
+                       if(fac1 <= 0.0f && fac2 >= 1.0f) 
+                               scrollers->vertfull= 1;
+               }
        }
        
        /* grid markings on scrollbars */
-       if (v2d->scroll & (V2D_SCROLL_SCALE_HORIZONTAL|V2D_SCROLL_SCALE_VERTICAL)) {
+       if (scroll & (V2D_SCROLL_SCALE_HORIZONTAL|V2D_SCROLL_SCALE_VERTICAL)) {
                /* store clamping */
                scrollers->xclamp= xclamp;
                scrollers->xunits= xunits;
@@ -1180,7 +1466,7 @@ static void scroll_printstr(View2DScrollers *scrollers, Scene *scene, float x, f
                 * rotation values (hence 'degrees') are divided by 10 to 
                 * be able to show the curves at the same time
                 */
-               if ELEM(unit, V2D_UNIT_DEGREES, V2D_UNIT_TIME) {
+               if (ELEM(unit, V2D_UNIT_DEGREES, V2D_UNIT_TIME)) {
                        power += 1;
                        val *= 10;
                }
@@ -1188,12 +1474,16 @@ static void scroll_printstr(View2DScrollers *scrollers, Scene *scene, float x, f
        
        /* get string to print */
        if (unit == V2D_UNIT_SECONDS) {
-               /* SMPTE timecode style:
+               /* Timecode:
                 *      - In general, minutes and seconds should be shown, as most clips will be
                 *        within this length. Hours will only be included if relevant.
                 *      - Only show frames when zoomed in enough for them to be relevant 
-                *        (using separator convention of ';' for frames, ala QuickTime).
+                *        (using separator of '!' for frames).
                 *        When showing frames, use slightly different display to avoid confusion with mm:ss format
+                * TODO: factor into reusable function.
+                * Meanwhile keep in sync:
+                *        source/blender/editors/animation/anim_draw.c
+                *        source/blender/editors/interface/view2d.c
                 */
                int hours=0, minutes=0, seconds=0, frames=0;
                char neg[2]= "";
@@ -1211,12 +1501,12 @@ static void scroll_printstr(View2DScrollers *scrollers, Scene *scene, float x, f
                         *         go against conventions...
                         */
                        hours= (int)val / 3600;
-                       val= fmod(val, 3600);
+                       val= (float)fmod(val, 3600);
                }
                if (val >= 60) {
                        /* minutes */
                        minutes= (int)val / 60;
-                       val= fmod(val, 60);
+                       val= (float)fmod(val, 60);
                }
                if (power <= 0) {
                        /* seconds + frames
@@ -1234,9 +1524,9 @@ static void scroll_printstr(View2DScrollers *scrollers, Scene *scene, float x, f
                /* print timecode to temp string buffer */
                if (power <= 0) {
                        /* include "frames" in display */
-                       if (hours) sprintf(str, "%s%02d:%02d:%02d;%02d", neg, hours, minutes, seconds, frames);
-                       else if (minutes) sprintf(str, "%s%02d:%02d;%02d", neg, minutes, seconds, frames);
-                       else sprintf(str, "%s%d;%02d", neg, seconds, frames);
+                       if (hours) sprintf(str, "%s%02d:%02d:%02d!%02d", neg, hours, minutes, seconds, frames);
+                       else if (minutes) sprintf(str, "%s%02d:%02d!%02d", neg, minutes, seconds, frames);
+                       else sprintf(str, "%s%d!%02d", neg, seconds, frames);
                }
                else {
                        /* don't include 'frames' in display */
@@ -1267,95 +1557,45 @@ static void scroll_printstr(View2DScrollers *scrollers, Scene *scene, float x, f
        }
        
        /* draw it */
-       ui_rasterpos_safe(x, y, 1.0);
-       UI_DrawString(G.fonts, str, 0); // XXX check this again when new text-drawing api is done
+       BLF_draw_default(x, y, 0.0f, str);
 }
 
-/* local defines for scrollers drawing */
-       /* radius of scroller 'button' caps */
-#define V2D_SCROLLCAP_RAD              5
-       /* shading factor for scroller 'bar' */
-#define V2D_SCROLLBAR_SHADE            0.1f
-       /* shading factor for scroller 'button' caps */
-#define V2D_SCROLLCAP_SHADE            0.2f
-
 /* Draw scrollbars in the given 2d-region */
 void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *vs)
 {
        Scene *scene= CTX_data_scene(C);
-       const short darker= -50, dark= -10, light= 20, lighter= 50;
-       rcti vert, hor, corner;
+       rcti vert, hor;
+       int scroll= view2d_scroll_mapped(v2d->scroll);
        
        /* make copies of rects for less typing */
-       vert= v2d->vert;
-       hor= v2d->hor;
+       vert= vs->vert;
+       hor= vs->hor;
        
        /* horizontal scrollbar */
-       if (v2d->scroll & V2D_SCROLL_HORIZONTAL) {
-               /* scroller backdrop */
-               UI_ThemeColorShade(TH_SHADE1, light);
-               glRecti(hor.xmin,  hor.ymin,  hor.xmax,  hor.ymax);
-               
-               /* scroller 'button' 
-                *      - if view is zoomable in x, draw handles too 
-                *      - handles are drawn darker
-                */
-               if (v2d->keepzoom & V2D_LOCKZOOM_X) {
-                       /* draw base bar as rounded shape */
-                       UI_ThemeColorShade(TH_SHADE1, dark);
-                       uiSetRoundBox(15);
+       if (scroll & V2D_SCROLL_HORIZONTAL) {
+               /* only draw scrollbar when it doesn't fill the entire space */
+               if(vs->horfull==0) {
+                       bTheme *btheme= U.themes.first;
+                       uiWidgetColors wcol= btheme->tui.wcol_scroll;
+                       rcti slider;
+                       int state;
                        
-                       /* check that box is large enough for round drawing */
-                       if ((vs->hor_max - vs->hor_min) < (V2D_SCROLLCAP_RAD * 2)) {
-                               /* Rounded box still gets drawn at the minimum size limit
-                                * This doesn't represent extreme scaling well, but looks nicer...
-                                */
-                               float mid= 0.5f * (vs->hor_max + vs->hor_min);
-                               
-                               gl_round_box_shade(GL_POLYGON, 
-                                       mid-V2D_SCROLLCAP_RAD, hor.ymin+2, 
-                                       mid+V2D_SCROLLCAP_RAD, hor.ymax-2, 
-                                       V2D_SCROLLCAP_RAD, V2D_SCROLLBAR_SHADE, -V2D_SCROLLBAR_SHADE);
-                       }
-                       else {
-                               /* draw rounded box as per normal */
-                               gl_round_box_shade(GL_POLYGON, 
-                                       vs->hor_min, hor.ymin+2, 
-                                       vs->hor_max, hor.ymax-2, 
-                                       V2D_SCROLLCAP_RAD, V2D_SCROLLBAR_SHADE, -V2D_SCROLLBAR_SHADE);
-                       }
-               }
-               else {
-                       /* base bar drawn as shaded rect */
-                       UI_ThemeColorShade(TH_SHADE1, dark);
-                       uiSetRoundBox(0);
-                       gl_round_box_shade(GL_POLYGON, 
-                               vs->hor_min, hor.ymin+2, 
-                               vs->hor_max, hor.ymax-2, 
-                               V2D_SCROLLCAP_RAD, V2D_SCROLLBAR_SHADE, -V2D_SCROLLBAR_SHADE);
-                       
-                       /* 'minimum' handle */
-                       uiSetRoundBox(9);
-                       UI_ThemeColorShade(TH_SHADE1, darker);
-                       
-                       gl_round_box_shade(GL_POLYGON, 
-                               vs->hor_min-V2D_SCROLLER_HANDLE_SIZE, hor.ymin+2, 
-                               vs->hor_min+V2D_SCROLLER_HANDLE_SIZE, hor.ymax-2, 
-                               V2D_SCROLLCAP_RAD, V2D_SCROLLCAP_SHADE, -V2D_SCROLLCAP_SHADE);
+                       slider.xmin= vs->hor_min;
+                       slider.xmax= vs->hor_max;
+                       slider.ymin= hor.ymin;
+                       slider.ymax= hor.ymax;
                        
-                       /* maximum handle */
-                       uiSetRoundBox(6);
-                       UI_ThemeColorShade(TH_SHADE1, darker);
+                       state= (v2d->scroll_ui & V2D_SCROLL_H_ACTIVE)?UI_SCROLL_PRESSED:0;
                        
-                       gl_round_box_shade(GL_POLYGON, 
-                               vs->hor_max-V2D_SCROLLER_HANDLE_SIZE, hor.ymin+2, 
-                               vs->hor_max+V2D_SCROLLER_HANDLE_SIZE, hor.ymax-2, 
-                               V2D_SCROLLCAP_RAD, V2D_SCROLLCAP_SHADE, -V2D_SCROLLCAP_SHADE);
+                       // TODO: disable this for button regions... 
+                       if (!(v2d->keepzoom & V2D_LOCKZOOM_X))
+                               state |= UI_SCROLL_ARROWS;
+                               
+                       uiWidgetScrollDraw(&wcol, &hor, &slider, state);
                }
                
                /* scale indicators */
-               // XXX will need to update the font drawing when the new stuff comes in
-               if ((v2d->scroll & V2D_SCROLL_SCALE_HORIZONTAL) && (vs->grid)) {
+               if ((scroll & V2D_SCROLL_SCALE_HORIZONTAL) && (vs->grid)) {
                        View2DGrid *grid= vs->grid;
                        float fac, dfac, fac2, val;
                        
@@ -1364,7 +1604,7 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v
                         *      - dfac is gap between scale markings
                         */
                        fac= (grid->startx - v2d->cur.xmin) / (v2d->cur.xmax - v2d->cur.xmin);
-                       fac= hor.xmin + fac*(hor.xmax - hor.xmin);
+                       fac= (float)hor.xmin + fac*(hor.xmax - hor.xmin);
                        
                        dfac= (grid->dx) / (v2d->cur.xmax - v2d->cur.xmin);
                        dfac= dfac * (hor.xmax - hor.xmin);
@@ -1384,113 +1624,77 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v
                                grid->powerx= 1;
                        
                        /* draw numbers in the appropriate range */
-                       if (dfac != 0.0f) {
-                               for (; fac < hor.xmax; fac+=dfac, val+=grid->dx) {
-                                       switch (vs->xunits) {
+                       if (dfac > 0.0f) {
+                               float h= 2.0f+(float)(hor.ymin);
+                               
+                               for (; fac < hor.xmax-10; fac+=dfac, val+=grid->dx) {
+                                       
+                                       /* make prints look nicer for scrollers */
+                                       if(fac < hor.xmin+10)
+                                               continue;
+                                       
+                                       switch (vs->xunits) {                                                   
                                                case V2D_UNIT_FRAMES:           /* frames (as whole numbers)*/
-                                                       scroll_printstr(vs, scene, fac, 3.0+(float)(hor.ymin), val, grid->powerx, V2D_UNIT_FRAMES, 'h');
+                                                       scroll_printstr(vs, scene, fac, h, val, grid->powerx, V2D_UNIT_FRAMES, 'h');
+                                                       break;
+                                                       
+                                               case V2D_UNIT_FRAMESCALE:       /* frames (not always as whole numbers) */
+                                                       scroll_printstr(vs, scene, fac, h, val, grid->powerx, V2D_UNIT_FRAMESCALE, 'h');
                                                        break;
                                                
                                                case V2D_UNIT_SECONDS:          /* seconds */
-                                                       fac2= val/FPS;
-                                                       scroll_printstr(vs, scene, fac, 3.0+(float)(hor.ymin), fac2, grid->powerx, V2D_UNIT_SECONDS, 'h');
+                                                       fac2= val/(float)FPS;
+                                                       scroll_printstr(vs, scene, fac, h, fac2, grid->powerx, V2D_UNIT_SECONDS, 'h');
                                                        break;
                                                        
                                                case V2D_UNIT_SECONDSSEQ:       /* seconds with special calculations (only used for sequencer only) */
                                                {
                                                        float time;
                                                        
-                                                       fac2= val/FPS;
-                                                       time= floor(fac2);
+                                                       fac2= val/(float)FPS;
+                                                       time= (float)floor(fac2);
                                                        fac2= fac2-time;
                                                        
-                                                       scroll_printstr(vs, scene, fac, 3.0+(float)(hor.ymin), time+FPS*fac2/100.0, grid->powerx, V2D_UNIT_SECONDSSEQ, 'h');
+                                                       scroll_printstr(vs, scene, fac, h, time+(float)FPS*fac2/100.0f, grid->powerx, V2D_UNIT_SECONDSSEQ, 'h');
                                                }
                                                        break;
                                                        
-                                               case V2D_UNIT_DEGREES:          /* IPO-Editor for rotation IPO-Drivers */
+                                               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(vs, scene, fac, 3.0+(float)(hor.ymin), val, grid->powerx, V2D_UNIT_DEGREES, 'v');
+                                                       scroll_printstr(vs, scene, fac, h, val, grid->powerx, V2D_UNIT_DEGREES, 'v');
                                                        break;
                                        }
                                }
                        }
                }
-               
-               /* decoration outer bevel line */
-               UI_ThemeColorShade(TH_SHADE1, lighter);
-               if (v2d->scroll & (V2D_SCROLL_BOTTOM|V2D_SCROLL_BOTTOM_O))
-                       sdrawline(hor.xmin, hor.ymax, hor.xmax, hor.ymax);
-               else if (v2d->scroll & V2D_SCROLL_TOP)
-                       sdrawline(hor.xmin, hor.ymin, hor.xmax, hor.ymin);
        }
        
        /* vertical scrollbar */
-       if (v2d->scroll & V2D_SCROLL_VERTICAL) {
-               /* scroller backdrop  */
-               UI_ThemeColorShade(TH_SHADE1, light);
-               glRecti(vert.xmin,  vert.ymin,  vert.xmax,  vert.ymax);
-               
-               /* scroller 'button' 
-                *      - if view is zoomable in y, draw handles too 
-                *      - handles are drawn darker
-                */
-               if (v2d->keepzoom & V2D_LOCKZOOM_Y) {
-                       /* draw base bar as rounded shape */
-                       UI_ThemeColorShade(TH_SHADE1, dark);
-                       uiSetRoundBox(15);
-                       
-                       /* check that box is large enough for round drawing */
-                       if ((vs->vert_max - vs->vert_min) < (V2D_SCROLLCAP_RAD * 2)) {
-                               /* Rounded box still gets drawn at the minimum size limit
-                                * This doesn't represent extreme scaling well, but looks nicer...
-                                */
-                               float mid= 0.5f * (vs->vert_max + vs->vert_min);
-                               
-                               gl_round_box_vertical_shade(GL_POLYGON, 
-                                       vert.xmin+2, mid-V2D_SCROLLCAP_RAD, 
-                                       vert.xmax-2, mid+V2D_SCROLLCAP_RAD, 
-                                       V2D_SCROLLCAP_RAD, V2D_SCROLLBAR_SHADE, -V2D_SCROLLBAR_SHADE);
-                       }
-                       else {
-                               /* draw rounded box as per normal */
-                               gl_round_box_vertical_shade(GL_POLYGON, 
-                                       vert.xmin+2, vs->vert_min, 
-                                       vert.xmax-2, vs->vert_max, 
-                                       V2D_SCROLLCAP_RAD, V2D_SCROLLBAR_SHADE, -V2D_SCROLLBAR_SHADE);
-                       }
-               }
-               else {
-                       /* base bar drawn as shaded rect */
-                       UI_ThemeColorShade(TH_SHADE1, dark);
-                       uiSetRoundBox(0);
-                       gl_round_box_vertical_shade(GL_POLYGON, 
-                               vert.xmin+2, vs->vert_min, 
-                               vert.xmax-2, vs->vert_max,
-                               V2D_SCROLLCAP_RAD, V2D_SCROLLBAR_SHADE, -V2D_SCROLLBAR_SHADE);
-                       
-                       /* 'minimum' handle */
-                       UI_ThemeColorShade(TH_SHADE1, darker);
-                       uiSetRoundBox(12);
+       if (scroll & V2D_SCROLL_VERTICAL) {
+               /* only draw scrollbar when it doesn't fill the entire space */
+               if(vs->vertfull==0) {
+                       bTheme *btheme= U.themes.first;
+                       uiWidgetColors wcol= btheme->tui.wcol_scroll;
+                       rcti slider;
+                       int state;
                        
-                       gl_round_box_vertical_shade(GL_POLYGON, 
-                               vert.xmin+2, vs->vert_min-V2D_SCROLLER_HANDLE_SIZE, 
-                               vert.xmax-2, vs->vert_min+V2D_SCROLLER_HANDLE_SIZE, 
-                               V2D_SCROLLCAP_RAD, V2D_SCROLLCAP_SHADE, -V2D_SCROLLCAP_SHADE);
+                       slider.xmin= vert.xmin;
+                       slider.xmax= vert.xmax;
+                       slider.ymin= vs->vert_min;
+                       slider.ymax= vs->vert_max;
                        
-                       /* maximum handle */
-                       UI_ThemeColorShade(TH_SHADE1, darker);
-                       uiSetRoundBox(3);
+                       state= (v2d->scroll_ui & V2D_SCROLL_V_ACTIVE)?UI_SCROLL_PRESSED:0;
                        
-                       gl_round_box_vertical_shade(GL_POLYGON, 
-                               vert.xmin+2, vs->vert_max-V2D_SCROLLER_HANDLE_SIZE, 
-                               vert.xmax-2, vs->vert_max+V2D_SCROLLER_HANDLE_SIZE, 
-                               V2D_SCROLLCAP_RAD, V2D_SCROLLCAP_SHADE, -V2D_SCROLLCAP_SHADE);
+                       // TODO: disable this for button regions...
+                       if (!(v2d->keepzoom & V2D_LOCKZOOM_Y)) 
+                               state |= UI_SCROLL_ARROWS;
+                               
+                       uiWidgetScrollDraw(&wcol, &vert, &slider, state);
                }
                
+               
                /* scale indiators */
-               // XXX will need to update the font drawing when the new stuff comes in
-               if ((v2d->scroll & V2D_SCROLL_SCALE_VERTICAL) && (vs->grid)) {
+               if ((scroll & V2D_SCROLL_SCALE_VERTICAL) && (vs->grid)) {
                        View2DGrid *grid= vs->grid;
                        float fac, dfac, val;
                        
@@ -1516,41 +1720,24 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v
                                fac += 0.5f * dfac;
                                
                        /* draw vertical steps */
-                       for (; fac < vert.ymax; fac+= dfac, val += grid->dy) {
-                               scroll_printstr(vs, scene, (float)(vert.xmax)-14.0, fac, val, grid->powery, vs->yunits, 'v');
-                       }                       
+                       if (dfac > 0.0f) {
+                               
+                               BLF_default_rotation(90.0f);
+                               
+                               for (; fac < vert.ymax-10; fac+= dfac, val += grid->dy) {
+                                       
+                                       /* make prints look nicer for scrollers */
+                                       if(fac < vert.ymin+10)
+                                               continue;
+                                       
+                                       scroll_printstr(vs, scene, (float)(vert.xmax)-2.0f, fac, val, grid->powery, vs->yunits, 'v');
+                               }
+                               
+                               BLF_default_rotation(0.0f);
+                       }
                }       
-               
-               /* decoration outer bevel line */
-               UI_ThemeColorShade(TH_SHADE1, lighter);
-               if (v2d->scroll & V2D_SCROLL_RIGHT)
-                       sdrawline(vert.xmin, vert.ymin, vert.xmin, vert.ymax);
-               else if (v2d->scroll & V2D_SCROLL_LEFT)
-                       sdrawline(vert.xmax, vert.ymin, vert.xmax, vert.ymax);
-       }
-       
-       /* draw a 'sunken square' to cover up any overlapping corners resulting from intersection of overflowing scroller data */
-       if ((v2d->scroll & V2D_SCROLL_VERTICAL) && (v2d->scroll & V2D_SCROLL_HORIZONTAL)) {
-               /* set bounds (these should be right) */
-               corner.xmin= vert.xmin;
-               corner.xmax= vert.xmax;
-               corner.ymin= hor.ymin;
-               corner.ymax= hor.ymax;
-               
-               /* firstly, draw using background color to cover up any overlapping junk */
-               UI_ThemeColor(TH_SHADE1);
-               glRecti(corner.xmin, corner.ymin, corner.xmax, corner.ymax);
-               
-               /* now, draw suggestive highlighting... */
-                       /* first, dark lines on top to suggest scrollers overlap box */
-               UI_ThemeColorShade(TH_SHADE1, darker);
-               sdrawline(corner.xmin, corner.ymin, corner.xmin, corner.ymax);
-               sdrawline(corner.xmin, corner.ymax, corner.xmax, corner.ymax);
-                       /* now, light lines on bottom to show box is sunken in */
-               UI_ThemeColorShade(TH_SHADE1, lighter);
-               sdrawline(corner.xmax, corner.ymin, corner.xmax, corner.ymax);
-               sdrawline(corner.xmin, corner.ymin, corner.xmax, corner.ymin);
        }
+       
 }
 
 /* free temporary memory used for drawing scrollers */
@@ -1561,6 +1748,107 @@ void UI_view2d_scrollers_free(View2DScrollers *scrollers)
        MEM_freeN(scrollers);
 }
 
+/* *********************************************************************** */
+/* List View Utilities */
+
+/* Get the view-coordinates of the nominated cell 
+ *     - columnwidth, rowheight        = size of each 'cell'
+ *     - startx, starty                        = coordinates (in 'tot' rect space) that the list starts from
+ *                                                       This should be (0,0) for most views. However, for those where the starting row was offsetted
+ *                                                       (like for Animation Editor channel lists, to make the first entry more visible), these will be 
+ *                                                       the min-coordinates of the first item.
+ *     - column, row                           = the 2d-corodinates (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, float startx, float starty, int column, int row, rctf *rect)
+{
+       /* sanity checks */
+       if ELEM(NULL, v2d, rect)
+               return;
+       if ((columnwidth <= 0) && (rowheight <= 0)) {
+               rect->xmin= rect->xmax= 0.0f;
+               rect->ymin= rect->ymax= 0.0f;
+               return;
+       }
+       
+       /* x-coordinates */
+       rect->xmin= startx + (float)(columnwidth * column);
+       rect->xmax= startx + (float)(columnwidth * (column + 1));
+       
+       if ((v2d->align & V2D_ALIGN_NO_POS_X) && !(v2d->align & V2D_ALIGN_NO_NEG_X)) {
+               /* simply negate the values for the coordinates if in negative half */
+               rect->xmin = -rect->xmin;
+               rect->xmax = -rect->xmax;
+       }
+       
+       /* y-coordinates */
+       rect->ymin= starty + (float)(rowheight * row);
+       rect->ymax= starty + (float)(rowheight * (row + 1));
+       
+       if ((v2d->align & V2D_ALIGN_NO_POS_Y) && !(v2d->align & V2D_ALIGN_NO_NEG_Y)) {
+               /* simply negate the values for the coordinates if in negative half */
+               rect->ymin = -rect->ymin;
+               rect->ymax = -rect->ymax;
+       }
+}
+
+/* Get the 'cell' (row, column) that the given 2D-view coordinates (i.e. in 'tot' rect space) lie in.
+ *     - columnwidth, rowheight        = size of each 'cell'
+ *     - startx, starty                        = coordinates (in 'tot' rect space) that the list starts from
+ *                                                       This should be (0,0) for most views. However, for those where the starting row was offsetted
+ *                                                       (like for Animation Editor channel lists, to make the first entry more visible), these will be 
+ *                                                       the min-coordinates of the first item.
+ *     - 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, 
+                                               float viewx, float viewy, int *column, int *row)
+{
+       /* adjust view coordinates to be all positive ints, corrected for the start offset */
+       const int x= (int)(floor(fabs(viewx) + 0.5f) - startx); 
+       const int y= (int)(floor(fabs(viewy) + 0.5f) - starty);
+       
+       /* sizes must not be negative */
+       if ( (v2d == NULL) || ((columnwidth <= 0) && (rowheight <= 0)) ) {
+               if (column) *column= 0;
+               if (row) *row= 0;
+               
+               return;
+       }
+       
+       /* get column */
+       if ((column) && (columnwidth > 0))
+               *column= x / columnwidth;
+       else if (column)
+               *column= 0;
+       
+       /* get row */
+       if ((row) && (rowheight > 0))
+               *row= y / rowheight;
+       else if (row)
+               *row= 0;
+}
+
+/* Get the 'extreme' (min/max) column and row indices which are visible within the 'cur' rect 
+ *     - columnwidth, rowheight        = size of each 'cell'
+ *     - 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, 
+                                               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 */
+       if (v2d) {
+               /* min */
+               UI_view2d_listview_view_to_cell(v2d, columnwidth, rowheight, startx, starty, 
+                                       v2d->cur.xmin, v2d->cur.ymin, column_min, row_min);
+                                       
+               /* max*/
+               UI_view2d_listview_view_to_cell(v2d, columnwidth, rowheight, startx, starty, 
+                                       v2d->cur.xmax, v2d->cur.ymax, column_max, row_max);
+       }
+}
+
 /* *********************************************************************** */
 /* Coordinate Conversions */
 
@@ -1574,15 +1862,15 @@ void UI_view2d_region_to_view(View2D *v2d, int x, int y, float *viewx, float *vi
        float div, ofs;
 
        if (viewx) {
-               div= v2d->mask.xmax - v2d->mask.xmin;
-               ofs= v2d->mask.xmin;
+               div= (float)(v2d->mask.xmax - v2d->mask.xmin);
+               ofs= (float)v2d->mask.xmin;
                
                *viewx= v2d->cur.xmin + (v2d->cur.xmax-v2d->cur.xmin) * ((float)x - ofs) / div;
        }
 
        if (viewy) {
-               div= v2d->mask.ymax - v2d->mask.ymin;
-               ofs= v2d->mask.ymin;
+               div= (float)(v2d->mask.ymax - v2d->mask.ymin);
+               ofs= (float)v2d->mask.ymin;
                
                *viewy= v2d->cur.ymin + (v2d->cur.ymax - v2d->cur.ymin) * ((float)y - ofs) / div;
        }
@@ -1594,7 +1882,7 @@ void UI_view2d_region_to_view(View2D *v2d, int x, int y, float *viewx, float *vi
  *     - x,y                           = coordinates to convert
  *     - regionx,regiony       = resultant coordinates 
  */
-void UI_view2d_view_to_region(View2D *v2d, float x, float y, short *regionx, short *regiony)
+void UI_view2d_view_to_region(View2D *v2d, float x, float y, int *regionx, int *regiony)
 {
        /* set initial value in case coordinate lies outside of bounds */
        if (regionx)
@@ -1609,9 +1897,9 @@ void UI_view2d_view_to_region(View2D *v2d, float x, float y, short *regionx, sho
        /* check if values are within bounds */
        if ((x>=0.0f) && (x<=1.0f) && (y>=0.0f) && (y<=1.0f)) {
                if (regionx)
-                       *regionx= v2d->mask.xmin + x*(v2d->mask.xmax-v2d->mask.xmin);
+                       *regionx= (int)(v2d->mask.xmin + x*(v2d->mask.xmax-v2d->mask.xmin));
                if (regiony)
-                       *regiony= v2d->mask.ymin + y*(v2d->mask.ymax-v2d->mask.ymin);
+                       *regiony= (int)(v2d->mask.ymin + y*(v2d->mask.ymax-v2d->mask.ymin));
        }
 }
 
@@ -1621,7 +1909,7 @@ void UI_view2d_view_to_region(View2D *v2d, float x, float y, short *regionx, sho
  *     - x,y                           = coordinates to convert
  *     - regionx,regiony       = resultant coordinates 
  */
-void UI_view2d_to_region_no_clip(View2D *v2d, float x, float y, short *regionx, short *regiony)
+void UI_view2d_to_region_no_clip(View2D *v2d, float x, float y, int *regionx, int *regiony)
 {
        /* step 1: express given coordinates as proportional values */
        x= (x - v2d->cur.xmin) / (v2d->cur.xmax - v2d->cur.xmin);
@@ -1631,16 +1919,16 @@ void UI_view2d_to_region_no_clip(View2D *v2d, float x, float y, short *regionx,
        x= v2d->mask.xmin + x*(v2d->mask.xmax - v2d->mask.xmin);
        y= v2d->mask.ymin + y*(v2d->mask.ymax - v2d->mask.ymin);
        
-       /* although we don't clamp to lie within region bounds, we must avoid exceeding size of shorts */
+       /* although we don't clamp to lie within region bounds, we must avoid exceeding size of ints */
        if (regionx) {
-               if (x < -32760) *regionx= -32760;
-               else if(x > 32760) *regionx= 32760;
-               else *regionx= x;
+               if (x < INT_MIN) *regionx= INT_MIN;
+               else if(x > INT_MAX) *regionx= INT_MAX;
+               else *regionx= (int)x;
        }
        if (regiony) {
-               if (y < -32760) *regiony= -32760;
-               else if(y > 32760) *regiony= 32760;
-               else *regiony= y;
+               if (y < INT_MIN) *regiony= INT_MIN;
+               else if(y > INT_MAX) *regiony= INT_MAX;
+               else *regiony= (int)y;
        }
 }
 
@@ -1689,3 +1977,115 @@ void UI_view2d_getscale(View2D *v2d, float *x, float *y)
        if (y) *y = (v2d->mask.ymax - v2d->mask.ymin) / (v2d->cur.ymax - v2d->cur.ymin);
 }
 
+/* Check if mouse is within scrollers
+ *     - Returns appropriate code for match
+ *             'h' = in horizontal scroller
+ *             'v' = in vertical scroller
+ *             0 = not in scroller
+ *     
+ *     - x,y   = mouse coordinates in screen (not region) space
+ */
+short UI_view2d_mouse_in_scrollers (const bContext *C, View2D *v2d, int x, int y)
+{
+       ARegion *ar= CTX_wm_region(C);
+       int co[2];
+       int scroll= view2d_scroll_mapped(v2d->scroll);
+       
+       /* clamp x,y to region-coordinates first */
+       co[0]= x - ar->winrct.xmin;
+       co[1]= y - ar->winrct.ymin;
+       
+       /* check if within scrollbars */
+       if (scroll & V2D_SCROLL_HORIZONTAL) {
+               if (IN_2D_HORIZ_SCROLL(v2d, co)) return 'h';
+       }
+       if (scroll & V2D_SCROLL_VERTICAL) {
+               if (IN_2D_VERT_SCROLL(v2d, co)) return 'v';
+       }       
+       
+       /* not found */
+       return 0;
+}
+
+/* ******************* view2d text drawing cache ******************** */
+
+/* assumes caches are used correctly, so for time being no local storage in v2d */
+static ListBase strings= {NULL, NULL};
+
+typedef struct View2DString {
+       struct View2DString *next, *prev;
+       float col[4];
+       char str[128]; 
+       short mval[2];
+       rcti rect;
+} View2DString;
+
+
+void UI_view2d_text_cache_add(View2D *v2d, float x, float y, char *str)
+{
+       int mval[2];
+       
+       UI_view2d_view_to_region(v2d, x, y, mval, mval+1);
+       
+       if(mval[0]!=V2D_IS_CLIPPED && mval[1]!=V2D_IS_CLIPPED) {
+               /* use calloc, rect has to be zeroe'd */
+               View2DString *v2s= MEM_callocN(sizeof(View2DString), "View2DString");
+               
+               BLI_addtail(&strings, v2s);
+               BLI_strncpy(v2s->str, str, 128);
+               v2s->mval[0]= mval[0];
+               v2s->mval[1]= mval[1];
+               glGetFloatv(GL_CURRENT_COLOR, v2s->col);
+       }
+}
+
+/* no clip (yet) */
+void UI_view2d_text_cache_rectf(View2D *v2d, rctf *rect, char *str)
+{
+       View2DString *v2s= MEM_callocN(sizeof(View2DString), "View2DString");
+       
+       UI_view2d_to_region_no_clip(v2d, rect->xmin, rect->ymin, &v2s->rect.xmin, &v2s->rect.ymin);
+       UI_view2d_to_region_no_clip(v2d, rect->xmax, rect->ymax, &v2s->rect.xmax, &v2s->rect.ymax);
+       
+       BLI_addtail(&strings, v2s);
+       BLI_strncpy(v2s->str, str, 128);
+       glGetFloatv(GL_CURRENT_COLOR, v2s->col);
+}
+
+
+void UI_view2d_text_cache_draw(ARegion *ar)
+{
+       View2DString *v2s;
+       
+       //      wmPushMatrix();
+       ED_region_pixelspace(ar);
+       
+       for(v2s= strings.first; v2s; v2s= v2s->next) {
+               glColor3fv(v2s->col);
+               if(v2s->rect.xmin==v2s->rect.xmax)
+                       BLF_draw_default((float)v2s->mval[0], (float)v2s->mval[1], 0.0, v2s->str);
+               else {
+                       int xofs=0, yofs;
+                       
+                       yofs= ceil( 0.5f*(v2s->rect.ymax - v2s->rect.ymin - BLF_height_default("28")));
+                       if(yofs<1) yofs= 1;
+                       
+                       BLF_clipping(v2s->rect.xmin-4, v2s->rect.ymin-4, v2s->rect.xmax+4, v2s->rect.ymax+4);
+                       BLF_enable(BLF_CLIPPING);
+                       
+                       BLF_draw_default(v2s->rect.xmin+xofs, v2s->rect.ymin+yofs, 0.0f, v2s->str);
+
+                       BLF_disable(BLF_CLIPPING);
+               }
+       }
+       
+       //      wmPopMatrix();
+       
+       if(strings.first) 
+               BLI_freelistN(&strings);
+}
+
+
+/* ******************************************************** */
+
+