The daily node commit: brought back panning background image.
authorTon Roosendaal <ton@blender.org>
Wed, 7 Apr 2010 17:06:22 +0000 (17:06 +0000)
committerTon Roosendaal <ton@blender.org>
Wed, 7 Apr 2010 17:06:22 +0000 (17:06 +0000)
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.

source/blender/editors/space_node/node_edit.c
source/blender/editors/space_node/node_intern.h
source/blender/editors/space_node/node_ops.c

index a7fe1b3..d211f8e 100644 (file)
@@ -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,68 +687,94 @@ static bNode *visible_node(SpaceNode *snode, rctf *rct)
        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)
+{
+       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)
 {
-       ScrArea *sa;
+       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) {
-               rectx = ibuf->x;
-               recty = ibuf->y;
-       } else {
-               rectx = recty = 1;
-       }
-       
-       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;
-       
-       getmouseco_sc(mvalo);
+       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;
        
-       /* store the old cursor to temporarily change it */
-       oldcursor=get_cursor();
-       win=winlay_get_active_window();
+       /* add modal handler */
+       WM_event_add_modal_handler(C, op);
        
-       SetBlenderCursor(BC_NSEW_SCROLLCURSOR);
+       return OPERATOR_RUNNING_MODAL;
+}
+
+
+void NODE_OT_backimage_move(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Background Image Move";
+       ot->idname= "NODE_OT_backimage_move";
        
-       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();
-       }
+       /* api callbacks */
+       ot->invoke= snode_bg_viewmove_invoke;
+       ot->modal= snode_bg_viewmove_modal;
+       ot->poll= ED_operator_node_active;
        
-       window_set_cursor(win, oldcursor);
+       /* flags */
+       ot->flag= OPTYPE_BLOCKING;
 }
-#endif
+
 
 /* ********************** size widget operator ******************** */
 
index f1a27f9..11731b3 100644 (file)
@@ -105,7 +105,7 @@ void NODE_OT_show_cyclic_dependencies(struct wmOperatorType *ot);
 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
 
index 594c25f..1e73ec0 100644 (file)
@@ -74,6 +74,8 @@ void node_operatortypes(void)
        
        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 @@ void node_keymap(struct wmKeyConfig *keyconf)
        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);