2.5
authorTon Roosendaal <ton@blender.org>
Thu, 30 Apr 2009 17:27:30 +0000 (17:27 +0000)
committerTon Roosendaal <ton@blender.org>
Thu, 30 Apr 2009 17:27:30 +0000 (17:27 +0000)
Cleanup of conventions for icon placement in menus.

Old code only allowed 1 icon per menu, forcing to pass on the sublevel
menu icon with exception handling.

Now sublevel icons are drawn automatically, allowing to add an icon
before name too. (Check shift+a menu)

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

index 26042f70b4af6ef9a92df9e92f87c44f2eeda8d2..0e34b3702ed60f7d09feaa7dcff0be847ce41640 100644 (file)
@@ -110,7 +110,7 @@ typedef struct uiLayout uiLayout;
 /* but->flag */
 #define UI_TEXT_LEFT   64
 #define UI_ICON_LEFT   128
-#define UI_ICON_RIGHT  256
+#define UI_ICON_SUBMENU        256
        /* control for button type block */
 #define UI_MAKE_TOP            512
 #define UI_MAKE_DOWN   1024
index 8a1086386e1e9d3bffa2a0c4bcc57567ae757723..fd082c34238fe6c83fd2bc195cfd58c474f34d12 100644 (file)
@@ -2741,7 +2741,7 @@ uiBut *uiDefMenuSep(uiBlock *block)
 uiBut *uiDefMenuSub(uiBlock *block, uiBlockCreateFunc func, char *name)
 {
        int y= ui_menu_y(block) - MENU_ITEM_HEIGHT;
-       return uiDefIconTextBlockBut(block, func, NULL, ICON_RIGHTARROW_THIN, name, 0, y, MENU_WIDTH, MENU_ITEM_HEIGHT-1, "");
+       return uiDefIconTextBlockBut(block, func, NULL, ICON_BLANK1, name, 0, y, MENU_WIDTH, MENU_ITEM_HEIGHT-1, "");
 }
 
 uiBut *uiDefMenuTogR(uiBlock *block, PointerRNA *ptr, char *propname, char *propvalue, char *name)
