Commit: 4ee29d3fdfffdefa670b28a4f909ab29e5f54b98
Author: Charlie Jolly
Date:   Fri Nov 30 12:06:04 2018 +0000
Branches: blender2.8
https://developer.blender.org/rB4ee29d3fdfffdefa670b28a4f909ab29e5f54b98

GP: Fix line primitive when using to square behaviour

Previously the shift key for line primitives only allowed diagonals.
This change allows the line to constrain to vertical and horizontal lines.

Differential Revision: https://developer.blender.org/D4012

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

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

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

diff --git a/source/blender/editors/gpencil/gpencil_primitive.c 
b/source/blender/editors/gpencil/gpencil_primitive.c
index ee2cf7fad48..ebd1f36b511 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -593,6 +593,24 @@ static void gpencil_primitive_interaction_end(bContext *C, 
wmOperator *op, wmWin
        gpencil_primitive_exit(C, op);
 }
 
+/* Helper to square a primitive */
+static void gpencil_primitive_to_square(tGPDprimitive *tgpi, const int x, 
const int y) {
+       int w = abs(x);
+       int h = abs(y);
+       if ((x > 0 && y > 0) || (x < 0 && y < 0)) {
+               if (w > h)
+                       tgpi->bottom[1] = tgpi->origin[1] + x;
+               else
+                       tgpi->bottom[0] = tgpi->origin[0] + y;
+       }
+       else {
+               if (w > h)
+                       tgpi->bottom[1] = tgpi->origin[1] - x;
+               else
+                       tgpi->bottom[0] = tgpi->origin[0] - y;
+       }
+}
+
 /* Modal handler: Events handling during interactive part */
 static int gpencil_primitive_modal(bContext *C, wmOperator *op, const wmEvent 
*event)
 {
@@ -684,19 +702,20 @@ static int gpencil_primitive_modal(bContext *C, 
wmOperator *op, const wmEvent *e
                                if (event->shift) {
                                        int x = tgpi->bottom[0] - 
tgpi->origin[0];
                                        int y = tgpi->bottom[1] - 
tgpi->origin[1];
-                                       int w = abs(x);
-                                       int h = abs(y);
-                                       if ((x > 0 && y > 0) || (x < 0 && y < 
0)) {
-                                               if (w > h)
-                                                       tgpi->bottom[1] = 
tgpi->origin[1] + x;
-                                               else
-                                                       tgpi->bottom[0] = 
tgpi->origin[0] + y;
+                                       if (tgpi->type == GP_STROKE_LINE) {
+                                               float angle = 
fabsf(atan2f((float)y, (float)x));
+                                               if (angle < 0.4f || angle > 
(M_PI - 0.4f)) {
+                                                       tgpi->bottom[1] = 
tgpi->origin[1];
+                                               }
+                                               else if (angle > (M_PI_2 - 
0.4f) && angle < (M_PI_2 + 0.4f)) {
+                                                       tgpi->bottom[0] = 
tgpi->origin[0];
+                                               }
+                                               else {
+                                                       
gpencil_primitive_to_square(tgpi, x, y);
+                                               }
                                        }
                                        else {
-                                               if (w > h)
-                                                       tgpi->bottom[1] = 
tgpi->origin[1] - x;
-                                               else
-                                                       tgpi->bottom[0] = 
tgpi->origin[0] - y;
+                                               
gpencil_primitive_to_square(tgpi, x, y);
                                        }
                                }
                                /* Center primitive if alt key */

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

Reply via email to