View2D: Scrollbar tweaks
authorJoshua Leung <aligorith@gmail.com>
Thu, 4 Dec 2008 05:37:55 +0000 (05:37 +0000)
committerJoshua Leung <aligorith@gmail.com>
Thu, 4 Dec 2008 05:37:55 +0000 (05:37 +0000)
* Added back vertical scale markings for vertical scrollbars. Currently untested (until IPO Editor can be put back in). Also, there was a special exception for the Sequencer, which will need to be checked when the time comes too.

* Fixed the display of frame numbers in scrollbars. Was caused by error in using an int, where a float was required (this is one place MSVC gives better warnings than GCC).

* Outliner horizontal scrollbar now displays a more useful range. The previous range was based on screen width, not width of content.

* Outliner horizontal scrollbar now draws with bevel-highlight line again. Was missed out in a previous commit.

* Added simple toggle Frames/Seconds operator to TimeLine to test if the View2D code is working right for this. This uses the same hotkey (TKEY) as it's counterpart (with a menu for input) did in previous incarnations of Blender.

source/blender/editors/include/UI_view2d.h
source/blender/editors/interface/view2d.c
source/blender/editors/space_outliner/space_outliner.c
source/blender/editors/space_time/space_time.c
source/blender/editors/space_time/time_ops.c

index b627c8061ba082c86485d07d6254b0aaa6d53480..07fc4e985190c33b023470f38783349ba4c2dc4b 100644 (file)
@@ -97,7 +97,7 @@ void UI_view2d_free_grid(View2DGrid *grid);
 
 /* scrollbar drawing */
 View2DScrollers *UI_view2d_calc_scrollers(const struct bContext *C, struct View2D *v2d, short xunits, short xclamp, short yunits, short yclamp);
-void UI_view2d_draw_scrollers(const struct bContext *C, struct View2D *v2d, View2DScrollers *scrollers, int flag);
+void UI_view2d_draw_scrollers(const struct bContext *C, struct View2D *v2d, View2DScrollers *scrollers);
 void UI_view2d_free_scrollers(View2DScrollers *scrollers);
 
 /* coordinate conversion */
