UI: workaround for text & icon alignment
Blender's icons weren't written to draw different sizes. For now ifdef in a hack to show toolbar icons larger.
This commit is contained in:
@@ -1229,4 +1229,9 @@ void UI_widgetbase_draw_cache_begin(void);
|
||||
void UI_widgetbase_draw_cache_flush(void);
|
||||
void UI_widgetbase_draw_cache_end(void);
|
||||
|
||||
/* Special drawing for toolbar, mainly workarounds for inflexible icon sizing. */
|
||||
#define USE_TOOLBAR_HACK
|
||||
|
||||
bool UI_but_is_tool(const uiBut *but);
|
||||
|
||||
#endif /* __UI_INTERFACE_H__ */
|
||||
|
||||
@@ -49,6 +49,8 @@ typedef struct IconFile {
|
||||
#define ICON_DEFAULT_HEIGHT 16
|
||||
#define ICON_DEFAULT_WIDTH 16
|
||||
|
||||
#define ICON_DEFAULT_HEIGHT_TOOLBAR 38
|
||||
|
||||
#define ICON_DEFAULT_HEIGHT_SCALE ((int)(UI_UNIT_Y * 0.8f))
|
||||
#define ICON_DEFAULT_WIDTH_SCALE ((int)(UI_UNIT_X * 0.8f))
|
||||
|
||||
|
||||
@@ -10232,3 +10232,18 @@ void ui_but_clipboard_free(void)
|
||||
{
|
||||
curvemapping_free_data(&but_copypaste_curve);
|
||||
}
|
||||
|
||||
bool UI_but_is_tool(const uiBut *but)
|
||||
{
|
||||
/* very evil! */
|
||||
if (but->optype != NULL) {
|
||||
static wmOperatorType *ot = NULL;
|
||||
if (ot == NULL) {
|
||||
ot = WM_operatortype_find("WM_OT_tool_set", false);
|
||||
}
|
||||
if (but->optype == ot) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1226,14 +1226,15 @@ static void icon_draw_size(
|
||||
/* We need to flush widget base first to ensure correct ordering. */
|
||||
UI_widgetbase_draw_cache_flush();
|
||||
|
||||
#ifdef USE_TOOLBAR_HACK
|
||||
/* TODO(campbell): scale icons up for toolbar, we need a way to detect larger buttons and do this automatic. */
|
||||
{
|
||||
/* Icons are currently 38 aligned, scale from 16 -> 38. */
|
||||
float scale = 2.375f;
|
||||
float scale = (float)ICON_DEFAULT_HEIGHT_TOOLBAR / (float)ICON_DEFAULT_HEIGHT;
|
||||
y = (y + (h / 2)) - ((h * scale) / 2);
|
||||
w *= scale;
|
||||
h *= scale;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* This could re-generate often if rendered at different sizes in the one interface.
|
||||
* TODO(campbell): support caching multiple sizes. */
|
||||
|
||||
@@ -2004,12 +2004,26 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB
|
||||
}
|
||||
/* Icons on the left with optional text label on the right */
|
||||
else if (but->flag & UI_HAS_ICON || show_menu_icon) {
|
||||
const bool is_tool = UI_but_is_tool(but);
|
||||
|
||||
const BIFIconID icon = (but->flag & UI_HAS_ICON) ? but->icon + but->iconadd : ICON_NONE;
|
||||
const float icon_size = ICON_DEFAULT_WIDTH_SCALE;
|
||||
int icon_size_init = is_tool ? ICON_DEFAULT_HEIGHT_TOOLBAR : ICON_DEFAULT_HEIGHT;
|
||||
const float icon_size = icon_size_init / (but->block->aspect / UI_DPI_FAC);
|
||||
|
||||
#ifdef USE_TOOLBAR_HACK
|
||||
if (is_tool) {
|
||||
/* pass (even if its a menu toolbar) */
|
||||
but->drawflag |= UI_BUT_TEXT_LEFT;
|
||||
but->drawflag |= UI_BUT_ICON_LEFT;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* menu item - add some more padding so menus don't feel cramped. it must
|
||||
* be part of the button so that this area is still clickable */
|
||||
if (ui_block_is_pie_menu(but->block)) {
|
||||
if (is_tool) {
|
||||
/* pass (even if its a menu toolbar) */
|
||||
}
|
||||
else if (ui_block_is_pie_menu(but->block)) {
|
||||
if (but->dt == UI_EMBOSS_RADIAL)
|
||||
rect->xmin += 0.3f * U.widget_unit;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user