Commit: ef757a2ef80a29a89447a422939b05b1ececc50e
Author: Charlie Jolly
Date:   Thu Dec 20 11:45:51 2018 +0000
Branches: greasepencil-object
https://developer.blender.org/rBef757a2ef80a29a89447a422939b05b1ececc50e

GP: Primitive: Fkey to size brush

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

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 4e998e2ddcb..f93952aae31 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 type;                         /* type of primitive */
        int orign_type;                   /* original type of primitive */
        bool curve;                       /* type of primitive is a curve */
+       int brush_size;                   /* brush size */
        short flip;                       /* flip option */
        tGPspoint *points;                /* array of data-points for stroke */
        int point_count;                  /* number of edges allocated */
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c 
b/source/blender/editors/gpencil/gpencil_primitive.c
index c95a0ce5b4a..3c3dd5aa622 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -96,6 +96,7 @@
 #define IN_PROGRESS 1
 #define IN_CURVE_EDIT 2
 #define IN_MOVE 3
+#define IN_BRUSH_SIZE 4
 
 #define SELECT_NONE 0
 #define SELECT_START 1
@@ -384,6 +385,9 @@ static void gpencil_primitive_add_segment(tGPDprimitive 
*tgpi)
 /* Helper: set control point */
 static void gp_primitive_set_cp(tGPDprimitive *tgpi, float p[2], float 
color[4], int size)
 {
+       if (tgpi->flag == IN_PROGRESS) {
+               return;
+       }
        bGPDcontrolpoint *cp_points = tgpi->gpd->runtime.cp_points;
 
        if (tgpi->gpd->runtime.tot_cp_points < MAX_CP) {
@@ -1370,6 +1374,29 @@ static void 
gpencil_primitive_edit_event_handling(bContext *C, wmOperator *op, w
        }
 }
 
+/* brush size */
+static void gpencil_primitive_size(tGPDprimitive *tgpi, bool reset)
+{
+       Brush *brush = tgpi->brush;
+       if (brush) {
+               if (reset) {
+                       brush->size = tgpi->brush_size;
+                       tgpi->brush_size = 0;
+               }
+               else {
+                       if (tgpi->brush_size == 0) {
+                               tgpi->brush_size = brush->size;
+                       }
+                       float move[2];
+                       sub_v2_v2v2(move, tgpi->mval, tgpi->mvalo);
+                       int adjust = (move[1] > 0.0f) ? 1 : -1;
+                       brush->size += adjust * 
(int)fabsf(len_manhattan_v2(move));
+               }
+               CLAMP_MIN(brush->size, 1);
+       }
+       
+}
+
 /* move */
 static void gpencil_primitive_move(tGPDprimitive *tgpi)
 {
@@ -1401,7 +1428,6 @@ static int gpencil_primitive_modal(bContext *C, 
wmOperator *op, const wmEvent *e
        copy_v2fl_v2i(tgpi->mval, event->mval);
 
        if (tgpi->flag == IN_MOVE) {
-
                switch (event->type) {
                        case MOUSEMOVE:
                                gpencil_primitive_move(tgpi);
@@ -1416,6 +1442,29 @@ static int gpencil_primitive_modal(bContext *C, 
wmOperator *op, const wmEvent *e
                copy_v2_v2(tgpi->mvalo, tgpi->mval);
                return OPERATOR_RUNNING_MODAL;
        }
+       if (tgpi->flag == IN_BRUSH_SIZE) {
+               switch (event->type) {
+               case MOUSEMOVE:
+                       gpencil_primitive_size(tgpi, false);
+                       gpencil_primitive_update(C, op, tgpi);
+                       break;
+               case ESCKEY:
+               case MIDDLEMOUSE:
+               case LEFTMOUSE:
+                       tgpi->brush_size = 0;
+                       tgpi->flag = IN_CURVE_EDIT;
+                       break;
+               case RIGHTMOUSE:
+                       if (event->val == KM_RELEASE) {
+                               tgpi->flag = IN_CURVE_EDIT;
+                               gpencil_primitive_size(tgpi, true);
+                               gpencil_primitive_update(C, op, tgpi);
+                       }
+                       break;
+               }
+               copy_v2_v2(tgpi->mvalo, tgpi->mval);
+               return OPERATOR_RUNNING_MODAL;
+       }
        else if (tgpi->flag != IDLE) {
                gpencil_primitive_edit_event_handling(C, op, win, event, tgpi);
        }
@@ -1520,6 +1569,14 @@ static int gpencil_primitive_modal(bContext *C, 
wmOperator *op, const wmEvent *e
                        }
                        break;
                }
+               case FKEY: /* brush thickness */
+               {
+                       if ((event->val == KM_PRESS)) {
+                               tgpi->flag = IN_BRUSH_SIZE;
+                               WM_cursor_modal_set(win, BC_NS_SCROLLCURSOR);
+                       }
+                       break;
+               }
                case CKEY: /* curve mode */
                {
                        if ((event->val == KM_PRESS) &&

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

Reply via email to