[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32449] trunk/blender/source/blender: bugfix [#23355] Square Color picker moving by itself and locking up

Campbell Barton ideasman42 at gmail.com
Wed Oct 13 15:53:49 CEST 2010


Revision: 32449
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32449
Author:   campbellbarton
Date:     2010-10-13 15:53:49 +0200 (Wed, 13 Oct 2010)

Log Message:
-----------
bugfix [#23355] Square Color picker moving by itself and locking up

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_math_color.h
    trunk/blender/source/blender/blenlib/intern/math_color.c
    trunk/blender/source/blender/editors/interface/interface.c
    trunk/blender/source/blender/editors/interface/interface_handlers.c
    trunk/blender/source/blender/editors/interface/interface_intern.h
    trunk/blender/source/blender/editors/interface/interface_regions.c
    trunk/blender/source/blender/editors/interface/interface_templates.c
    trunk/blender/source/blender/editors/interface/interface_widgets.c

Modified: trunk/blender/source/blender/blenlib/BLI_math_color.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_color.h	2010-10-13 13:10:35 UTC (rev 32448)
+++ trunk/blender/source/blender/blenlib/BLI_math_color.h	2010-10-13 13:53:49 UTC (rev 32449)
@@ -61,6 +61,7 @@
 void rgb_to_yuv(float r, float g, float b, float *ly, float *lu, float *lv);
 void rgb_to_ycc(float r, float g, float b, float *ly, float *lcb, float *lcr, int colorspace);
 void rgb_to_hsv(float r, float g, float b, float *lh, float *ls, float *lv);
+void rgb_to_hsv_compat(float r, float g, float b, float *lh, float *ls, float *lv);
 unsigned int rgb_to_cpack(float r, float g, float b);
 unsigned int hsv_to_cpack(float h, float s, float v);
 

Modified: trunk/blender/source/blender/blenlib/intern/math_color.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_color.c	2010-10-13 13:10:35 UTC (rev 32448)
+++ trunk/blender/source/blender/blenlib/intern/math_color.c	2010-10-13 13:53:49 UTC (rev 32449)
@@ -232,6 +232,26 @@
 	*lv = v;
 }
 
+void rgb_to_hsv_compat(float r, float g, float b, float *lh, float *ls, float *lv)
+{
+	float orig_h= *lh;
+	float orig_s= *ls;
+
+	rgb_to_hsv(r, g, b, lh, ls, lv);
+
+	if(*lv <= 0.0f) {
+		*lh= orig_h;
+		*ls= orig_s;
+	}
+	else if (*ls <= 0.0f) {
+		*lh= orig_h;
+	}
+
+	if(*lh==0.0f && orig_h >= 1.0f) {
+		*lh= 1.0f;
+	}
+}
+
 /*http://brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html */
 
 void xyz_to_rgb(float xc, float yc, float zc, float *r, float *g, float *b, int colorspace)

Modified: trunk/blender/source/blender/editors/interface/interface.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface.c	2010-10-13 13:10:35 UTC (rev 32448)
+++ trunk/blender/source/blender/editors/interface/interface.c	2010-10-13 13:53:49 UTC (rev 32449)
@@ -2136,11 +2136,6 @@
 
 	case HSVCUBE:
 	case HSVCIRCLE:
-		{
-			float rgb[3];
-			ui_get_but_vectorf(but, rgb);
-			rgb_to_hsv(rgb[0], rgb[1], rgb[2], but->hsv, but->hsv+1, but->hsv+2);
-		}
 		break;
 	default:
 		strncpy(but->drawstr, but->str, UI_MAX_DRAW_STR);

Modified: trunk/blender/source/blender/editors/interface/interface_handlers.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_handlers.c	2010-10-13 13:10:35 UTC (rev 32448)
+++ trunk/blender/source/blender/editors/interface/interface_handlers.c	2010-10-13 13:53:49 UTC (rev 32449)
@@ -2830,17 +2830,18 @@
 		}
 		else if(but->type==COL) {
 			if( ELEM(event->type, WHEELDOWNMOUSE, WHEELUPMOUSE) && event->alt) {
+				float *hsv= ui_block_hsv_get(but->block);
 				float col[3];
 				
 				ui_get_but_vectorf(but, col);
-				rgb_to_hsv(col[0], col[1], col[2], but->hsv, but->hsv+1, but->hsv+2);
+				rgb_to_hsv_compat(col[0], col[1], col[2], hsv, hsv+1, hsv+2);
 
 				if(event->type==WHEELDOWNMOUSE)
-					but->hsv[2]= CLAMPIS(but->hsv[2]-0.05f, 0.0f, 1.0f);
+					hsv[2]= CLAMPIS(hsv[2]-0.05f, 0.0f, 1.0f);
 				else
-					but->hsv[2]= CLAMPIS(but->hsv[2]+0.05f, 0.0f, 1.0f);
+					hsv[2]= CLAMPIS(hsv[2]+0.05f, 0.0f, 1.0f);
 				
-				hsv_to_rgb(but->hsv[0], but->hsv[1], but->hsv[2], data->vec, data->vec+1, data->vec+2);
+				hsv_to_rgb(hsv[0], hsv[1], hsv[2], data->vec, data->vec+1, data->vec+2);
 				ui_set_but_vectorf(but, data->vec);
 				
 				button_activate_state(C, but, BUTTON_STATE_EXIT);
@@ -2970,7 +2971,8 @@
 
 static int ui_numedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data, int mx, int my)
 {
-	float rgb[3], hsv[3];
+	float rgb[3];
+	float *hsv= ui_block_hsv_get(but->block);
 	float x, y;
 	int changed= 1;
 	int color_profile = but->block->color_profile;
@@ -2979,10 +2981,11 @@
 		if (RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA)
 			color_profile = BLI_PR_NONE;
 	}
-	
+
 	ui_get_but_vectorf(but, rgb);
-	rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
-		
+
+	rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
+
 	/* relative position within box */
 	x= ((float)mx-but->x1)/(but->x2-but->x1);
 	y= ((float)my-but->y1)/(but->y2-but->y1);
@@ -3059,21 +3062,22 @@
 		}
 		else if (event->type == ZEROKEY && event->val == KM_PRESS) {
 			if (but->a1==9){
-				float rgb[3], hsv[3], def_hsv[3];
-				float *def;
 				int len;
 				
 				/* reset only value */
 				
 				len= RNA_property_array_length(&but->rnapoin, but->rnaprop);
 				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);
 					rgb_to_hsv(def[0], def[1], def[2], def_hsv, def_hsv+1, def_hsv+2);
 					
 					ui_get_but_vectorf(but, rgb);
-					rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
+					rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
 					
 					hsv_to_rgb(hsv[0], hsv[1], def_hsv[2], rgb, rgb+1, rgb+2);
 					ui_set_but_vectorf(but, rgb);
@@ -3111,13 +3115,15 @@
 {
 	rcti rect;
 	int changed= 1;
-	float rgb[3], hsv[3];
+	float rgb[3];
+	float hsv[3];
 	
 	rect.xmin= but->x1; rect.xmax= but->x2;
 	rect.ymin= but->y1; rect.ymax= but->y2;
 	
 	ui_get_but_vectorf(but, rgb);
-	rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
+	copy_v3_v3(hsv, ui_block_hsv_get(but->block));
+	rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
 	
 	/* exception, when using color wheel in 'locked' value state:
 	 * allow choosing a hue for black values, by giving a tiny increment */
@@ -3176,21 +3182,22 @@
 			return WM_UI_HANDLER_BREAK;
 		}
 		else if (event->type == ZEROKEY && event->val == KM_PRESS) {
-			float rgb[3], hsv[3], def_hsv[3];
-			float *def;
 			int len;
 			
 			/* reset only saturation */
 			
 			len= RNA_property_array_length(&but->rnapoin, but->rnaprop);
 			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);
 				rgb_to_hsv(def[0], def[1], def[2], def_hsv, def_hsv+1, def_hsv+2);
 				
 				ui_get_but_vectorf(but, rgb);
-				rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
+				rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
 				
 				hsv_to_rgb(hsv[0], def_hsv[1], hsv[2], rgb, rgb+1, rgb+2);
 				ui_set_but_vectorf(but, rgb);
@@ -3210,12 +3217,14 @@
 		}
 		/* XXX hardcoded keymap check.... */
 		else if(event->type == WHEELDOWNMOUSE) {
-			but->hsv[2]= CLAMPIS(but->hsv[2]-0.05f, 0.0f, 1.0f);
+			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) {
-			but->hsv[2]= CLAMPIS(but->hsv[2]+0.05f, 0.0f, 1.0f);
+			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);
 		}

