[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20832] branches/blender2.5/blender/source /blender/editors: 2.5

Ton Roosendaal ton at blender.org
Fri Jun 12 16:22:29 CEST 2009


Revision: 20832
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20832
Author:   ton
Date:     2009-06-12 16:22:27 +0200 (Fri, 12 Jun 2009)

Log Message:
-----------
2.5

Quick Color picker alternative!

- only a color circle + value slider
- exits immediate after use, or slight mouse move outside picker
- use scrollwheel to change HSV 'value'. Also works while picking.
- added nicer AA'ed cursor in picker
- All color swatches change 'value' on ALT+Wheel mouse-over

Old picker is still there, under SHIFT+click on swatch. Needs
evaluation... part of UI keymap? Per button type? Or divide
picker in left/right? Or just have all those old picker buttons
in another panel... I'm not to fond of this giant old popup.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/editors/include/UI_interface.h
    branches/blender2.5/blender/source/blender/editors/interface/interface.c
    branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c
    branches/blender2.5/blender/source/blender/editors/interface/interface_intern.h
    branches/blender2.5/blender/source/blender/editors/interface/interface_regions.c
    branches/blender2.5/blender/source/blender/editors/interface/interface_widgets.c
    branches/blender2.5/blender/source/blender/editors/preview/previewrender.c

Modified: branches/blender2.5/blender/source/blender/editors/include/UI_interface.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/include/UI_interface.h	2009-06-12 14:02:37 UTC (rev 20831)
+++ branches/blender2.5/blender/source/blender/editors/include/UI_interface.h	2009-06-12 14:22:27 UTC (rev 20832)
@@ -195,6 +195,7 @@
 #define OPTIONN		(39<<9)
 #define SEARCH_MENU	(40<<9)
 #define BUT_EXTRA	(41<<9)
+#define HSVCIRCLE	(42<<9)
 #define BUTTYPE	(63<<9)
 
 /* Drawing

Modified: branches/blender2.5/blender/source/blender/editors/interface/interface.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/interface.c	2009-06-12 14:02:37 UTC (rev 20831)
+++ branches/blender2.5/blender/source/blender/editors/interface/interface.c	2009-06-12 14:22:27 UTC (rev 20832)
@@ -2232,7 +2232,7 @@
 		}
 	}
 	
-	if(but->type==HSVCUBE) { /* hsv buttons temp storage */
+	if(ELEM(but->type, HSVCUBE, HSVCIRCLE)) { /* hsv buttons temp storage */
 		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);

Modified: branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c	2009-06-12 14:02:37 UTC (rev 20831)
+++ branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c	2009-06-12 14:22:27 UTC (rev 20832)
@@ -621,6 +621,7 @@
 			break;
 		case BUT_NORMAL:
 		case HSVCUBE:
+		case HSVCIRCLE:
 			ui_apply_but_VEC(C, but, data);
 			break;
 		case BUT_COLORBAND:
@@ -1432,7 +1433,7 @@
 		data->coba= (ColorBand*)but->poin;
 		but->editcoba= data->coba;
 	}
-	else if(ELEM(but->type, BUT_NORMAL, HSVCUBE)) {
+	else if(ELEM3(but->type, BUT_NORMAL, HSVCUBE, HSVCIRCLE)) {
 		ui_get_but_vectorf(but, data->origvec);
 		VECCOPY(data->vec, data->origvec);
 		but->editvec= data->vec;
@@ -2100,6 +2101,25 @@
 				return WM_UI_HANDLER_BREAK;
 			}
 		}
+		else if(but->type==COL) {
+			if( ELEM(event->type, WHEELDOWNMOUSE, WHEELUPMOUSE) && event->alt) {
+				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);
+
+				if(event->type==WHEELDOWNMOUSE)
+					but->hsv[2]= CLAMPIS(but->hsv[2]-0.05f, 0.0f, 1.0f);
+				else
+					but->hsv[2]= CLAMPIS(but->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);
+				
+				button_activate_state(C, but, BUTTON_STATE_EXIT);
+				ui_apply_button(C, but->block, but, data, 1);
+				return WM_UI_HANDLER_BREAK;
+			}
+		}
 	}
 
 	return WM_UI_HANDLER_CONTINUE;
@@ -2223,8 +2243,11 @@
 		but->hsv[2]= x; 
 		but->hsv[1]= y; 
 	}
+	else if(but->a1==3) {
+		but->hsv[0]= x; 
+	}
 	else
-		but->hsv[0]= x; 
+		but->hsv[2]= y; 
 
 	ui_set_but_hsv(but);	// converts to rgb
 	
