[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59639] branches/soc-2013-ui_replay/source /blender/editors/interface: Implemented the first parts of the draggable operator buttons for custom panels .

Vincent Akkermans vincent at ack-err.net
Thu Aug 29 17:35:59 CEST 2013


Revision: 59639
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59639
Author:   ack-err
Date:     2013-08-29 15:35:59 +0000 (Thu, 29 Aug 2013)
Log Message:
-----------
Implemented the first parts of the draggable operator buttons for custom panels.

Modified Paths:
--------------
    branches/soc-2013-ui_replay/source/blender/editors/interface/interface_handlers.c
    branches/soc-2013-ui_replay/source/blender/editors/interface/interface_intern.h
    branches/soc-2013-ui_replay/source/blender/editors/interface/interface_panel.c

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-29 14:52:36 UTC (rev 59638)
+++ branches/soc-2013-ui_replay/source/blender/editors/interface/interface_handlers.c	2013-08-29 15:35:59 UTC (rev 59639)
@@ -5545,7 +5545,7 @@
 	return BLI_rctf_isect_pt(&but->rect, mx, my);
 }
 
-static uiBut *ui_but_find_activated(ARegion *ar)
+uiBut *ui_but_find_activated(ARegion *ar)
 {
 	uiBlock *block;
 	uiBut *but;

Modified: branches/soc-2013-ui_replay/source/blender/editors/interface/interface_intern.h
===================================================================
--- branches/soc-2013-ui_replay/source/blender/editors/interface/interface_intern.h	2013-08-29 14:52:36 UTC (rev 59638)
+++ branches/soc-2013-ui_replay/source/blender/editors/interface/interface_intern.h	2013-08-29 15:35:59 UTC (rev 59639)
@@ -517,6 +517,7 @@
 extern void ui_button_activate_do(struct bContext *C, struct ARegion *ar, uiBut *but);
 extern void ui_button_execute_do(struct bContext *C, struct ARegion *ar, uiBut *but);
 extern void ui_button_active_free(const struct bContext *C, uiBut *but);
+extern uiBut *ui_but_find_activated(ARegion *ar);
 extern bool ui_button_is_active(struct ARegion *ar);
 extern int ui_button_open_menu_direction(uiBut *but);
 extern void ui_button_text_password_hide(char password_str[UI_MAX_DRAW_STR], uiBut *but, int restore);

Modified: branches/soc-2013-ui_replay/source/blender/editors/interface/interface_panel.c
===================================================================
--- branches/soc-2013-ui_replay/source/blender/editors/interface/interface_panel.c	2013-08-29 14:52:36 UTC (rev 59638)
+++ branches/soc-2013-ui_replay/source/blender/editors/interface/interface_panel.c	2013-08-29 15:35:59 UTC (rev 59639)
@@ -75,7 +75,9 @@
 	PANEL_STATE_DRAG_SCALE,
 	PANEL_STATE_WAIT_UNTAB,
 	PANEL_STATE_ANIMATION,
-	PANEL_STATE_EXIT
+	PANEL_STATE_EXIT,
+	PANEL_STATE_DRAG_BUTTON_WAITING,
+	PANEL_STATE_DRAG_BUTTON
 } uiHandlePanelState;
 
 typedef struct uiHandlePanelData {
@@ -89,6 +91,10 @@
 	int startx, starty;
 	int startofsx, startofsy;
 	int startsizex, startsizey;
+	
+	/* dragging custom button */
+	OperatorListItem *oli;
+	
 } uiHandlePanelData;
 
 static void panel_activate_state(const bContext *C, Panel *pa, uiHandlePanelState state);
@@ -1109,6 +1115,28 @@
 	ED_region_tag_redraw(ar);
 }
 
+static void ui_do_drag_button(const bContext *C, const wmEvent *event, Panel *panel)
+{
+	uiHandlePanelData *data = panel->activedata;
+	ScrArea *sa = CTX_wm_area(C);
+	ARegion *ar = CTX_wm_region(C);
+
+	// TODO: deal with the reordering of buttons
+	
+	ED_region_tag_redraw(ar);
+}
+
+static void ui_do_drag_button_finish(const bContext *C, const wmEvent *event, Panel *panel)
+{
+	uiHandlePanelData *data = panel->activedata;
+	ScrArea *sa = CTX_wm_area(C);
+	ARegion *ar = CTX_wm_region(C);
+	
+	// TODO: finish and clean up the reordering of buttons
+	
+	ED_region_tag_redraw(ar);
+}
+
 /******************* region level panel interaction *****************/
 
 static void panel_popup_draw(bContext *C, uiBlock *block, Panel *pa)
@@ -1301,7 +1329,6 @@
 		case 1:
 			/* collapse */
 			if (ctrl)
-				// TODO: CTRL AKEY doesn't seem to arrive here ~ ack-err
 				uiCollapseAllPanels(sa, ar, CTX_data_mode_string(C));
 
 			if (block->panel->flag & PNL_CLOSED) {
@@ -1393,24 +1420,48 @@
 		}
 		
 		/* XXX hardcoded key warning */
