Commit: 19deb16965e9787ab87672ee4d4df91bc3020ebd
Author: Antonio Vazquez
Date:   Sat Jun 10 20:02:11 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB19deb16965e9787ab87672ee4d4df91bc3020ebd

New operator and keymaps to select sculpt brushes

Now it's possible to select the sculpt brush sing a key between 1 and 9.

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

M       source/blender/editors/gpencil/gpencil_data.c
M       source/blender/editors/gpencil/gpencil_intern.h
M       source/blender/editors/gpencil/gpencil_ops.c

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

diff --git a/source/blender/editors/gpencil/gpencil_data.c 
b/source/blender/editors/gpencil/gpencil_data.c
index e27b625317f..7612454ca6f 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -1440,6 +1440,58 @@ void GPENCIL_OT_brush_select(wmOperatorType *ot)
        RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "Index of 
Drawing Brush", 0, INT_MAX);
 }
 
+/* ***************** Select Sculpt Brush ************************ */
+
+static int gp_sculpt_select_exec(bContext *C, wmOperator *op)
+{
+       ToolSettings *ts = CTX_data_tool_settings(C);
+
+       /* if there's no existing container */
+       if (ts == NULL) {
+               BKE_report(op->reports, RPT_ERROR, "Nowhere to go");
+               return OPERATOR_CANCELLED;
+       }
+
+       const int index = RNA_int_get(op->ptr, "index");
+       GP_BrushEdit_Settings *gp_sculpt = &ts->gp_sculpt;
+       /* sanity checks */
+       if (ELEM(NULL, gp_sculpt)) {
+               return OPERATOR_CANCELLED;
+       }
+
+       if (index < TOT_GP_EDITBRUSH_TYPES) {
+               if (index < 7) {
+                       gp_sculpt->brushtype = index;
+               }
+               else {
+                       /* brushes 7 and 8 not used */
+                       gp_sculpt->brushtype = index + 2;
+               }
+       }
+       /* notifiers */
+       WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
+
+       return OPERATOR_FINISHED;
+}
+
+void GPENCIL_OT_sculpt_select(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name = "Select Sculpt Brush";
+       ot->idname = "GPENCIL_OT_sculpt_select";
+       ot->description = "Select a Grease Pencil sculpt brush";
+
+       /* callbacks */
+       ot->exec = gp_sculpt_select_exec;
+       ot->poll = gp_add_poll;
+
+       /* flags */
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+       /* properties */
+       RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "Index of Sculpt 
Brush", 0, INT_MAX);
+}
+
 /* ******************* Convert animation data ************************ */
 static int gp_convert_old_palettes_poll(bContext *C)
 {
diff --git a/source/blender/editors/gpencil/gpencil_intern.h 
b/source/blender/editors/gpencil/gpencil_intern.h
index a7420f04d82..9881fcb4e22 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -328,6 +328,8 @@ void GPENCIL_OT_brush_presets_create(struct wmOperatorType 
*ot);
 void GPENCIL_OT_brush_copy(struct wmOperatorType *ot);
 void GPENCIL_OT_brush_select(struct wmOperatorType *ot);
 
+void GPENCIL_OT_sculpt_select(struct wmOperatorType *ot);
+
 void GPENCIL_OT_palette_add(struct wmOperatorType *ot);
 void GPENCIL_OT_palette_remove(struct wmOperatorType *ot);
 void GPENCIL_OT_palette_change(struct wmOperatorType *ot);
diff --git a/source/blender/editors/gpencil/gpencil_ops.c 
b/source/blender/editors/gpencil/gpencil_ops.c
index 544a2824c87..fe924fa45fb 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -414,6 +414,7 @@ static void ed_keymap_gpencil_painting(wmKeyConfig *keyconf)
 static void ed_keymap_gpencil_sculpting(wmKeyConfig *keyconf)
 {
        wmKeyMap *keymap = WM_keymap_find(keyconf, "Grease Pencil Stroke Sculpt 
Mode", 0, 0);
+       wmKeyMapItem *kmi;
 
        /* set poll callback - so that this keymap only gets enabled when 
stroke sculptmode is enabled */
        keymap->poll = gp_stroke_sculptmode_poll;
@@ -427,6 +428,26 @@ static void ed_keymap_gpencil_sculpting(wmKeyConfig 
*keyconf)
        /* sculpt */
        ed_keymap_gpencil_sculpt(keymap);
 
+       /* Select sculpt brush using index */
+       kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_sculpt_select", ONEKEY, 
KM_PRESS, 0, 0);
+       RNA_int_set(kmi->ptr, "index", 0);
+       kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_sculpt_select", TWOKEY, 
KM_PRESS, 0, 0);
+       RNA_int_set(kmi->ptr, "index", 1);
+       kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_sculpt_select", THREEKEY, 
KM_PRESS, 0, 0);
+       RNA_int_set(kmi->ptr, "index", 2);
+       kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_sculpt_select", FOURKEY, 
KM_PRESS, 0, 0);
+       RNA_int_set(kmi->ptr, "index", 3);
+       kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_sculpt_select", FIVEKEY, 
KM_PRESS, 0, 0);
+       RNA_int_set(kmi->ptr, "index", 4);
+       kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_sculpt_select", SIXKEY, 
KM_PRESS, 0, 0);
+       RNA_int_set(kmi->ptr, "index", 5);
+       kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_sculpt_select", SEVENKEY, 
KM_PRESS, 0, 0);
+       RNA_int_set(kmi->ptr, "index", 6);
+       kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_sculpt_select", EIGHTKEY, 
KM_PRESS, 0, 0);
+       RNA_int_set(kmi->ptr, "index", 7);
+       kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_sculpt_select", NINEKEY, 
KM_PRESS, 0, 0);
+       RNA_int_set(kmi->ptr, "index", 8);
+
        /* Enter EditMode */
        WM_keymap_add_item(keymap, "GPENCIL_OT_editmode_toggle", TABKEY, 
KM_PRESS, KM_SHIFT, 0);
        /* Enter PaintMode */
@@ -531,6 +552,8 @@ void ED_operatortypes_gpencil(void)
        WM_operatortype_append(GPENCIL_OT_brush_copy);
        WM_operatortype_append(GPENCIL_OT_brush_select);
 
+       WM_operatortype_append(GPENCIL_OT_sculpt_select);
+
        /* conversion of old palettes */
        WM_operatortype_append(GPENCIL_OT_convert_old_palettes);

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

Reply via email to