[Bf-blender-cvs] [90c1afb] master: Fix T41708, active palette indicator not refreshing when clicking

Antony Riakiotakis noreply at git.blender.org
Thu Sep 18 12:53:13 CEST 2014


Commit: 90c1afb02005671bb631c0fcb8b4981c3aa6e89e
Author: Antony Riakiotakis
Date:   Thu Sep 18 12:45:49 2014 +0200
Branches: master
https://developer.blender.org/rB90c1afb02005671bb631c0fcb8b4981c3aa6e89e

Fix T41708, active palette indicator not refreshing when clicking

Issue, after a lot of blood sweat and tears, was found in
ui_but_update_from_old_block, where we restore a button to its old
values when possible. The problem here is that a1 and a2 are not really
meant to store temporary variables, because they tend to get overriden
and palette selection is one of those temporary states.

Instead, we now store the position of each button in the palette in a2
and pointer to the palette in the customdata pointer of each button and
use that to test if it's active. The positions won't change when
clicking so we are guaranteed that the old button won't override the new
one with garbage.

It's still hacky but it is better than testing button types when copying
old values.

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

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_handlers.c
M	source/blender/editors/interface/interface_intern.h
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/interface/interface_widgets.c

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

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 1e9756f..bc794bf 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -295,7 +295,6 @@ typedef enum {
 #define UI_GRAD_L_ALT   10
 
 #define UI_PALETTE_COLOR 20
-#define UI_PALETTE_COLOR_ACTIVE 1
 
 /* Drawing
  *
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 17f898b..d3c9ec1 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -4318,9 +4318,7 @@ static int ui_do_but_COLOR(bContext *C, uiBut *but, uiHandleButtonData *data, co
 		else if ((int)(but->a1) == UI_PALETTE_COLOR &&
 		         event->type == DELKEY && event->val == KM_PRESS)
 		{
-			Scene *scene = CTX_data_scene(C);
-			Paint *paint = BKE_paint_get_active(scene);
-			Palette *palette = BKE_paint_palette(paint);
+			Palette *palette = but->rnapoin.id.data;
 			PaletteColor *color = but->rnapoin.data;
 
 			BKE_palette_color_remove(palette, color);
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index cdc611a..2f66c4a 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -225,7 +225,7 @@ struct uiBut {
 	 * (type == NUM),        Use to store RNA 'precision' value, for dragging and click-step.
 	 * (type == LABEL),      If (a1 == 1.0f) use a2 as a blending factor.
 	 * (type == SEARCH_MENU) Use as number or columns.
-	 * (type == COLOR)       Use as indication of active palette color
+	 * (type == COLOR)       Use as index in palette (not so good, needs refactor)
 	 */
 	float a2;
 
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 364a62b..b0bea42 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -2407,8 +2407,7 @@ void uiTemplatePalette(uiLayout *layout, PointerRNA *ptr, const char *propname,
 
 		RNA_pointer_create(&palette->id, &RNA_PaletteColor, color, &ptr);
 		uiDefButR(block, COLOR, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, &ptr, "color", -1, 0.0, 1.0,
-		          UI_PALETTE_COLOR, (col_id == palette->active_color) ? UI_PALETTE_COLOR_ACTIVE : 0.0, "");
-
+		          UI_PALETTE_COLOR, col_id, "");
 		row_cols++;
 		col_id++;
 	}
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 0ffd45e..5cd6b1e 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -2898,7 +2898,7 @@ static void widget_swatch(uiBut *but, uiWidgetColors *wcol, rcti *rect, int stat
 
 	widgetbase_draw(&wtb, wcol);
 	
-	if (but->a1 == UI_PALETTE_COLOR && but->a2 == UI_PALETTE_COLOR_ACTIVE) {
+	if (but->a1 == UI_PALETTE_COLOR && ((Palette *)but->rnapoin.id.data)->active_color == (int)but->a2) {
 		float width = rect->xmax - rect->xmin;
 		float height = rect->ymax - rect->ymin;
 		/* find color luminance and change it slightly */




More information about the Bf-blender-cvs mailing list