[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58343] branches/soc-2013-paint/source/ blender/editors/interface/interface_handlers.c: Uability feature to make palettes and other colour stuff work nice:

Antony Riakiotakis kalast at gmail.com
Wed Jul 17 17:22:02 CEST 2013


Revision: 58343
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58343
Author:   psy-fi
Date:     2013-07-17 15:22:01 +0000 (Wed, 17 Jul 2013)
Log Message:
-----------
Uability feature to make palettes and other colour stuff work nice:
Support drag'n drop of colours from colour widgets.

This requires a few changes to the way colour pickers pop up, they now
spawn on mouse release instead of mouse press.

Dragging to another colour copies the first colour to the second.
Unfortunately there's no undo here yet.

Modified Paths:
--------------
    branches/soc-2013-paint/source/blender/editors/interface/interface_handlers.c

Modified: branches/soc-2013-paint/source/blender/editors/interface/interface_handlers.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/interface/interface_handlers.c	2013-07-17 15:02:49 UTC (rev 58342)
+++ branches/soc-2013-paint/source/blender/editors/interface/interface_handlers.c	2013-07-17 15:22:01 UTC (rev 58343)
@@ -673,6 +673,10 @@
 
 #ifdef USE_DRAG_TOGGLE
 
+typedef struct uiDragColorHandle {
+	float color[3];
+} uiDragColorHandle;
+
 typedef struct uiDragToggleHandle {
 	/* init */
 	bool is_init;
@@ -785,6 +789,50 @@
 	copy_v2_v2_int(drag_info->xy_last, xy);
 }
 
+
+static void ui_handler_region_drag_color_remove(bContext *UNUSED(C), void *userdata)
+{
+	uiDragColorHandle *drag_info = userdata;
+	MEM_freeN(drag_info);
+}
+
+static int ui_handler_region_drag_color(bContext *C, const wmEvent *event, void *userdata)
+{
+	uiDragColorHandle *drag_info = userdata;
+
+	switch (event->type) {
+		case LEFTMOUSE:
+		{
+			if (event->val != KM_PRESS) {
+				wmWindow *win = CTX_wm_window(C);
+				ARegion *ar = CTX_wm_region(C);
+
+				/* find button under mouse, check if it has RNA color property and
+				 * if it does copy the data */
+				uiBut *but = ui_but_find_mouse_over(ar, event->x, event->y);
+
+				if (but && but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) {
+					RNA_property_float_set_array(&but->rnapoin, but->rnaprop, drag_info->color);
+					RNA_property_update(C, &but->rnapoin, but->rnaprop);
+				}
+
+				WM_event_remove_ui_handler(&win->modalhandlers,
+				                           ui_handler_region_drag_color,
+				                           ui_handler_region_drag_color_remove,
+				                           drag_info, false);
+				ui_handler_region_drag_color_remove(C, drag_info);
+
+				WM_event_add_mousemove(C);
+				return WM_UI_HANDLER_BREAK;
+			}
+			break;
+		}
+	}
+
+	return WM_UI_HANDLER_CONTINUE;
+}
+
+
 static void ui_handler_region_drag_toggle_remove(bContext *UNUSED(C), void *userdata)
 {
 	uiDragToggleHandle *drag_info = userdata;
@@ -846,7 +894,7 @@
 	
 	BLI_rcti_rctf_copy(&rect, &but->rect);
 	
-	if (but->imb) {
+	if (but->imb || but->type == COLOR) {
 		/* use button size itself */
 	}
 	else if (but->flag & UI_ICON_LEFT) {
@@ -899,6 +947,26 @@
 		}
 		else
 #endif
+		if (but->type == COLOR) {
+			bool valid = false;
+			uiDragColorHandle *drag_info = MEM_callocN(sizeof(*drag_info), __func__);
+
+			/* TODO support more button pointer types */
+			if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) {
+				RNA_property_float_get_array(&but->rnapoin, but->rnaprop, drag_info->color);
+				valid = true;
+			} else if (but->pointype == UI_BUT_POIN_FLOAT) {
+				copy_v3_v3(drag_info->color, (float *)but->poin);
+				valid = true;
+			}
+
+			if (valid)
+				WM_event_add_ui_handler(C, &data->window->modalhandlers,
+			                        ui_handler_region_drag_color,
+			                        ui_handler_region_drag_color_remove,
+			                        drag_info);
+		}
+		else
 		{
 			wmDrag *drag;
 
@@ -3422,7 +3490,7 @@
 			}
 		}
 #ifdef USE_DRAG_TOGGLE
-		if (event->type == LEFTMOUSE && ui_is_but_bool(but)) {
+		if (event->type == LEFTMOUSE && (ui_is_but_bool(but) || but->type == COLOR)) {
 			button_activate_state(C, but, BUTTON_STATE_WAIT_DRAG);
 			data->dragstartx = event->x;
 			data->dragstarty = event->y;




More information about the Bf-blender-cvs mailing list