Commit: 1f5216c57ae2f7896c9392668fae5019e481c723
Author: Charlie Jolly
Date:   Thu Nov 29 10:50:21 2018 +0000
Branches: blender2.8
https://developer.blender.org/rB1f5216c57ae2f7896c9392668fae5019e481c723

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

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

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 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);

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

Reply via email to