Modified: trunk/blender/source/blender/editors/interface/interface_intern.h
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_intern.h	2010-10-13 13:10:35 UTC (rev 32448)
+++ trunk/blender/source/blender/editors/interface/interface_intern.h	2010-10-13 13:53:49 UTC (rev 32449)
@@ -171,8 +171,9 @@
 
 	char *poin;
 	float hardmin, hardmax, softmin, softmax;
-	float a1, a2, hsv[3];	// hsv is temp memory for hsv buttons
+	float a1, a2;
 	float aspect;
+	char col[4];
 
 	uiButHandleFunc func;
 	void *func_arg1;
@@ -396,7 +397,7 @@
 	int butretval;
 	int menuretval;
 	float retvalue;
-	float retvec[4];
+	float retvec[8];
 };
 
 uiBlock *ui_block_func_COL(struct bContext *C, uiPopupBlockHandle *handle, void *arg_but);
@@ -408,6 +409,8 @@
 
 uiBut *ui_popup_menu_memory(uiBlock *block, uiBut *but);
 
+float *ui_block_hsv_get(uiBlock *block);
+
 /* searchbox for string button */
 ARegion *ui_searchbox_create(struct bContext *C, struct ARegion *butregion, uiBut *but);
 int ui_searchbox_inside(struct ARegion *ar, int x, int y);

