2.5 / Drag & Drop
authorElia Sarti <vekoon@gmail.com>
Sat, 25 Jul 2009 15:26:06 +0000 (15:26 +0000)
committerElia Sarti <vekoon@gmail.com>
Sat, 25 Jul 2009 15:26:06 +0000 (15:26 +0000)
Commit of basic architecture. Sorry, nothing fun to play with yet.
Added two events: MOUSEDRAG and MOUSEDROP. MOUSEDRAG is sent when left-mouse clicking and then moving the cursor and every time the cursor is moved until the user releases the mouse button, thus generating a MOUSEDROP.
Also added two dummy drag operators in view3d and outliner (place holders for now).

Brecht and Ton: feel free to check/edit especially the event system code. I'm not sure that's the right way to do it. Also, I'm getting some mem leaks which I suspect are caused by my code.

source/blender/editors/space_outliner/outliner.c
source/blender/editors/space_outliner/outliner_intern.h
source/blender/editors/space_outliner/outliner_ops.c
source/blender/editors/space_view3d/view3d_intern.h
source/blender/editors/space_view3d/view3d_ops.c
source/blender/editors/space_view3d/view3d_select.c
source/blender/makesdna/DNA_windowmanager_types.h
source/blender/windowmanager/intern/wm_event_system.c
source/blender/windowmanager/wm_event_types.h

index 6ac094b3ad34ba1d04aab231536d5f11618d5061..0df0cb46473aeb50c69083d1612d43a36421b709 100644 (file)
@@ -3452,6 +3452,57 @@ void OUTLINER_OT_data_operation(wmOperatorType *ot)
 }
 
 
+/* ****** Drag & Drop ****** */
+
+static int outliner_drag_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       wmWindow *win= CTX_wm_window(C);
+       Object *ob= CTX_data_active_object(C);
+       PointerRNA ptr;
+
+       RNA_pointer_create(NULL, &RNA_Object, ob, &ptr);
+
+       return OPERATOR_RUNNING_MODAL;
+}
+
+static int outliner_drag_modal(bContext *C, wmOperator *op, wmEvent *event)
+{
+       switch(event->type) {
+               case MOUSEDRAG:
+
+                       break;
+               case MOUSEDROP:
+                       return OPERATOR_FINISHED;
+               case ESCKEY:
+                       return OPERATOR_CANCELLED;
+       }
+
+       return OPERATOR_RUNNING_MODAL;
+}
+
+static int outliner_drag_exec(bContext *C, wmOperator *op)
+{
+       return OPERATOR_FINISHED;
+}
+
+void OUTLINER_OT_drag(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Drag";
+       ot->idname= "OUTLINER_OT_drag";
+
+       /* api callbacks */
+       ot->invoke= outliner_drag_invoke;
+       ot->modal= outliner_drag_modal;
+       ot->exec= outliner_drag_exec;
+
+       ot->poll= ED_operator_outliner_active;
+
+       /* flags */
+       /* ot->flag= OPTYPE_UNDO; */
+}
+
+
 /* ******************** */
 
 
index fc305361fe1ddcf15c738472816313cd7a9df3b8..d5986f3ebbddbe9d28ca93abc962aaa392effa76 100644 (file)
@@ -127,6 +127,8 @@ void OUTLINER_OT_group_operation(struct wmOperatorType *ot);
 void OUTLINER_OT_id_operation(struct wmOperatorType *ot);
 void OUTLINER_OT_data_operation(struct wmOperatorType *ot);
 
+void OUTLINER_OT_drag(struct wmOperatorType *ot);
+
 void OUTLINER_OT_show_one_level(struct wmOperatorType *ot);
 void OUTLINER_OT_show_active(struct wmOperatorType *ot);
 void OUTLINER_OT_show_hierarchy(struct wmOperatorType *ot);
index 2e11eb379b4905bf24fb0715dc54fb59f3a8a188..417851982a33f27e08f70dfaa7c87eb773604ab8 100644 (file)
@@ -56,6 +56,8 @@ void outliner_operatortypes(void)
        WM_operatortype_append(OUTLINER_OT_id_operation);
        WM_operatortype_append(OUTLINER_OT_data_operation);
 
