[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [28073] trunk/blender/source/blender/ editors/space_node: The daily node commit: brought back panning background image.

Ton Roosendaal ton at blender.org
Wed Apr 7 19:06:22 CEST 2010


Revision: 28073
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28073
Author:   ton
Date:     2010-04-07 19:06:22 +0200 (Wed, 07 Apr 2010)

Log Message:
-----------
The daily node commit: brought back panning background image.
For now it is on ALT+MiddleMouse. The view2d code eats the shift+mmb,
which is not necessary, but will have to ask Joshua to be sure. 

Probably tomorrow it's shift+mmb as for 2.49.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_node/node_edit.c
    trunk/blender/source/blender/editors/space_node/node_intern.h
    trunk/blender/source/blender/editors/space_node/node_ops.c

Modified: trunk/blender/source/blender/editors/space_node/node_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/node_edit.c	2010-04-07 14:46:06 UTC (rev 28072)
+++ trunk/blender/source/blender/editors/space_node/node_edit.c	2010-04-07 17:06:22 UTC (rev 28073)
@@ -61,6 +61,7 @@
 
 #include "RE_pipeline.h"
 
+#include "IMB_imbuf_types.h"
 
 #include "ED_node.h"
 #include "ED_screen.h"
@@ -73,7 +74,7 @@
 
 #include "UI_interface.h"
 #include "UI_view2d.h"
- 
+
 #include "node_intern.h"
 
 #define SOCK_IN		1
@@ -686,69 +687,95 @@
 	return tnode;
 }
 
-#if 0
-static void snode_bg_viewmove(SpaceNode *snode)
+/* **************************** */
+
+typedef struct NodeViewMove {
+	short mvalo[2];
+	int xmin, ymin, xmax, ymax;
+} NodeViewMove;
+
+static int snode_bg_viewmove_modal(bContext *C, wmOperator *op, wmEvent *event)
 {
-	ScrArea *sa;
+	SpaceNode *snode= CTX_wm_space_node(C);
+	ARegion *ar= CTX_wm_region(C);
+	NodeViewMove *nvm= op->customdata;
+
+	switch (event->type) {
+		case MOUSEMOVE:
+			
+			snode->xof -= (nvm->mvalo[0]-event->mval[0]);
+			snode->yof -= (nvm->mvalo[1]-event->mval[1]);
+			nvm->mvalo[0]= event->mval[0];
+			nvm->mvalo[1]= event->mval[1];
+			
+			/* prevent dragging image outside of the window and losing it! */
+			CLAMP(snode->xof, nvm->xmin, nvm->xmax);
+			CLAMP(snode->yof, nvm->ymin, nvm->ymax);
+			
+			ED_region_tag_redraw(ar);
+			
+			break;
+			
+		case LEFTMOUSE:
+		case MIDDLEMOUSE:
+		case RIGHTMOUSE:
+			
+			MEM_freeN(nvm);
+			op->customdata= NULL;
+			
+			return OPERATOR_FINISHED;
+	}
+	
+	return OPERATOR_RUNNING_MODAL;
+}
+
+static int snode_bg_viewmove_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+	ARegion *ar= CTX_wm_region(C);
+	NodeViewMove *nvm;
 	Image *ima;
 	ImBuf *ibuf;
-	Window *win;
-	short mval[2], mvalo[2];
-	short rectx, recty, xmin, xmax, ymin, ymax, pad;
-	int oldcursor;
+	int pad= 10;
 	
 	ima= BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
 	ibuf= BKE_image_get_ibuf(ima, NULL);
 	
-	sa = snode->area;
+	if(ibuf == NULL)
+		return OPERATOR_CANCELLED;
+
+	nvm= MEM_callocN(sizeof(NodeViewMove), "NodeViewMove struct");
+	op->customdata= nvm;
+	nvm->mvalo[0]= event->mval[0];
+	nvm->mvalo[1]= event->mval[1];
+
+	nvm->xmin = -(ar->winx/2) - ibuf->x/2 + pad;
+	nvm->xmax = ar->winx/2 + ibuf->x/2 - pad;
+	nvm->ymin = -(ar->winy/2) - ibuf->y/2 + pad;
+	nvm->ymax = ar->winy/2 + ibuf->y/2 - pad;
 	