Modified: trunk/blender/source/blender/editors/interface/interface_regions.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_regions.c	2010-10-13 13:10:35 UTC (rev 32448)
+++ trunk/blender/source/blender/editors/interface/interface_regions.c	2010-10-13 13:53:49 UTC (rev 32449)
@@ -1571,27 +1571,22 @@
 void ui_set_but_hsv(uiBut *but)
 {
 	float col[3];
+	float *hsv= ui_block_hsv_get(but->block);
 	
-	hsv_to_rgb(but->hsv[0], but->hsv[1], but->hsv[2], col, col+1, col+2);
+	hsv_to_rgb(hsv[0], hsv[1], hsv[2], col, col+1, col+2);
 	ui_set_but_vectorf(but, col);
 }
 
 /* also used by small picker, be careful with name checks below... */
-void ui_update_block_buts_rgb(uiBlock *block, float *rgb, float *rhsv)
+void ui_update_block_buts_rgb(uiBlock *block, float *rgb)
 {
 	uiBut *bt;
-	float hsv[3];
+	float *hsv= ui_block_hsv_get(block);
 	
 	/* this is to keep the H and S value when V is equal to zero
 	 * and we are working in HSV mode, of course!
 	 */
-	if (rhsv) {
-		hsv[0]= rhsv[0];
-		hsv[1]= rhsv[1];
-		hsv[2]= rhsv[2];
-	}
-	else
-		rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
+	rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
 	
 	// this updates button strings, is hackish... but button pointers are on stack of caller function
 	for(bt= block->buttons.first; bt; bt= bt->next) {
@@ -1657,23 +1652,23 @@
 	
 	if (prop) {
 		RNA_property_float_get_array(&ptr, prop, rgb);
-		ui_update_block_buts_rgb(but->block, rgb, NULL);
+		ui_update_block_buts_rgb(but->block, rgb);
 	}
 	
 	if(popup)
 		popup->menuretval= UI_RETURN_UPDATE;
 }
 
-static void do_hsv_rna_cb(bContext *C, void *bt1, void *hsv_arg)
+static void do_hsv_rna_cb(bContext *C, void *bt1, void *arg_dummy)
 {
 	uiBut *but= (uiBut *)bt1;
 	uiPopupBlockHandle *popup= but->block->handle;
-	float *hsv = (float *)hsv_arg;
 	float rgb[3];
+	float *hsv= ui_block_hsv_get(but->block);
 	
 	hsv_to_rgb(hsv[0], hsv[1], hsv[2], rgb, rgb+1, rgb+2);
 	
-	ui_update_block_buts_rgb(but->block, rgb, hsv);
+	ui_update_block_buts_rgb(but->block, rgb);
 	
 	if(popup)
 		popup->menuretval= UI_RETURN_UPDATE;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list