Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-11-07 03:38:10 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-11-07 03:42:30 +0300
commitc19dafd2a62fe0bebe6f834017b108e77d133682 (patch)
tree812a90384c375ea82bdc34893bcdd3bd2f01154a
parent895295a9f0cb85c7c48c395621b9c9d7e5fc78a3 (diff)
Paint: paint.brush_select now supports gpencil
Replace grease pencil specific brush select operator.
-rw-r--r--release/scripts/startup/bl_ui/space_toolsystem_common.py12
-rw-r--r--source/blender/blenkernel/BKE_paint.h1
-rw-r--r--source/blender/blenkernel/intern/paint.c15
-rw-r--r--source/blender/editors/gpencil/gpencil_data.c51
-rw-r--r--source/blender/editors/gpencil/gpencil_intern.h1
-rw-r--r--source/blender/editors/gpencil/gpencil_ops.c1
-rw-r--r--source/blender/editors/interface/interface_region_tooltip.c22
-rw-r--r--source/blender/editors/sculpt_paint/paint_ops.c59
-rw-r--r--source/blender/makesrna/intern/rna_brush.c8
9 files changed, 46 insertions, 124 deletions
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_common.py b/release/scripts/startup/bl_ui/space_toolsystem_common.py
index f23b76c5911..6ddfcd97940 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_common.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_common.py
@@ -812,11 +812,13 @@ def keymap_from_context(context, space_type):
if item.data_block:
# PAINT_OT_brush_select
mode = context.active_object.mode
+ # See: BKE_paint_get_tool_prop_id_from_paintmode
attr = {
'SCULPT': "sculpt_tool",
- 'WEIGHT_PAINT': "weight_paint_tool",
- 'VERTEX_PAINT': "vertex_paint_tool",
- 'TEXTURE_PAINT': "texture_paint_tool",
+ 'VERTEX_PAINT': "vertex_tool",
+ 'WEIGHT_PAINT': "weight_tool",
+ 'TEXTURE_PAINT': "image_tool",
+ 'GPENCIL_PAINT': "gpencil_tool",
}.get(mode, (None, None))
if attr is not None:
kmi_hack_brush_select_properties.paint_mode = mode
@@ -826,10 +828,6 @@ def keymap_from_context(context, space_type):
context='INVOKE_REGION_WIN',
properties=kmi_hack_brush_select_properties,
)[1]
- elif mode == 'GPENCIL_PAINT':
- # TODO: gpencil.brush_select
- # By default no keys are mapped to this, pass.
- pass
else:
print("Unsupported mode:", mode)
del mode, attr
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 3ebe041dd36..b4b667ecb6b 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -140,6 +140,7 @@ void BKE_paint_cavity_curve_preset(struct Paint *p, int preset);
eObjectMode BKE_paint_object_mode_from_paintmode(ePaintMode mode);
struct Paint *BKE_paint_get_active_from_paintmode(struct Scene *sce, ePaintMode mode);
const struct EnumPropertyItem *BKE_paint_get_tool_enum_from_paintmode(ePaintMode mode);
+const char *BKE_paint_get_tool_prop_id_from_paintmode(ePaintMode mode);
uint BKE_paint_get_brush_tool_offset_from_paintmode(const ePaintMode mode);
struct Paint *BKE_paint_get_active(struct Scene *sce, struct ViewLayer *view_layer);
struct Paint *BKE_paint_get_active_from_context(const struct bContext *C);
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 86af8604e70..db7cd513bf4 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -196,6 +196,21 @@ const EnumPropertyItem *BKE_paint_get_tool_enum_from_paintmode(ePaintMode mode)
return NULL;
}
+const char *BKE_paint_get_tool_prop_id_from_paintmode(ePaintMode mode)
+{
+ switch (mode) {
+ case ePaintSculpt: return "sculpt_tool";
+ case ePaintVertex: return "vertex_tool";
+ case ePaintWeight: return "weight_tool";
+ case ePaintTexture2D:
+ case ePaintTextureProjective: return "image_tool";
+ case ePaintGpencil: return "gpencil_tool";
+ default:
+ /* invalid paint mode */
+ return NULL;
+ }
+}
+
Paint *BKE_paint_get_active(Scene *sce, ViewLayer *view_layer)
{
if (sce && view_layer) {
diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c
index 8c7068c0a7c..458e9d0eb41 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -1546,57 +1546,6 @@ void GPENCIL_OT_brush_presets_create(wmOperatorType *ot)
}
-/* ***************** Select Brush ************************ */
-
-static int gp_brush_select_exec(bContext *C, wmOperator *op)
-{
- ToolSettings *ts = CTX_data_tool_settings(C);
- Main *bmain = CTX_data_main(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");
-
- Paint *paint = &ts->gp_paint->paint;
- int i = 0;
- for (Brush *brush = bmain->brush.first; brush; brush = brush->id.next) {
- if (brush->ob_mode == OB_MODE_GPENCIL_PAINT) {
- if (i == index) {
- BKE_paint_brush_set(paint, brush);
-
- /* notifiers */
- WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
- return OPERATOR_FINISHED;
- }
- i++;
- }
- }
-
- return OPERATOR_CANCELLED;
-}
-
-void GPENCIL_OT_brush_select(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Select Brush";
- ot->idname = "GPENCIL_OT_brush_select";
- ot->description = "Select a Grease Pencil drawing brush";
-
- /* callbacks */
- ot->exec = gp_brush_select_exec;
- ot->poll = gp_active_brush_poll;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
- /* properties */
- 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)
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index f7117189c32..bed4811d7bb 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -386,7 +386,6 @@ void GPENCIL_OT_stroke_separate(struct wmOperatorType *ot);
void GPENCIL_OT_stroke_split(struct wmOperatorType *ot);
void GPENCIL_OT_brush_presets_create(struct wmOperatorType *ot);
-void GPENCIL_OT_brush_select(struct wmOperatorType *ot);
void GPENCIL_OT_sculpt_select(struct wmOperatorType *ot);
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index d9a233b78d8..968233866f6 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -763,7 +763,6 @@ void ED_operatortypes_gpencil(void)
WM_operatortype_append(GPENCIL_OT_stroke_split);
WM_operatortype_append(GPENCIL_OT_brush_presets_create);
- WM_operatortype_append(GPENCIL_OT_brush_select);
WM_operatortype_append(GPENCIL_OT_sculpt_select);
diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c
index 6d3ba95fda5..e8a73eaf56d 100644
--- a/source/blender/editors/interface/interface_region_tooltip.c
+++ b/source/blender/editors/interface/interface_region_tooltip.c
@@ -459,27 +459,7 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but, bool is
if (shortcut == NULL) {
ePaintMode paint_mode = BKE_paintmode_get_active_from_context(C);
- const char *tool_attr = NULL;
-
- switch (paint_mode) {
- case ePaintSculpt:
- tool_attr = "sculpt_tool";
- break;
- case ePaintVertex:
- tool_attr = "vertex_paint_tool";
- break;
- case ePaintWeight:
- tool_attr = "weight_paint_tool";
- break;
- case ePaintTexture2D:
- case ePaintTextureProjective:
- tool_attr = "texture_paint_tool";
- paint_mode = ePaintTextureProjective;
- break;
- default:
- break;
- }
-
+ const char *tool_attr = BKE_paint_get_tool_prop_id_from_paintmode(paint_mode);
if (tool_attr != NULL) {
const EnumPropertyItem *items = BKE_paint_get_tool_enum_from_paintmode(paint_mode);
const int i = RNA_enum_from_name(items, tool_name);
diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c
index be59d8e2c71..9bad1324aa6 100644
--- a/source/blender/editors/sculpt_paint/paint_ops.c
+++ b/source/blender/editors/sculpt_paint/paint_ops.c
@@ -466,18 +466,10 @@ static int brush_select_exec(bContext *C, wmOperator *op)
Paint *paint = BKE_paint_get_active_from_paintmode(scene, paint_mode);
const EnumPropertyItem *items = BKE_paint_get_tool_enum_from_paintmode(paint_mode);
- const char *op_prop_id = NULL;
-
- switch (paint_mode) {
- case ePaintSculpt: op_prop_id = "sculpt_tool"; break;
- case ePaintVertex: op_prop_id = "vertex_paint_tool"; break;
- case ePaintWeight: op_prop_id = "weight_paint_tool"; break;
- case ePaintTexture2D:
- case ePaintTextureProjective: op_prop_id = "texture_paint_tool"; break;
- default:
- /* invalid paint mode */
- BLI_assert(0);
- return OPERATOR_CANCELLED;
+ const char *op_prop_id = BKE_paint_get_tool_prop_id_from_paintmode(paint_mode);
+
+ if (op_prop_id == NULL) {
+ return OPERATOR_CANCELLED;
}
const int tool = RNA_enum_get(op->ptr, op_prop_id);
@@ -490,12 +482,14 @@ static int brush_select_exec(bContext *C, wmOperator *op)
static void PAINT_OT_brush_select(wmOperatorType *ot)
{
+ /* Keep names matching 'rna_enum_object_mode_items' (besides active). */
static const EnumPropertyItem paint_mode_items[] = {
{ePaintInvalid, "ACTIVE", 0, "Current", "Set brush for active paint mode"},
{ePaintSculpt, "SCULPT", ICON_SCULPTMODE_HLT, "Sculpt", ""},
{ePaintVertex, "VERTEX_PAINT", ICON_VPAINT_HLT, "Vertex Paint", ""},
{ePaintWeight, "WEIGHT_PAINT", ICON_WPAINT_HLT, "Weight Paint", ""},
{ePaintTextureProjective, "TEXTURE_PAINT", ICON_TPAINT_HLT, "Texture Paint", ""},
+ {ePaintGpencil, "GPENCIL_PAINT", ICON_GREASEPENCIL, "Grease Pencil Paint", ""},
{0, NULL, 0, NULL, NULL}
};
PropertyRNA *prop;
@@ -515,14 +509,13 @@ static void PAINT_OT_brush_select(wmOperatorType *ot)
/* All properties are hidden, so as not to show the redo panel. */
prop = RNA_def_enum(ot->srna, "paint_mode", paint_mode_items, ePaintInvalid, "Paint Mode", "");
RNA_def_property_flag(prop, PROP_HIDDEN);
- prop = RNA_def_enum(ot->srna, "sculpt_tool", rna_enum_brush_sculpt_tool_items, 0, "Sculpt Tool", "");
- RNA_def_property_flag(prop, PROP_HIDDEN);
- prop = RNA_def_enum(ot->srna, "vertex_paint_tool", rna_enum_brush_vertex_tool_items, 0, "Vertex Paint Tool", "");
- RNA_def_property_flag(prop, PROP_HIDDEN);
- prop = RNA_def_enum(ot->srna, "weight_paint_tool", rna_enum_brush_weight_tool_items, 0, "Weight Paint Tool", "");
- RNA_def_property_flag(prop, PROP_HIDDEN);
- prop = RNA_def_enum(ot->srna, "texture_paint_tool", rna_enum_brush_image_tool_items, 0, "Texture Paint Tool", "");
- RNA_def_property_flag(prop, PROP_HIDDEN);
+
+ for (const EnumPropertyItem *item = paint_mode_items + 1; item->identifier; item++) {
+ const ePaintMode paint_mode = item->value;
+ const char *prop_id = BKE_paint_get_tool_prop_id_from_paintmode(paint_mode);
+ prop = RNA_def_enum(ot->srna, prop_id, BKE_paint_get_tool_enum_from_paintmode(paint_mode), 0, prop_id, "");
+ RNA_def_property_flag(prop, PROP_HIDDEN);
+ }
prop = RNA_def_boolean(ot->srna, "toggle", 0, "Toggle", "Toggle between two brushes rather than cycling");
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
@@ -536,30 +529,10 @@ static wmKeyMapItem *keymap_brush_select(
int keymap_modifier)
{
wmKeyMapItem *kmi;
- kmi = WM_keymap_add_item(
- keymap, "PAINT_OT_brush_select",
- keymap_type, KM_PRESS, keymap_modifier, 0);
-
+ kmi = WM_keymap_add_item(keymap, "PAINT_OT_brush_select", keymap_type, KM_PRESS, keymap_modifier, 0);
RNA_enum_set(kmi->ptr, "paint_mode", paint_mode);
-
- switch (paint_mode) {
- case ePaintSculpt:
- RNA_enum_set(kmi->ptr, "sculpt_tool", tool);
- break;
- case ePaintVertex:
- RNA_enum_set(kmi->ptr, "vertex_paint_tool", tool);
- break;
- case ePaintWeight:
- RNA_enum_set(kmi->ptr, "weight_paint_tool", tool);
- break;
- case ePaintTexture2D:
- case ePaintTextureProjective:
- RNA_enum_set(kmi->ptr, "texture_paint_tool", tool);
- break;
- default:
- BLI_assert(0);
- }
-
+ const char *prop_id = BKE_paint_get_tool_prop_id_from_paintmode(paint_mode);
+ RNA_enum_set(kmi->ptr, prop_id, tool);
return kmi;
}
diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c
index 4506519e7f5..f369c0a323e 100644
--- a/source/blender/makesrna/intern/rna_brush.c
+++ b/source/blender/makesrna/intern/rna_brush.c
@@ -1316,6 +1316,12 @@ static void rna_def_brush(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Blending mode", "Brush blending mode");
RNA_def_property_update(prop, 0, "rna_Brush_update");
+
+ /**
+ * Begin per-mode tool properties.
+ *
+ * keep in sync with #BKE_paint_get_tool_prop_id_from_paintmode
+ */
prop = RNA_def_property(srna, "sculpt_tool", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(prop, rna_enum_brush_sculpt_tool_items);
RNA_def_property_ui_text(prop, "Sculpt Tool", "");
@@ -1344,6 +1350,8 @@ static void rna_def_brush(BlenderRNA *brna)
RNA_def_property_enum_items(prop, rna_enum_brush_gpencil_types_items);
RNA_def_property_ui_text(prop, "Type", "Category of the brush");
RNA_def_parameter_clear_flags(prop, PROP_ANIMATABLE, 0);
+ /** End per mode tool properties. */
+
prop = RNA_def_property(srna, "direction", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");