-	if(ibuf) {
-		rectx = ibuf->x;
-		recty = ibuf->y;
-	} else {
-		rectx = recty = 1;
-	}
+	/* add modal handler */
+	WM_event_add_modal_handler(C, op);
 	
-	pad = 10;
-	xmin = -(sa->winx/2) - rectx/2 + pad;
-	xmax = sa->winx/2 + rectx/2 - pad;
-	ymin = -(sa->winy/2) - recty/2 + pad;
-	ymax = sa->winy/2 + recty/2 - pad;
+	return OPERATOR_RUNNING_MODAL;
+}
+
+
+void NODE_OT_backimage_move(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name= "Background Image Move";
+	ot->idname= "NODE_OT_backimage_move";
 	
-	getmouseco_sc(mvalo);
+	/* api callbacks */
+	ot->invoke= snode_bg_viewmove_invoke;
+	ot->modal= snode_bg_viewmove_modal;
+	ot->poll= ED_operator_node_active;
 	
-	/* store the old cursor to temporarily change it */
-	oldcursor=get_cursor();
-	win=winlay_get_active_window();
-	
-	SetBlenderCursor(BC_NSEW_SCROLLCURSOR);
-	
-	while(get_mbut()&(L_MOUSE|M_MOUSE)) {
-		
-		getmouseco_sc(mval);
-		
-		if(mvalo[0]!=mval[0] || mvalo[1]!=mval[1]) {
-			
-			snode->xof -= (mvalo[0]-mval[0]);
-			snode->yof -= (mvalo[1]-mval[1]);
-			
-			/* prevent dragging image outside of the window and losing it! */
-			CLAMP(snode->xof, xmin, xmax);
-			CLAMP(snode->yof, ymin, ymax);
-			
-			mvalo[0]= mval[0];
-			mvalo[1]= mval[1];
-			
-			scrarea_do_windraw(curarea);
-			screen_swapbuffers();
-		}
-		else BIF_wait_for_statechange();
-	}
-	
-	window_set_cursor(win, oldcursor);
+	/* flags */
+	ot->flag= OPTYPE_BLOCKING;
 }
-#endif
 
+
 /* ********************** size widget operator ******************** */
 
 typedef struct NodeSizeWidget {

Modified: trunk/blender/source/blender/editors/space_node/node_intern.h
===================================================================
--- trunk/blender/source/blender/editors/space_node/node_intern.h	2010-04-07 14:46:06 UTC (rev 28072)
+++ trunk/blender/source/blender/editors/space_node/node_intern.h	2010-04-07 17:06:22 UTC (rev 28073)
@@ -105,8 +105,8 @@
 void NODE_OT_link_viewer(struct wmOperatorType *ot);
 void NODE_OT_read_fullsamplelayers(struct wmOperatorType *ot);
 void NODE_OT_read_renderlayers(struct wmOperatorType *ot);
+void NODE_OT_backimage_move(struct wmOperatorType *ot);
 
-
 // XXXXXX
 
 // XXX from BSE_node.h

Modified: trunk/blender/source/blender/editors/space_node/node_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/node_ops.c	2010-04-07 14:46:06 UTC (rev 28072)
+++ trunk/blender/source/blender/editors/space_node/node_ops.c	2010-04-07 17:06:22 UTC (rev 28073)
@@ -74,6 +74,8 @@
 	
 	WM_operatortype_append(NODE_OT_read_renderlayers);
 	WM_operatortype_append(NODE_OT_read_fullsamplelayers);
+	
+	WM_operatortype_append(NODE_OT_backimage_move);
 }
 
 void ED_operatormacros_node(void)
@@ -122,6 +124,8 @@
 	WM_keymap_add_item(keymap, "NODE_OT_links_cut", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
 	WM_keymap_add_item(keymap, "NODE_OT_select_link_viewer", LEFTMOUSE, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
 	
+	WM_keymap_add_item(keymap, "NODE_OT_backimage_move", MIDDLEMOUSE, KM_PRESS, KM_ALT, 0);
+	
 	WM_keymap_add_item(keymap, "NODE_OT_link_make", FKEY, KM_PRESS, 0, 0);
 	RNA_boolean_set(WM_keymap_add_item(keymap, "NODE_OT_link_make", FKEY, KM_PRESS, KM_CTRL, 0)->ptr, "replace", 1);
 	





More information about the Bf-blender-cvs mailing list