[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59295] branches/soc-2013-ui_replay/source /blender: Makes operator buttons draggable.

Vincent Akkermans vincent at ack-err.net
Mon Aug 19 14:17:32 CEST 2013


Revision: 59295
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59295
Author:   ack-err
Date:     2013-08-19 12:17:31 +0000 (Mon, 19 Aug 2013)
Log Message:
-----------
Makes operator buttons draggable.

Modified Paths:
--------------
    branches/soc-2013-ui_replay/source/blender/editors/include/UI_interface.h
    branches/soc-2013-ui_replay/source/blender/editors/interface/interface.c
    branches/soc-2013-ui_replay/source/blender/editors/interface/interface_handlers.c
    branches/soc-2013-ui_replay/source/blender/editors/interface/interface_layout.c
    branches/soc-2013-ui_replay/source/blender/windowmanager/WM_types.h
    branches/soc-2013-ui_replay/source/blender/windowmanager/intern/wm_dragdrop.c

Modified: branches/soc-2013-ui_replay/source/blender/editors/include/UI_interface.h
===================================================================
--- branches/soc-2013-ui_replay/source/blender/editors/include/UI_interface.h	2013-08-19 12:05:18 UTC (rev 59294)
+++ branches/soc-2013-ui_replay/source/blender/editors/include/UI_interface.h	2013-08-19 12:17:31 UTC (rev 59295)
@@ -442,6 +442,7 @@
 void    uiButSetDragRNA(uiBut *but, struct PointerRNA *ptr);
 void    uiButSetDragPath(uiBut *but, const char *path);
 void    uiButSetDragName(uiBut *but, const char *name);
+void	uiButSetDragOp(uiBut *but, const struct wmOperatorType *ot);
 void    uiButSetDragValue(uiBut *but);
 void    uiButSetDragImage(uiBut *but, const char *path, int icon, struct ImBuf *ima, float scale);
 

Modified: branches/soc-2013-ui_replay/source/blender/editors/interface/interface.c
===================================================================
--- branches/soc-2013-ui_replay/source/blender/editors/interface/interface.c	2013-08-19 12:05:18 UTC (rev 59294)
+++ branches/soc-2013-ui_replay/source/blender/editors/interface/interface.c	2013-08-19 12:17:31 UTC (rev 59295)
@@ -3499,6 +3499,12 @@
 	but->dragpoin = (void *)name;
 }
 
+void uiButSetDragOp(uiBut *but, const wmOperatorType *ot)
+{
+	but->dragtype = WM_DRAG_OP;
+	but->dragpoin = (void *)ot;
+}
+
 /* value from button itself */
 void uiButSetDragValue(uiBut *but)
 {

Modified: branches/soc-2013-ui_replay/source/blender/editors/interface/interface_handlers.c
===================================================================
--- branches/soc-2013-ui_replay/source/blender/editors/interface/interface_handlers.c	2013-08-19 12:05:18 UTC (rev 59294)
+++ branches/soc-2013-ui_replay/source/blender/editors/interface/interface_handlers.c	2013-08-19 12:17:31 UTC (rev 59295)
@@ -2480,7 +2480,14 @@
 static int ui_do_but_BUT(bContext *C, uiBut *but, uiHandleButtonData *data, const wmEvent *event)
 {
 	if (data->state == BUTTON_STATE_HIGHLIGHT) {
-		if (event->type == LEFTMOUSE && event->val == KM_PRESS) {
+		/* first handle click on icondrag type button */
+		if (event->type == LEFTMOUSE && but->dragpoin && event->val == KM_PRESS) {
+			button_activate_state(C, but, BUTTON_STATE_WAIT_DRAG);
+			data->dragstartx = event->x;
+			data->dragstarty = event->y;
+			return WM_UI_HANDLER_BREAK;
+		}
+		else if (event->type == LEFTMOUSE && event->val == KM_PRESS) {
 			button_activate_state(C, but, BUTTON_STATE_WAIT_RELEASE);
 			return WM_UI_HANDLER_BREAK;
 		}
@@ -2504,6 +2511,25 @@
 			return WM_UI_HANDLER_BREAK;
 		}
 	}
+	else if (data->state == BUTTON_STATE_WAIT_DRAG) {
+		
+		/* this function also ends state */
+		if (ui_but_start_drag(C, but, data, event)) {
+			return WM_UI_HANDLER_BREAK;
+		}
+		
+		/* If the mouse has been pressed and released, getting to
+		 * this point without triggering a drag, then clear the
+		 * drag state for this button and continue to pass on the event */
+		if (event->type == LEFTMOUSE && event->val == KM_RELEASE) {
+			button_activate_state(C, but, BUTTON_STATE_EXIT);
+			return WM_UI_HANDLER_CONTINUE;
+		}
+		
+		/* while waiting for a drag to be triggered, always block
+		 * other events from getting handled */
+		return WM_UI_HANDLER_BREAK;
+	}
 
 	return WM_UI_HANDLER_CONTINUE;
 }

Modified: branches/soc-2013-ui_replay/source/blender/editors/interface/interface_layout.c
===================================================================
--- branches/soc-2013-ui_replay/source/blender/editors/interface/interface_layout.c	2013-08-19 12:05:18 UTC (rev 59294)
+++ branches/soc-2013-ui_replay/source/blender/editors/interface/interface_layout.c	2013-08-19 12:17:31 UTC (rev 59295)
@@ -730,7 +730,10 @@
 	   indicated the shortcut should be shown */
 	if (flag & UI_ITEM_O_SHORTCUT && block->flag & UI_BLOCK_SHORTCUTS)
 		but->flag2 |= UI_BUT2_EXTRA_TEXT;
-
+	
+	/* Make operator buttons draggable */
+	uiButSetDragOp(but, ot);
+	
 	assert(but->optype != NULL);
 
 	/* text alignment for toolbar buttons */

Modified: branches/soc-2013-ui_replay/source/blender/windowmanager/WM_types.h
===================================================================
--- branches/soc-2013-ui_replay/source/blender/windowmanager/WM_types.h	2013-08-19 12:05:18 UTC (rev 59294)
+++ branches/soc-2013-ui_replay/source/blender/windowmanager/WM_types.h	2013-08-19 12:17:31 UTC (rev 59295)
@@ -629,6 +629,7 @@
 #define WM_DRAG_PATH	2
 #define WM_DRAG_NAME	3
 #define WM_DRAG_VALUE	4
+#define WM_DRAG_OP		5
 
 /* note: structs need not exported? */
 

Modified: branches/soc-2013-ui_replay/source/blender/windowmanager/intern/wm_dragdrop.c
===================================================================
--- branches/soc-2013-ui_replay/source/blender/windowmanager/intern/wm_dragdrop.c	2013-08-19 12:05:18 UTC (rev 59294)
+++ branches/soc-2013-ui_replay/source/blender/windowmanager/intern/wm_dragdrop.c	2013-08-19 12:17:31 UTC (rev 59295)
@@ -279,6 +279,11 @@
 			return drag->path;
 		case WM_DRAG_NAME:
 			return (char *)drag->path;
+		case WM_DRAG_OP:
+		{
+			wmOperatorType *ot = (wmOperatorType*)drag->poin;
+			return ot->name;
+		}
 	}
 	return "";
 }




More information about the Bf-blender-cvs mailing list