diff options
author | Antonio Vazquez <blendergit@gmail.com> | 2020-03-09 18:27:24 +0300 |
---|---|---|
committer | Antonio Vazquez <blendergit@gmail.com> | 2020-03-09 18:27:24 +0300 |
commit | 29f3af95272590d26f610ae828b2eeee89c82a00 (patch) | |
tree | a696a58a2561c48f7ec6166e369e22081e0a64d8 /release/scripts/startup/bl_ui/properties_grease_pencil_common.py | |
parent | dcb93126876879d969a30a7865700abd072066f8 (diff) |
GPencil: Refactor of Draw Engine, Vertex Paint and all internal functions
This commit is a full refactor of the grease pencil modules including Draw Engine, Modifiers, VFX, depsgraph update, improvements in operators and conversion of Sculpt and Weight paint tools to real brushes.
Also, a huge code cleanup has been done at all levels.
Thanks to @fclem for his work and yo @pepeland and @mendio for the testing and help in the development.
Differential Revision: https://developer.blender.org/D6293
Diffstat (limited to 'release/scripts/startup/bl_ui/properties_grease_pencil_common.py')
-rw-r--r-- | release/scripts/startup/bl_ui/properties_grease_pencil_common.py | 564 |
1 files changed, 271 insertions, 293 deletions
diff --git a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py index 2001f46820f..fced848641e 100644 --- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py +++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py @@ -19,7 +19,7 @@ # <pep8 compliant> import bpy -from bpy.types import Menu, UIList +from bpy.types import Menu, UIList, Operator from bpy.app.translations import pgettext_iface as iface_ @@ -108,11 +108,6 @@ class AnnotationDrawingToolsPanel: sub.operator("gpencil.blank_frame_add", icon='FILE_NEW') sub.operator("gpencil.active_frames_delete_all", icon='X', text="Delete Frame(s)") - #sub = col.column(align=True) - #sub.prop(context.tool_settings, "use_gpencil_draw_additive", text="Additive Drawing") - #sub.prop(context.tool_settings, "use_gpencil_continuous_drawing", text="Continuous Drawing") - #sub.prop(context.tool_settings, "use_gpencil_draw_onback", text="Draw on Back") - col.separator() col.separator() @@ -125,9 +120,6 @@ class AnnotationDrawingToolsPanel: elif is_clip_editor: row.prop(context.space_data, "grease_pencil_source", expand=True) - # col.separator() - # col.separator() - gpencil_stroke_placement_settings(context, col) @@ -136,29 +128,33 @@ class GreasePencilSculptOptionsPanel: @classmethod def poll(cls, context): - settings = context.tool_settings.gpencil_sculpt - tool = settings.sculpt_tool + tool_settings = context.scene.tool_settings + settings = tool_settings.gpencil_sculpt_paint + brush = settings.brush + tool = brush.gpencil_sculpt_tool - return bool(tool in {'SMOOTH', 'RANDOMIZE', 'SMOOTH'}) + return bool(tool in {'SMOOTH', 'RANDOMIZE'}) def draw(self, context): layout = self.layout layout.use_property_split = True layout.use_property_decorate = False - settings = context.tool_settings.gpencil_sculpt - tool = settings.sculpt_tool + tool_settings = context.scene.tool_settings + settings = tool_settings.gpencil_sculpt_paint brush = settings.brush + gp_settings = brush.gpencil_settings + tool = brush.gpencil_sculpt_tool if tool in {'SMOOTH', 'RANDOMIZE'}: - layout.prop(settings, "use_edit_position", text="Affect Position") - layout.prop(settings, "use_edit_strength", text="Affect Strength") - layout.prop(settings, "use_edit_thickness", text="Affect Thickness") + layout.prop(gp_settings, "use_edit_position", text="Affect Position") + layout.prop(gp_settings, "use_edit_strength", text="Affect Strength") + layout.prop(gp_settings, "use_edit_thickness", text="Affect Thickness") if tool == 'SMOOTH': - layout.prop(brush, "use_edit_pressure") + layout.prop(gp_settings, "use_edit_pressure") - layout.prop(settings, "use_edit_uv", text="Affect UV") + layout.prop(gp_settings, "use_edit_uv", text="Affect UV") # GP Object Tool Settings @@ -174,7 +170,7 @@ class GreasePencilDisplayPanel: if context.mode == 'PAINT_GPENCIL': return brush.gpencil_tool != 'ERASE' else: - # GP Sculpt and Weight Paint always have Brush Tip panel. + # GP Sculpt, Vertex and Weight Paint always have Brush Tip panel. return True return False @@ -182,16 +178,18 @@ class GreasePencilDisplayPanel: if self.is_popover: return + tool_settings = context.tool_settings if context.mode == 'PAINT_GPENCIL': - brush = context.tool_settings.gpencil_paint.brush - gp_settings = brush.gpencil_settings - - self.layout.prop(gp_settings, "use_cursor", text="") - elif context.mode in {'SCULPT_GPENCIL', 'WEIGHT_GPENCIL'}: - settings = context.tool_settings.gpencil_sculpt - brush = settings.brush - - self.layout.prop(brush, "use_cursor", text="") + settings = tool_settings.gpencil_paint + elif context.mode == 'SCULPT_GPENCIL': + settings = tool_settings.gpencil_sculpt_paint + elif context.mode == 'WEIGHT_GPENCIL': + settings = tool_settings.gpencil_weight_paint + elif context.mode == 'VERTEX_GPENCIL': + settings = tool_settings.gpencil_vertex_paint + brush = settings.brush + if brush: + self.layout.prop(settings, "show_brush", text="") def draw(self, context): layout = self.layout @@ -199,279 +197,101 @@ class GreasePencilDisplayPanel: layout.use_property_decorate = False tool_settings = context.tool_settings - ob = context.active_object + if context.mode == 'PAINT_GPENCIL': + settings = tool_settings.gpencil_paint + elif context.mode == 'SCULPT_GPENCIL': + settings = tool_settings.gpencil_sculpt_paint + elif context.mode == 'WEIGHT_GPENCIL': + settings = tool_settings.gpencil_weight_paint + elif context.mode == 'VERTEX_GPENCIL': + settings = tool_settings.gpencil_vertex_paint + brush = settings.brush + gp_settings = brush.gpencil_settings + ob = context.active_object if ob.mode == 'PAINT_GPENCIL': - brush = tool_settings.gpencil_paint.brush - gp_settings = brush.gpencil_settings if self.is_popover: row = layout.row(align=True) - row.prop(gp_settings, "use_cursor", text="") + row.prop(settings, "show_brush", text="") row.label(text="Display Cursor") col = layout.column(align=True) - col.active = gp_settings.use_cursor + col.active = settings.show_brush if brush.gpencil_tool == 'DRAW': col.prop(gp_settings, "show_lasso", text="Show Fill Color While Drawing") - if brush.gpencil_tool == 'FILL': - col.prop(brush, "cursor_color_add", text="Cursor Color") - - elif ob.mode in {'SCULPT_GPENCIL', 'WEIGHT_GPENCIL'}: - settings = tool_settings.gpencil_sculpt - brush = settings.brush - tool = settings.sculpt_tool - - if self.is_popover: - row = layout.row(align=True) - row.prop(brush, "use_cursor", text="") - row.label(text="Display Cursor") - + elif ob.mode == 'SCULPT_GPENCIL': col = layout.column(align=True) - col.active = brush.use_cursor + col.active = settings.show_brush col.prop(brush, "cursor_color_add", text="Cursor Color") - if tool in {'THICKNESS', 'STRENGTH', 'PINCH', 'TWIST'}: - col.prop(brush, "cursor_color_sub", text="Inverse Cursor Color") - - -class GPENCIL_MT_pie_tool_palette(Menu): - """A pie menu for quick access to Grease Pencil tools""" - bl_label = "Grease Pencil Tools" - - def draw(self, context): - layout = self.layout - - pie = layout.menu_pie() - gpd = context.gpencil_data - - # W - Drawing Types - col = pie.column() - col.operator("gpencil.draw", text="Draw", icon='GREASEPENCIL').mode = 'DRAW' - col.operator("gpencil.draw", text="Straight Lines", icon='LINE_DATA').mode = 'DRAW_STRAIGHT' - col.operator("gpencil.draw", text="Poly", icon='MESH_DATA').mode = 'DRAW_POLY' - - # E - Eraser - # XXX: needs a dedicated icon... - col = pie.column() - col.operator("gpencil.draw", text="Eraser", icon='FORCE_CURVE').mode = 'ERASER' - - # E - "Settings" Palette is included here too, since it needs to be in a stable position... - if gpd and gpd.layers.active: - col.separator() - col.operator( - "wm.call_menu_pie", - text="Settings...", - icon='SCRIPTWIN').name = "GPENCIL_MT_pie_settings_palette" - - # Editing tools - if gpd: - if gpd.use_stroke_edit_mode and context.editable_gpencil_strokes: - # S - Exit Edit Mode - pie.operator("gpencil.editmode_toggle", text="Exit Edit Mode", icon='EDIT') - - # N - Transforms - col = pie.column() - row = col.row(align=True) - row.operator("transform.translate", icon='MAN_TRANS') - row.operator("transform.rotate", icon='MAN_ROT') - row.operator("transform.resize", text="Scale", icon='MAN_SCALE') - row = col.row(align=True) - row.label(text="Proportional Edit:") - row.prop(context.tool_settings, "use_proportional_edit", text="", icon_only=True) - row.prop(context.tool_settings, "proportional_edit_falloff", text="", icon_only=True) - - # NW - Select (Non-Modal) - col = pie.column() - col.operator("gpencil.select_all", text="Select All", icon='PARTICLE_POINT') - col.operator("gpencil.select_all", text="Select Inverse", icon='BLANK1') - col.operator("gpencil.select_linked", text="Select Linked", icon='LINKED') - col.operator("gpencil.palettecolor_select", text="Select Color", icon='COLOR') - - # NE - Select (Modal) - col = pie.column() - col.operator("gpencil.select_box", text="Box Select", icon='BORDER_RECT') - col.operator("gpencil.select_circle", text="Circle Select", icon='META_EMPTY') - col.operator("gpencil.select_lasso", text="Lasso Select", icon='BORDER_LASSO') - col.operator("gpencil.select_alternate", text="Alternate Select", icon='BORDER_LASSO') - - # SW - Edit Tools - col = pie.column() - col.operator("gpencil.duplicate_move", icon='PARTICLE_PATH', text="Duplicate") - col.operator("gpencil.delete", icon='X', text="Delete...") - - # SE - More Tools - pie.operator("wm.call_menu_pie", text="More...").name = "GPENCIL_MT_pie_tools_more" - else: - # Toggle Edit Mode - pie.operator("gpencil.editmode_toggle", text="Enable Stroke Editing", icon='EDIT') + if brush.gpencil_sculpt_tool in {'THICKNESS', 'STRENGTH', 'PINCH', 'TWIST'}: + col.prop(brush, "cursor_color_subtract", text="Inverse Cursor Color") + elif ob.mode == 'WEIGHT_GPENCIL': + col = layout.column(align=True) + col.active = settings.show_brush -class GPENCIL_MT_pie_settings_palette(Menu): - """A pie menu for quick access to Grease Pencil settings""" - bl_label = "Grease Pencil Settings" + col.prop(brush, "cursor_color_add", text="Cursor Color") - @classmethod - def poll(cls, context): - return bool(context.gpencil_data and context.active_gpencil_layer) + elif ob.mode == 'VERTEX_GPENCIL': + row = layout.row(align=True) + row.prop(settings, "show_brush", text="") + row.label(text="Display Cursor") - def draw(self, context): - layout = self.layout - pie = layout.menu_pie() - gpd = context.gpencil_data - gpl = context.active_gpencil_layer - palcolor = None # context.active_gpencil_palettecolor - - is_editmode = bool(gpd and gpd.use_stroke_edit_mode and context.editable_gpencil_strokes) - - # W - Stroke draw settings - col = pie.column(align=True) - if palcolor is not None: - col.enabled = not palcolor.lock - col.label(text="Stroke") - col.prop(palcolor, "color", text="") - col.prop(palcolor, "alpha", text="", slider=True) - - # E - Fill draw settings - col = pie.column(align=True) - if palcolor is not None: - col.enabled = not palcolor.lock - col.label(text="Fill") - col.prop(palcolor, "fill_color", text="") - col.prop(palcolor, "fill_alpha", text="", slider=True) - - # S Brush settings - gpencil_active_brush_settings_simple(context, pie) - - # N - Active Layer - col = pie.column() - col.label(text="Active Layer: ") - - row = col.row() - row.operator_context = 'EXEC_REGION_WIN' - row.operator_menu_enum("gpencil.layer_change", "layer", text="", icon='GREASEPENCIL') - row.prop(gpl, "info", text="") - row.operator("gpencil.layer_remove", text="", icon='X') - - row = col.row() - row.prop(gpl, "lock") - row.prop(gpl, "hide") - col.prop(gpl, "use_onion_skinning") - - # NW/NE/SW/SE - These operators are only available in editmode - # as they require strokes to be selected to work - if is_editmode: - # NW - Move stroke Down - col = pie.column(align=True) - col.label(text="Arrange Strokes") - col.operator("gpencil.stroke_arrange", text="Send to Back").direction = 'BOTTOM' - col.operator("gpencil.stroke_arrange", text="Send Backward").direction = 'DOWN' - - # NE - Move stroke Up - col = pie.column(align=True) - col.label(text="Arrange Strokes") - col.operator("gpencil.stroke_arrange", text="Bring to Front").direction = 'TOP' - col.operator("gpencil.stroke_arrange", text="Bring Forward").direction = 'UP' - - # SW - Move stroke to color - col = pie.column(align=True) - col.operator("gpencil.stroke_change_color", text="Move to Color") - - # SE - Join strokes - col = pie.column(align=True) - col.label(text="Join Strokes") - row = col.row() - row.operator("gpencil.stroke_join", text="Join").type = 'JOIN' - row.operator("gpencil.stroke_join", text="Join & Copy").type = 'JOINCOPY' - col.operator("gpencil.stroke_flip", text="Flip Direction") - - col.prop(gpd, "show_stroke_direction", text="Show Drawing Direction") - - -class GPENCIL_MT_pie_tools_more(Menu): - """A pie menu for accessing more Grease Pencil tools""" - bl_label = "More Grease Pencil Tools" +class GreasePencilBrushFalloff: + bl_label = "Falloff" + bl_options = {'DEFAULT_CLOSED'} @classmethod def poll(cls, context): - gpd = context.gpencil_data - return bool(gpd and gpd.use_stroke_edit_mode and context.editable_gpencil_strokes) - - def draw(self, _context): - layout = self.layout - - pie = layout.menu_pie() - # gpd = context.gpencil_data - - col = pie.column(align=True) - col.operator("gpencil.copy", text="Copy", icon='COPYDOWN') - col.operator("gpencil.paste", text="Paste", icon='PASTEDOWN').type = 'ACTIVE' - col.operator("gpencil.paste", text="Paste by Layer").type = 'LAYER' - - col = pie.column(align=True) - col.operator("gpencil.select_more", icon='ADD') - col.operator("gpencil.select_less", icon='REMOVE') - - pie.operator("transform.mirror", icon='MOD_MIRROR') - pie.operator("transform.bend", icon='MOD_SIMPLEDEFORM') - pie.operator("transform.shear", icon='MOD_TRIANGULATE') - pie.operator("transform.tosphere", icon='MOD_MULTIRES') - - pie.operator("gpencil.convert", icon='OUTLINER_OB_CURVE', text="Convert...") - pie.operator("wm.call_menu_pie", text="Back to Main Palette...").name = "GPENCIL_MT_pie_tool_palette" - - -class GPENCIL_MT_pie_sculpt(Menu): - """A pie menu for accessing Grease Pencil stroke sculpt settings""" - bl_label = "Grease Pencil Sculpt" + ts = context.tool_settings + settings = None + if context.mode == 'PAINT_GPENCIL': + settings = ts.gpencil_paint + if context.mode == 'SCULPT_GPENCIL': + settings = ts.gpencil_sculpt_paint + elif context.mode == 'WEIGHT_GPENCIL': + settings = ts.gpencil_weight_paint + elif context.mode == 'VERTEX_GPENCIL': + settings = ts.gpencil_vertex_paint - @classmethod - def poll(cls, context): - gpd = context.gpencil_data - return bool(gpd and gpd.use_stroke_edit_mode and context.editable_gpencil_strokes) + return (settings and settings.brush and settings.brush.curve) def draw(self, context): layout = self.layout + ts = context.tool_settings + settings = None + if context.mode == 'PAINT_GPENCIL': + settings = ts.gpencil_paint + if context.mode == 'SCULPT_GPENCIL': + settings = ts.gpencil_sculpt_paint + elif context.mode == 'WEIGHT_GPENCIL': + settings = ts.gpencil_weight_paint + elif context.mode == 'VERTEX_GPENCIL': + settings = ts.gpencil_vertex_paint + + if settings: + brush = settings.brush - pie = layout.menu_pie() - - settings = context.tool_settings.gpencil_sculpt - brush = settings.brush - - # W - Launch Sculpt Mode - col = pie.column() - # col.label(text="Tool:") - col.prop(settings, "sculpt_tool", text="") - col.operator("gpencil.sculpt_paint", text="Sculpt", icon='SCULPTMODE_HLT') - - # E - Common Settings - col = pie.column(align=True) - col.prop(brush, "size", slider=True) - row = col.row(align=True) - row.prop(brush, "strength", slider=True) - # row.prop(brush, "use_pressure_strength", text="", icon_only=True) - col.prop(brush, "use_falloff") - if settings.sculpt_tool in {'SMOOTH', 'RANDOMIZE'}: + col = layout.column(align=True) row = col.row(align=True) - row.prop(settings, "use_edit_position", text="Position", icon='MESH_DATA', toggle=True) - row.prop(settings, "use_edit_strength", text="Strength", icon='COLOR', toggle=True) - row.prop(settings, "use_edit_thickness", text="Thickness", icon='LINE_DATA', toggle=True) + row.prop(brush, "curve_preset", text="") - # S - Change Brush Type Shortcuts - row = pie.row() - row.prop_enum(settings, "tool", value='GRAB') - row.prop_enum(settings, "tool", value='PUSH') - row.prop_enum(settings, "tool", value='CLONE') + if brush.curve_preset == 'CUSTOM': + layout.template_curve_mapping(brush, "curve", brush=True) - # N - Change Brush Type Shortcuts - row = pie.row() - row.prop_enum(settings, "tool", value='SMOOTH') - row.prop_enum(settings, "tool", value='THICKNESS') - row.prop_enum(settings, "tool", value='STRENGTH') - row.prop_enum(settings, "tool", value='RANDOMIZE') + col = layout.column(align=True) + row = col.row(align=True) + row.operator("brush.curve_preset", icon='SMOOTHCURVE', text="").shape = 'SMOOTH' + row.operator("brush.curve_preset", icon='SPHERECURVE', text="").shape = 'ROUND' + row.operator("brush.curve_preset", icon='ROOTCURVE', text="").shape = 'ROOT' + row.operator("brush.curve_preset", icon='SHARPCURVE', text="").shape = 'SHARP' + row.operator("brush.curve_preset", icon='LINCURVE', text="").shape = 'LINE' + row.operator("brush.curve_preset", icon='NOCURVE', text="").shape = 'MAX' class GPENCIL_MT_snap(Menu): @@ -515,6 +335,32 @@ class GPENCIL_MT_move_to_layer(Menu): layout.operator("gpencil.layer_add", text="New Layer", icon='ADD') +class GPENCIL_MT_layer_active(Menu): + bl_label = "Change Active Layer" + + def draw(self, context): + layout = self.layout + layout.operator_context = 'INVOKE_REGION_WIN' + + gpd = context.gpencil_data + if gpd: + gpl_active = context.active_gpencil_layer + tot_layers = len(gpd.layers) + i = tot_layers - 1 + while i >= 0: + gpl = gpd.layers[i] + if gpl.info == gpl_active.info: + icon = 'GREASEPENCIL' + else: + icon = 'NONE' + layout.operator("gpencil.layer_active", text=gpl.info, icon=icon).layer = i + i -= 1 + + layout.separator() + + layout.operator("gpencil.layer_add", text="New Layer", icon='ADD') + + class GPENCIL_MT_gpencil_draw_delete(Menu): bl_label = "Delete" @@ -800,11 +646,7 @@ class GreasePencilMaterialsPanel: if ma is not None and ma.grease_pencil is not None: gpcolor = ma.grease_pencil - if ( - gpcolor.stroke_style == 'SOLID' or - gpcolor.use_stroke_pattern or - gpcolor.use_stroke_texture_mix - ): + if gpcolor.stroke_style == 'SOLID': row = layout.row() row.prop(gpcolor, "color", text="Stroke Color") @@ -813,6 +655,48 @@ class GreasePencilMaterialsPanel: row.template_ID(space, "pin_id") +class GreasePencilVertexcolorPanel: + + def draw(self, context): + layout = self.layout + layout.use_property_split = True + layout.use_property_decorate = False + + ts = context.scene.tool_settings + is_vertex = context.mode == 'VERTEX_GPENCIL' + gpencil_paint = ts.gpencil_vertex_paint if is_vertex else ts.gpencil_paint + brush = gpencil_paint.brush + gp_settings = brush.gpencil_settings + tool = brush.gpencil_vertex_tool if is_vertex else brush.gpencil_tool + + ob = context.object + + if ob: + col = layout.column() + col.template_color_picker(brush, "color", value_slider=True) + + sub_row = layout.row(align=True) + sub_row.prop(brush, "color", text="") + sub_row.prop(brush, "secondary_color", text="") + + sub_row.operator("gpencil.tint_flip", icon='FILE_REFRESH', text="") + + row = layout.row(align=True) + row.template_ID(gpencil_paint, "palette", new="palette.new") + if gpencil_paint.palette: + layout.template_palette(gpencil_paint, "palette", color=True) + + if tool in {'DRAW', 'FILL'} and is_vertex is False: + row = layout.row(align=True) + row.prop(gp_settings, "vertex_mode", text="Mode") + row = layout.row(align=True) + row.prop(gp_settings, "vertex_color_factor", slider=True, text="Mix Factor") + + if tool == 'TINT' or is_vertex is True: + row = layout.row(align=True) + row.prop(gp_settings, "vertex_mode", text="Mode") + + class GPENCIL_UL_layer(UIList): def draw_item(self, _context, layout, _data, item, icon, _active_data, _active_propname, _index): # assert(isinstance(item, bpy.types.GPencilLayer) @@ -830,9 +714,10 @@ class GPENCIL_UL_layer(UIList): row.prop(gpl, "info", text="", emboss=False) row = layout.row(align=True) - row.prop(gpl, "mask_layer", text="", - icon='MOD_MASK' if gpl.mask_layer else 'LAYER_ACTIVE', - emboss=False) + + icon_mask = 'MOD_MASK' if gpl.use_mask_layer else 'LAYER_ACTIVE' + + row.prop(gpl, "use_mask_layer", text="", icon=icon_mask, emboss=False) subrow = row.row(align=True) subrow.prop( @@ -868,16 +753,12 @@ class GreasePencilSimplifyPanel: layout.active = rd.simplify_gpencil col = layout.column() - col.prop(rd, "simplify_gpencil_onplay", text="Playback Only") - col.prop(rd, "simplify_gpencil_view_modifier", text="Modifiers") - col.prop(rd, "simplify_gpencil_shader_fx", text="ShaderFX") - col.prop(rd, "simplify_gpencil_blend", text="Layers Blending") - col.prop(rd, "simplify_gpencil_tint", text="Layers Tinting") - + col.prop(rd, "simplify_gpencil_onplay") col.prop(rd, "simplify_gpencil_view_fill") - sub = col.column() - sub.active = rd.simplify_gpencil_view_fill - sub.prop(rd, "simplify_gpencil_remove_lines", text="Lines") + col.prop(rd, "simplify_gpencil_modifier") + col.prop(rd, "simplify_gpencil_shader_fx") + col.prop(rd, "simplify_gpencil_tint") + col.prop(rd, "simplify_gpencil_antialiasing") class GreasePencilLayerAdjustmentsPanel: @@ -913,6 +794,65 @@ class GreasePencilLayerAdjustmentsPanel: col.prop(gpl, "lock_material") +class GPENCIL_UL_masks(UIList): + def draw_item(self, _context, layout, _data, item, icon, _active_data, _active_propname, _index): + mask = item + if self.layout_type in {'DEFAULT', 'COMPACT'}: + row = layout.row(align=True) + row.prop(mask, "name", text="", emboss=False, icon_value=icon) + row.prop(mask, "invert", text="", emboss=False) + row.prop(mask, "hide", text="", emboss=False) + elif self.layout_type == 'GRID': + layout.alignment = 'CENTER' + layout.prop(mask, "name", text="", emboss=False, icon_value=icon) + + +class GPENCIL_MT_layer_mask_menu(Menu): + bl_label = "Layer Specials" + + def draw(self, context): + layout = self.layout + ob = context.object + gpd = ob.data + gpl_active = gpd.layers.active + done = False + for gpl in gpd.layers: + if gpl != gpl_active and gpl.info not in gpl_active.mask_layers: + done = True + layout.operator("gpencil.layer_mask_add", text=gpl.info).name=gpl.info + + if done is False: + layout.label(text="No layers to add") + + +class GreasePencilLayerMasksPanel: + def draw_header(self, context): + ob = context.active_object + gpd = ob.data + gpl = gpd.layers.active + + self.layout.prop(gpl, "use_mask_layer", text="") + + def draw(self, context): + ob = context.active_object + gpd = ob.data + gpl = gpd.layers.active + + layout = self.layout + layout.enabled = gpl.use_mask_layer + + if gpl: + rows = 4 + row = layout.row() + col = row.column() + col.template_list("GPENCIL_UL_masks", "", gpl, "mask_layers", gpl.mask_layers, + "active_mask_index", rows=rows, sort_lock=True) + + col2 = row.column(align=True) + col2.menu("GPENCIL_MT_layer_mask_menu", icon='ADD', text="") + col2.operator("gpencil.layer_mask_remove", icon='REMOVE', text="") + + class GreasePencilLayerRelationsPanel: def draw(self, context): @@ -952,20 +892,58 @@ class GreasePencilLayerDisplayPanel: col.prop(gpl, "use_solo_mode", text="Show Only On Keyframed") -classes = ( - GPENCIL_MT_pie_tool_palette, - GPENCIL_MT_pie_settings_palette, - GPENCIL_MT_pie_tools_more, - GPENCIL_MT_pie_sculpt, +class GreasePencilFlipTintColors(Operator): + bl_label = "Flip Colors" + bl_idname = "gpencil.tint_flip" + bl_description = "Switch Tint colors" + + def execute(self, context): + try: + ts = context.tool_settings + settings = None + if context.mode == 'PAINT_GPENCIL': + settings = ts.gpencil_paint + if context.mode == 'SCULPT_GPENCIL': + settings = ts.gpencil_sculpt_paint + elif context.mode == 'WEIGHT_GPENCIL': + settings = ts.gpencil_weight_paint + elif context.mode == 'VERTEX_GPENCIL': + settings = ts.gpencil_vertex_paint + brush = settings.brush + if brush is not None: + color = brush.color + secondary_color = brush.secondary_color + + orig_prim = color.hsv + orig_sec = secondary_color.hsv + + color.hsv = orig_sec + secondary_color.hsv = orig_prim + + return {'FINISHED'} + + except Exception as e: + utils_core.error_handlers(self, "gpencil.tint_flip", e, + "Flip Colors could not be completed") + + return {'CANCELLED'} + + +classes = ( GPENCIL_MT_snap, GPENCIL_MT_cleanup, GPENCIL_MT_move_to_layer, + GPENCIL_MT_layer_active, GPENCIL_MT_gpencil_draw_delete, + GPENCIL_MT_layer_mask_menu, GPENCIL_UL_annotation_layer, GPENCIL_UL_layer, + GPENCIL_UL_masks, + + GreasePencilFlipTintColors, ) if __name__ == "__main__": # only for live edit. |