index ac1ce45ab94301989e832ea3b2140b5003757fc7..577d3bc7289d1ffb5af354c2a52ce21913d9392b 100644 (file)
@@ -734,7 +734,7 @@ static void scroll_printstr(View2DScrollers *scrollers, float x, float y, float
 
 
 /* Draw scrollbars in the given 2d-region */
-void UI_view2d_draw_scrollers(const bContext *C, View2D *v2d, View2DScrollers *scrollers, int flag)
+void UI_view2d_draw_scrollers(const bContext *C, View2D *v2d, View2DScrollers *scrollers)
 {
        const int darker= -40, dark= 0, light= 20, lighter= 50;
        rcti vert, hor;
@@ -766,8 +766,7 @@ void UI_view2d_draw_scrollers(const bContext *C, View2D *v2d, View2DScrollers *s
                // XXX will need to update the font drawing when the new stuff comes in
                if (v2d->scroll & HOR_SCROLLGRID) {
                        View2DGrid *grid= scrollers->grid;
-                       float fac, dfac, fac2;
-                       int val;
+                       float fac, dfac, fac2, val;
                        
                        /* the numbers: convert grid->startx and -dx to scroll coordinates 
                         *      - fac is x-coordinate to draw to
@@ -777,8 +776,9 @@ void UI_view2d_draw_scrollers(const bContext *C, View2D *v2d, View2DScrollers *s
                        fac= hor.xmin + fac*(hor.xmax - hor.xmin);
                        
                        dfac= (grid->dx) / (v2d->cur.xmax - v2d->cur.xmin);
-                       dfac= dfac*(hor.xmax-hor.xmin);
+                       dfac= dfac * (hor.xmax - hor.xmin);
                        
+                       /* set starting value, and text color */
                        UI_ThemeColor(TH_TEXT);
                        val= grid->startx;
                        
@@ -828,7 +828,7 @@ void UI_view2d_draw_scrollers(const bContext *C, View2D *v2d, View2DScrollers *s
                
                /* decoration outer bevel line */
                UI_ThemeColorShade(TH_SHADE1, lighter);
-               if (v2d->scroll & B_SCROLL)
+               if (v2d->scroll & (B_SCROLL|B_SCROLLO))
                        sdrawline(hor.xmin, hor.ymax, hor.xmax, hor.ymax);
                else if (v2d->scroll & T_SCROLL)
                        sdrawline(hor.xmin, hor.ymin, hor.xmax, hor.ymin);
@@ -857,14 +857,41 @@ void UI_view2d_draw_scrollers(const bContext *C, View2D *v2d, View2DScrollers *s
                /* scale indiators */
                // XXX will need to update the font drawing when the new stuff comes in
                if (v2d->scroll & VERT_SCROLLGRID) {
+                       View2DGrid *grid= scrollers->grid;
+                       float fac, dfac, val;
+                       
+                       /* the numbers: convert grid->starty and dy to scroll coordinates 
+                        *      - fac is y-coordinate to draw to
+                        *      - dfac is gap between scale markings
+                        *      - these involve a correction for horizontal scrollbar
+                        *        NOTE: it's assumed that that scrollbar is there if this is involved!
+                        */
+                       fac= (grid->starty- v2d->cur.ymin) / (v2d->cur.ymax - v2d->cur.ymin);
+                       fac= (vert.ymin + SCROLLH) + fac*(vert.ymax - vert.ymin - SCROLLH);
                        
+                       dfac= (grid->dy) / (v2d->cur.ymax - v2d->cur.ymin);
+                       dfac= dfac * (vert.ymax - vert.ymin - SCROLLH);
+                       
+                       /* set starting value, and text color */
+                       UI_ThemeColor(TH_TEXT);
+                       val= grid->starty;
+                       
+                       /* if vertical clamping (to whole numbers) is used (i.e. in Sequencer), apply correction */
+                       // XXX only relevant to Sequencer, so need to review this when we port that code
+                       if (scrollers->yclamp == V2D_GRID_CLAMP)
+                               fac += 0.5f * dfac;
+                               
+                       /* draw vertical steps */
+                       for (; fac < vert.ymax; fac+= dfac, val += grid->dy) {
+                               scroll_printstr(scrollers, (float)(vert.xmax)-14.0, fac, val, grid->powery, scrollers->yunits, 'v');
+                       }                       
                }       
                
                /* decoration outer bevel line */
                UI_ThemeColorShade(TH_SHADE1, lighter);
                if (v2d->scroll & R_SCROLL)
                        sdrawline(vert.xmin, vert.ymin, vert.xmin, vert.ymax);
-               else 
+               else if (v2d->scroll & L_SCROLL)
                        sdrawline(vert.xmax, vert.ymin, vert.xmax, vert.ymax);
        }
 }
index 9c92e2320dd6c14e3963be1609898322b4ea6a05..2518d809d297fc24761a6f05ac40304813d0677c 100644 (file)
@@ -348,8 +348,8 @@ static void outliner_main_area_draw(const bContext *C, ARegion *ar)
        glClear(GL_COLOR_BUFFER_BIT);
 
        // XXX width should be depend on max length of items (like height)...
-       awidth= width= ar->winrct.xmax - ar->winrct.xmin;
-       aheight= height= ar->winrct.ymax - ar->winrct.ymin;
+       awidth= width= ar->winrct.xmax - ar->winrct.xmin + 1;
+       aheight= height= ar->winrct.ymax - ar->winrct.ymin + 1;
        
        UI_view2d_update_size(v2d, awidth, aheight);
        
@@ -394,6 +394,7 @@ static void outliner_main_area_draw(const bContext *C, ARegion *ar)
 
        if ((rows*ROW_HEIGHT) > height)
                height= rows * ROW_HEIGHT;
+       width= (cols + 1) * COLUMN_WIDTH;
        
        /* need to validate view2d after updating size of tot */
        v2d->tot.xmin= 0;
@@ -423,8 +424,8 @@ static void outliner_main_area_draw(const bContext *C, ARegion *ar)
        UI_view2d_view_restore(C);
        
        /* scrollers */
-       scrollers= UI_view2d_calc_scrollers(C, v2d, 0, 0, 0, 0); // XXX last two vars here are useless
-       UI_view2d_draw_scrollers(C, v2d, scrollers, (0));
+       scrollers= UI_view2d_calc_scrollers(C, v2d, 0, 0, 0, 0);
+       UI_view2d_draw_scrollers(C, v2d, scrollers);
        UI_view2d_free_scrollers(scrollers);
 }
 
index fffbbb5f1aba0900a52f68221f8d9d54745c1286..b4d5986ba699167f88229946dd4547c71e8be6b0 100644 (file)
@@ -119,9 +119,10 @@ static void time_main_area_draw(const bContext *C, ARegion *ar)
        View2DScrollers *scrollers;
        float col[3];
        int unit, winx, winy;
-
-       winx= ar->winrct.xmax-ar->winrct.xmin;
-       winy= ar->winrct.ymax-ar->winrct.ymin;
+       
+       // XXX this should become stored in regions too...
+       winx= ar->winrct.xmax - ar->winrct.xmin + 1;
+       winy= ar->winrct.ymax - ar->winrct.ymin + 1;
        
        UI_view2d_update_size(v2d, winx, winy);
 
@@ -153,7 +154,7 @@ static void time_main_area_draw(const bContext *C, ARegion *ar)
        
        /* scrollers */
        scrollers= UI_view2d_calc_scrollers(C, v2d, unit, V2D_GRID_CLAMP, 0, 0);
-       UI_view2d_draw_scrollers(C, v2d, scrollers, (0));
+       UI_view2d_draw_scrollers(C, v2d, scrollers);
        UI_view2d_free_scrollers(scrollers);
 }
 
index 86ff9d9b0abec1c8cd81889c875d6a9801c7a844..9b7af8b3f45718c61af4cf9ad01fbdd58ead782c 100644 (file)
@@ -39,6 +39,7 @@
 #include "BLI_blenlib.h"
 
 #include "BKE_global.h"
+#include "BKE_utildefines.h"
 
 #include "UI_interface.h"
 #include "UI_view2d.h"
@@ -175,16 +176,46 @@ void ED_TIME_OT_change_frame(wmOperatorType *ot)
        prop= RNA_def_property(ot->srna, "frame", PROP_INT, PROP_NONE);
 }
 
+/* ****************** time display toggle operator ****************************/
+
+static int toggle_time_exec(bContext *C, wmOperator *op)
+{
+       SpaceTime *stime;
+       
+       if (ELEM(NULL, C->area, C->area->spacedata.first))
+               return OPERATOR_CANCELLED;
+       
+       /* simply toggle draw frames flag for now */
+       // XXX in past, this displayed menu to choose... (for later!)
+       stime= C->area->spacedata.first;
+       stime->flag ^= TIME_DRAWFRAMES;
+       
+       return OPERATOR_FINISHED;
+}
+
+void ED_TIME_OT_toggle_time(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Toggle Frames/Seconds";
+       ot->idname= "ED_TIME_OT_toggle_time";
+       
+       /* api callbacks */
+       ot->exec= toggle_time_exec;
+}
+
 /* ************************** registration **********************************/
 
 void time_operatortypes(void)
 {
        WM_operatortype_append(ED_TIME_OT_change_frame);
+       WM_operatortype_append(ED_TIME_OT_toggle_time);
 }
 
 void time_keymap(wmWindowManager *wm)
 {
        WM_keymap_verify_item(&wm->timekeymap, "ED_TIME_OT_change_frame", LEFTMOUSE, KM_PRESS, 0, 0);
+       WM_keymap_verify_item(&wm->timekeymap, "ED_TIME_OT_toggle_time", TKEY, KM_PRESS, 0, 0);
+       
 
        /* markers (XXX move to function?) */
        WM_keymap_verify_item(&wm->timekeymap, "ED_MARKER_OT_add", MKEY, KM_PRESS, 0, 0);