-		if ((inside || inside_header) && event->val == KM_PRESS) {
-			if (event->type == AKEY && !ELEM4(KM_MOD_FIRST, event->ctrl, event->oskey, event->shift, event->alt)) {
-				
-				if (pa->flag & PNL_CLOSEDY) {
-					if ((block->rect.ymax <= my) && (block->rect.ymax + PNL_HEADER >= my))
+		if (inside || inside_header) {
+			if (event->val == KM_PRESS) {
+				if (event->type == AKEY && !ELEM4(KM_MOD_FIRST, event->ctrl, event->oskey, event->shift, event->alt)) {
+					
+					if (pa->flag & PNL_CLOSEDY) {
+						if ((block->rect.ymax <= my) && (block->rect.ymax + PNL_HEADER >= my))
+							ui_handle_panel_header(C, block, mx, my, event->type, event->ctrl);
+					}
+					else
 						ui_handle_panel_header(C, block, mx, my, event->type, event->ctrl);
+					
+					retval = WM_UI_HANDLER_BREAK;
+					continue;
 				}
-				else
-					ui_handle_panel_header(C, block, mx, my, event->type, event->ctrl);
-				
-				retval = WM_UI_HANDLER_BREAK;
-				continue;
 			}
 		}
 		
-		/* on active button, do not handle panels */
-		if (ui_button_is_active(ar))
+		/* This catches the drag events here so that we can do our own custom drag instead
+		 * of having the drag & drop system handle the button/op drag. */
+		
+		
+		/* on active button, do a possible button drag for reordering, but panels should
+		 * not be handled. */
+		
+		if (ui_button_is_active(ar)) {
+			uiBut *but = ui_but_find_activated(ar);
+			uiHandlePanelData *data;
+			
+			if (inside && but && pa->flag & PNL_CUSTOM_PANEL) {
+				// Are we starting a potential drag?
+				if (event->type == LEFTMOUSE && event->val == KM_PRESS) {
+					panel_activate_state(C, pa, PANEL_STATE_DRAG_BUTTON_WAITING);
+					// pass the oli that is being dragged
+					data = pa->activedata;
+					data->oli = BLI_findstring(&pa->operators, but->optype->idname, offsetof(OperatorListItem, optype_idname));
+				}
+			}
+			
+			// Don't handle events for the panels if a button was activated
 			continue;
+		}
+			
 		
 		if (inside || inside_header) {
 
@@ -1496,13 +1547,17 @@
 {
 	Panel *panel = userdata;
 	uiHandlePanelData *data = panel->activedata;
+	ScrArea *sa = CTX_wm_area(C);
+	ARegion *ar = CTX_wm_region(C);
+	uiBut *but;
 
 	/* verify if we can stop */
+	
 	if (event->type == LEFTMOUSE && event->val != KM_PRESS) {
-		ScrArea *sa = CTX_wm_area(C);
-		ARegion *ar = CTX_wm_region(C);
 		int align = panel_aligned(sa, ar);
 
+		if (data->state == PANEL_STATE_DRAG_BUTTON)
+			ui_do_drag_button_finish(C, event, panel);
 		if (align)
 			panel_activate_state(C, panel, PANEL_STATE_ANIMATION);
 		else
@@ -1511,6 +1566,14 @@
 	else if (event->type == MOUSEMOVE) {
 		if (data->state == PANEL_STATE_DRAG)
 			ui_do_drag(C, event, panel);
+		if (data->state == PANEL_STATE_DRAG_BUTTON_WAITING) {
+			panel_activate_state(C, panel, PANEL_STATE_DRAG_BUTTON);
+			but = ui_but_find_activated(ar);
+			ui_button_active_free(C, but);
+			return WM_UI_HANDLER_BREAK;
+		}
+		if (data->state == PANEL_STATE_DRAG_BUTTON)
+			ui_do_drag_button(C, event, panel);
 	}
 	else if (event->type == TIMER && event->customdata == data->animtimer) {
 		if (data->state == PANEL_STATE_ANIMATION)
@@ -1622,11 +1685,21 @@
 
 static void custom_panel_draw(const bContext *UNUSED(C), Panel *pa)
 {
+	uiHandlePanelData *data = pa->activedata;
 	uiLayout *layout = pa->layout;
 	uiLayout *column = uiLayoutColumn(layout, TRUE);
+	const char *idname;
+	OperatorListItem *oli_drag = NULL, *oli;
+	int drag_state = data ? (data->state == PANEL_STATE_DRAG_BUTTON) : 0;
 	
-	for (OperatorListItem *oli = pa->operators.first; oli; oli = oli->next) {
-		uiItemO(column, NULL, ICON_NONE, oli->optype_idname);
+	for (oli = pa->operators.first; oli; oli = oli->next) {
+		if (drag_state && data->oli == oli) {
+			uiItemS(column);
+			uiItemS(column);
+		}
+		else {
+			uiItemO(column, NULL, ICON_NONE, oli->optype_idname);
+		}
 	}
 }
 




More information about the Bf-blender-cvs mailing list