[Bf-blender-cvs] [b5667c2ca7f] blender2.8: UI: allow off/on icons to be in reverse order.

Brecht Van Lommel noreply at git.blender.org
Mon Oct 29 19:11:00 CET 2018


Commit: b5667c2ca7f7cc33903b7f664dfbd3bccd8cdd22
Author: Brecht Van Lommel
Date:   Mon Oct 29 16:58:34 2018 +0100
Branches: blender2.8
https://developer.blender.org/rBb5667c2ca7f7cc33903b7f664dfbd3bccd8cdd22

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.

===================================================================

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface.c
M	source/blender/editors/interface/interface_widgets.c
M	source/blender/makesrna/RNA_define.h
M	source/blender/makesrna/RNA_types.h
M	source/blender/makesrna/intern/rna_define.c

===================================================================

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;
diff --git a/source/blender/makesrna/RNA_define.h b/source/blender/makesrna/RNA_define.h
index 551805f6a80..e14dcbea09e 100644
--- a/source/blender/makesrna/RNA_define.h
+++ b/source/blender/makesrna/RNA_define.h
@@ -175,7 +175,7 @@ void RNA_def_property_string_default(PropertyRNA *prop, const char *value);
 
 void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description);
 void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision);
-void RNA_def_property_ui_icon(PropertyRNA *prop, int icon, bool consecutive);
+void RNA_def_property_ui_icon(PropertyRNA *prop, int icon, int consecutive);
 
 void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *updatefunc);
 void RNA_def_property_editable_func(PropertyRNA *prop, const char *editable);
diff --git a/source/blender/makesrna/RNA_types.h b/source/blender/makesrna/RNA_types.h
index 0e7c3956d7b..72e1c05de3c 100644
--- a/source/blender/makesrna/RNA_types.h
+++ b/source/blender/makesrna/RNA_types.h
@@ -184,6 +184,7 @@ typedef enum PropertyFlag {
 
 	/* icon */
 	PROP_ICONS_CONSECUTIVE       = (1 << 12),
+	PROP_ICONS_REVERSE           = (1 << 8),
 
 	/* hidden in  the user interface */
 	PROP_HIDDEN                  = (1 << 19),
diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c
index c3c7367283e..42db80c83c0 100644
--- a/source/blender/makesrna/intern/rna_define.c
+++ b/source/blender/makesrna/intern/rna_define.c
@@ -1426,11 +1426,13 @@ void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *d
 	prop->description = description;
 }
 
-void RNA_def_property_ui_icon(PropertyRNA *prop, int icon, bool consecutive)
+void RNA_def_property_ui_icon(PropertyRNA *prop, int icon, int consecutive)
 {
 	prop->icon = icon;
-	if (consecutive)
+	if (consecutive != 0)
 		prop->flag |= PROP_ICONS_CONSECUTIVE;
+	if (consecutive < 0)
+		prop->flag |= PROP_ICONS_REVERSE;
 }
 
 /**



More information about the Bf-blender-cvs mailing list