GPencil: Alt-S can now be used to adjust the pressure values (i.e. thickness) of...
authorJoshua Leung <aligorith@gmail.com>
Thu, 12 Feb 2015 13:46:14 +0000 (02:46 +1300)
committerJoshua Leung <aligorith@gmail.com>
Thu, 12 Feb 2015 13:48:50 +0000 (02:48 +1300)
source/blender/editors/gpencil/gpencil_ops.c
source/blender/editors/include/ED_transform.h
source/blender/editors/transform/transform.c
source/blender/editors/transform/transform_conversions.c
source/blender/editors/transform/transform_ops.c

index f18eefe2a9d3061f9d36d47a8003cfb2d4034e25..3fae208a2e2b9fcd952d6bf2b675207cbfcb8758 100644 (file)
@@ -210,6 +210,10 @@ static void ed_keymap_gpencil_editing(wmKeyConfig *keyconf)
        WM_keymap_add_item(keymap, "TRANSFORM_OT_shear", SKEY, KM_PRESS, KM_ALT | KM_CTRL | KM_SHIFT, 0);
        RNA_boolean_set(kmi->ptr, "gpencil_strokes", true);
        
+       kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, KM_ALT, 0);
+       RNA_enum_set(kmi->ptr, "mode", TFM_GPENCIL_SHRINKFATTEN);
+       RNA_boolean_set(kmi->ptr, "gpencil_strokes", true);
+       
        /* Proportional Editing */
        ED_keymap_proportional_cycle(keyconf, keymap);
        ED_keymap_proportional_editmode(keyconf, keymap, true);
