2.5
authorTon Roosendaal <ton@blender.org>
Fri, 3 Jul 2009 13:21:09 +0000 (13:21 +0000)
committerTon Roosendaal <ton@blender.org>
Fri, 3 Jul 2009 13:21:09 +0000 (13:21 +0000)
More scroller work:

- Added subtle arrow widgets to denote a scroller can zoom the view.
- Made zoom symmetric (old convention to only zoom "one side" just
  worked badly)

source/blender/editors/include/UI_interface.h
source/blender/editors/include/UI_view2d.h
source/blender/editors/interface/interface_widgets.c
source/blender/editors/interface/view2d.c
source/blender/editors/interface/view2d_ops.c
source/blender/editors/space_text/text_draw.c

index b7c13505d2e7b1ae5126d1e7c732fd5973ae80ed..cf284e7b111d42db3556b09fbdcd66630d65d92b 100644 (file)
@@ -216,9 +216,11 @@ void uiRoundRect(float minx, float miny, float maxx, float maxy, float rad);
 void uiDrawMenuBox(float minx, float miny, float maxx, float maxy, short flag, short direction);
 void uiDrawBoxShadow(unsigned char alpha, float minx, float miny, float maxx, float maxy);
 
+/* state for scrolldrawing */
+#define UI_SCROLL_PRESSED      1
+#define UI_SCROLL_ARROWS       2
 void uiWidgetScrollDraw(struct uiWidgetColors *wcol, struct rcti *rect, struct rcti *slider, int state);
 
-
 /* Menu Callbacks */
 
 typedef void (*uiMenuCreateFunc)(struct bContext *C, struct uiLayout *layout, void *arg1);
