[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48184] branches/soc-2012-bratwurst/source /blender: Clicking and dragging an a series of toggle buttons with the same function toggles them all to the same state .

Jorge Rodriguez bs.vino at gmail.com
Fri Jun 22 04:43:42 CEST 2012


Revision: 48184
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48184
Author:   vino
Date:     2012-06-22 02:43:40 +0000 (Fri, 22 Jun 2012)
Log Message:
-----------
Clicking and dragging an a series of toggle buttons with the same function toggles them all to the same state. Works for lots of different kinds of toggle buttons, such as the layout buttons, buttons in the outliner, and listbox buttons. State variables are stored in G, which is perhaps not appropriate, but is the best place I've found so far to store such things.

Modified Paths:
--------------
    branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_global.h
    branches/soc-2012-bratwurst/source/blender/blenkernel/intern/blender.c
    branches/soc-2012-bratwurst/source/blender/editors/interface/interface_handlers.c
    branches/soc-2012-bratwurst/source/blender/windowmanager/intern/wm_event_system.c

Modified: branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_global.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_global.h	2012-06-22 02:40:23 UTC (rev 48183)
+++ branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_global.h	2012-06-22 02:43:40 UTC (rev 48184)
@@ -93,6 +93,10 @@
 	int windowstate;
 
 	double last_tooltip_close;
+
+	// Fields to enable dragging a list of toggle buttons to turn them all on or off
+	void* drag_button_func;	// It's a func pointer, but we only need the value to compare and we won't call the function, so I use void* to avoid a dependency on uiButHandleFunc
+	int drag_button_state;	// Turn them on or off as we drag?
 } Global;
 
 /* **************** GLOBAL ********************* */

Modified: branches/soc-2012-bratwurst/source/blender/blenkernel/intern/blender.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/blenkernel/intern/blender.c	2012-06-22 02:40:23 UTC (rev 48183)
+++ branches/soc-2012-bratwurst/source/blender/blenkernel/intern/blender.c	2012-06-22 02:43:40 UTC (rev 48184)
@@ -150,6 +150,8 @@
 #else
 	G.f &= ~G_SCRIPT_AUTOEXEC;
 #endif
+
+	G.drag_button_func = 0;
 }
 
 /***/

Modified: branches/soc-2012-bratwurst/source/blender/editors/interface/interface_handlers.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/interface/interface_handlers.c	2012-06-22 02:40:23 UTC (rev 48183)
+++ branches/soc-2012-bratwurst/source/blender/editors/interface/interface_handlers.c	2012-06-22 02:43:40 UTC (rev 48184)
@@ -2231,8 +2231,24 @@
 			data->togdual = event->ctrl;
 			data->togonly = !event->shift;
 			button_activate_state(C, but, BUTTON_STATE_EXIT);
+
+			G.drag_button_func = but->func;
+			G.drag_button_state = (ui_get_but_val(but) == 0);
+
 			return WM_UI_HANDLER_BREAK;
 		}
+
+		if (G.drag_button_func == but->func && G.drag_button_state == (ui_get_but_val(but) == 0))
+		{
+			wmWindow *win = CTX_wm_window(C);
+
+			button_activate_state(C, but, BUTTON_STATE_EXIT);
+
+			// Kind of a hack. We don't want this assignment to turn off others, so force shift on to cause handle_layer_buttons to skip that.
+			win->eventstate->shift = 1;
+
+			return WM_UI_HANDLER_BREAK;
+		}
 	}
 	return WM_UI_HANDLER_CONTINUE;
 }
@@ -5545,6 +5561,8 @@
 	return NULL;
 }
 
+int ui_handle_button_event(bContext *C, wmEvent *event, uiBut *but);
+
 static int ui_handle_button_over(bContext *C, wmEvent *event, ARegion *ar)
 {
 	uiBut *but;
@@ -5553,7 +5571,13 @@
 	if (event->type == MOUSEMOVE) {
 		but = ui_but_find_mouse_over(ar, event->x, event->y);
 		if (but)
+		{
 			button_activate_init(C, ar, but, BUTTON_ACTIVATE_OVER);
+
+			if (G.drag_button_func)
+				// Make sure the button gets the event so it can toggle itself
+				ui_handle_button_event(C, event, but);
+		}
 	}
 	else if (event->type == EVT_BUT_OPEN) {
 		but = uit_but_find_open_event(ar, event);
@@ -5648,6 +5672,10 @@
 					button_tooltip_timer_reset(C, but);
 				}
 
+				if (G.drag_button_func)
+					// Make sure the button gets the event so it can toggle itself
+					retval = ui_do_button(C, block, but, event);
+
 				break;
 			case TIMER: {
 				/* handle tooltip timer */

Modified: branches/soc-2012-bratwurst/source/blender/windowmanager/intern/wm_event_system.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/windowmanager/intern/wm_event_system.c	2012-06-22 02:40:23 UTC (rev 48183)
+++ branches/soc-2012-bratwurst/source/blender/windowmanager/intern/wm_event_system.c	2012-06-22 02:43:40 UTC (rev 48184)
@@ -2123,6 +2123,12 @@
 				}
 			}
 
+			if (event->val == KM_RELEASE)
+			{
+				G.drag_button_func = 0;
+				win->eventstate->shift = 0; // This was set in ui_do_but_TOG(). Clear it now that we're done toggling buttons.
+			}
+
 			/* unlink and free here, blender-quit then frees all */
 			BLI_remlink(&win->queue, event);
 			wm_event_free(event);




More information about the Bf-blender-cvs mailing list