Fix drawing of MENU buttons with only an icon, was not aligned right
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 28 Sep 2009 15:59:09 +0000 (15:59 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 28 Sep 2009 15:59:09 +0000 (15:59 +0000)
and showing unneeded triangles (+ buttons in Boids Brain).

source/blender/editors/include/UI_interface.h
source/blender/editors/interface/interface.c
source/blender/editors/interface/interface_intern.h
source/blender/editors/interface/interface_layout.c
source/blender/editors/interface/interface_widgets.c

index dc4744c9832f73a37b5048f05a501905e4810511..e17629916763cb721014f842c3805cf99727126d 100644 (file)
@@ -424,6 +424,7 @@ int uiIconFromID(struct ID *id);
 uiBut *uiDefPulldownBut(uiBlock *block, uiBlockCreateFunc func, void *arg, char *str, short x1, short y1, short x2, short y2, char *tip);
 uiBut *uiDefMenuBut(uiBlock *block, uiMenuCreateFunc func, void *arg, char *str, short x1, short y1, short x2, short y2, char *tip);
 uiBut *uiDefIconTextMenuBut(uiBlock *block, uiMenuCreateFunc func, void *arg, int icon, char *str, short x1, short y1, short x2, short y2, char *tip);
+uiBut *uiDefIconMenuBut(uiBlock *block, uiMenuCreateFunc func, void *arg, int icon, short x1, short y1, short x2, short y2, char *tip);
 
 uiBut *uiDefBlockBut(uiBlock *block, uiBlockCreateFunc func, void *func_arg1, char *str, short x1, short y1, short x2, short y2, char *tip);
 uiBut *uiDefBlockButN(uiBlock *block, uiBlockCreateFunc func, void *argN, char *str, short x1, short y1, short x2, short y2, char *tip);
index 1b05958b67918a111eaeeeeee968f899991cfc4f..3e5cc0e6d67575714c26152b09af45eb4dd05a9d 100644 (file)
@@ -3064,6 +3064,20 @@ uiBut *uiDefIconTextMenuBut(uiBlock *block, uiMenuCreateFunc func, void *arg, in
        return but;
 }
 
+uiBut *uiDefIconMenuBut(uiBlock *block, uiMenuCreateFunc func, void *arg, int icon, short x1, short y1, short x2, short y2, char *tip)
+{
+       uiBut *but= ui_def_but(block, PULLDOWN, 0, "", x1, y1, x2, y2, arg, 0.0, 0.0, 0.0, 0.0, tip);
+
+       but->icon= (BIFIconID) icon;
+       but->flag |= UI_HAS_ICON;
+       but->flag &=~ UI_ICON_LEFT;
+
+       but->menu_create_func= func;
+       ui_check_but(but);
+
+       return but;
+}
+
 /* Block button containing both string label and icon */
 uiBut *uiDefIconTextBlockBut(uiBlock *block, uiBlockCreateFunc func, void *arg, int icon, char *str, short x1, short y1, short x2, short y2, char *tip)
 {
index 885005ba06e5dadd1450930f57cb23b477b3165a..292c85e9072512dfacc1456af05e2c41dc492957 100644 (file)
@@ -72,6 +72,7 @@ typedef enum {
        
        /* menus */
        UI_WTYPE_MENU_RADIO,
+       UI_WTYPE_MENU_ICON_RADIO,
        UI_WTYPE_MENU_POINTER_LINK,
        
        UI_WTYPE_PULLDOWN,
index e3c392a145ebe4e970181f21eea48fbb17ec08ab..64a45efc5518f1d030db73397df4d856cc2619e5 100644 (file)
@@ -1183,8 +1183,10 @@ static void ui_item_menu(uiLayout *layout, char *name, int icon, uiMenuCreateFun
        if(layout->root->type == UI_LAYOUT_HEADER) /* ugly .. */
                w -= 10;
 
-       if(icon)
+       if(name[0] && icon)
                but= uiDefIconTextMenuBut(block, func, arg, icon, (char*)name, 0, 0, w, h, "");
+       else if(icon)
+               but= uiDefIconMenuBut(block, func, arg, icon, 0, 0, w, h, "");
        else
                but= uiDefMenuBut(block, func, arg, (char*)name, 0, 0, w, h, "");
 
index ac8750f84e6600c8a7af1c48bea4da316bc1ef8d..d9a6c50315adb31d6159efdceea2d7c996061cfa 100644 (file)
@@ -1973,7 +1973,19 @@ static void widget_menubut(uiWidgetColors *wcol, rcti *rect, int state, int roun
        
        /* text space */
        rect->xmax -= (rect->ymax-rect->ymin);
+}
+
+static void widget_menuiconbut(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
+{
+       uiWidgetBase wtb;
+       
+       widget_init(&wtb);
+       
+       /* half rounded */
+       round_box_edges(&wtb, roundboxalign, rect, 4.0f);
        
+       /* decoration */
+       widgetbase_draw(&wtb, wcol);
 }
 
 static void widget_pulldownbut(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
@@ -2209,13 +2221,17 @@ static uiWidgetType *widget_type(uiWidgetTypeEnum type)
                        wt.wcol_theme= &btheme->tui.wcol_menu;
                        wt.draw= widget_menubut;
                        break;
+
+               case UI_WTYPE_MENU_ICON_RADIO:
+                       wt.wcol_theme= &btheme->tui.wcol_menu;
+                       wt.draw= widget_menuiconbut;
+                       break;
                        
                case UI_WTYPE_MENU_POINTER_LINK:
                        wt.wcol_theme= &btheme->tui.wcol_menu;
                        wt.draw= widget_menubut;
                        break;
                        
-                       
                case UI_WTYPE_PULLDOWN:
                        wt.wcol_theme= &btheme->tui.wcol_pulldown;
                        wt.draw= widget_pulldownbut;
@@ -2405,7 +2421,10 @@ void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rct
                        case MENU:
                        case BLOCK:
                        case ICONTEXTROW:
-                               wt= widget_type(UI_WTYPE_MENU_RADIO);
+                               if(!but->str[0] && but->icon)
+                                       wt= widget_type(UI_WTYPE_MENU_ICON_RADIO);
+                               else
+                                       wt= widget_type(UI_WTYPE_MENU_RADIO);
                                break;
                                
                        case PULLDOWN: