[Bf-blender-cvs] [ca0cc0518f2] master: Cleanup: simplify toggle button logic

Campbell Barton noreply at git.blender.org
Mon Mar 25 06:22:18 CET 2019


Commit: ca0cc0518f23ad0fa8c0a3c3614d6a469f4af20e
Author: Campbell Barton
Date:   Mon Mar 25 16:17:39 2019 +1100
Branches: master
https://developer.blender.org/rBca0cc0518f23ad0fa8c0a3c3614d6a469f4af20e

Cleanup: simplify toggle button logic

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

M	source/blender/editors/interface/interface_handlers.c
M	source/blender/editors/interface/interface_intern.h

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

diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 7448de07e0e..6474ccc7794 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -856,44 +856,23 @@ static void ui_apply_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data
 
 static void ui_apply_but_TOG(bContext *C, uiBut *but, uiHandleButtonData *data)
 {
-	double value;
-	int w, lvalue, push;
-
-	value = ui_but_value_get(but);
-	lvalue = (int)value;
-
+	const double value = ui_but_value_get(but);
+	int value_toggle;
 	if (but->bit) {
-		w = UI_BITBUT_TEST(lvalue, but->bitnr);
-		if (w) {
-			lvalue = UI_BITBUT_CLR(lvalue, but->bitnr);
-		}
-		else {
-			lvalue = UI_BITBUT_SET(lvalue, but->bitnr);
-		}
-
-		ui_but_value_set(but, (double)lvalue);
-		if (but->type == UI_BTYPE_ICON_TOGGLE || but->type == UI_BTYPE_ICON_TOGGLE_N) {
-			ui_but_update_edited(but);
-		}
+		value_toggle = UI_BITBUT_VALUE_TOGGLED((int)value, but->bitnr);
 	}
 	else {
-
-		if (value == 0.0) {
-			push = 1;
-		}
-		else {
-			push = 0;
-		}
-
+		value_toggle = (value == 0.0);
 		if (ELEM(but->type, UI_BTYPE_TOGGLE_N, UI_BTYPE_ICON_TOGGLE_N, UI_BTYPE_CHECKBOX_N)) {
-			push = !push;
-		}
-		ui_but_value_set(but, (double)push);
-		if (but->type == UI_BTYPE_ICON_TOGGLE || but->type == UI_BTYPE_ICON_TOGGLE_N) {
-			ui_but_update_edited(but);
+			value_toggle = !value_toggle;
 		}
 	}
 
+	ui_but_value_set(but, (double)value_toggle);
+	if (but->type == UI_BTYPE_ICON_TOGGLE || but->type == UI_BTYPE_ICON_TOGGLE_N) {
+		ui_but_update_edited(but);
+	}
+
 	ui_apply_but_func(C, but);
 
 	data->retval = but->retval;
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index 58d81be1b51..eefed26ef55 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -115,9 +115,11 @@ extern const short ui_radial_dir_to_angle[8];
 
 /* bit button defines */
 /* Bit operations */
-#define UI_BITBUT_TEST(a, b)    ( ( (a) & 1 << (b) ) != 0)
-#define UI_BITBUT_SET(a, b)     ( (a) | 1 << (b) )
-#define UI_BITBUT_CLR(a, b)     ( (a) & ~(1 << (b)) )
+#define UI_BITBUT_TEST(a, b)           (((a) &  (1 << (b))) != 0)
+#define UI_BITBUT_VALUE_TOGGLED(a, b)   ((a) ^  (1 << (b)))
+#define UI_BITBUT_VALUE_ENABLED(a, b)   ((a) |  (1 << (b)))
+#define UI_BITBUT_VALUE_DISABLED(a, b)  ((a) & ~(1 << (b)))
+
 /* bit-row */
 #define UI_BITBUT_ROW(min, max)  (((max) >= 31 ? 0xFFFFFFFF : (1 << ((max) + 1)) - 1) - ((min) ? ((1 << (min)) - 1) : 0) )



More information about the Bf-blender-cvs mailing list