[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50810] trunk/blender/source/blender/ editors/interface: fix [#32609] RGB Curves Mouse Pointer Problem

Campbell Barton ideasman42 at gmail.com
Sat Sep 22 14:25:54 CEST 2012


Revision: 50810
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50810
Author:   campbellbarton
Date:     2012-09-22 12:25:54 +0000 (Sat, 22 Sep 2012)
Log Message:
-----------
fix [#32609] RGB Curves Mouse Pointer Problem

this was working as intended but users complained that the mouse cursor stayed in the same location after using the color picker and curves with continuous grab enabled.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/interface/interface.c
    trunk/blender/source/blender/editors/interface/interface_handlers.c

Modified: trunk/blender/source/blender/editors/interface/interface.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface.c	2012-09-22 12:23:17 UTC (rev 50809)
+++ trunk/blender/source/blender/editors/interface/interface.c	2012-09-22 12:25:54 UTC (rev 50810)
@@ -2619,6 +2619,9 @@
 	uiBut *but;
 	int slen;
 
+	BLI_assert(width >= 0);
+	BLI_assert(height >= 0);
+
 	/* we could do some more error checks here */
 	if ((type & BUTTYPE) == LABEL) {
 		BLI_assert((poin != NULL || min != 0.0f || max != 0.0f || (a1 == 0.0f && a2 != 0.0f) || (a1 != 0.0f && a1 != 1.0f)) == FALSE);

Modified: trunk/blender/source/blender/editors/interface/interface_handlers.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_handlers.c	2012-09-22 12:23:17 UTC (rev 50809)
+++ trunk/blender/source/blender/editors/interface/interface_handlers.c	2012-09-22 12:25:54 UTC (rev 50810)
@@ -78,6 +78,9 @@
 #include "WM_api.h"
 #include "WM_types.h"
 
+/* place the mouse at the scaled down location when un-grabbing */
+#define USE_CONT_MOUSE_CORRECT
+
 /* proto */
 static void ui_add_smart_controller(bContext *C, uiBut *from, uiBut *to);
 static void ui_add_link(bContext *C, uiBut *from, uiBut *to);
@@ -152,6 +155,12 @@
 	float dragf, dragfstart;
 	CBData *dragcbd;
 
+#ifdef USE_CONT_MOUSE_CORRECT
+	/* when ungrabbing buttons which are #ui_is_a_warp_but(), we may want to position them
+	 * FLT_MAX signifies do-nothing, use #ui_block_to_window_fl() to get this into a usable space  */
+	float ungrab_mval[2];
+#endif
+
 	/* menu open (watch uiFreeActiveButtons) */
 	uiPopupBlockHandle *menu;
 	int menuretval;
@@ -3191,6 +3200,15 @@
 	
 	ui_mouse_scale_warp(data, mx, my, &mx_fl, &my_fl, shift);
 
+#ifdef USE_CONT_MOUSE_CORRECT
+	if (ui_is_a_warp_but(but)) {
+		/* OK but can go outside bounds */
+		data->ungrab_mval[0] = mx_fl;
+		data->ungrab_mval[1] = my_fl;
+		BLI_rctf_clamp_pt_v(&but->rect, data->ungrab_mval);
+	}
+#endif
+
 	if (but->rnaprop) {
 		if (RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA)
 			color_profile = FALSE;
@@ -3415,6 +3433,22 @@
 	
 	ui_mouse_scale_warp(data, mx, my, &mx_fl, &my_fl, shift);
 
+#ifdef USE_CONT_MOUSE_CORRECT
+	if (ui_is_a_warp_but(but)) {
+		/* OK but can go outside bounds */
+		data->ungrab_mval[0] = mx_fl;
+		data->ungrab_mval[1] = my_fl;
+		{	/* clamp */
+			const float radius = minf(BLI_rctf_size_x(&but->rect), BLI_rctf_size_y(&but->rect)) / 2.0f;
+			const float cent[2] = {BLI_rctf_cent_x(&but->rect), BLI_rctf_cent_y(&but->rect)};
+			const float len = len_v2v2(cent, data->ungrab_mval);
+			if (len > radius) {
+				dist_ensure_v2_v2fl(data->ungrab_mval, cent, radius);
+			}
+		}
+	}
+#endif
+
 	BLI_rcti_rctf_copy(&rect, &but->rect);
 
 	ui_get_but_vectorf(but, rgb);
@@ -3706,9 +3740,10 @@
 	}
 
 	if (data->dragsel != -1) {
+		CurveMapPoint *cmp_last = NULL;
 		const float mval_factor = ui_mouse_scale_warp_factor(shift);
 		int moved_point = 0;     /* for ctrl grid, can't use orig coords because of sorting */
-		
+
 		fx = (mx - data->draglastx) / zoomx;
 		fy = (my - data->draglasty) / zoomy;
 
@@ -3726,6 +3761,8 @@
 				}
 				if (cmp[a].x != origx || cmp[a].y != origy)
 					moved_point = 1;
+
+				cmp_last = &cmp[a];
 			}
 		}
 
@@ -3735,6 +3772,18 @@
 			data->draglastx = mx;
 			data->draglasty = my;
 			changed = 1;
+
+#ifdef USE_CONT_MOUSE_CORRECT
+			/* note: using 'cmp_last' is weak since there may be multiple points selected,
+			 * but in practice this isnt really an issue */
+			if (ui_is_a_warp_but(but)) {
+				/* OK but can go outside bounds */
+				data->ungrab_mval[0] = but->rect.xmin + ((cmp_last->x - cumap->curr.xmin) * zoomx);
+				data->ungrab_mval[1] = but->rect.ymin + ((cmp_last->y - cumap->curr.ymin) * zoomy);
+				BLI_rctf_clamp_pt_v(&but->rect, data->ungrab_mval);
+			}
+#endif
+
 		}
 
 		data->dragchange = 1; /* mark for selection */
@@ -5322,8 +5371,17 @@
 	}
 	else if (data->state == BUTTON_STATE_NUM_EDITING) {
 		ui_numedit_end(but, data);
-		if (ui_is_a_warp_but(but))
+		if (ui_is_a_warp_but(but)) {
 			WM_cursor_grab_disable(CTX_wm_window(C));
+
+			/* XXX, you can see that the cursor is revealed, then moved - should do at once */
+#ifdef USE_CONT_MOUSE_CORRECT
+			if (data->ungrab_mval[0] != FLT_MAX) {
+				ui_block_to_window_fl(data->region, but->block, &data->ungrab_mval[0], &data->ungrab_mval[1]);
+				WM_cursor_warp(CTX_wm_window(C), data->ungrab_mval[0], data->ungrab_mval[1]);
+			}
+#endif
+		}
 	}
 	/* menu open */
 	if (state == BUTTON_STATE_MENU_OPEN)
@@ -5386,6 +5444,10 @@
 	data->window = CTX_wm_window(C);
 	data->region = ar;
 
+#ifdef USE_CONT_MOUSE_CORRECT
+	copy_v2_fl(data->ungrab_mval, FLT_MAX);
+#endif
+
 	if (ELEM(but->type, BUT_CURVE, SEARCH_MENU)) {
 		/* XXX curve is temp */
 	}




More information about the Bf-blender-cvs mailing list