+       WM_operatortype_append(OUTLINER_OT_drag);
+
        WM_operatortype_append(OUTLINER_OT_show_one_level);
        WM_operatortype_append(OUTLINER_OT_show_active);
        WM_operatortype_append(OUTLINER_OT_show_hierarchy);
@@ -87,6 +89,9 @@ void outliner_keymap(wmWindowManager *wm)
        WM_keymap_add_item(keymap, "OUTLINER_OT_item_rename", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
        WM_keymap_add_item(keymap, "OUTLINER_OT_operation", RIGHTMOUSE, KM_PRESS, 0, 0);
 
+       /* drag & drop */
+       WM_keymap_add_item(keymap, "OUTLINER_OT_drag", MOUSEDRAG, KM_ANY, 0, 0);
+
        WM_keymap_add_item(keymap, "OUTLINER_OT_show_hierarchy", HOMEKEY, KM_PRESS, 0, 0);
        
        WM_keymap_add_item(keymap, "OUTLINER_OT_show_active", PERIODKEY, KM_PRESS, 0, 0);
index 3e9382509f4ca9d15fe2e8be2fb098ca5df822d3..382ba68e95f926116e4a2dfaf1befbd479e06143 100644 (file)
@@ -115,6 +115,7 @@ void VIEW3D_OT_select_extend(struct wmOperatorType *ot);
 void VIEW3D_OT_select_circle(struct wmOperatorType *ot);
 void VIEW3D_OT_select_border(struct wmOperatorType *ot);
 void VIEW3D_OT_select_lasso(struct wmOperatorType *ot);
+void VIEW3D_OT_drag(struct wmOperatorType *ot);
 
 /* view3d_view.c */
 void VIEW3D_OT_smoothview(struct wmOperatorType *ot);
index 112847272e5312d9a0034708a4686c92b9e6b562..69b297b2e03153d63e235fc09659439171403482 100644 (file)
@@ -73,6 +73,7 @@ void view3d_operatortypes(void)
        WM_operatortype_append(VIEW3D_OT_view_center);
        WM_operatortype_append(VIEW3D_OT_select);
        WM_operatortype_append(VIEW3D_OT_select_border);
+       WM_operatortype_append(VIEW3D_OT_drag);
        WM_operatortype_append(VIEW3D_OT_clip_border);
        WM_operatortype_append(VIEW3D_OT_select_circle);
        WM_operatortype_append(VIEW3D_OT_smoothview);
@@ -216,6 +217,9 @@ void view3d_keymap(wmWindowManager *wm)
        WM_keymap_add_item(keymap, "VIEW3D_OT_camera_to_view", PAD0, KM_PRESS, KM_ALT|KM_CTRL, 0);
        
        WM_keymap_add_item(keymap, "VIEW3D_OT_snap_menu", SKEY, KM_PRESS, KM_SHIFT, 0);
+
+       /* drag & drop */
+       WM_keymap_add_item(keymap, "VIEW3D_OT_drag", MOUSEDRAG, KM_ANY, 0, 0);
        
        /* radial control */
        RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_radial_control", FKEY, KM_PRESS, 0, 0)->ptr, "mode", WM_RADIALCONTROL_SIZE);
index 2537982210a685c95201b911f9d4b7f1d8b72e98..8182069c142e4172c9c6f36c56debb8a4f5023f4 100644 (file)
@@ -1598,6 +1598,56 @@ void VIEW3D_OT_select(wmOperatorType *ot)
 }
 
 
