Commit: 4ce6dfcd85c48498c302a2310c7b266111fb980d
Author: Charlie Jolly
Date:   Wed Dec 12 14:13:03 2018 +0000
Branches: greasepencil-object
https://developer.blender.org/rB4ce6dfcd85c48498c302a2310c7b266111fb980d

GP: Primitive: Arc tool changes

Added back constraint option to draw perfect arcs
Added back flip option

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

M       source/blender/editors/gpencil/gpencil_intern.h
M       source/blender/editors/gpencil/gpencil_primitive.c

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

diff --git a/source/blender/editors/gpencil/gpencil_intern.h 
b/source/blender/editors/gpencil/gpencil_intern.h
index df36529ca18..956ad0643c9 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -156,6 +156,7 @@ typedef struct tGPDprimitive {
        struct bGPDframe *gpf;            /* frame */
        int type;                         /* type of primitive */
        bool curve;                       /* type of primitive is a curve */
+       short flip;                       /* flip option */
        tGPspoint *points;                /* array of data-points for stroke */
        int point_count;                  /* number of edges allocated */
        int tot_stored_edges;             /* stored number of polygon edges */
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c 
b/source/blender/editors/gpencil/gpencil_primitive.c
index e2f072530a6..3feb8b9ce5a 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -466,7 +466,8 @@ static void gp_primitive_arc(tGPDprimitive *tgpi, tGPspoint 
*points2D)
        float corner[2];
        float midpoint[2];
        float a = 0.0f;
-       
+
+       mid_v2_v2v2(tgpi->midpoint, tgpi->start, tgpi->end);
        copy_v2_v2(start, tgpi->start);
        copy_v2_v2(end, tgpi->end);
        copy_v2_v2(cp1, tgpi->cp1);
@@ -485,8 +486,12 @@ static void gp_primitive_arc(tGPDprimitive *tgpi, 
tGPspoint *points2D)
        UI_GetThemeColor4fv(TH_ACTIVE_VERT, color);
        gp_primitive_set_cp(tgpi, tgpi->start, color, BIG_SIZE_CTL);
        gp_primitive_set_cp(tgpi, tgpi->end, color, BIG_SIZE_CTL);
+       /*UI_GetThemeColor4fv(TH_REDALERT, color);
+       gp_primitive_set_cp(tgpi, tgpi->midpoint, color, SMALL_SIZE_CTL);
+       gp_primitive_set_cp(tgpi, corner, color, SMALL_SIZE_CTL);*/
        UI_GetThemeColor4fv(TH_GP_VERTEX_SELECT, color);
        gp_primitive_set_cp(tgpi, tgpi->cp1, color, BIG_SIZE_CTL * 0.9f);
+       
 }
 
 /* create a bezier */
@@ -569,6 +574,7 @@ static void gp_primitive_update_strokes(bContext *C, 
tGPDprimitive *tgpi)
 
        /* compute screen-space coordinates for points */
        tGPspoint *points2D = tgpi->points;
+       
        switch (tgpi->type) {
                case GP_STROKE_BOX:
                        gp_primitive_rectangle(tgpi, points2D);
@@ -998,14 +1004,6 @@ static void gpencil_primitive_interaction_end(bContext 
*C, wmOperator *op, wmWin
        gpencil_primitive_exit(C, op);
 }
 
-/* Helper to set bezier cp */
-static void gpencil_primitive_set_midpoint(tGPDprimitive *tgpi)
-{
-       mid_v2_v2v2(tgpi->midpoint, tgpi->start, tgpi->end);
-       copy_v2_v2(tgpi->cp1, tgpi->midpoint);
-       copy_v2_v2(tgpi->cp2, tgpi->cp1);
-}
-
 /* Helper to square a primitive */
 static void gpencil_primitive_to_square(tGPDprimitive *tgpi, const float x, 
const float y)
 {
@@ -1025,6 +1023,23 @@ static void gpencil_primitive_to_square(tGPDprimitive 
*tgpi, const float x, cons
        }
 }
 
+/* Helper to update cps */
+static void gp_primitive_update_cps(tGPDprimitive *tgpi)
+{
+       if (tgpi->type == GP_STROKE_ARC) {
+               if (tgpi->flip)
+                       copy_v2_fl2(tgpi->cp1, tgpi->start[0], tgpi->end[1]);
+               else
+                       copy_v2_fl2(tgpi->cp1, tgpi->end[0], tgpi->start[1]);
+               mid_v2_v2v2(tgpi->midpoint, tgpi->start, tgpi->end);
+       }
+       else if (tgpi->type == GP_STROKE_CURVE) {
+               mid_v2_v2v2(tgpi->midpoint, tgpi->start, tgpi->end);
+               copy_v2_v2(tgpi->cp1, tgpi->midpoint);
+               copy_v2_v2(tgpi->cp2, tgpi->cp1);
+       }
+}
+
 #define MOVE_NONE 0
 #define MOVE_ENDS 1
 #define MOVE_CP 2
@@ -1066,12 +1081,12 @@ static void 
gpencil_primitive_arc_event_handling(bContext *C, wmOperator *op, wm
                                        copy_v2_v2(tgpi->cp2, tgpi->cp1);
                        }
                        copy_v2_v2(tgpi->mvalo, tgpi->mval);
-
+                       
                        /* update screen */
                        gpencil_primitive_update(C, op, tgpi);
                }
