Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharlie Jolly <mistajolly@gmail.com>2018-11-30 15:06:04 +0300
committerCharlie Jolly <mistajolly@gmail.com>2018-12-02 17:44:50 +0300
commit4ee29d3fdfffdefa670b28a4f909ab29e5f54b98 (patch)
tree5f021366e1b7a951e9e563eb8f5d9e01870cad71 /source/blender/editors/gpencil/gpencil_primitive.c
parentebfea8c2bb004f461ee186138e3ce25027296788 (diff)
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
Diffstat (limited to 'source/blender/editors/gpencil/gpencil_primitive.c')
-rw-r--r--source/blender/editors/gpencil/gpencil_primitive.c41
1 files changed, 30 insertions, 11 deletions
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 */