diff options
author | Charlie Jolly <mistajolly@gmail.com> | 2018-11-29 13:50:21 +0300 |
---|---|---|
committer | Charlie Jolly <mistajolly@gmail.com> | 2018-11-29 18:44:20 +0300 |
commit | 1f5216c57ae2f7896c9392668fae5019e481c723 (patch) | |
tree | 70e6485b94d80f1d2fb79613b12d656d3e440c14 | |
parent | 1c0bc19e3f55eff4bc2df4c2affb64272c5f5cb7 (diff) |
GP: Add option to draw primatives from center
This allows primatives to be drawn from the center using the ALT key.
Also fixes SHIFT constraint not working correctly in all directions.
Both options can be used together.
Differential Revision: https://developer.blender.org/D4009
-rw-r--r-- | source/blender/editors/gpencil/gpencil_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_primitive.c | 37 |
2 files changed, 32 insertions, 6 deletions
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h index a55d984cd13..93d75063bff 100644 --- a/source/blender/editors/gpencil/gpencil_intern.h +++ b/source/blender/editors/gpencil/gpencil_intern.h @@ -157,6 +157,7 @@ typedef struct tGPDprimitive { int tot_edges; /* number of polygon edges */ int top[2]; /* first box corner */ int bottom[2]; /* last box corner */ + int origin[2]; /* initial box corner */ int flag; /* flag to determine operations in progress */ int lock_axis; /* lock to viewport axis */ diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c index 9d9410d0885..ee2cf7fad48 100644 --- a/source/blender/editors/gpencil/gpencil_primitive.c +++ b/source/blender/editors/gpencil/gpencil_primitive.c @@ -210,13 +210,13 @@ static void gpencil_primitive_status_indicators(bContext *C, tGPDprimitive *tgpi char msg_str[UI_MAX_DRAW_STR]; if (tgpi->type == GP_STROKE_BOX) { - BLI_strncpy(msg_str, IFACE_("Rectangle: ESC/RMB to cancel, LMB set origin, Enter/LMB to confirm, Shift to square"), UI_MAX_DRAW_STR); + BLI_strncpy(msg_str, IFACE_("Rectangle: ESC/RMB to cancel, LMB set origin, Enter/LMB to confirm, Shift to square, Alt to center"), UI_MAX_DRAW_STR); } else if (tgpi->type == GP_STROKE_LINE) { - BLI_strncpy(msg_str, IFACE_("Line: ESC/RMB to cancel, LMB set origin, Enter/LMB to confirm"), UI_MAX_DRAW_STR); + BLI_strncpy(msg_str, IFACE_("Line: ESC/RMB to cancel, LMB set origin, Enter/LMB to confirm, Alt to center"), UI_MAX_DRAW_STR); } else { - BLI_strncpy(msg_str, IFACE_("Circle: ESC/RMB to cancel, Enter/LMB to confirm, WHEEL to adjust edge number, Shift to square"), UI_MAX_DRAW_STR); + BLI_strncpy(msg_str, IFACE_("Circle: ESC/RMB to cancel, Enter/LMB to confirm, WHEEL to adjust edge number, Shift to square, Alt to center"), UI_MAX_DRAW_STR); } if (tgpi->type == GP_STROKE_CIRCLE) { @@ -408,6 +408,9 @@ static void gpencil_primitive_update(bContext *C, wmOperator *op, tGPDprimitive static void gpencil_primitive_interaction_begin(tGPDprimitive *tgpi, const wmEvent *event) { + tgpi->origin[0] = event->mval[0]; + tgpi->origin[1] = event->mval[1]; + tgpi->top[0] = event->mval[0]; tgpi->top[1] = event->mval[1]; @@ -671,13 +674,35 @@ static int gpencil_primitive_modal(bContext *C, wmOperator *op, const wmEvent *e /* update position of mouse */ tgpi->bottom[0] = event->mval[0]; tgpi->bottom[1] = event->mval[1]; + tgpi->top[0] = tgpi->origin[0]; + tgpi->top[1] = tgpi->origin[1]; if (tgpi->flag == IDLE) { - tgpi->top[0] = event->mval[0]; - tgpi->top[1] = event->mval[1]; + tgpi->origin[0] = event->mval[0]; + tgpi->origin[1] = event->mval[1]; } /* Keep square if shift key */ if (event->shift) { - tgpi->bottom[1] = tgpi->top[1] - (tgpi->bottom[0] - tgpi->top[0]); + 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; + } + else { + if (w > h) + tgpi->bottom[1] = tgpi->origin[1] - x; + else + tgpi->bottom[0] = tgpi->origin[0] - y; + } + } + /* Center primitive if alt key */ + if (event->alt) { + tgpi->top[0] = tgpi->origin[0] - (tgpi->bottom[0] - tgpi->origin[0]); + tgpi->top[1] = tgpi->origin[1] - (tgpi->bottom[1] - tgpi->origin[1]); } /* update screen */ gpencil_primitive_update(C, op, tgpi); |