-               else if ((event->val == KM_PRESS)) {
-                       gpencil_primitive_set_midpoint(tgpi);
+               else if ((tgpi->flag == IN_PROGRESS)) {         
+                       gp_primitive_update_cps(tgpi);
                        gpencil_primitive_update(C, op, tgpi);
                }
                break;
@@ -1090,21 +1105,38 @@ static void 
gpencil_primitive_arc_event_handling(bContext *C, wmOperator *op, wm
                else if ((event->val == KM_RELEASE) && (tgpi->flag == 
IN_PROGRESS)) {
                        /* set control points and enter edit mode */
                        tgpi->flag = IN_CURVE_EDIT;
-                       gpencil_primitive_set_midpoint(tgpi);
-                       copy_v2_v2(tgpi->mvalo, tgpi->mval);
+                       gp_primitive_update_cps(tgpi);
                        gpencil_primitive_update(C, op, tgpi);
                }
                else {
                        tgpi->sel_cp = SELECT_NONE;
                }
                break;
+       case FKEY:
+       {
+               if ((event->val == KM_RELEASE)) {
+                       tgpi->flip ^= 1;
+                       
+                       if ((tgpi->flag == IN_PROGRESS)) {
+                               gp_primitive_update_cps(tgpi);
+                       }
+                       else if ((tgpi->flag == IN_CURVE_EDIT)) {
+                               mid_v2_v2v2(tgpi->midpoint, tgpi->start, 
tgpi->end);
+                               tgpi->cp1[0] = tgpi->midpoint[0] - 
(tgpi->cp1[0] - tgpi->midpoint[0]);
+                               tgpi->cp1[1] = tgpi->midpoint[1] - 
(tgpi->cp1[1] - tgpi->midpoint[1]);
+                       }
+                       gpencil_primitive_update(C, op, tgpi);
+               }
+               break;
+       }
+
        case AKEY:
                if (tgpi->flag == IN_CURVE_EDIT) {
                        tgpi->flag = IN_PROGRESS;
                        gpencil_primitive_add_segment(tgpi);
                        copy_v2_v2(tgpi->start, tgpi->end);
                        copy_v2_v2(tgpi->origin, tgpi->start);
-                       gpencil_primitive_set_midpoint(tgpi);
+                       gp_primitive_update_cps(tgpi);
                        copy_v2_v2(tgpi->mvalo, tgpi->mval);
                }
                break;
@@ -1163,7 +1195,7 @@ static void 
gpencil_primitive_bezier_event_handling(bContext *C, wmOperator *op,
                        gpencil_primitive_update(C, op, tgpi);
                }
                else if ((event->val == KM_PRESS)) {
-                       gpencil_primitive_set_midpoint(tgpi);
+                       gp_primitive_update_cps(tgpi);
                        gpencil_primitive_update(C, op, tgpi);
                }
                break;
@@ -1182,7 +1214,7 @@ static void 
gpencil_primitive_bezier_event_handling(bContext *C, wmOperator *op,
                else if ((event->val == KM_RELEASE) && (tgpi->flag == 
IN_PROGRESS)) {
                        /* set control points and enter edit mode */
                        tgpi->flag = IN_CURVE_EDIT;
-                       gpencil_primitive_set_midpoint(tgpi);
+                       gp_primitive_update_cps(tgpi);
                        copy_v2_v2(tgpi->mvalo, tgpi->mval);
                        gpencil_primitive_update(C, op, tgpi);
                }
@@ -1196,7 +1228,7 @@ static void 
gpencil_primitive_bezier_event_handling(bContext *C, wmOperator *op,
                        gpencil_primitive_add_segment(tgpi);
                        copy_v2_v2(tgpi->start, tgpi->end);
                        copy_v2_v2(tgpi->origin, tgpi->start);
-                       gpencil_primitive_set_midpoint(tgpi);
+                       gp_primitive_update_cps(tgpi);
                        copy_v2_v2(tgpi->mvalo, tgpi->mval);
                }
                break;

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to