@@ -2991,7 +2991,7 @@ uiBut *uiDefIconTextMenuBut(uiBlock *block, uiMenuCreateFunc func, void *arg, in
        but->flag|= UI_HAS_ICON;
 
        but->flag|= UI_ICON_LEFT;
-       but->flag|= UI_ICON_RIGHT;
+       but->flag|= UI_ICON_SUBMENU;
 
        but->menu_create_func= func;
        ui_check_but(but);
@@ -3004,11 +3004,13 @@ uiBut *uiDefIconTextBlockBut(uiBlock *block, uiBlockCreateFunc func, void *arg,
 {
        uiBut *but= ui_def_but(block, BLOCK, 0, str, x1, y1, x2, y2, arg, 0.0, 0.0, 0.0, 0.0, tip);
        
-       but->icon= (BIFIconID) icon;
+       /* XXX temp, old menu calls pass on icon arrow, which is now UI_ICON_SUBMENU flag */
+       if(icon!=ICON_RIGHTARROW_THIN) {
+               but->icon= (BIFIconID) icon;
+               but->flag|= UI_ICON_LEFT;
+       }
        but->flag|= UI_HAS_ICON;
-
-       but->flag|= UI_ICON_LEFT;
-       but->flag|= UI_ICON_RIGHT;
+       but->flag|= UI_ICON_SUBMENU;
 
        but->block_create_func= func;
        ui_check_but(but);
@@ -3025,7 +3027,7 @@ uiBut *uiDefIconBlockBut(uiBlock *block, uiBlockCreateFunc func, void *arg, int
        but->flag|= UI_HAS_ICON;
        
        but->flag|= UI_ICON_LEFT;
-       but->flag|= UI_ICON_RIGHT;
+       but->flag|= UI_ICON_SUBMENU;
        
        but->block_create_func= func;
        ui_check_but(but);
index 6ed02a38ca1bbae1f2c9c85caa35457c8d4d1687..6a02e99239022bc8cc7e98a2d269f72a780c304c 100644 (file)
@@ -887,9 +887,6 @@ void uiItemMenuF(uiLayout *layout, char *name, int icon, uiMenuCreateFunc func)
 
        menuitem= MEM_callocN(sizeof(uiItemMenu), "uiItemMenu");
 
-       if(!icon && layout->type == UI_LAYOUT_MENU)
-               icon= ICON_RIGHTARROW_THIN,
-
        ui_item_name(&menuitem->item, name);
        menuitem->item.icon= icon;
        menuitem->item.type= ITEM_MENU;
@@ -931,8 +928,6 @@ void uiItemMenuEnumO(uiLayout *layout, char *name, int icon, char *opname, char
 
        menuitem= MEM_callocN(sizeof(uiItemMenu), "uiItemMenu");
 
-       if(!icon && layout->type == UI_LAYOUT_MENU)
-               icon= ICON_RIGHTARROW_THIN;
        if(!name)
                name= ot->name;
 
@@ -978,8 +973,6 @@ void uiItemMenuEnumR(uiLayout *layout, char *name, int icon, struct PointerRNA *
 
        menuitem= MEM_callocN(sizeof(uiItemMenu), "uiItemMenu");
 
-       if(!icon && layout->type == UI_LAYOUT_MENU)
-               icon= ICON_RIGHTARROW_THIN;
        if(!name)
                name= (char*)RNA_property_ui_name(prop);
 
index baf5486ac3a6c1c16c4b64ce4e2ff380a1a75462..f557b2e97a472fcc475c1e5d238c34e2dc2b5f21 100644 (file)
@@ -633,7 +633,7 @@ static void widget_draw_icon(uiBut *but, BIFIconID icon, int blend, rcti *rect)
        float xs=0, ys=0, aspect, height;
        
        /* this icon doesn't need draw... */
-       if(icon==ICON_BLANK1) return;
+       if(icon==ICON_BLANK1 && (but->flag & UI_ICON_SUBMENU)==0) return;
        
        /* we need aspect from block, for menus... these buttons are scaled in uiPositionBlock() */
        aspect= but->block->aspect;
@@ -650,45 +650,49 @@ static void widget_draw_icon(uiBut *but, BIFIconID icon, int blend, rcti *rect)
        else
                height= ICON_HEIGHT;
        
-       if(but->flag & UI_ICON_LEFT) {
-               if (but->type==BUT_TOGDUAL) {
-                       if (but->drawstr[0]) {
-                               xs= rect->xmin-1.0;
-                       } else {
-                               xs= (rect->xmin+rect->xmax- height)/2.0;
+       /* calculate blend color */
+       if ELEM3(but->type, TOG, ROW, TOGN) {
+               if(but->flag & UI_SELECT);
+               else if(but->flag & UI_ACTIVE);
+               else blend= -60;
+       }
+       
+       glEnable(GL_BLEND);
+       
+       if(icon && icon!=ICON_BLANK1) {
+               if(but->flag & UI_ICON_LEFT) {
+                       if (but->type==BUT_TOGDUAL) {
+                               if (but->drawstr[0]) {
+                                       xs= rect->xmin-1.0;
+                               } else {
+                                       xs= (rect->xmin+rect->xmax- height)/2.0;
+                               }
                        }
-               }
-               else if (but->block->flag & UI_BLOCK_LOOP) {
-                       xs= rect->xmin+1.0;
-               }
-               else if ((but->type==ICONROW) || (but->type==ICONTEXTROW)) {
-                       xs= rect->xmin+3.0;
+                       else if (but->block->flag & UI_BLOCK_LOOP) {
+                               xs= rect->xmin+1.0;
+                       }
+                       else if ((but->type==ICONROW) || (but->type==ICONTEXTROW)) {
+                               xs= rect->xmin+3.0;
+                       }
+                       else {
+                               xs= rect->xmin+4.0;
+                       }
+                       ys= (rect->ymin+rect->ymax- height)/2.0;
                }
                else {
-                       xs= rect->xmin+4.0;
+                       xs= (rect->xmin+rect->xmax- height)/2.0;
+                       ys= (rect->ymin+rect->ymax- height)/2.0;
                }
-               ys= (rect->ymin+rect->ymax- height)/2.0;
+       
+               UI_icon_draw_aspect_blended(xs, ys, icon, aspect, blend);
        }
-       if(but->flag & UI_ICON_RIGHT) {
+       
+       if(but->flag & UI_ICON_SUBMENU) {
                xs= rect->xmax-17.0;
                ys= (rect->ymin+rect->ymax- height)/2.0;
+               
+               UI_icon_draw_aspect_blended(xs, ys, ICON_RIGHTARROW_THIN, aspect, blend);
        }
-       if (!((but->flag & UI_ICON_RIGHT) || (but->flag & UI_ICON_LEFT))) {
-               xs= (rect->xmin+rect->xmax- height)/2.0;
-               ys= (rect->ymin+rect->ymax- height)/2.0;
-       }
-       
-       glEnable(GL_BLEND);
-       
-       /* calculate blend color */
-       if ELEM3(but->type, TOG, ROW, TOGN) {
-               if(but->flag & UI_SELECT);
-               else if(but->flag & UI_ACTIVE);
-               else blend= -60;
-       }
-       if (but->flag & UI_BUT_DISABLED) blend = -100;
-       
-       UI_icon_draw_aspect_blended(xs, ys, icon, aspect, blend);
        
        glDisable(GL_BLEND);
 }
@@ -843,7 +847,7 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB
                        /* If there's an icon too (made with uiDefIconTextBut) then draw the icon
                        and offset the text label to accomodate it */
                        
-                       if ( (but->flag & UI_HAS_ICON) && (but->flag & UI_ICON_LEFT) ) {
+                       if (but->flag & UI_HAS_ICON) {
                                widget_draw_icon(but, but->icon, 0, rect);
                                
                                rect->xmin += UI_icon_get_width(but->icon);