index cf8480981888617cb1311b63c90f6a388e73cf65..a3b4981dad87727a20eb5ca8088dbc5977019091 100644 (file)
@@ -73,6 +73,7 @@ enum TfmMode {
        TFM_BONE_ENVELOPE,
        TFM_CURVE_SHRINKFATTEN,
        TFM_MASK_SHRINKFATTEN,
+       TFM_GPENCIL_SHRINKFATTEN,
        TFM_BONE_ROLL,
        TFM_TIME_TRANSLATE,
        TFM_TIME_SLIDE,
index 7044b75fefd4498ea2afc58547f8c9243585afbc..b928343d8bf28f24058268a4b424f212fbcd7af2 100644 (file)
@@ -139,6 +139,9 @@ static void applyCurveShrinkFatten(TransInfo *t, const int mval[2]);
 static void initMaskShrinkFatten(TransInfo *t);
 static void applyMaskShrinkFatten(TransInfo *t, const int mval[2]);
 
+static void initGPShrinkFatten(TransInfo *t);
+static void applyGPShrinkFatten(TransInfo *t, const int mval[2]);
+
 static void initTrackball(TransInfo *t);
 static void applyTrackball(TransInfo *t, const int mval[2]);
 
@@ -2165,6 +2168,9 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
                case TFM_MASK_SHRINKFATTEN:
                        initMaskShrinkFatten(t);
                        break;
+               case TFM_GPENCIL_SHRINKFATTEN:
+                       initGPShrinkFatten(t);
+                       break;
                case TFM_TRACKBALL:
                        initTrackball(t);
                        break;
@@ -4668,6 +4674,83 @@ static void applyMaskShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
 /** \} */
 
 
+/* -------------------------------------------------------------------- */
+/* Transform (GPencil Shrink/Fatten) */
+
+/** \name Transform GPencil Strokes Shrink/Fatten
+ * \{ */
+
+static void initGPShrinkFatten(TransInfo *t)
+{
+       t->mode = TFM_GPENCIL_SHRINKFATTEN;
+       t->transform = applyGPShrinkFatten;
+
+       initMouseInputMode(t, &t->mouse, INPUT_SPRING);
+
+       t->idx_max = 0;
+       t->num.idx_max = 0;
+       t->snap[0] = 0.0f;
+       t->snap[1] = 0.1f;
+       t->snap[2] = t->snap[1] * 0.1f;
+
+       copy_v3_fl(t->num.val_inc, t->snap[1]);
+       t->num.unit_sys = t->scene->unit.system;
+       t->num.unit_type[0] = B_UNIT_NONE;
+
+       t->flag |= T_NO_ZERO;
+#ifdef USE_NUM_NO_ZERO
+       t->num.val_flag[0] |= NUM_NO_ZERO;
+#endif
+
+       t->flag |= T_NO_CONSTRAINT;
+}
+
+static void applyGPShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
+{
+       TransData *td = t->data;
+       float ratio;
+       int i;
+       char str[MAX_INFO_LEN];
+
+       ratio = t->values[0];
+
+       snapGridIncrement(t, &ratio);
+
+       applyNumInput(&t->num, &ratio);
+
+       /* header print for NumInput */
+       if (hasNumInput(&t->num)) {
+               char c[NUM_STR_REP_LEN];
+
+               outputNumInput(&(t->num), c, &t->scene->unit);
+               BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Shrink/Fatten: %s"), c);
+       }
+       else {
+               BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Shrink/Fatten: %3f"), ratio);
+       }
+
+       for (i = 0; i < t->total; i++, td++) {
+               if (td->flag & TD_NOACTION)
+                       break;
+
+               if (td->flag & TD_SKIP)
+                       continue;
+
+               if (td->val) {
+                       *td->val = td->ival * ratio;
+                       /* apply PET */
+                       *td->val = (*td->val * td->factor) + ((1.0f - td->factor) * td->ival);
+                       if (*td->val <= 0.0f) *td->val = 0.001f;
+               }
+       }
+
+       recalcData(t);
+
+       ED_area_headerprint(t->sa, str);
+}
+/** \} */
+
+
 /* -------------------------------------------------------------------- */
 /* Transform (Push/Pull) */
 
index 4802f8dc127991682581db563653783249bcbb62..b50f56aae3eeb1419c58adf6bf182a5664376c61 100644 (file)
@@ -7502,6 +7502,12 @@ static void createTransGPencil(bContext *C, TransInfo *t)
                                                        
                                                        if (pt->flag & GP_SPOINT_SELECT)
                                                                td->flag |= TD_SELECTED;
+                                                               
+                                                       /* for other transform modes (e.g. shrink-fatten), need to additional data */
+                                                       if (t->mode == TFM_GPENCIL_SHRINKFATTEN) {
+                                                               td->val = &pt->pressure;
+                                                               td->ival = pt->pressure;
+                                                       }
                                                        
                                                        /* configure 2D points so that they don't play up... */
                                                        if (gps->flag & (GP_STROKE_2DSPACE | GP_STROKE_2DIMAGE)) {
index 1498e2894d4b347eda281b7bb265cde3430d5618..0ee5ab96a85d381edb9fc604c205e9bae0c95f79 100644 (file)
@@ -142,6 +142,7 @@ EnumPropertyItem transform_mode_types[] =
        {TFM_BONE_ENVELOPE, "BONE_ENVELOPE", 0, "Bone_Envelope", ""},
        {TFM_CURVE_SHRINKFATTEN, "CURVE_SHRINKFATTEN", 0, "Curve_Shrinkfatten", ""},
        {TFM_MASK_SHRINKFATTEN, "MASK_SHRINKFATTEN", 0, "Mask_Shrinkfatten", ""},
+       {TFM_GPENCIL_SHRINKFATTEN, "GPENCIL_SHRINKFATTEN", 0, "GPencil_Shrinkfatten", ""},
        {TFM_BONE_ROLL, "BONE_ROLL", 0, "Bone_Roll", ""},
        {TFM_TIME_TRANSLATE, "TIME_TRANSLATE", 0, "Time_Translate", ""},
        {TFM_TIME_SLIDE, "TIME_SLIDE", 0, "Time_Slide", ""},
@@ -974,7 +975,7 @@ static void TRANSFORM_OT_transform(struct wmOperatorType *ot)
 
        RNA_def_float_vector(ot->srna, "value", 4, NULL, -FLT_MAX, FLT_MAX, "Values", "", -FLT_MAX, FLT_MAX);
 
-       Transform_Properties(ot, P_AXIS | P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_ALIGN_SNAP);
+       Transform_Properties(ot, P_AXIS | P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_ALIGN_SNAP | P_GPENCIL_EDIT);
 }
 
 void transform_operatortypes(void)