@@ -2276,6 +2299,79 @@
 	return WM_UI_HANDLER_CONTINUE;
 }
 
+static int ui_numedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data, int mx, int my)
+{
+	rcti rect;
+	int changed= 1;
+
+	rect.xmin= but->x1; rect.xmax= but->x2;
+	rect.ymin= but->y1; rect.ymax= but->y2;
+	
+	ui_hsvcircle_vals_from_pos(but->hsv, but->hsv+1, &rect, (float)mx, (float)my);
+	
+	ui_set_but_hsv(but);	// converts to rgb
+	
+	// update button values and strings
+	// XXX ui_update_block_buts_hsv(but->block, but->hsv);
+	
+	data->draglastx= mx;
+	data->draglasty= my;
+	
+	return changed;
+}
+
+
+static int ui_do_but_HSVCIRCLE(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, wmEvent *event)
+{
+	int mx, my;
+	
+	mx= event->x;
+	my= event->y;
+	ui_window_to_block(data->region, block, &mx, &my);
+	
+	if(data->state == BUTTON_STATE_HIGHLIGHT) {
+		if(event->type==LEFTMOUSE && event->val==KM_PRESS) {
+			data->dragstartx= mx;
+			data->dragstarty= my;
+			data->draglastx= mx;
+			data->draglasty= my;
+			button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
+			
+			/* also do drag the first time */
+			if(ui_numedit_but_HSVCIRCLE(but, data, mx, my))
+				ui_numedit_apply(C, block, but, data);
+			
+			return WM_UI_HANDLER_BREAK;
+		}
+	}
+	else if(data->state == BUTTON_STATE_NUM_EDITING) {
+		/* XXX hardcoded keymap check.... */
+		if(event->type == WHEELDOWNMOUSE) {
+			but->hsv[2]= CLAMPIS(but->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);
+			ui_set_but_hsv(but);	// converts to rgb
+			ui_numedit_apply(C, block, but, data);
+		}
+		else if(event->type == MOUSEMOVE) {
+			if(mx!=data->draglastx || my!=data->draglasty) {
+				if(ui_numedit_but_HSVCIRCLE(but, data, mx, my))
+					ui_numedit_apply(C, block, but, data);
+			}
+		}
+		else if(event->type==LEFTMOUSE && event->val!=KM_PRESS)
+			button_activate_state(C, but, BUTTON_STATE_EXIT);
+		
+		return WM_UI_HANDLER_BREAK;
+	}
+	
+	return WM_UI_HANDLER_CONTINUE;
+}
+
+
 static int verg_colorband(const void *a1, const void *a2)
 {
 	const CBData *x1=a1, *x2=a2;
@@ -2847,6 +2943,9 @@
 	case HSVCUBE:
 		retval= ui_do_but_HSVCUBE(C, block, but, data, event);
 		break;
+	case HSVCIRCLE:
+		retval= ui_do_but_HSVCIRCLE(C, block, but, data, event);
+		break;
 #ifdef INTERNATIONAL
 	case CHARTAB:
 		retval= ui_do_but_CHARTAB(C, block, but, data, event);
@@ -3545,8 +3644,10 @@
 		if(event->type == MOUSEMOVE)
 			ui_mouse_motion_towards_init(menu, mx, my, 0);
 
+		/* first block own event func */
+		if(block->block_event_func && block->block_event_func(C, block, event));
 		/* events not for active search menu button */
-		if(but==NULL || but->type!=SEARCH_MENU) {
+		else if(but==NULL || but->type!=SEARCH_MENU) {
 			switch(event->type) {
 				/* closing sublevels of pulldowns */
 				case LEFTARROWKEY:

Modified: branches/blender2.5/blender/source/blender/editors/interface/interface_intern.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/interface_intern.h	2009-06-12 14:02:37 UTC (rev 20831)
+++ branches/blender2.5/blender/source/blender/editors/interface/interface_intern.h	2009-06-12 14:22:27 UTC (rev 20832)
@@ -254,6 +254,9 @@
 	uiBlockHandleFunc handle_func;
 	void *handle_func_arg;
 	
+	/* custom extra handling */
+	int (*block_event_func)(const struct bContext *C, struct uiBlock *, struct wmEvent *);
+	
 	/* extra draw function for custom blocks */
 	void (*drawextra)(const struct bContext *C, void *idv, rcti *rect);
 
@@ -306,6 +309,8 @@
 extern void ui_get_but_vectorf(uiBut *but, float *vec);
 extern void ui_set_but_vectorf(uiBut *but, float *vec);
 
+extern void ui_hsvcircle_vals_from_pos(float *valrad, float *valdist, rcti *rect, float mx, float my);
+
 extern void ui_get_but_string(uiBut *but, char *str, int maxlen);
 extern int ui_set_but_string(struct bContext *C, uiBut *but, const char *str);
 extern int ui_get_but_string_max_length(uiBut *but);

Modified: branches/blender2.5/blender/source/blender/editors/interface/interface_regions.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/interface_regions.c	2009-06-12 14:02:37 UTC (rev 20831)
+++ branches/blender2.5/blender/source/blender/editors/interface/interface_regions.c	2009-06-12 14:22:27 UTC (rev 20832)
@@ -1393,6 +1393,7 @@
 	}
 }
 
+/* also used by small picker, be careful with name checks below... */
 void ui_update_block_buts_hsv(uiBlock *block, float *hsv)
 {
 	uiBut *bt;
@@ -1406,7 +1407,7 @@
 	update_picker_hex(block, rgb);
 
 	for(bt= block->buttons.first; bt; bt= bt->next) {
-		if(bt->type==HSVCUBE) {
+		if(ELEM(bt->type, HSVCUBE, HSVCIRCLE)) {
 			VECCOPY(bt->hsv, hsv);
 			ui_set_but_hsv(bt);
 		}
@@ -1701,22 +1702,103 @@
 	uiBlockEndAlign(block);
 }
 
+/* bt1 is num but, hsv1 is pointer to original color in hsv space*/
+/* callback to handle changes */
+static void do_picker_small_cb(bContext *C, void *bt1, void *hsv1)
+{
+	uiBut *but1= (uiBut *)bt1;
+	uiPopupBlockHandle *popup= but1->block->handle;
+	float *hsv= (float *)hsv1;
+	float *fp= NULL;
+	
+	fp= (float *)but1->poin;
+	rgb_to_hsv(fp[0], fp[1], fp[2], hsv, hsv+1, hsv+2);
+
+	ui_update_block_buts_hsv(but1->block, hsv);
+	
+	if(popup)
+		popup->menuretval= UI_RETURN_UPDATE;
+}
+
+
+/* only the color, a circle, slider */
+void uiBlockPickerSmall(uiBlock *block, float *col, float *hsv, float *old, char *hexcol, char mode, short retval)
+{
+	uiBut *bt;
+	
+	VECCOPY(old, col);	// old color stored there, for palette_cb to work
+	
+	/* HS circle */
+	bt= uiDefButF(block, HSVCIRCLE, retval, "",	0, 0,SPICK,SPICK, col, 0.0, 0.0, 0, 0, "");
+	uiButSetFunc(bt, do_picker_small_cb, bt, hsv);
+
+	/* value */
+	bt= uiDefButF(block, HSVCUBE, retval, "",	SPICK+DPICK,0,14,SPICK, col, 0.0, 0.0, 4, 0, "");
+	uiButSetFunc(bt, do_picker_small_cb, bt, hsv);
+
+}
+
+static int ui_picker_small_wheel(const bContext *C, uiBlock *block, wmEvent *event)
+{
+	float add= 0.0f;
+	
+	if(event->type==WHEELUPMOUSE)
+		add= 0.05f;
+	else if(event->type==WHEELDOWNMOUSE)
+		add= -0.05f;
+	
+	if(add!=0.0f) {
+		uiBut *but;
+		
+		for(but= block->buttons.first; but; but= but->next) {
+			if(but->type==HSVCUBE && but->active==NULL) {
+				uiPopupBlockHandle *popup= block->handle;
+				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);
+				but->hsv[2]= CLAMPIS(but->hsv[2]+add, 0.0f, 1.0f);
+				hsv_to_rgb(but->hsv[0], but->hsv[1], but->hsv[2], col, col+1, col+2);
+
+				ui_set_but_vectorf(but, col);
+				
+				ui_update_block_buts_hsv(block, but->hsv);
+				if(popup)
+					popup->menuretval= UI_RETURN_UPDATE;
+				
+				return 1;
+			}
+		}
+	}
+	return 0;
+}
+
 uiBlock *ui_block_func_COL(bContext *C, uiPopupBlockHandle *handle, void *arg_but)
 {
+	wmWindow *win= CTX_wm_window(C); // XXX temp, needs to become keymap to detect type?
 	uiBut *but= arg_but;
 	uiBlock *block;
 	static float hsvcol[3], oldcol[3];
 	static char hexcol[128];
 	
 	block= uiBeginBlock(C, handle->region, "colorpicker", UI_EMBOSS);
-	block->flag= UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_KEEP_OPEN;
 	
 	VECCOPY(handle->retvec, but->editvec);
-	uiBlockPickerButtons(block, handle->retvec, hsvcol, oldcol, hexcol, 'p', 0);
-

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list