Tool System: use enum for gp sculpt/weight paint

Fixes T57525
This commit is contained in:
2018-11-13 16:52:39 +11:00
parent 3437cd9ac2
commit b657e9875c
7 changed files with 113 additions and 205 deletions

View File

@@ -1188,18 +1188,10 @@ static bool gpsculpt_brush_init(bContext *C, wmOperator *op)
const bool is_weight_mode = ob->mode == OB_MODE_GPENCIL_WEIGHT;
/* set the brush using the tool */
#if 0
GP_BrushEdit_Settings *gset = &ts->gp_sculpt;
eGP_EditBrush_Types mode = RNA_enum_get(op->ptr, "mode");
const bool keep_brush = RNA_boolean_get(op->ptr, "keep_brush");
if (!keep_brush) {
if (is_weight_mode) {
gset->weighttype = mode;
}
else {
gset->brushtype = mode;
}
}
eGP_EditBrush_Types mode = is_weight_mode ? gset->weighttype : gset->brushtype;
#endif
tGP_BrushEditData *gso;
/* setup operator data */
@@ -2099,22 +2091,6 @@ static int gpsculpt_brush_modal(bContext *C, wmOperator *op, const wmEvent *even
return OPERATOR_RUNNING_MODAL;
}
/* Operator --------------------------------------------- */
static const EnumPropertyItem prop_gpencil_sculpt_brush_items[] = {
{GP_EDITBRUSH_TYPE_SMOOTH, "SMOOTH", 0, "Smooth", "Smooth stroke points" },
{GP_EDITBRUSH_TYPE_THICKNESS, "THICKNESS", 0, "Thickness", "Adjust thickness of strokes" },
{GP_EDITBRUSH_TYPE_STRENGTH, "STRENGTH", 0, "Strength", "Adjust color strength of strokes" },
{GP_EDITBRUSH_TYPE_GRAB, "GRAB", 0, "Grab", "Translate the set of points initially within the brush circle" },
{GP_EDITBRUSH_TYPE_PUSH, "PUSH", 0, "Push", "Move points out of the way, as if combing them" },
{GP_EDITBRUSH_TYPE_TWIST, "TWIST", 0, "Twist", "Rotate points around the midpoint of the brush" },
{GP_EDITBRUSH_TYPE_PINCH, "PINCH", 0, "Pinch", "Pull points towards the midpoint of the brush" },
{GP_EDITBRUSH_TYPE_RANDOMIZE, "RANDOMIZE", 0, "Randomize", "Introduce jitter/randomness into strokes" },
{GP_EDITBRUSH_TYPE_CLONE, "CLONE", 0, "Clone", "Paste copies of the strokes stored on the clipboard" },
{GP_EDITBRUSH_TYPE_WEIGHT, "WEIGHT", 0, "Weight", "Weight Paint" },
{0, NULL, 0, NULL, NULL }
};
void GPENCIL_OT_brush_paint(wmOperatorType *ot)
{
/* identifiers */
@@ -2133,9 +2109,6 @@ void GPENCIL_OT_brush_paint(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
/* properties */
ot->prop = RNA_def_enum(ot->srna, "mode", prop_gpencil_sculpt_brush_items, 0, "Mode", "Brush mode");
RNA_def_property_flag(ot->prop, PROP_HIDDEN | PROP_SKIP_SAVE);
PropertyRNA *prop;
prop = RNA_def_collection_runtime(ot->srna, "stroke", &RNA_OperatorStrokeElement, "Stroke", "");
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
@@ -2143,10 +2116,4 @@ void GPENCIL_OT_brush_paint(wmOperatorType *ot)
prop = RNA_def_boolean(ot->srna, "wait_for_input", true, "Wait for Input",
"Enter a mini 'sculpt-mode' if enabled, otherwise, exit after drawing a single stroke");
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
prop = RNA_def_boolean(ot->srna, "keep_brush", false, "Keep Brush",
"Keep current brush activated");
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
}
/* ************************************************ */

View File

@@ -127,6 +127,7 @@ extern const EnumPropertyItem rna_enum_brush_image_tool_items[];
extern const EnumPropertyItem rna_enum_particle_edit_hair_brush_items[];
extern const EnumPropertyItem rna_enum_particle_edit_disconnected_hair_brush_items[];
extern const EnumPropertyItem rna_enum_gpencil_sculpt_brush_items[];
extern const EnumPropertyItem rna_enum_gpencil_weight_brush_items[];
extern const EnumPropertyItem rna_enum_uv_sculpt_tool_items[];

View File

@@ -78,12 +78,12 @@ const EnumPropertyItem rna_enum_gpencil_sculpt_brush_items[] = {
{ 0, NULL, 0, NULL, NULL }
};
#ifndef RNA_RUNTIME
static EnumPropertyItem rna_enum_gpencil_weight_brush_items[] = {
const EnumPropertyItem rna_enum_gpencil_weight_brush_items[] = {
{GP_EDITBRUSH_TYPE_WEIGHT, "WEIGHT", ICON_GPBRUSH_WEIGHT, "Weight", "Weight Paint for Vertex Groups"},
{0, NULL, 0, NULL, NULL}
};
#ifndef RNA_RUNTIME
static const EnumPropertyItem rna_enum_gpencil_lock_axis_items[] = {
{GP_LOCKAXIS_VIEW, "VIEW", ICON_RESTRICT_VIEW_ON, "View", "Align strokes to current view plane"},
{GP_LOCKAXIS_Y, "AXIS_Y", ICON_AXIS_FRONT, "Front (X-Z)", "Project strokes to plane locked to Y"},
@@ -1193,7 +1193,7 @@ static void rna_def_gpencil_sculpt(BlenderRNA *brna)
RNA_def_struct_path_func(srna, "rna_GPencilSculptSettings_path");
RNA_def_struct_ui_text(srna, "GPencil Sculpt Settings", "Properties for Grease Pencil stroke sculpting tool");
prop = RNA_def_property(srna, "tool", PROP_ENUM, PROP_NONE);
prop = RNA_def_property(srna, "sculpt_tool", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "brushtype");
RNA_def_property_enum_items(prop, rna_enum_gpencil_sculpt_brush_items);
RNA_def_property_ui_text(prop, "Tool", "");

View File

@@ -182,6 +182,9 @@ static void toolsystem_ref_link__refresh_image_uv_sculpt(bContext *C, Scene *sce
RNA_property_update(C, &ptr, prop);
}
/**
* \see #toolsystem_ref_link
*/
static void toolsystem_ref_link(bContext *C, WorkSpace *workspace, bToolRef *tref)
{
bToolRef_Runtime *tref_rt = tref->runtime;
@@ -200,9 +203,43 @@ static void toolsystem_ref_link(bContext *C, WorkSpace *workspace, bToolRef *tre
if (tref_rt->data_block[0]) {
Main *bmain = CTX_data_main(C);
if ((tref->space_type == SPACE_VIEW3D) &&
(tref->mode == CTX_MODE_PARTICLE))
if ((tref->space_type == SPACE_VIEW3D) &&
(tref->mode == CTX_MODE_GPENCIL_SCULPT))
{
const EnumPropertyItem *items = rna_enum_gpencil_sculpt_brush_items;
const int i = RNA_enum_from_identifier(items, tref_rt->data_block);
if (i != -1) {
const int value = items[i].value;
wmWindowManager *wm = bmain->wm.first;
for (wmWindow *win = wm->windows.first; win; win = win->next) {
if (workspace == WM_window_get_active_workspace(win)) {
Scene *scene = WM_window_get_active_scene(win);
ToolSettings *ts = scene->toolsettings;
ts->gp_sculpt.brushtype = value;
}
}
}
}
else if ((tref->space_type == SPACE_VIEW3D) &&
(tref->mode == CTX_MODE_GPENCIL_WEIGHT))
{
const EnumPropertyItem *items = rna_enum_gpencil_weight_brush_items;
const int i = RNA_enum_from_identifier(items, tref_rt->data_block);
if (i != -1) {
const int value = items[i].value;
wmWindowManager *wm = bmain->wm.first;
for (wmWindow *win = wm->windows.first; win; win = win->next) {
if (workspace == WM_window_get_active_workspace(win)) {
Scene *scene = WM_window_get_active_scene(win);
ToolSettings *ts = scene->toolsettings;
ts->gp_sculpt.weighttype = value;
}
}
}
}
else if ((tref->space_type == SPACE_VIEW3D) &&
(tref->mode == CTX_MODE_PARTICLE))
{
const EnumPropertyItem *items = rna_enum_particle_edit_hair_brush_items;
const int i = RNA_enum_from_identifier(items, tref_rt->data_block);
@@ -218,8 +255,8 @@ static void toolsystem_ref_link(bContext *C, WorkSpace *workspace, bToolRef *tre
}
}
}
if ((tref->space_type == SPACE_IMAGE) &&
(tref->mode == SI_MODE_UV))
else if ((tref->space_type == SPACE_IMAGE) &&
(tref->mode == SI_MODE_UV))
{
/* Note that switching uv-sculpt boolean is a hack at the moment.
* It would be best to make this either an operator or a higher level mode (like mesh-object sculpt mode). */
@@ -410,6 +447,8 @@ void WM_toolsystem_ref_set_from_runtime(
/**
* Sync the internal active state of a tool back into the tool system,
* this is needed for active brushes where the real active state is not stored in the tool system.
*
* \see #toolsystem_ref_link
*/
void WM_toolsystem_ref_sync_from_context(
Main *bmain, WorkSpace *workspace, bToolRef *tref)
@@ -431,6 +470,30 @@ void WM_toolsystem_ref_sync_from_context(
if (ob == NULL) {
/* pass */
}
else if ((tref->space_type == SPACE_VIEW3D) &&
(tref->mode == CTX_MODE_GPENCIL_SCULPT) &&
(ob->mode & OB_MODE_GPENCIL_SCULPT))
{
const EnumPropertyItem *items = rna_enum_gpencil_sculpt_brush_items;
const int i = RNA_enum_from_value(items, ts->gp_sculpt.brushtype);
const EnumPropertyItem *item = &items[i];
if (!STREQ(tref_rt->data_block, item->identifier)) {
STRNCPY(tref_rt->data_block, item->identifier);
STRNCPY(tref->idname, item->name);
}
}
else if ((tref->space_type == SPACE_VIEW3D) &&
(tref->mode == CTX_MODE_GPENCIL_WEIGHT) &&
(ob->mode & OB_MODE_GPENCIL_WEIGHT))
{
const EnumPropertyItem *items = rna_enum_gpencil_weight_brush_items;
const int i = RNA_enum_from_value(items, ts->gp_sculpt.weighttype);
const EnumPropertyItem *item = &items[i];
if (!STREQ(tref_rt->data_block, item->identifier)) {
STRNCPY(tref_rt->data_block, item->identifier);
STRNCPY(tref->idname, item->name);
}
}
else if ((tref->space_type == SPACE_VIEW3D) &&
(tref->mode == CTX_MODE_PARTICLE) &&
(ob->mode & OB_MODE_PARTICLE_EDIT))
@@ -445,8 +508,7 @@ void WM_toolsystem_ref_sync_from_context(
}
else if ((tref->space_type == SPACE_IMAGE) &&
(tref->mode == SI_MODE_UV) &&
(ob->mode &
OB_MODE_EDIT))
(ob->mode & OB_MODE_EDIT))
{
const EnumPropertyItem *items = rna_enum_uv_sculpt_tool_items;
const int i = RNA_enum_from_value(items, ts->uv_sculpt_tool);