GP: Primitive: Add RMB behaviour to Grab/Move
authorCharlie Jolly <mistajolly@gmail.com>
Wed, 19 Dec 2018 10:17:14 +0000 (10:17 +0000)
committerCharlie Jolly <mistajolly@gmail.com>
Wed, 19 Dec 2018 12:18:45 +0000 (12:18 +0000)
source/blender/editors/gpencil/gpencil_intern.h
source/blender/editors/gpencil/gpencil_primitive.c

index e2cbeda273373d771d320195dde15d55974102e6..7d386c18c64e8ee12c6268c8133b8ad05a2890dc 100644 (file)
@@ -162,6 +162,7 @@ typedef struct tGPDprimitive {
        int point_count;                  /* number of edges allocated */
        int tot_stored_edges;             /* stored number of polygon edges */
        int tot_edges;                    /* number of polygon edges */
+       float move[2];                    /* move distance */
        float origin[2];                  /* initial box corner */
        float start[2];                   /* first box corner */
        float end[2];                     /* last box corner */
index f13235926f10f1547a3ae9c0e36effe58e80a174..d856c1859bbef25bd77366465398e420118b00ca 100644 (file)
@@ -1302,10 +1302,19 @@ static void gpencil_primitive_edit_event_handling(bContext *C, wmOperator *op, w
 }
 
 /* move */
-static void gpencil_primitive_move(tGPDprimitive *tgpi)
+static void gpencil_primitive_move(tGPDprimitive *tgpi, bool reset)
 {
        float move[2];
-       sub_v2_v2v2(move, tgpi->mval, tgpi->mvalo);
+       zero_v2(move);
+
+       if (reset) {
+               sub_v2_v2(move, tgpi->move);
+               zero_v2(tgpi->move);
+       }
+       else {
+               sub_v2_v2v2(move, tgpi->mval, tgpi->mvalo);
+               add_v2_v2(tgpi->move, move);
+       }
 
        bGPDstroke *gps = tgpi->gpf->strokes.first;
        tGPspoint *points2D = tgpi->points;
@@ -1335,14 +1344,21 @@ static int gpencil_primitive_modal(bContext *C, wmOperator *op, const wmEvent *e
 
                switch (event->type) {
                        case MOUSEMOVE:
-                               gpencil_primitive_move(tgpi);
+                               gpencil_primitive_move(tgpi, false);
                                gpencil_primitive_update(C, op, tgpi);
                                break;
                        case ESCKEY:
-                       case RIGHTMOUSE:
                        case LEFTMOUSE:
+                               zero_v2(tgpi->move);
                                tgpi->flag = IN_CURVE_EDIT;
                                break;
+                       case RIGHTMOUSE:
+                               if (event->val == KM_RELEASE) {
+                                       tgpi->flag = IN_CURVE_EDIT;
+                                       gpencil_primitive_move(tgpi, true);
+                                       gpencil_primitive_update(C, op, tgpi);
+                               }
+                               break;
                }
                copy_v2_v2(tgpi->mvalo, tgpi->mval);
                return OPERATOR_RUNNING_MODAL;