index b5e675af64ec7a6de4d6822cb6be721916e19f6f..537c1b42b972868a65b5b6c8b009bee4b9ef84a7 100644 (file)
@@ -101,8 +101,8 @@ enum {
 #define V2D_SCROLL_HEIGHT      17
 #define V2D_SCROLL_WIDTH       17
 
-/* half the size (in pixels) of scroller 'handles' */
-#define V2D_SCROLLER_HANDLE_SIZE       5
+/* scroller 'handles' hotspot radius for mouse */
+#define V2D_SCROLLER_HANDLE_SIZE       12
 
 /* ------ Define for UI_view2d_sync ----- */
 
index b63c7f105c3b4ecd68a8b6d22dfe99d152d3a405..2cd7c1d61cd0c22cd59f46f2fd719e1ed35aefe9 100644 (file)
@@ -435,22 +435,33 @@ static void round_box_edges(uiWidgetBase *wt, int roundboxalign, rcti *rect, flo
 /* based on button rect, return scaled array of triangles */
 static void widget_num_tria(uiWidgetTrias *tria, rcti *rect, float triasize, char where)
 {
-       float centx, centy, size;
-       int a;
+       float centx, centy, sizex, sizey, minsize;
+       int a, i1=0, i2=1;
+       
+       minsize= MIN2(rect->xmax-rect->xmin, rect->ymax-rect->ymin);
        
        /* center position and size */
-       centx= (float)rect->xmin + 0.5f*(rect->ymax-rect->ymin);
-       centy= (float)rect->ymin + 0.5f*(rect->ymax-rect->ymin);
-       size= -0.5f*triasize*(rect->ymax-rect->ymin);
+       centx= (float)rect->xmin + 0.5f*minsize;
+       centy= (float)rect->ymin + 0.5f*minsize;
+       sizex= sizey= -0.5f*triasize*minsize;
 
        if(where=='r') {
-               centx= (float)rect->xmax - 0.5f*(rect->ymax-rect->ymin);
-               size= -size;
+               centx= (float)rect->xmax - 0.5f*minsize;
+               sizex= -sizex;
+       }       
+       else if(where=='t') {
+               centy= (float)rect->ymax - 0.5f*minsize;
+               sizey= -sizey;
+               i2=0; i1= 1;
+       }       
+       else if(where=='b') {
+               sizex= -sizex;
+               i2=0; i1= 1;
        }       
        
        for(a=0; a<19; a++) {
-               tria->vec[a][0]= size*num_tria_vert[a][0] + centx;
-               tria->vec[a][1]= size*num_tria_vert[a][1] + centy;
+               tria->vec[a][0]= sizex*num_tria_vert[a][i1] + centx;
+               tria->vec[a][1]= sizey*num_tria_vert[a][i2] + centy;
        }
        
        tria->tot= 19;
@@ -1576,7 +1587,7 @@ static void widget_numbut(uiWidgetColors *wcol, rcti *rect, int state, int round
        
        /* decoration */
        if(!(state & UI_TEXTINPUT)) {
-               widget_num_tria(&wtb.tria1, rect, 0.6f, 0);
+               widget_num_tria(&wtb.tria1, rect, 0.6f, 'l');
                widget_num_tria(&wtb.tria2, rect, 0.6f, 'r');
        }       
        widgetbase_draw(&wtb, wcol);
@@ -1676,15 +1687,30 @@ void uiWidgetScrollDraw(uiWidgetColors *wcol, rcti *rect, rcti *slider, int stat
                        wcol->shadetop+= 20;    /* XXX violates themes... */
                else wcol->shadedown+= 20;
                
-               if(state & UI_SELECT)
+               if(state & UI_SCROLL_PRESSED)
                        SWAP(short, wcol->shadetop, wcol->shadedown);
 
                /* draw */
                wtb.emboss= 0; /* only emboss once */
                
                round_box_edges(&wtb, 15, slider, rad); 
-               widgetbase_draw(&wtb, wcol);
                
+               if(state & UI_SCROLL_ARROWS) {
+                       if(wcol->item[0] > 48) wcol->item[0]-= 48;
+                       if(wcol->item[1] > 48) wcol->item[1]-= 48;
+                       if(wcol->item[2] > 48) wcol->item[2]-= 48;
+                       wcol->item[3]= 255;
+                       
+                       if(horizontal) {
+                               widget_num_tria(&wtb.tria1, slider, 0.6f, 'l');
+                               widget_num_tria(&wtb.tria2, slider, 0.6f, 'r');
+                       }
+                       else {
+                               widget_num_tria(&wtb.tria1, slider, 0.6f, 'b');
+                               widget_num_tria(&wtb.tria2, slider, 0.6f, 't');
+                       }
+               }
+               widgetbase_draw(&wtb, wcol);
        }       
 }
 
@@ -1718,6 +1744,10 @@ static void widget_scroll(uiBut *but, uiWidgetColors *wcol, rcti *rect, int stat
                rect1.ymin= rect1.ymax - ceil(fac*(but->a1 - but->softmin));
        }
 
+       if(state & UI_SELECT)
+               state= UI_SCROLL_PRESSED;
+       else
+               state= 0;
        uiWidgetScrollDraw(wcol, rect, &rect1, state);
 
 }
index 705963981c86bd72d6e89d461518edca58b9ac4d..11714df0491b5d6f3960631d51e3be7459ee6460 100644 (file)
@@ -1207,14 +1207,14 @@ void UI_view2d_grid_free(View2DGrid *grid)
  *                For now, we don't need to have a separate (internal) header for structs like this...
  */
 struct View2DScrollers {
-       rcti hor, vert;                 /* exact size of slider backdrop */
-       int horfull, vertfull;  /* set if sliders are full, we don't draw them */
-       
                /* 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 */
@@ -1455,13 +1455,17 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v
                        bTheme *btheme= U.themes.first;
                        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;
                        
-                       uiWidgetScrollDraw(&wcol, &hor, &slider, (v2d->scroll_ui & V2D_SCROLL_H_ACTIVE)?UI_SELECT:0);
+                       state= (v2d->scroll_ui & V2D_SCROLL_H_ACTIVE)?UI_SCROLL_PRESSED:0;
+                       if (!(v2d->keepzoom & V2D_LOCKZOOM_X))
+                               state |= UI_SCROLL_ARROWS;
+                       uiWidgetScrollDraw(&wcol, &hor, &slider, state);
                }
                
                /* scale indicators */
@@ -1547,13 +1551,17 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v
                        bTheme *btheme= U.themes.first;
                        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;
                        
-                       uiWidgetScrollDraw(&wcol, &vert, &slider, (v2d->scroll_ui & V2D_SCROLL_V_ACTIVE)?UI_SELECT:0);
+                       state= (v2d->scroll_ui & V2D_SCROLL_V_ACTIVE)?UI_SCROLL_PRESSED:0;
+                       if (!(v2d->keepzoom & V2D_LOCKZOOM_Y))
+                               state |= UI_SCROLL_ARROWS;
+                       uiWidgetScrollDraw(&wcol, &vert, &slider, state);
                }
                
                
index ae89e215a034e69037633cf983842e95a22a0336..101d89da618180636cd1c9e4812d0156e6f5b7a5 100644 (file)
@@ -1010,15 +1010,7 @@ static short mouse_in_scroller_handle(int mouse, int sc_min, int sc_max, int sh_
        
        
        if (in_view == 0) {
-               /* handles are only activated if the mouse is within the relative quater lengths of the scroller */
-               int qLen = (sc_max + sc_min) / 4;
-               
-               if (mouse >= (sc_max - qLen))
-                       return SCROLLHANDLE_MAX;
-               else if (mouse <= qLen)
-                       return SCROLLHANDLE_MIN;
-               else
-                       return SCROLLHANDLE_BAR;
+               return SCROLLHANDLE_BAR;
        }
        
        /* check if mouse is in or past either handle */
@@ -1128,14 +1120,14 @@ static void scroller_activate_apply(bContext *C, wmOperator *op)
        /* type of movement */
        switch (vsm->zone) {
                case SCROLLHANDLE_MIN:
+               case SCROLLHANDLE_MAX:
+                       
                        /* only expand view on axis if zoom is allowed */
                        if ((vsm->scroller == 'h') && !(v2d->keepzoom & V2D_LOCKZOOM_X))
                                v2d->cur.xmin -= temp;
                        if ((vsm->scroller == 'v') && !(v2d->keepzoom & V2D_LOCKZOOM_Y))
                                v2d->cur.ymin -= temp;
-                       break;
                
-               case SCROLLHANDLE_MAX:
                        /* only expand view on axis if zoom is allowed */
                        if ((vsm->scroller == 'h') && !(v2d->keepzoom & V2D_LOCKZOOM_X))
                                v2d->cur.xmax += temp;
index 03b6a8dd86266eb088b7c101f4cf620a2c523b65..48c14804b13c5bc99343ce1d1f4e608c441554de 100644 (file)
@@ -826,7 +826,7 @@ static void draw_textscroll(SpaceText *st, ARegion *ar, rcti *scroll)
 
 //     uiEmboss(st->txtbar.xmin, st->txtbar.ymin, st->txtbar.xmax, st->txtbar.ymax, st->flags & ST_SCROLL_SELECT);
        
-       uiWidgetScrollDraw(&wcol, scroll, &st->txtbar, (st->flags & ST_SCROLL_SELECT)?1:0);
+       uiWidgetScrollDraw(&wcol, scroll, &st->txtbar, (st->flags & ST_SCROLL_SELECT)?UI_SCROLL_PRESSED:0);
 
        uiSetRoundBox(15);
        rad= 0.4f*MIN2(st->txtscroll.xmax - st->txtscroll.xmin, st->txtscroll.ymax - st->txtscroll.ymin);