+/* ****** Drag & Drop ****** */
+
+static int view3d_drag_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       wmWindow *win= CTX_wm_window(C);
+       Object *ob= CTX_data_active_object(C);
+       PointerRNA ptr;
+
+       RNA_pointer_create(NULL, &RNA_Object, ob, &ptr);
+
+       return OPERATOR_RUNNING_MODAL;
+}
+
+static int view3d_drag_modal(bContext *C, wmOperator *op, wmEvent *event)
+{
+       switch(event->type) {
+               case MOUSEDRAG:
+
+                       break;
+               case MOUSEDROP:
+                       return OPERATOR_FINISHED;
+               case ESCKEY:
+                       return OPERATOR_CANCELLED;
+       }
+
+       return OPERATOR_RUNNING_MODAL;
+}
+
+static int view3d_drag_exec(bContext *C, wmOperator *op)
+{
+       return OPERATOR_FINISHED;
+}
+
+void VIEW3D_OT_drag(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Drag";
+       ot->idname= "VIEW3D_OT_drag";
+       
+       /* api callbacks */
+       ot->invoke= view3d_drag_invoke;
+       ot->modal= view3d_drag_modal;
+       ot->exec= view3d_drag_exec;
+       ot->poll= ED_operator_view3d_active;
+       
+       /* flags */
+       /* ot->flag= OPTYPE_UNDO; */
+}
+
+
 /* -------------------- circle select --------------------------------------------- */
 
 static void mesh_circle_doSelectVert(void *userData, EditVert *eve, int x, int y, int index)
index 895bc943e9f3d3d1e1c3c9ae96e43c4d10974606..f6f0fc1a7539c6bb178f285f75c66ac0afea0ca8 100644 (file)
@@ -146,7 +146,9 @@ typedef struct wmWindow {
        short cursor;           /* current mouse cursor type */
        short lastcursor;       /* for temp waitcursor */
        short addmousemove;     /* internal: tag this for extra mousemove event, makes cursors/buttons active on UI switching */
-       int pad3;
+       short downstate; /* used for drag & drop: remembers mouse button down state */
+       short downx, downy; /* mouse coords for button down event */
+       short pad3, pad4, pad5;
        
        struct wmEvent *eventstate;     /* storage for event system */
        
index 7f40ec401a853cf3f88102a86560d406bf5e2cf7..78c7f7a7383367cb36f454b6469e2842c81fa39c 100644 (file)
@@ -1435,6 +1435,19 @@ void wm_event_add_ghostevent(wmWindow *win, int type, void *customdata)
                                
                                update_tablet_data(win, &event);
                                wm_event_add(win, &event);
+
+                               cx = abs((win->downx - event.x));
+                               cy = abs((win->downy - event.y));
+
+                               /* probably minimum drag size should be #defined instead of hardcoded 3 */
+                               if (win->downstate == LEFTMOUSE && (cx > 3 || cy > 3)) {
+                                       wmEvent dragevt= *evt;
+                                       dragevt.type= MOUSEDRAG;
+                                       dragevt.customdata= NULL;
+                                       dragevt.customdatafree= 0;
+
+                                       wm_event_add(win, &dragevt);
+                               }
                        }
                        break;
                }
@@ -1458,6 +1471,23 @@ void wm_event_add_ghostevent(wmWindow *win, int type, void *customdata)
                        
                        update_tablet_data(win, &event);
                        wm_event_add(win, &event);
+
+                       if (event.val) {
+                               win->downstate= event.type;
+                               win->downx= event.x;
+                               win->downy= event.y;
+                       }
+                       else if (win->downstate) {
+                               wmEvent dropevt= *evt;
+                               dropevt.type= MOUSEDROP;
+                               dropevt.customdata= NULL;
+                               dropevt.customdatafree= 0;
+                               win->downstate= 0;
+                               win->downx= 0;
+                               win->downy= 0;
+
+                               wm_event_add(win, &dropevt);
+                       }
                        
                        break;
                }
index 6f64cdbde32c2aa536ff61d930e08936f508988e..6e7186542de366e75ff98c66cc826fde89a9f98b 100644 (file)
@@ -56,6 +56,9 @@
                /* only use if you want user option switch possible */
 #define ACTIONMOUSE            0x005
 #define SELECTMOUSE            0x006
+               /* drag & drop support */
+#define MOUSEDRAG              0x007
+#define MOUSEDROP              0x008
                /* defaults from ghost */
 #define WHEELUPMOUSE   0x00a   
 #define WHEELDOWNMOUSE 0x00b