diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-10-29 18:58:34 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-10-29 21:04:07 +0300 |
commit | b5667c2ca7f7cc33903b7f664dfbd3bccd8cdd22 (patch) | |
tree | 189f7a60d860c563c6abf37899aae3fcf85c46cf /source/blender/editors | |
parent | 4c7f08e5ebc107e13501a5b1e82a44edeaf7b7c3 (diff) |
UI: allow off/on icons to be in reverse order.
The same icons are reused for "hide" and "show" properties, which need
to be in reverse order compared to each other.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/include/UI_interface.h | 2 | ||||
-rw-r--r-- | source/blender/editors/interface/interface.c | 6 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_widgets.c | 19 |
3 files changed, 24 insertions, 3 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 92423d84c3f..ac463fe87a2 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -236,6 +236,8 @@ enum { UI_BUT_ACTIVE_RIGHT = (1 << 22), /* Active right part of number button */ UI_BUT_HAS_SHORTCUT = (1 << 23), /* Button has shortcut text */ + + UI_BUT_ICON_REVERSE = (1 << 24), /* Reverse order of consecutive off/on icons */ }; /* scale fixed button widths by this to account for DPI */ diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 3e8d32c0e2b..1e1c9c1fa3f 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -2985,7 +2985,11 @@ void ui_but_update_ex(uiBut *but, const bool validate) case UI_BTYPE_ICON_TOGGLE: case UI_BTYPE_ICON_TOGGLE_N: - if (!but->rnaprop || (RNA_property_flag(but->rnaprop) & PROP_ICONS_CONSECUTIVE)) { + if ((but->rnaprop == NULL) || (RNA_property_flag(but->rnaprop) & PROP_ICONS_CONSECUTIVE)) { + if (but->rnaprop && RNA_property_flag(but->rnaprop) & PROP_ICONS_REVERSE) { + but->drawflag |= UI_BUT_ICON_REVERSE; + } + but->iconadd = (but->flag & UI_SELECT) ? 1 : 0; } break; diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index 99022a14b6a..b8a661c5542 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -2016,6 +2016,21 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b } } +static BIFIconID widget_icon_id(uiBut *but) +{ + if (!(but->flag & UI_HAS_ICON)) { + return ICON_NONE; + } + + /* Consecutive icons can be toggle between. */ + if (but->drawflag & UI_BUT_ICON_REVERSE) { + return but->icon - but->iconadd; + } + else { + return but->icon + but->iconadd; + } +} + /* draws text and icons for buttons */ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *but, rcti *rect) { @@ -2039,7 +2054,7 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB /* Big previews with optional text label below */ if (but->flag & UI_BUT_ICON_PREVIEW && ui_block_is_menu(but->block)) { - const BIFIconID icon = (but->flag & UI_HAS_ICON) ? but->icon + but->iconadd : ICON_NONE; + const BIFIconID icon = widget_icon_id(but); int icon_size = BLI_rcti_size_y(rect); int text_size = 0; @@ -2076,7 +2091,7 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB } #endif - const BIFIconID icon = (but->flag & UI_HAS_ICON) ? but->icon + but->iconadd : ICON_NONE; + const BIFIconID icon = widget_icon_id(but); 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); const float icon_padding = 2 * UI_DPI_FAC; |