[Bf-blender-cvs] [0627bc2] master: Fix T42208 color pickers are coupled.

Antony Riakiotakis noreply at git.blender.org
Thu Nov 6 20:19:37 CET 2014


Commit: 0627bc22f598651cf86ee629d8211ebee7cc85ed
Author: Antony Riakiotakis
Date:   Thu Nov 6 20:19:21 2014 +0100
Branches: master
https://developer.blender.org/rB0627bc22f598651cf86ee629d8211ebee7cc85ed

Fix T42208 color pickers are coupled.

Decouple color picker hsv data from the whole block. Basically, each
color picker now takes care of creating its own color picker role. For
this bug report it can be seen that probably HSV is not the best space
for gamma/lift/gain workflow because it is bounded at 1.0 but this is a
separate issue.

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

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

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

diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index abbe95e..eb12f19 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -1170,8 +1170,7 @@ void uiBlockUpdateFromOld(const bContext *C, uiBlock *block)
 	block->auto_open = block->oldblock->auto_open;
 	block->auto_open_last = block->oldblock->auto_open_last;
 	block->tooltipdisabled = block->oldblock->tooltipdisabled;
-	copy_v3_v3(ui_block_hsv_get(block),
-	           ui_block_hsv_get(block->oldblock));
+	BLI_movelisttolist(&block->color_pickers.list, &block->oldblock->color_pickers.list);
 
 	block->oldblock = NULL;
 }
@@ -2446,6 +2445,7 @@ void uiFreeBlock(const bContext *C, uiBlock *block)
 	CTX_store_free_list(&block->contexts);
 
 	BLI_freelistN(&block->saferct);
