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)
This commit is contained in:
2009-04-30 17:27:30 +00:00
parent 3ee6c11e31
commit d576ee99ed
4 changed files with 48 additions and 49 deletions

View 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

View 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);

View 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);

View 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;
}
}
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;
}
if(but->flag & UI_ICON_RIGHT) {
xs= rect->xmax-17.0;
ys= (rect->ymin+rect->ymax- height)/2.0;
}
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);
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 {
xs= rect->xmin+4.0;
}
ys= (rect->ymin+rect->ymax- height)/2.0;
}
else {
xs= (rect->xmin+rect->xmax- 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_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);
}
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);