GP: Allow different cap shape in each extrem of the stroke

This commit is contained in:
2019-01-05 16:38:04 +01:00
parent ef57bc2d5f
commit 13fedec4ab
8 changed files with 42 additions and 31 deletions

View File

@@ -191,7 +191,7 @@ class GreasePencilStrokeEditPanel:
col.operator("gpencil.duplicate_move", text="Duplicate")
if is_3d_view:
col.operator("gpencil.stroke_cyclical_set", text="Toggle Cyclic").type = 'TOGGLE'
col.operator("gpencil.stroke_caps_set", text="Toggle Caps").type = 'TOGGLE'
col.operator_menu_enum("gpencil.stroke_caps_set", text="Toggle Caps...", property="type")
layout.separator()

View File

@@ -3955,7 +3955,7 @@ class VIEW3D_MT_edit_gpencil(Menu):
layout.menu("VIEW3D_MT_edit_gpencil_delete")
layout.operator("gpencil.stroke_cyclical_set", text="Toggle Cyclic").type = 'TOGGLE'
layout.operator("gpencil.stroke_caps_set", text="Toggle Caps").type = 'TOGGLE'
layout.operator_menu_enum("gpencil.stroke_caps_set", text="Toggle Caps...", property="type")
layout.separator()
@@ -5564,7 +5564,7 @@ class VIEW3D_MT_gpencil_edit_specials(Menu):
layout.operator("gpencil.stroke_join", text="Join").type = 'JOIN'
layout.operator("gpencil.stroke_join", text="Join & Copy").type = 'JOINCOPY'
layout.operator("gpencil.stroke_flip", text="Flip Direction")
layout.operator("gpencil.stroke_caps_set", text="Toggle Caps").type = 'TOGGLE'
layout.operator_menu_enum("gpencil.stroke_caps_set", text="Toggle Caps...", property="type")
layout.separator()
layout.operator("gpencil.frame_duplicate", text="Duplicate Active Frame")

View File