+	BLI_freelistN(&block->color_pickers.list);
 	
 	MEM_freeN(block);
 }
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index a3c52ec..0e3b8e8 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -4294,7 +4294,9 @@ static int ui_do_but_COLOR(bContext *C, uiBut *but, uiHandleButtonData *data, co
 			return WM_UI_HANDLER_BREAK;
 		}
 		else if (ELEM(event->type, MOUSEPAN, WHEELDOWNMOUSE, WHEELUPMOUSE) && event->alt) {
-			float *hsv = ui_block_hsv_get(but->block);
+			ColorPicker *cpicker = but->custom_data;
+			float hsv_static[3] = {0.0f};
+			float *hsv = cpicker ? cpicker->color_data : hsv_static;
 			float col[3];
 
 			ui_get_but_vectorf(but, col);
@@ -4473,8 +4475,9 @@ static bool ui_numedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data,
                                    int mx, int my,
                                    const enum eSnapType snap, const bool shift)
 {
+	ColorPicker *cpicker = but->custom_data;
+	float *hsv = cpicker->color_data;
 	float rgb[3];
-	float *hsv = ui_block_hsv_get(but->block);
 	float x, y;
 	float mx_fl, my_fl;
 	bool changed = true;
@@ -4510,7 +4513,7 @@ static bool ui_numedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data,
 		if (use_display_colorspace)
 			ui_block_to_display_space_v3(but->block, rgb);
 		
-		copy_v3_v3(hsvo, ui_block_hsv_get(but->block));
+		copy_v3_v3(hsvo, hsv);
 
 		ui_rgb_to_color_picker_HSVCUBE_compat_v(but, rgb, hsvo);
 		
@@ -4591,7 +4594,8 @@ static void ui_ndofedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data,
                                     const wmNDOFMotionData *ndof,
                                     const enum eSnapType snap, const bool shift)
 {
-	float *hsv = ui_block_hsv_get(but->block);
+	ColorPicker *cpicker = but->custom_data;
+	float *hsv = cpicker->color_data;
 	const float hsv_v_max = max_ff(hsv[2], but->softmax);
 	float rgb[3];
 	float sensitivity = (shift ? 0.15f : 0.3f) * ndof->dt;
@@ -4704,8 +4708,9 @@ static int ui_do_but_HSVCUBE(bContext *C, uiBlock *block, uiBut *but, uiHandleBu
 				if (ELEM(len, 3, 4)) {
 					float rgb[3], def_hsv[3];
 					float def[4];
-					float *hsv = ui_block_hsv_get(but->block);
-					
+					ColorPicker *cpicker = but->custom_data;
+					float *hsv = cpicker->color_data;
+
 					RNA_property_float_get_default_array(&but->rnapoin, but->rnaprop, def);
 					ui_rgb_to_color_picker_HSVCUBE_v(but, def, def_hsv);
 
@@ -4758,7 +4763,8 @@ static bool ui_numedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data,
 	bool changed = true;
 	float mx_fl, my_fl;
 	float rgb[3];
-	float *hsv = ui_block_hsv_get(but->block);
+	ColorPicker *cpicker = but->custom_data;
+	float *hsv = cpicker->color_data;
 	bool use_display_colorspace = ui_color_picker_use_display_colorspace(but);
 
 	ui_mouse_scale_warp(data, mx, my, &mx_fl, &my_fl, shift);
@@ -4794,8 +4800,8 @@ static bool ui_numedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data,
 			if (hsv[2] == 0.f) hsv[2] = 0.0001f;
 		}
 		else {
-			if (hsv[2] == 0.f) hsv[2] = 0.0001f;
-			if (hsv[2] == 1.f) hsv[2] = 0.9999f;
+			if (hsv[2] == 0.0f) hsv[2] = 0.0001f;
+			if (hsv[2] >= 0.9999f) hsv[2] = 0.9999f;
 		}
 	}
 
@@ -4804,7 +4810,7 @@ static bool ui_numedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data,
 		float xpos, ypos, hsvo[3], rgbo[3];
 		
 		/* calculate original hsv again */
-		copy_v3_v3(hsvo, ui_block_hsv_get(but->block));
+		copy_v3_v3(hsvo, hsv);
 		copy_v3_v3(rgbo, data->origvec);
 		if (use_display_colorspace)
 			ui_block_to_display_space_v3(but->block, rgbo);
@@ -4850,7 +4856,8 @@ static void ui_ndofedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data,
                                       const wmNDOFMotionData *ndof,
                                       const enum eSnapType snap, const bool shift)
 {
-	float *hsv = ui_block_hsv_get(but->block);
+	ColorPicker *cpicker = but->custom_data;
+	float *hsv = cpicker->color_data;
 	bool use_display_colorspace = ui_color_picker_use_display_colorspace(but);
 	float rgb[3];
 	float phi, r /*, sqr */ /* UNUSED */, v[2];
@@ -4919,6 +4926,8 @@ static void ui_ndofedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data,
 
 static int ui_do_but_HSVCIRCLE(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event)
 {
+	ColorPicker *cpicker = but->custom_data;
+	float *hsv = cpicker->color_data;
 	int mx, my;
 	mx = event->x;
 	my = event->y;
@@ -4960,7 +4969,6 @@ static int ui_do_but_HSVCIRCLE(bContext *C, uiBlock *block, uiBut *but, uiHandle
 			if (len >= 3) {
 				float rgb[3], def_hsv[3];
 				float *def;
-				float *hsv = ui_block_hsv_get(but->block);
 				def = MEM_callocN(sizeof(float) * len, "reset_defaults - float");
 				
 				RNA_property_float_get_default_array(&but->rnapoin, but->rnaprop, def);
@@ -4992,13 +5000,11 @@ static int ui_do_but_HSVCIRCLE(bContext *C, uiBlock *block, uiBut *but, uiHandle
 		}
 		/* XXX hardcoded keymap check.... */
 		else if (event->type == WHEELDOWNMOUSE) {
-			float *hsv = ui_block_hsv_get(but->block);
 			hsv[2] = CLAMPIS(hsv[2] - 0.05f, 0.0f, 1.0f);
 			ui_set_but_hsv(but);    /* converts to rgb */
 			ui_numedit_apply(C, block, but, data);
 		}
 		else if (event->type == WHEELUPMOUSE) {
-			float *hsv = ui_block_hsv_get(but->block);
 			hsv[2] = CLAMPIS(hsv[2] + 0.05f, 0.0f, 1.0f);
 			ui_set_but_hsv(but);    /* converts to rgb */
 			ui_numedit_apply(C, block, but, data);
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index 47d0e29..54e15a2 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -36,6 +36,7 @@
 #include "BLI_compiler_attrs.h"
 #include "UI_resources.h"
 #include "RNA_types.h"
+#include "DNA_listBase.h"
 
 struct ARegion;
 struct bContext;
@@ -306,6 +307,16 @@ struct uiBut {
 	uiBlock *block;
 };
 
+typedef struct ColorPicker {
+	struct ColorPicker *next, *prev;
+	float color_data[3]; /* colr data may be HSV or HSL for now */
+	int representation; /* store hsv/hsl value */
+} ColorPicker;
+
+typedef struct ColorPickerData {
+	ListBase list;
+} ColorPickerData;
+
 struct PieMenuData {
 	float pie_dir[2];
 	float pie_center_init[2];
@@ -392,7 +403,7 @@ struct uiBlock {
 	void *evil_C;               /* XXX hack for dynamic operator enums */
 
 	struct UnitSettings *unit;  /* unit system, used a lot for numeric buttons so include here rather then fetching through the scene every time. */
-	float _hsv[3];              /* XXX, only access via ui_block_hsv_get() */
+	ColorPickerData color_pickers; /* XXX, only accessed by color picker templates */
 
 	bool color_profile;         /* color profile for correcting linear colors for display */
 
@@ -540,7 +551,7 @@ void   ui_popup_menu_memory_set(uiBlock *block, struct uiBut *but);
 
 void   ui_popup_translate(struct bContext *C, struct ARegion *ar, const int mdiff[2]);
 
-float *ui_block_hsv_get(struct uiBlock *block);
+ColorPicker *ui_block_picker_new(struct uiBlock *block);
 void ui_popup_block_scrolltest(struct uiBlock *block);
 
 void ui_rgb_to_color_picker_compat_v(const float rgb[3], float r_cp[3]);
diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c
index db89389..097dbe9 100644
--- a/source/blender/editors/interface/interface_regions.c
+++ b/source/blender/editors/interface/interface_regions.c
@@ -1878,18 +1878,20 @@ static void ui_warp_pointer(int x, int y)
 void ui_set_but_hsv(uiBut *but)
 {
 	float col[3];
-	const float *hsv = ui_block_hsv_get(but->block);
-	
+	ColorPicker *cpicker = but->custom_data;
+	float *hsv = cpicker->color_data;
+
 	ui_color_picker_to_rgb_v(hsv, col);
 
 	ui_set_but_vectorf(but, col);
 }
 
-/* also used by small picker, be careful with name checks below... */
-static void ui_update_block_buts_rgb(uiBlock *block, const float rgb[3], bool is_display_space)
+/* Updates all buttons who share the same color picker as the one passed
+ * also used by small picker, be careful with name checks below... */
+static void ui_update_color_picker_buts_rgb(uiBlock *block, ColorPicker *cpicker, const float rgb[3], bool is_display_space)
 {
 	uiBut *bt;
-	float *hsv = ui_block_hsv_get(block);
+	float *hsv = cpicker->color_data;
 	struct ColorManagedDisplay *display = NULL;
 	/* this is to keep the H and S value when V is equal to zero
 	 * and we are working in HSV mode, of course!
@@ -1911,6 +1913,9 @@ static void ui_update_block_buts_rgb(uiBlock *block, const float rgb[3], bool is
 	
 	/* this updates button strings, is hackish... but button pointers are on stack of caller function */
 	for (bt = block->buttons.first; bt; bt = bt->next) {
+		if (bt->custom_data != cpicker)
+			continue;
+
 		if (bt->rnaprop) {
 			
 			ui_set_but_vectorf(bt, rgb);
@@ -1978,7 +1983,7 @@ static void do_picker_rna_cb(bContext *UNUSED(C), void *bt1, void *UNUSED(arg))
 	
 	if (prop) {
 		RNA_property_float_get_array(&ptr, prop, rgb);
-		ui_update_block_buts_rgb(but->block, rgb, (RNA_property_subtype(prop) == PROP_COLOR_GAMMA));
+		ui_update_color_picker_buts_rgb(but->block, but->custom_data, rgb, (RNA_property_subtype(prop) == PROP_COLOR_GAMMA));
 	}
 	
 	if (popup)
@@ -1990,7 +1995,8 @@ static void do_c

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list