diff options
7 files changed, 292 insertions, 152 deletions
diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py index b945a92020f..80ebff8982f 100644 --- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py +++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py @@ -6382,12 +6382,12 @@ def km_3d_view_tool_paint_gpencil_line(params): "3D View Tool: Paint Gpencil, Line", {"space_type": 'VIEW_3D', "region_type": 'WINDOW'}, {"items": [ - ("gpencil.primitive", {"type": params.tool_tweak, "value": 'ANY'}, - {"properties": [("type", 'LINE'), ("wait_for_input", False)]}), - ("gpencil.primitive", {"type": 'LEFTMOUSE', "value": 'PRESS', "shift": True}, - {"properties": [("type", 'LINE'), ("wait_for_input", False)]}), - ("gpencil.primitive", {"type": 'LEFTMOUSE', "value": 'PRESS', "alt": True}, - {"properties": [("type", 'LINE'), ("wait_for_input", False)]}), + ("gpencil.primitive_line", {"type": params.tool_tweak, "value": 'ANY'}, + {"properties": [("wait_for_input", False)]}), + ("gpencil.primitive_line", {"type": 'LEFTMOUSE', "value": 'PRESS', "shift": True}, + {"properties": [("wait_for_input", False)]}), + ("gpencil.primitive_line", {"type": 'LEFTMOUSE', "value": 'PRESS', "alt": True}, + {"properties": [("wait_for_input", False)]}), # Lasso select ("gpencil.select_lasso", {"type": params.action_tweak, "value": 'ANY', "ctrl": True, "alt": True}, None), ]}, @@ -6398,10 +6398,10 @@ def km_3d_view_tool_paint_gpencil_polyline(params): "3D View Tool: Paint Gpencil, Polyline", {"space_type": 'VIEW_3D', "region_type": 'WINDOW'}, {"items": [ - ("gpencil.primitive", {"type": params.tool_tweak, "value": 'ANY'}, - {"properties": [("type", 'POLYLINE'), ("wait_for_input", False)]}), - ("gpencil.primitive", {"type": 'LEFTMOUSE', "value": 'PRESS', "shift": True}, - {"properties": [("type", 'POLYLINE'), ("wait_for_input", False)]}), + ("gpencil.primitive_polyline", {"type": params.tool_tweak, "value": 'ANY'}, + {"properties": [("wait_for_input", False)]}), + ("gpencil.primitive_polyline", {"type": 'LEFTMOUSE', "value": 'PRESS', "shift": True}, + {"properties": [("wait_for_input", False)]}), # Lasso select ("gpencil.select_lasso", {"type": params.action_tweak, "value": 'ANY', "ctrl": True, "alt": True}, None), ]}, @@ -6412,12 +6412,12 @@ def km_3d_view_tool_paint_gpencil_box(params): "3D View Tool: Paint Gpencil, Box", {"space_type": 'VIEW_3D', "region_type": 'WINDOW'}, {"items": [ - ("gpencil.primitive", {"type": params.tool_tweak, "value": 'ANY'}, - {"properties": [("type", 'BOX'), ("wait_for_input", False)]}), - ("gpencil.primitive", {"type": 'LEFTMOUSE', "value": 'PRESS', "shift": True}, - {"properties": [("type", 'BOX'), ("wait_for_input", False)]}), - ("gpencil.primitive", {"type": 'LEFTMOUSE', "value": 'PRESS', "alt": True}, - {"properties": [("type", 'BOX'), ("wait_for_input", False)]}), + ("gpencil.primitive_box", {"type": params.tool_tweak, "value": 'ANY'}, + {"properties": [("wait_for_input", False)]}), + ("gpencil.primitive_box", {"type": 'LEFTMOUSE', "value": 'PRESS', "shift": True}, + {"properties": [("wait_for_input", False)]}), + ("gpencil.primitive_box", {"type": 'LEFTMOUSE', "value": 'PRESS', "alt": True}, + {"properties": [("wait_for_input", False)]}), # Lasso select ("gpencil.select_lasso", {"type": params.action_tweak, "value": 'ANY', "ctrl": True, "alt": True}, None), ]}, @@ -6429,12 +6429,12 @@ def km_3d_view_tool_paint_gpencil_circle(params): "3D View Tool: Paint Gpencil, Circle", {"space_type": 'VIEW_3D', "region_type": 'WINDOW'}, {"items": [ - ("gpencil.primitive", {"type": params.tool_tweak, "value": 'ANY'}, - {"properties": [("type", 'CIRCLE'), ("wait_for_input", False)]}), - ("gpencil.primitive", {"type": 'LEFTMOUSE', "value": 'PRESS', "shift": True}, - {"properties": [("type", 'CIRCLE'), ("wait_for_input", False)]}), - ("gpencil.primitive", {"type": 'LEFTMOUSE', "value": 'PRESS', "alt": True}, - {"properties": [("type", 'CIRCLE'), ("wait_for_input", False)]}), + ("gpencil.primitive_circle", {"type": params.tool_tweak, "value": 'ANY'}, + {"properties": [("wait_for_input", False)]}), + ("gpencil.primitive_circle", {"type": 'LEFTMOUSE', "value": 'PRESS', "shift": True}, + {"properties": [("wait_for_input", False)]}), + ("gpencil.primitive_circle", {"type": 'LEFTMOUSE', "value": 'PRESS', "alt": True}, + {"properties": [("wait_for_input", False)]}), # Lasso select ("gpencil.select_lasso", {"type": params.action_tweak, "value": 'ANY', "ctrl": True, "alt": True}, None), ]}, @@ -6446,12 +6446,12 @@ def km_3d_view_tool_paint_gpencil_arc(params): "3D View Tool: Paint Gpencil, Arc", {"space_type": 'VIEW_3D', "region_type": 'WINDOW'}, {"items": [ - ("gpencil.primitive", {"type": params.tool_tweak, "value": 'ANY'}, - {"properties": [("type", 'ARC'), ("wait_for_input", False)]}), - ("gpencil.primitive", {"type": 'LEFTMOUSE', "value": 'PRESS', "shift": True}, + ("gpencil.primitive_curve", {"type": params.tool_tweak, "value": 'ANY'}, {"properties": [("type", 'ARC'), ("wait_for_input", False)]}), - ("gpencil.primitive", {"type": 'LEFTMOUSE', "value": 'PRESS', "alt": True}, + ("gpencil.primitive_curve", {"type": 'LEFTMOUSE', "value": 'PRESS', "shift": True}, {"properties": [("type", 'ARC'), ("wait_for_input", False)]}), + ("gpencil.primitive_curve", {"type": 'LEFTMOUSE', "value": 'PRESS', "alt": True}, + {"properties": [("type",'ARC'), ("wait_for_input", False)]}), # Lasso select ("gpencil.select_lasso", {"type": params.action_tweak, "value": 'ANY', "ctrl": True, "alt": True}, None), ]}, @@ -6463,7 +6463,7 @@ def km_3d_view_tool_paint_gpencil_curve(params): "3D View Tool: Paint Gpencil, Curve", {"space_type": 'VIEW_3D', "region_type": 'WINDOW'}, {"items": [ - ("gpencil.primitive", {"type": params.tool_tweak, "value": 'ANY'}, + ("gpencil.primitive_curve", {"type": params.tool_tweak, "value": 'ANY'}, {"properties": [("type", 'CURVE'), ("wait_for_input", False)]}), # Lasso select ("gpencil.select_lasso", {"type": params.action_tweak, "value": 'ANY', "ctrl": True, "alt": True}, None), diff --git a/release/scripts/startup/bl_ui/properties_paint_common.py b/release/scripts/startup/bl_ui/properties_paint_common.py index f1004358418..397ce5d0324 100644 --- a/release/scripts/startup/bl_ui/properties_paint_common.py +++ b/release/scripts/startup/bl_ui/properties_paint_common.py @@ -1109,6 +1109,45 @@ def brush_basic_texpaint_settings(layout, context, brush, *, compact=False): header=True ) +def brush_basic__draw_color_selector(context, layout, brush, gp_settings, props): + tool_settings = context.scene.tool_settings + settings = tool_settings.gpencil_paint + ma = gp_settings.material + + row = layout.row(align=True) + if not gp_settings.use_material_pin: + ma = context.object.active_material + icon_id = 0 + if ma: + icon_id = ma.id_data.preview.icon_id + txt_ma = ma.name + maxw = 25 + if len(txt_ma) > maxw: + txt_ma = txt_ma[:maxw - 5] + '..' + txt_ma[-3:] + else: + txt_ma = "" + + sub = row.row() + sub.ui_units_x = 8 + sub.popover( + panel="TOPBAR_PT_gpencil_materials", + text=txt_ma, + icon_value=icon_id, + ) + + row.prop(gp_settings, "use_material_pin", text="") + + if brush.gpencil_tool in {'DRAW', 'FILL'}: + row.separator(factor=1.0) + row.prop_enum(settings, "color_mode", 'MATERIAL', text="", icon='MATERIAL') + row.prop_enum(settings, "color_mode", 'VERTEXCOLOR', text="", icon='VPAINT_HLT') + sub_row = row.row(align=True) + sub_row.enabled = settings.color_mode == 'VERTEXCOLOR' + sub_row.prop_with_popover(brush, "color", text="", panel="TOPBAR_PT_gpencil_vertexcolor") + + if props: + row = layout.row(align=True) + row.prop(props, "subdivision") def brush_basic_gpencil_paint_settings(layout, context, brush, *, compact=False): tool_settings = context.tool_settings diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py index d07241203fb..ae144d9e8d0 100644 --- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py +++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py @@ -1671,6 +1671,29 @@ class _defs_image_uv_sculpt: class _defs_gpencil_paint: @staticmethod + def gpencil_primitive_toolbar(context, layout, tool, props): + paint = context.tool_settings.gpencil_paint + brush = paint.brush + + if brush is None: + return False + + gp_settings = brush.gpencil_settings + + row = layout.row(align=True) + tool_settings = context.scene.tool_settings + settings = tool_settings.gpencil_paint + row.template_ID_preview(settings, "brush", rows=3, cols=8, hide_buttons=True) + + from bl_ui.properties_paint_common import ( + brush_basic_gpencil_paint_settings, + brush_basic__draw_color_selector, + ) + + brush_basic__draw_color_selector(context, layout, brush, gp_settings, props) + brush_basic_gpencil_paint_settings(layout, context, brush, compact=True) + + @staticmethod def generate_from_brushes(context): return generate_from_enum_ex( context, @@ -1697,6 +1720,10 @@ class _defs_gpencil_paint: @ToolDef.from_fn def line(): + def draw_settings(context, layout, tool): + props = tool.operator_properties("gpencil.primitive_line") + _defs_gpencil_paint.gpencil_primitive_toolbar(context, layout, tool, props) + return dict( idname="builtin.line", label="Line", @@ -1704,10 +1731,15 @@ class _defs_gpencil_paint: cursor='CROSSHAIR', widget=None, keymap=(), + draw_settings=draw_settings, ) @ToolDef.from_fn def polyline(): + def draw_settings(context, layout, tool): + props = tool.operator_properties("gpencil.primitive_polyline") + _defs_gpencil_paint.gpencil_primitive_toolbar(context, layout, tool, props) + return dict( idname="builtin.polyline", label="Polyline", @@ -1715,10 +1747,15 @@ class _defs_gpencil_paint: cursor='CROSSHAIR', widget=None, keymap=(), + draw_settings=draw_settings, ) @ToolDef.from_fn def box(): + def draw_settings(context, layout, tool): + props = tool.operator_properties("gpencil.primitive_box") + _defs_gpencil_paint.gpencil_primitive_toolbar(context, layout, tool, props) + return dict( idname="builtin.box", label="Box", @@ -1726,10 +1763,15 @@ class _defs_gpencil_paint: cursor='CROSSHAIR', widget=None, keymap=(), + draw_settings=draw_settings, ) @ToolDef.from_fn def circle(): + def draw_settings(context, layout, tool): + props = tool.operator_properties("gpencil.primitive_circle") + _defs_gpencil_paint.gpencil_primitive_toolbar(context, layout, tool, props) + return dict( idname="builtin.circle", label="Circle", @@ -1737,10 +1779,15 @@ class _defs_gpencil_paint: cursor='CROSSHAIR', widget=None, keymap=(), + draw_settings=draw_settings, ) @ToolDef.from_fn def arc(): + def draw_settings(context, layout, tool): + props = tool.operator_properties("gpencil.primitive_curve") + _defs_gpencil_paint.gpencil_primitive_toolbar(context, layout, tool, props) + return dict( idname="builtin.arc", label="Arc", @@ -1748,10 +1795,15 @@ class _defs_gpencil_paint: cursor='CROSSHAIR', widget=None, keymap=(), + draw_settings=draw_settings, ) @ToolDef.from_fn def curve(): + def draw_settings(context, layout, tool): + props = tool.operator_properties("gpencil.primitive_curve") + _defs_gpencil_paint.gpencil_primitive_toolbar(context, layout, tool, props) + return dict( idname="builtin.curve", label="Curve", @@ -1759,6 +1811,7 @@ class _defs_gpencil_paint: cursor='CROSSHAIR', widget=None, keymap=(), + draw_settings=draw_settings, ) @ToolDef.from_fn diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py index a9e1b933338..c251b4bfcac 100644 --- a/release/scripts/startup/bl_ui/space_view3d.py +++ b/release/scripts/startup/bl_ui/space_view3d.py @@ -385,19 +385,7 @@ class _draw_tool_settings_context_mode: if tool is None: return False - # is_paint = True - # FIXME: tools must use their own UI drawing! - if tool.idname in { - "builtin.line", - "builtin.box", - "builtin.circle", - "builtin.arc", - "builtin.curve", - "builtin.polyline", - }: - # is_paint = False - pass - elif tool.idname == "builtin.cutter": + if tool.idname == "builtin.cutter": row = layout.row(align=True) row.prop(context.tool_settings.gpencil_sculpt, "intersection_threshold") return False @@ -411,47 +399,16 @@ class _draw_tool_settings_context_mode: gp_settings = brush.gpencil_settings - def draw_color_selector(): - ma = gp_settings.material - row = layout.row(align=True) - if not gp_settings.use_material_pin: - ma = context.object.active_material - icon_id = 0 - if ma: - icon_id = ma.id_data.preview.icon_id - txt_ma = ma.name - maxw = 25 - if len(txt_ma) > maxw: - txt_ma = txt_ma[:maxw - 5] + '..' + txt_ma[-3:] - else: - txt_ma = "" - - sub = row.row() - sub.ui_units_x = 8 - sub.popover( - panel="TOPBAR_PT_gpencil_materials", - text=txt_ma, - icon_value=icon_id, - ) - - row.prop(gp_settings, "use_material_pin", text="") - - if brush.gpencil_tool in {'DRAW', 'FILL'}: - row.separator(factor=1.0) - subrow = row.row(align=True) - row.prop_enum(settings, "color_mode", 'MATERIAL', text="", icon='MATERIAL') - row.prop_enum(settings, "color_mode", 'VERTEXCOLOR', text="", icon='VPAINT_HLT') - sub_row = row.row(align=True) - sub_row.enabled = settings.color_mode == 'VERTEXCOLOR' - sub_row.prop_with_popover(brush, "color", text="", panel="TOPBAR_PT_gpencil_vertexcolor") - row = layout.row(align=True) tool_settings = context.scene.tool_settings settings = tool_settings.gpencil_paint row.template_ID_preview(settings, "brush", rows=3, cols=8, hide_buttons=True) if context.object and brush.gpencil_tool in {'FILL', 'DRAW'}: - draw_color_selector() + from bl_ui.properties_paint_common import ( + brush_basic__draw_color_selector, + ) + brush_basic__draw_color_selector(context, layout, brush, gp_settings, None) if context.object and brush.gpencil_tool == 'TINT': row.separator(factor=0.4) diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h index fa75c2a7cee..e6fdbf1ad17 100644 --- a/source/blender/editors/gpencil/gpencil_intern.h +++ b/source/blender/editors/gpencil/gpencil_intern.h @@ -202,6 +202,8 @@ typedef struct tGPDprimitive { tGPspoint *points; /** number of edges allocated */ int point_count; + /** number of subdivisions. */ + int subdiv; /** stored number of polygon edges */ int tot_stored_edges; /** number of polygon edges */ @@ -553,7 +555,11 @@ void GPENCIL_OT_interpolate_reverse(struct wmOperatorType *ot); /* primitives ---------- */ -void GPENCIL_OT_primitive(struct wmOperatorType *ot); +void GPENCIL_OT_primitive_box(struct wmOperatorType *ot); +void GPENCIL_OT_primitive_line(struct wmOperatorType *ot); +void GPENCIL_OT_primitive_polyline(struct wmOperatorType *ot); +void GPENCIL_OT_primitive_circle(struct wmOperatorType *ot); +void GPENCIL_OT_primitive_curve(struct wmOperatorType *ot); /* vertex groups ------------ */ void GPENCIL_OT_vertex_group_assign(struct wmOperatorType *ot); diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c index 3892f451e18..211ff895e67 100644 --- a/source/blender/editors/gpencil/gpencil_ops.c +++ b/source/blender/editors/gpencil/gpencil_ops.c @@ -665,7 +665,11 @@ void ED_operatortypes_gpencil(void) WM_operatortype_append(GPENCIL_OT_interpolate_reverse); /* Primitives */ - WM_operatortype_append(GPENCIL_OT_primitive); + WM_operatortype_append(GPENCIL_OT_primitive_box); + WM_operatortype_append(GPENCIL_OT_primitive_line); + WM_operatortype_append(GPENCIL_OT_primitive_polyline); + WM_operatortype_append(GPENCIL_OT_primitive_circle); + WM_operatortype_append(GPENCIL_OT_primitive_curve); /* convert old 2.7 files to 2.8 */ WM_operatortype_append(GPENCIL_OT_convert_old_files); diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c index 28ea9535a80..75f08c37cba 100644 --- a/source/blender/editors/gpencil/gpencil_primitive.c +++ b/source/blender/editors/gpencil/gpencil_primitive.c @@ -109,7 +109,15 @@ /* ************************************************ */ /* Core/Shared Utilities */ - +const static EnumPropertyItem gpencil_primitive_type[] = { + {GP_STROKE_BOX, "BOX", 0, "Box", ""}, + {GP_STROKE_LINE, "LINE", 0, "Line", ""}, + {GP_STROKE_POLYLINE, "POLYLINE", 0, "Polyline", ""}, + {GP_STROKE_CIRCLE, "CIRCLE", 0, "Circle", ""}, + {GP_STROKE_ARC, "ARC", 0, "Arc", ""}, + {GP_STROKE_CURVE, "CURVE", 0, "Curve", ""}, + {0, NULL, 0, NULL, NULL}, +}; /* clear the session buffers (call this before AND after a paint operation) */ static void gpencil_session_validatebuffer(tGPDprimitive *p) { @@ -427,19 +435,20 @@ static void gpencil_primitive_status_indicators(bContext *C, tGPDprimitive *tgpi } else if (tgpi->type == GP_STROKE_CIRCLE) { BLI_strncpy(msg_str, - TIP_("Circle: ESC to cancel, Enter/MMB to confirm, WHEEL/+- to adjust edge " + TIP_("Circle: ESC to cancel, Enter/MMB to confirm, WHEEL/+- to adjust subdivision " "number, Shift to square, Alt to center"), UI_MAX_DRAW_STR); } else if (tgpi->type == GP_STROKE_ARC) { - BLI_strncpy(msg_str, - TIP_("Arc: ESC to cancel, Enter/MMB to confirm, WHEEL/+- to adjust edge number, " - "Shift to square, Alt to center, M: Flip, E: extrude"), - UI_MAX_DRAW_STR); + BLI_strncpy( + msg_str, + TIP_("Arc: ESC to cancel, Enter/MMB to confirm, WHEEL/+- to adjust subdivision number, " + "Shift to square, Alt to center, M: Flip, E: extrude"), + UI_MAX_DRAW_STR); } else if (tgpi->type == GP_STROKE_CURVE) { BLI_strncpy(msg_str, - TIP_("Curve: ESC to cancel, Enter/MMB to confirm, WHEEL/+- to adjust edge " + TIP_("Curve: ESC to cancel, Enter/MMB to confirm, WHEEL/+- to adjust subdivision " "number, Shift to square, Alt to center, E: extrude"), UI_MAX_DRAW_STR); } @@ -519,16 +528,23 @@ static void gpencil_primitive_rectangle(tGPDprimitive *tgpi, tGPspoint *points2D coords[4][0] = tgpi->start[0]; coords[4][1] = tgpi->start[1]; - const float step = 1.0f / (float)(tgpi->tot_edges); - int i = tgpi->tot_stored_edges; - - for (int j = 0; j < 4; j++) { - float a = 0.0f; - for (int k = 0; k < tgpi->tot_edges; k++) { - tGPspoint *p2d = &points2D[i]; - interp_v2_v2v2(&p2d->x, coords[j], coords[j + 1], a); - a += step; - i++; + if (tgpi->tot_edges == 1) { + for (int j = 0; j < 4; j++) { + tGPspoint *p2d = &points2D[j]; + copy_v2_v2(&p2d->x, coords[j]); + } + } + else { + const float step = 1.0f / (float)(tgpi->tot_edges); + int i = tgpi->tot_stored_edges; + for (int j = 0; j < 4; j++) { + float a = 0.0f; + for (int k = 0; k < tgpi->tot_edges; k++) { + tGPspoint *p2d = &points2D[i]; + interp_v2_v2v2(&p2d->x, coords[j], coords[j + 1], a); + a += step; + i++; + } } } @@ -701,6 +717,7 @@ static void gpencil_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) (tgpi->rv3d->persp == RV3D_CAMOB) && (!is_depth); if (tgpi->type == GP_STROKE_BOX) { + tgpi->tot_edges--; gps->totpoints = (tgpi->tot_edges * 4 + tgpi->tot_stored_edges); } else { @@ -716,7 +733,7 @@ static void gpencil_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) /* compute screen-space coordinates for points */ tGPspoint *points2D = tgpi->points; - if (tgpi->tot_edges > 1) { + if (tgpi->tot_edges > 0) { switch (tgpi->type) { case GP_STROKE_BOX: gpencil_primitive_rectangle(tgpi, points2D); @@ -1211,31 +1228,10 @@ static void gpencil_primitive_init(bContext *C, wmOperator *op) tgpi->curve = false; } - /* set default edge count */ - switch (tgpi->type) { - case GP_STROKE_POLYLINE: { - RNA_int_set(op->ptr, "edges", 8); - break; - } - case GP_STROKE_LINE: { - RNA_int_set(op->ptr, "edges", 8); - break; - } - case GP_STROKE_BOX: { - RNA_int_set(op->ptr, "edges", 8); - break; - } - case GP_STROKE_CIRCLE: { - RNA_int_set(op->ptr, "edges", 96); - break; - } - default: { - RNA_int_set(op->ptr, "edges", 64); - break; - } - } - tgpi->tot_stored_edges = 0; + + tgpi->subdiv = RNA_int_get(op->ptr, "subdivision"); + RNA_int_set(op->ptr, "edges", tgpi->subdiv + 2); tgpi->tot_edges = RNA_int_get(op->ptr, "edges"); tgpi->flag = IDLE; tgpi->lock_axis = ts->gp_sculpt.lock_axis; @@ -1351,11 +1347,6 @@ static void gpencil_primitive_interaction_end(bContext *C, } } - /* Close stroke with geometry */ - if ((tgpi->type == GP_STROKE_BOX) || (tgpi->type == GP_STROKE_CIRCLE)) { - BKE_gpencil_stroke_close(gps); - } - DEG_id_tag_update(&tgpi->gpd->id, ID_RECALC_COPY_ON_WRITE); DEG_id_tag_update(&tgpi->gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY); @@ -1629,9 +1620,12 @@ static int gpencil_primitive_modal(bContext *C, wmOperator *op, const wmEvent *e case RIGHTMOUSE: { if (event->val == KM_PRESS) { tgpi->flag = IDLE; + int last_edges = tgpi->tot_edges; tgpi->tot_edges = tgpi->tot_stored_edges ? 1 : 0; + RNA_int_set(op->ptr, "edges", tgpi->tot_edges); gpencil_primitive_update_strokes(C, tgpi); gpencil_primitive_interaction_end(C, op, win, tgpi); + RNA_int_set(op->ptr, "edges", last_edges); return OPERATOR_FINISHED; } break; @@ -1958,22 +1952,45 @@ static void gpencil_primitive_cancel(bContext *C, wmOperator *op) gpencil_primitive_exit(C, op); } -void GPENCIL_OT_primitive(wmOperatorType *ot) +static void gpencil_primitive_common_props(wmOperatorType *ot, int subdiv, int type) { - static EnumPropertyItem primitive_type[] = { - {GP_STROKE_BOX, "BOX", 0, "Box", ""}, - {GP_STROKE_LINE, "LINE", 0, "Line", ""}, - {GP_STROKE_POLYLINE, "POLYLINE", 0, "Polyline", ""}, - {GP_STROKE_CIRCLE, "CIRCLE", 0, "Circle", ""}, - {GP_STROKE_ARC, "ARC", 0, "Arc", ""}, - {GP_STROKE_CURVE, "CURVE", 0, "Curve", ""}, - {0, NULL, 0, NULL, NULL}, - }; + PropertyRNA *prop; + prop = RNA_def_int(ot->srna, + "subdivision", + subdiv, + 0, + MAX_EDGES, + "Subdivisions", + "Number of subdivision by edges", + 0, + MAX_EDGES); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); + + /* Internal prop. */ + prop = RNA_def_int(ot->srna, + "edges", + MIN_EDGES, + MIN_EDGES, + MAX_EDGES, + "Edges", + "Number of points by edge", + MIN_EDGES, + MAX_EDGES); + RNA_def_property_flag(prop, PROP_SKIP_SAVE | PROP_HIDDEN); + + RNA_def_enum(ot->srna, "type", gpencil_primitive_type, type, "Type", "Type of shape"); + + prop = RNA_def_boolean(ot->srna, "wait_for_input", true, "Wait for Input", ""); + RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); +} + +void GPENCIL_OT_primitive_box(wmOperatorType *ot) +{ /* identifiers */ - ot->name = "Grease Pencil Shapes"; - ot->idname = "GPENCIL_OT_primitive"; - ot->description = "Create predefined grease pencil stroke shapes"; + ot->name = "Grease Pencil Box Shape"; + ot->idname = "GPENCIL_OT_primitive_box"; + ot->description = "Create predefined grease pencil stroke box shapes"; /* callbacks */ ot->invoke = gpencil_primitive_invoke; @@ -1982,24 +1999,88 @@ void GPENCIL_OT_primitive(wmOperatorType *ot) ot->poll = gpencil_primitive_add_poll; /* flags */ - ot->flag = OPTYPE_UNDO | OPTYPE_BLOCKING; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING; /* properties */ - PropertyRNA *prop; + gpencil_primitive_common_props(ot, 3, GP_STROKE_BOX); +} - prop = RNA_def_int(ot->srna, - "edges", - 4, - MIN_EDGES, - MAX_EDGES, - "Edges", - "Number of polygon edges", - MIN_EDGES, - MAX_EDGES); - RNA_def_property_flag(prop, PROP_SKIP_SAVE); +void GPENCIL_OT_primitive_line(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Grease Pencil Line Shape"; + ot->idname = "GPENCIL_OT_primitive_line"; + ot->description = "Create predefined grease pencil stroke lines"; + + /* callbacks */ + ot->invoke = gpencil_primitive_invoke; + ot->modal = gpencil_primitive_modal; + ot->cancel = gpencil_primitive_cancel; + ot->poll = gpencil_primitive_add_poll; - RNA_def_enum(ot->srna, "type", primitive_type, GP_STROKE_BOX, "Type", "Type of shape"); + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING; - prop = RNA_def_boolean(ot->srna, "wait_for_input", true, "Wait for Input", ""); - RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); + /* properties */ + gpencil_primitive_common_props(ot, 6, GP_STROKE_LINE); +} + +void GPENCIL_OT_primitive_polyline(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Grease Pencil Polyline Shape"; + ot->idname = "GPENCIL_OT_primitive_polyline"; + ot->description = "Create predefined grease pencil stroke polylines"; + + /* callbacks */ + ot->invoke = gpencil_primitive_invoke; + ot->modal = gpencil_primitive_modal; + ot->cancel = gpencil_primitive_cancel; + ot->poll = gpencil_primitive_add_poll; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING; + + /* properties */ + gpencil_primitive_common_props(ot, 6, GP_STROKE_POLYLINE); +} + +void GPENCIL_OT_primitive_circle(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Grease Pencil Circle Shape"; + ot->idname = "GPENCIL_OT_primitive_circle"; + ot->description = "Create predefined grease pencil stroke circle shapes"; + + /* callbacks */ + ot->invoke = gpencil_primitive_invoke; + ot->modal = gpencil_primitive_modal; + ot->cancel = gpencil_primitive_cancel; + ot->poll = gpencil_primitive_add_poll; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING; + + /* properties */ + gpencil_primitive_common_props(ot, 94, GP_STROKE_CIRCLE); +} + +void GPENCIL_OT_primitive_curve(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Grease Pencil Curve Shape"; + ot->idname = "GPENCIL_OT_primitive_curve"; + ot->description = "Create predefined grease pencil stroke curve shapes"; + + /* callbacks */ + ot->invoke = gpencil_primitive_invoke; + ot->modal = gpencil_primitive_modal; + ot->cancel = gpencil_primitive_cancel; + ot->poll = gpencil_primitive_add_poll; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING; + + /* properties */ + gpencil_primitive_common_props(ot, 62, GP_STROKE_CURVE); } |