diff options
Diffstat (limited to 'source/blender/editors/interface/interface_widgets.c')
-rw-r--r-- | source/blender/editors/interface/interface_widgets.c | 121 |
1 files changed, 87 insertions, 34 deletions
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index ae40b01c77d..064fa14a75e 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -42,6 +42,8 @@ #include "BLF_api.h" +#include "ED_node.h" + #include "UI_interface.h" #include "UI_interface_icons.h" @@ -2394,6 +2396,30 @@ static void widget_draw_extra_icons(const uiWidgetColors *wcol, } } +static void widget_draw_node_link_socket(const uiWidgetColors *wcol, + const rcti *rect, + uiBut *but, + float alpha) +{ + /* Node socket pointer can be passed as custom_data, see UI_but_node_link_set(). */ + if (but->custom_data) { + const float scale = 0.9f / but->block->aspect; + + float col[4]; + rgba_uchar_to_float(col, but->col); + col[3] *= alpha; + + GPU_blend(true); + UI_widgetbase_draw_cache_flush(); + GPU_blend(false); + + ED_node_socket_draw(but->custom_data, rect, col, scale); + } + else { + widget_draw_icon(but, ICON_LAYER_USED, alpha, rect, wcol->text); + } +} + /* draws text and icons for buttons */ static void widget_draw_text_icon(const uiFontStyle *fstyle, const uiWidgetColors *wcol, @@ -2403,15 +2429,27 @@ static void widget_draw_text_icon(const uiFontStyle *fstyle, const bool show_menu_icon = ui_but_draw_menu_icon(but); float alpha = (float)wcol->text[3] / 255.0f; char password_str[UI_MAX_DRAW_STR]; + bool no_text_padding = but->drawflag & UI_BUT_NO_TEXT_PADDING; ui_but_text_password_hide(password_str, but, false); /* check for button text label */ if (ELEM(but->type, UI_BTYPE_MENU, UI_BTYPE_POPOVER) && (but->flag & UI_BUT_NODE_LINK)) { rcti temp = *rect; - temp.xmin = rect->xmax - BLI_rcti_size_y(rect) - 1; - widget_draw_icon(but, ICON_LAYER_USED, alpha, &temp, wcol->text); - rect->xmax = temp.xmin; + const int size = BLI_rcti_size_y(rect) + 1; /* Not the icon size! */ + + if (but->drawflag & UI_BUT_ICON_LEFT) { + temp.xmax = rect->xmin + size; + rect->xmin = temp.xmax; + /* Further padding looks off. */ + no_text_padding = true; + } + else { + temp.xmin = rect->xmax - size; + rect->xmax = temp.xmin; + } + + widget_draw_node_link_socket(wcol, &temp, but, alpha); } /* If there's an icon too (made with uiDefIconTextBut) then draw the icon @@ -2496,28 +2534,30 @@ static void widget_draw_text_icon(const uiFontStyle *fstyle, rect->xmin += icon_size + icon_padding; } - int text_padding = (UI_TEXT_MARGIN_X * U.widget_unit) / but->block->aspect; - if (but->editstr) { - rect->xmin += text_padding; - } - else if (but->flag & UI_BUT_DRAG_MULTI) { - bool text_is_edited = ui_but_drag_multi_edit_get(but) != NULL; - if (text_is_edited) { + if (!no_text_padding) { + int text_padding = (UI_TEXT_MARGIN_X * U.widget_unit) / but->block->aspect; + if (but->editstr) { rect->xmin += text_padding; } - } - else if (but->drawflag & UI_BUT_TEXT_LEFT) { - - /* Reduce the left padding for labels without an icon. */ - if ((but->type == UI_BTYPE_LABEL) && !(but->flag & UI_HAS_ICON) && - !ui_block_is_menu(but->block)) { - text_padding /= 2; + else if (but->flag & UI_BUT_DRAG_MULTI) { + bool text_is_edited = ui_but_drag_multi_edit_get(but) != NULL; + if (text_is_edited) { + rect->xmin += text_padding; + } } + else if (but->drawflag & UI_BUT_TEXT_LEFT) { - rect->xmin += text_padding; - } - else if (but->drawflag & UI_BUT_TEXT_RIGHT) { - rect->xmax -= text_padding; + /* Reduce the left padding for labels without an icon. */ + if ((but->type == UI_BTYPE_LABEL) && !(but->flag & UI_HAS_ICON) && + !ui_block_is_menu(but->block)) { + text_padding /= 2; + } + + rect->xmin += text_padding; + } + else if (but->drawflag & UI_BUT_TEXT_RIGHT) { + rect->xmax -= text_padding; + } } /* Menu contains sub-menu items with triangle icon on their right. Shortcut @@ -4121,10 +4161,10 @@ static void widget_optionbut(uiWidgetColors *wcol, /* smaller */ delta = 1 + BLI_rcti_size_y(&recttemp) / 8; - recttemp.xmin += delta; - recttemp.ymin += delta; - recttemp.xmax -= delta; - recttemp.ymax -= delta; + BLI_rcti_resize( + &recttemp, BLI_rcti_size_x(&recttemp) - delta * 2, BLI_rcti_size_y(&recttemp) - delta * 2); + /* Keep one edge in place. */ + BLI_rcti_translate(&recttemp, text_before_widget ? delta : -delta, 0); rad = wcol->roundness * BLI_rcti_size_y(&recttemp); round_box_edges(&wtb, UI_CNR_ALL, &recttemp, rad); @@ -4136,13 +4176,13 @@ static void widget_optionbut(uiWidgetColors *wcol, widgetbase_draw(&wtb, wcol); - /* text space */ - const float offset = BLI_rcti_size_y(rect) * 0.7 + delta; + /* Text space - factor is really just eyeballed. */ + const float offset = delta * 0.9; if (text_before_widget) { - rect->xmax -= offset; + rect->xmax = recttemp.xmin - offset; } else { - rect->xmin += offset; + rect->xmin = recttemp.xmax + offset; } } @@ -4699,9 +4739,14 @@ void ui_draw_but(const bContext *C, ARegion *region, uiStyle *style, uiBut *but, case UI_BTYPE_CHECKBOX_N: if (!(but->flag & UI_HAS_ICON)) { wt = widget_type(UI_WTYPE_CHECKBOX); + if ((but->drawflag & (UI_BUT_TEXT_LEFT | UI_BUT_TEXT_RIGHT)) == 0) { but->drawflag |= UI_BUT_TEXT_LEFT; } + /* widget_optionbut() carefully sets the text rectangle for fine tuned paddings. If the + * text drawing were to add its own padding, DPI and zoom factor would be applied twice + * in the final padding, so it's difficult to control it. */ + but->drawflag |= UI_BUT_NO_TEXT_PADDING; } else { wt = widget_type(UI_WTYPE_TOGGLE); @@ -5252,15 +5297,23 @@ void ui_draw_tooltip_background(const uiStyle *UNUSED(style), uiBlock *UNUSED(bl wt->draw(&wt->wcol, rect, 0, 0); } -/* helper call to draw a menu item without button */ -/* state: UI_ACTIVE or 0 */ +/** + * Helper call to draw a menu item without a button. + * + * \param state: The state of the button, + * typically #UI_ACTIVE, #UI_BUT_DISABLED, #UI_BUT_INACTIVE. + * \param use_sep: When true, characters after the last #UI_SEP_CHAR are right aligned, + * use for displaying key shortcuts. + * \param r_xmax: The right hand position of the text, this takes into the icon, + * padding and text clipping when there is not enough room to display the full text. + */ void ui_draw_menu_item(const uiFontStyle *fstyle, rcti *rect, const char *name, int iconid, int state, bool use_sep, - int *r_name_width) + int *r_xmax) { uiWidgetType *wt = widget_type(UI_WTYPE_MENU_ITEM); rcti _rect = *rect; @@ -5323,8 +5376,8 @@ void ui_draw_menu_item(const uiFontStyle *fstyle, &xofs, &yofs, &info); - if (r_name_width != NULL) { - *r_name_width = xofs + info.width; + if (r_xmax != NULL) { + *r_xmax = xofs + info.width; } } |