Commit: 26eae6315c05526021b93d9e32b064208a9d7ab8
Author: Antony Riakiotakis
Date:   Thu Jul 3 13:04:29 2014 +0300
https://developer.blender.org/rB26eae6315c05526021b93d9e32b064208a9d7ab8

Make Cursor placement operation a modal operator.

* Allows drag and place workflow in addition to click workflow
* Should be compatible with future use of calling operator and placing
instead of left-clicking

===================================================================

M       source/blender/editors/space_view3d/view3d_edit.c

===================================================================

diff --git a/source/blender/editors/space_view3d/view3d_edit.c 
b/source/blender/editors/space_view3d/view3d_edit.c
index 762288a..e3260db 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -4435,20 +4435,46 @@ void ED_view3d_cursor3d_position(bContext *C, float 
fp[3], const int mval[2])
        }
 }
 
-static int view3d_cursor3d_invoke(bContext *C, wmOperator *UNUSED(op), const 
wmEvent *event)
+static void view3d_cursor3d_update(bContext *C, const int *mval)
 {
        Scene *scene = CTX_data_scene(C);
        View3D *v3d = CTX_wm_view3d(C);
        float *fp = ED_view3d_cursor3d_get(scene, v3d);
 
-       ED_view3d_cursor3d_position(C, fp, event->mval);
-       
+       ED_view3d_cursor3d_position(C, fp, mval);
+
        if (v3d && v3d->localvd)
                WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
        else
                WM_event_add_notifier(C, NC_SCENE | NA_EDITED, scene);
-       
-       return OPERATOR_FINISHED;
+}
+
+static int view3d_cursor3d_invoke(bContext *C, wmOperator *op, const wmEvent 
*event)
+{
+       view3d_cursor3d_update(C, event->mval);
+       op->customdata = SET_INT_IN_POINTER(event->type);
+       WM_event_add_modal_handler(C, op);
+
+       return OPERATOR_RUNNING_MODAL;
+}
+
+static int view3d_cursor3d_modal(bContext *C, wmOperator *op, const wmEvent 
*event)
+{
+       int event_type = GET_INT_FROM_POINTER(op->customdata);
+
+       if (event->type == event_type) {
+               return OPERATOR_FINISHED;
+       }
+
+       switch (event->type) {
+               case MOUSEMOVE:
+                       view3d_cursor3d_update(C, event->mval);
+                       break;
+               case LEFTMOUSE:
+                       return OPERATOR_FINISHED;
+       }
+
+       return OPERATOR_RUNNING_MODAL;
 }
 
 void VIEW3D_OT_cursor3d(wmOperatorType *ot)
@@ -4461,6 +4487,7 @@ void VIEW3D_OT_cursor3d(wmOperatorType *ot)
 
        /* api callbacks */
        ot->invoke = view3d_cursor3d_invoke;
+       ot->modal  = view3d_cursor3d_modal;
 
        ot->poll = ED_operator_view3d_active;

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to