@@ -387,8 +387,9 @@ DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(
DRW_shgroup_uniform_int(grp, "color_type", &stl->shgroups[id].color_type, 1);
DRW_shgroup_uniform_float(grp, "pixfactor", &gpd->pixfactor, 1);
stl->shgroups[id].caps_mode = ((gps) && (gps->flag & GP_STROKE_FLATCAPS)) ? 1 : 0;
DRW_shgroup_uniform_int(grp, "caps_mode", &stl->shgroups[id].caps_mode, 1);
stl->shgroups[id].caps_mode[0] = ((gps) && (gps->flag & GP_STROKE_FLATCAPS_START)) ? 1 : 0;
stl->shgroups[id].caps_mode[1] = ((gps) && (gps->flag & GP_STROKE_FLATCAPS_END)) ? 1 : 0;
DRW_shgroup_uniform_int(grp, "caps_mode", &stl->shgroups[id].caps_mode[0], 2);
}
else {
stl->storage->obj_scale = 1.0f;
@@ -403,8 +404,8 @@ DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(
else {
DRW_shgroup_uniform_float(grp, "pixfactor", &stl->storage->pixfactor, 1);
}
const int zero = 0;
DRW_shgroup_uniform_int(grp, "caps_mode", &zero, 1);
const int zero[2] = { 0, 0 };
DRW_shgroup_uniform_int(grp, "caps_mode", &zero[0], 2);
}
if ((gpd) && (id > -1)) {

View File

@@ -114,7 +114,7 @@ typedef struct GPENCIL_shgroup {
int texture_clamp;
int fill_style;
int keep_size;
int caps_mode;
int caps_mode[2];
float obj_scale;
} GPENCIL_shgroup;

View File

@@ -2,7 +2,7 @@ uniform mat4 ModelViewProjectionMatrix;
uniform vec2 Viewport;
uniform int xraymode;
uniform int color_type;
uniform int caps_mode;
uniform int caps_mode[2];
layout(lines_adjacency) in;
layout(triangle_strip, max_vertices = 13) out;
@@ -162,7 +162,7 @@ void main(void)
}
/* generate the start endcap (alpha < 0 used as endcap flag)*/
if ((caps_mode != GPENCIL_FLATCAP) && is_equal(P0,P2) &&
if ((caps_mode[0] != GPENCIL_FLATCAP) && is_equal(P0,P2) &&
(color_type == GPENCIL_COLOR_SOLID))
{
mTexCoord = vec2(2, 1);
@@ -204,7 +204,7 @@ void main(void)
EmitVertex();
/* generate the end endcap (alpha < 0 used as endcap flag)*/
if ((caps_mode != GPENCIL_FLATCAP) && is_equal(P1,P3) &&
if ((caps_mode[1] != GPENCIL_FLATCAP) && is_equal(P1,P3) &&
(color_type == GPENCIL_COLOR_SOLID) && (finaluvdata[2].x > 0))
{
mTexCoord = vec2(finaluvdata[2].x, 2);

View File

@@ -2518,9 +2518,10 @@ void GPENCIL_OT_stroke_cyclical_set(wmOperatorType *ot)
/* ******************* Flat Stroke Caps ************************** */
enum {
GP_STROKE_CAPS_ROUND = 0,
GP_STROKE_CAPS_FLAT = 1,
GP_STROKE_CAPS_TOGGLE = 2
GP_STROKE_CAPS_TOGGLE_BOTH = 0,
GP_STROKE_CAPS_TOGGLE_START = 1,
GP_STROKE_CAPS_TOGGLE_END = 2,
GP_STROKE_CAPS_TOGGLE_DEFAULT = 3
};
static int gp_stroke_caps_set_exec(bContext *C, wmOperator *op)
@@ -2551,17 +2552,19 @@ static int gp_stroke_caps_set_exec(bContext *C, wmOperator *op)
continue;
switch (type) {
case GP_STROKE_CAPS_ROUND:
/* Disable */
gps->flag &= ~GP_STROKE_FLATCAPS;
case GP_STROKE_CAPS_TOGGLE_BOTH:
gps->flag ^= GP_STROKE_FLATCAPS_START;
gps->flag ^= GP_STROKE_FLATCAPS_END;
break;
case GP_STROKE_CAPS_FLAT:
/* Enable */
gps->flag |= GP_STROKE_FLATCAPS;
case GP_STROKE_CAPS_TOGGLE_START:
gps->flag ^= GP_STROKE_FLATCAPS_START;
break;
case GP_STROKE_CAPS_TOGGLE:
/* Just toggle flag... */
gps->flag ^= GP_STROKE_FLATCAPS;
case GP_STROKE_CAPS_TOGGLE_END:
gps->flag ^= GP_STROKE_FLATCAPS_END;
break;
case GP_STROKE_CAPS_TOGGLE_DEFAULT:
gps->flag &= ~GP_STROKE_FLATCAPS_START;
gps->flag &= ~GP_STROKE_FLATCAPS_END;
break;
default:
BLI_assert(0);
@@ -2583,10 +2586,11 @@ static int gp_stroke_caps_set_exec(bContext *C, wmOperator *op)
*/
void GPENCIL_OT_stroke_caps_set(wmOperatorType *ot)
{
static const EnumPropertyItem cyclic_type[] = {
{GP_STROKE_CAPS_ROUND, "ROUND", 0, "Rounded caps", ""},
{GP_STROKE_CAPS_FLAT, "FLAT", 0, "Flat caps", ""},
{GP_STROKE_CAPS_TOGGLE, "TOGGLE", 0, "Toggle", ""},
static const EnumPropertyItem toggle_type[] = {
{GP_STROKE_CAPS_TOGGLE_BOTH, "TOGGLE", 0, "Both", ""},
{GP_STROKE_CAPS_TOGGLE_START, "START", 0, "Start", ""},
{GP_STROKE_CAPS_TOGGLE_END, "END", 0, "End", ""},
{GP_STROKE_CAPS_TOGGLE_DEFAULT, "TOGGLE", 0, "Default", "Set as default rounded"},
{0, NULL, 0, NULL, NULL}
};
@@ -2603,7 +2607,7 @@ void GPENCIL_OT_stroke_caps_set(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* properties */
ot->prop = RNA_def_enum(ot->srna, "type", cyclic_type, GP_STROKE_CAPS_TOGGLE, "Type", "");
ot->prop = RNA_def_enum(ot->srna, "type", toggle_type, GP_STROKE_CAPS_TOGGLE_BOTH, "Type", "");
}
/* ******************* Stroke join ************************** */

View File

@@ -203,7 +203,8 @@ typedef enum eGPDstroke_Flag {
/* Flag used to indicate that stroke is used for fill close and must use fill color for stroke and no fill area */
GP_STROKE_NOFILL = (1 << 8),
/* Flag used to indicate if the stroke has flat caps (by default rounded) */
GP_STROKE_FLATCAPS = (1 << 9),
GP_STROKE_FLATCAPS_START = (1 << 9),
GP_STROKE_FLATCAPS_END = (1 << 10),
/* only for use with stroke-buffer (while drawing eraser) */
GP_STROKE_ERASER = (1 << 15)
} eGPDstroke_Flag;

View File

@@ -969,8 +969,13 @@ static void rna_def_gpencil_stroke(BlenderRNA *brna)
RNA_def_property_update(prop, 0, "rna_GPencil_update");
/* Enable Flat Caps mode */
prop = RNA_def_property(srna, "is_flat_caps", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_STROKE_FLATCAPS);
prop = RNA_def_property(srna, "is_start_flat_caps", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_STROKE_FLATCAPS_START);
RNA_def_property_ui_text(prop, "Flat", "Stroke caps are flat (rounded by default)");
RNA_def_property_update(prop, 0, "rna_GPencil_update");
prop = RNA_def_property(srna, "is_end_flat_caps", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_STROKE_FLATCAPS_END);
RNA_def_property_ui_text(prop, "Flat", "Stroke caps are flat (rounded by default)");
RNA_def_property_update(prop, 0, "rna_GPencil_update");