Cleanup: pep8
[blender.git] / release / scripts / startup / bl_ui / properties_grease_pencil_common.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20
21 import bpy
22 from bpy.types import Menu, UIList
23 from bpy.app.translations import pgettext_iface as iface_
24
25
26 def gpencil_stroke_placement_settings(context, layout):
27     if context.space_data.type == 'VIEW_3D':
28         propname = "annotation_stroke_placement_view3d"
29     elif context.space_data.type == 'SEQUENCE_EDITOR':
30         propname = "annotation_stroke_placement_sequencer_preview"
31     elif context.space_data.type == 'IMAGE_EDITOR':
32         propname = "annotation_stroke_placement_image_editor"
33     else:
34         propname = "annotation_stroke_placement_view2d"
35
36     tool_settings = context.tool_settings
37
38     col = layout.column(align=True)
39
40     if context.space_data.type != 'VIEW_3D':
41         col.label(text="Stroke Placement:")
42         row = col.row(align=True)
43         row.prop_enum(tool_settings, propname, 'VIEW')
44         row.prop_enum(tool_settings, propname, 'CURSOR', text="Cursor")
45
46
47 def gpencil_active_brush_settings_simple(context, layout):
48     tool_settings = context.tool_settings
49     brush = tool_settings.gpencil_paint.brush
50     if brush is None:
51         layout.label(text="No Active Brush")
52         return
53
54     col = layout.column()
55     col.label(text="Active Brush:      ")
56
57     row = col.row(align=True)
58     row.operator_context = 'EXEC_REGION_WIN'
59     row.operator_menu_enum("gpencil.brush_change", "brush", text="", icon='BRUSH_DATA')
60     row.prop(brush, "name", text="")
61
62     col.prop(brush, "size", slider=True)
63     row = col.row(align=True)
64     row.prop(brush, "use_random_pressure", text="", icon='RNDCURVE')
65     row.prop(brush, "pen_sensitivity_factor", slider=True)
66     row.prop(brush, "use_pressure", text="", icon='STYLUS_PRESSURE')
67     row = col.row(align=True)
68     row.prop(brush, "use_random_strength", text="", icon='RNDCURVE')
69     row.prop(brush, "strength", slider=True)
70     row.prop(brush, "use_strength_pressure", text="", icon='STYLUS_PRESSURE')
71     row = col.row(align=True)
72     row.prop(brush, "jitter", slider=True)
73     row.prop(brush, "use_jitter_pressure", text="", icon='STYLUS_PRESSURE')
74     row = col.row()
75     row.prop(brush, "angle", slider=True)
76     row.prop(brush, "angle_factor", text="Factor", slider=True)
77
78
79 # XXX: To be replaced with active tools
80 class AnnotationDrawingToolsPanel:
81     # subclass must set
82     # bl_space_type = 'IMAGE_EDITOR'
83     bl_label = "Annotation"
84     bl_category = "Annotation"
85     bl_region_type = 'TOOLS'
86
87     def draw(self, context):
88         layout = self.layout
89
90         is_3d_view = context.space_data.type == 'VIEW_3D'
91         is_clip_editor = context.space_data.type == 'CLIP_EDITOR'
92
93         col = layout.column(align=True)
94
95         col.label(text="Draw:")
96         row = col.row(align=True)
97         row.operator("gpencil.annotate", icon='GREASEPENCIL', text="Draw").mode = 'DRAW'
98         # XXX: Needs a dedicated icon
99         row.operator("gpencil.annotate", icon='FORCE_CURVE', text="Erase").mode = 'ERASER'
100
101         row = col.row(align=True)
102         row.operator("gpencil.annotate", icon='LINE_DATA', text="Line").mode = 'DRAW_STRAIGHT'
103         row.operator("gpencil.annotate", icon='MESH_DATA', text="Poly").mode = 'DRAW_POLY'
104
105         col.separator()
106
107         sub = col.column(align=True)
108         sub.operator("gpencil.blank_frame_add", icon='FILE_NEW')
109         sub.operator("gpencil.active_frames_delete_all", icon='X', text="Delete Frame(s)")
110
111         #sub = col.column(align=True)
112         #sub.prop(context.tool_settings, "use_gpencil_draw_additive", text="Additive Drawing")
113         #sub.prop(context.tool_settings, "use_gpencil_continuous_drawing", text="Continuous Drawing")
114         #sub.prop(context.tool_settings, "use_gpencil_draw_onback", text="Draw on Back")
115
116         col.separator()
117         col.separator()
118
119         if context.space_data.type in {'CLIP_EDITOR'}:
120             col.separator()
121             col.label(text="Data Source:")
122             row = col.row(align=True)
123             if is_3d_view:
124                 row.prop(context.tool_settings, "grease_pencil_source", expand=True)
125             elif is_clip_editor:
126                 row.prop(context.space_data, "grease_pencil_source", expand=True)
127
128         # col.separator()
129         # col.separator()
130
131         gpencil_stroke_placement_settings(context, col)
132
133
134 class GreasePencilStrokeEditPanel:
135     # subclass must set
136     # bl_space_type = 'IMAGE_EDITOR'
137     bl_label = "Edit Strokes"
138     bl_category = "Tools"
139     bl_region_type = 'TOOLS'
140
141     @classmethod
142     def poll(cls, context):
143         if context.gpencil_data is None:
144             return False
145
146         gpd = context.gpencil_data
147         return bool(context.editable_gpencil_strokes) and bool(gpd.use_stroke_edit_mode)
148
149     def draw(self, context):
150         layout = self.layout
151
152         is_3d_view = context.space_data.type == 'VIEW_3D'
153
154         if not is_3d_view:
155             layout.label(text="Select:")
156             col = layout.column(align=True)
157             col.operator("gpencil.select_all", text="Select All")
158             col.operator("gpencil.select_box")
159             col.operator("gpencil.select_circle")
160
161             layout.separator()
162
163             col = layout.column(align=True)
164             col.operator("gpencil.select_linked")
165             col.operator("gpencil.select_more")
166             col.operator("gpencil.select_less")
167             col.operator("gpencil.select_alternate")
168
169         layout.label(text="Edit:")
170         row = layout.row(align=True)
171         row.operator("gpencil.copy", text="Copy")
172         row.operator("gpencil.paste", text="Paste").type = 'COPY'
173         row.operator("gpencil.paste", text="Paste & Merge").type = 'MERGE'
174
175         col = layout.column(align=True)
176         col.operator("gpencil.delete")
177         col.operator("gpencil.duplicate_move", text="Duplicate")
178         if is_3d_view:
179             col.operator("gpencil.stroke_cyclical_set", text="Toggle Cyclic").type = 'TOGGLE'
180             col.operator_menu_enum("gpencil.stroke_caps_set", text="Toggle Caps...", property="type")
181
182         layout.separator()
183
184         if not is_3d_view:
185             col = layout.column(align=True)
186             col.operator("transform.translate")                # icon='MAN_TRANS'
187             col.operator("transform.rotate")                   # icon='MAN_ROT'
188             col.operator("transform.resize", text="Scale")     # icon='MAN_SCALE'
189
190             layout.separator()
191
192         layout.separator()
193         col = layout.column(align=True)
194         col.operator_menu_enum("gpencil.stroke_arrange", text="Arrange Strokes...", property="direction")
195         col.operator("gpencil.stroke_change_color", text="Assign Material")
196
197         layout.separator()
198         col = layout.column(align=True)
199         col.operator("gpencil.stroke_subdivide", text="Subdivide")
200         row = col.row(align=True)
201         row.operator("gpencil.stroke_simplify_fixed", text="Simplify")
202         row.operator("gpencil.stroke_simplify", text="Adaptive")
203         row.operator("gpencil.stroke_trim", text="Trim")
204
205         col.separator()
206
207         row = col.row(align=True)
208         row.operator("gpencil.stroke_merge", text="Merge")
209         row.operator("gpencil.stroke_join", text="Join").type = 'JOIN'
210         row.operator("gpencil.stroke_join", text="& Copy").type = 'JOINCOPY'
211
212         col.operator("gpencil.stroke_flip", text="Flip Direction")
213
214         if is_3d_view:
215             layout.separator()
216
217             col = layout.column(align=True)
218             col.operator_menu_enum("gpencil.stroke_separate", text="Separate...", property="mode")
219             col.operator("gpencil.stroke_split", text="Split")
220
221             col = layout.column(align=True)
222             col.label(text="Cleanup:")
223             col.operator_menu_enum("gpencil.reproject", text="Reproject Strokes...", property="type")
224             col.operator_menu_enum("gpencil.frame_clean_fill", text="Clean Boundary Strokes...", property="mode")
225
226
227 class GreasePencilStrokeSculptPanel:
228     # subclass must set
229     # bl_space_type = 'IMAGE_EDITOR'
230     bl_label = "Sculpt Strokes"
231     bl_category = "Tools"
232
233     def draw(self, context):
234         layout = self.layout
235         layout.use_property_split = True
236         layout.use_property_decorate = False
237
238         settings = context.tool_settings.gpencil_sculpt
239         brush = settings.brush
240
241         layout.template_icon_view(settings, "sculpt_tool", show_labels=True)
242
243         if not self.is_popover:
244             from .properties_paint_common import (
245                 brush_basic_gpencil_sculpt_settings,
246             )
247             brush_basic_gpencil_sculpt_settings(layout, context, brush)
248
249
250 class GreasePencilSculptOptionsPanel:
251     bl_label = "Sculpt Strokes"
252
253     @classmethod
254     def poll(cls, context):
255         settings = context.tool_settings.gpencil_sculpt
256         tool = settings.sculpt_tool
257
258         return bool(tool in {'SMOOTH', 'RANDOMIZE', 'SMOOTH'})
259
260     def draw(self, context):
261         layout = self.layout
262         layout.use_property_split = True
263         layout.use_property_decorate = False
264
265         settings = context.tool_settings.gpencil_sculpt
266         tool = settings.sculpt_tool
267         brush = settings.brush
268
269         if tool in {'SMOOTH', 'RANDOMIZE'}:
270             layout.prop(settings, "use_edit_position", text="Affect Position")
271             layout.prop(settings, "use_edit_strength", text="Affect Strength")
272             layout.prop(settings, "use_edit_thickness", text="Affect Thickness")
273
274             if tool == 'SMOOTH':
275                 layout.prop(brush, "use_edit_pressure")
276
277             layout.prop(settings, "use_edit_uv", text="Affect UV")
278
279
280 # GP Object Tool Settings
281 class GreasePencilAppearancePanel:
282     bl_label = "Brush Appearance"
283     bl_options = {'DEFAULT_CLOSED'}
284
285     @classmethod
286     def poll(cls, context):
287         ob = context.active_object
288         return ob and ob.type == 'GPENCIL'
289
290     def draw(self, context):
291         layout = self.layout
292         layout.use_property_split = True
293         layout.use_property_decorate = False
294
295         tool_settings = context.tool_settings
296         ob = context.active_object
297
298         if ob.mode == 'PAINT_GPENCIL':
299             brush = tool_settings.gpencil_paint.brush
300             gp_settings = brush.gpencil_settings
301
302             sub = layout.column(align=True)
303             sub.enabled = not brush.use_custom_icon
304             sub.prop(gp_settings, "gp_icon", text="Icon")
305
306             layout.prop(brush, "use_custom_icon")
307             sub = layout.column()
308             sub.active = brush.use_custom_icon
309             sub.prop(brush, "icon_filepath", text="")
310
311             layout.prop(gp_settings, "use_cursor", text="Show Brush")
312
313             if brush.gpencil_tool == 'DRAW':
314                 layout.prop(gp_settings, "show_lasso", text="Show fill color while drawing")
315
316             if brush.gpencil_tool == 'FILL':
317                 layout.prop(brush, "cursor_color_add", text="Color")
318
319         elif ob.mode in {'SCULPT_GPENCIL', 'WEIGHT_GPENCIL'}:
320             settings = tool_settings.gpencil_sculpt
321             brush = settings.brush
322             tool = settings.sculpt_tool
323
324             col = layout.column(align=True)
325             col.prop(brush, "use_cursor", text="Show Brush")
326
327             if tool in {'THICKNESS', 'STRENGTH'}:
328                 col.prop(brush, "cursor_color_add", text="Add")
329                 col.prop(brush, "cursor_color_sub", text="Subtract")
330             elif tool == 'PINCH':
331                 col.prop(brush, "cursor_color_add", text="Pinch")
332                 col.prop(brush, "cursor_color_sub", text="Inflate")
333             elif tool == 'TWIST':
334                 col.prop(brush, "cursor_color_add", text="CCW")
335                 col.prop(brush, "cursor_color_sub", text="CW")
336             else:
337                 col.prop(brush, "cursor_color_add", text="")
338
339
340 class GPENCIL_MT_pie_tool_palette(Menu):
341     """A pie menu for quick access to Grease Pencil tools"""
342     bl_label = "Grease Pencil Tools"
343
344     def draw(self, context):
345         layout = self.layout
346
347         pie = layout.menu_pie()
348         gpd = context.gpencil_data
349
350         # W - Drawing Types
351         col = pie.column()
352         col.operator("gpencil.draw", text="Draw", icon='GREASEPENCIL').mode = 'DRAW'
353         col.operator("gpencil.draw", text="Straight Lines", icon='LINE_DATA').mode = 'DRAW_STRAIGHT'
354         col.operator("gpencil.draw", text="Poly", icon='MESH_DATA').mode = 'DRAW_POLY'
355
356         # E - Eraser
357         # XXX: needs a dedicated icon...
358         col = pie.column()
359         col.operator("gpencil.draw", text="Eraser", icon='FORCE_CURVE').mode = 'ERASER'
360
361         # E - "Settings" Palette is included here too, since it needs to be in a stable position...
362         if gpd and gpd.layers.active:
363             col.separator()
364             col.operator(
365                 "wm.call_menu_pie",
366                 text="Settings...",
367                 icon='SCRIPTWIN').name = "GPENCIL_MT_pie_settings_palette"
368
369         # Editing tools
370         if gpd:
371             if gpd.use_stroke_edit_mode and context.editable_gpencil_strokes:
372                 # S - Exit Edit Mode
373                 pie.operator("gpencil.editmode_toggle", text="Exit Edit Mode", icon='EDIT')
374
375                 # N - Transforms
376                 col = pie.column()
377                 row = col.row(align=True)
378                 row.operator("transform.translate", icon='MAN_TRANS')
379                 row.operator("transform.rotate", icon='MAN_ROT')
380                 row.operator("transform.resize", text="Scale", icon='MAN_SCALE')
381                 row = col.row(align=True)
382                 row.label(text="Proportional Edit:")
383                 row.prop(context.tool_settings, "use_proportional_edit", text="", icon_only=True)
384                 row.prop(context.tool_settings, "proportional_edit_falloff", text="", icon_only=True)
385
386                 # NW - Select (Non-Modal)
387                 col = pie.column()
388                 col.operator("gpencil.select_all", text="Select All", icon='PARTICLE_POINT')
389                 col.operator("gpencil.select_all", text="Select Inverse", icon='BLANK1')
390                 col.operator("gpencil.select_linked", text="Select Linked", icon='LINKED')
391                 col.operator("gpencil.palettecolor_select", text="Select Color", icon='COLOR')
392
393                 # NE - Select (Modal)
394                 col = pie.column()
395                 col.operator("gpencil.select_box", text="Box Select", icon='BORDER_RECT')
396                 col.operator("gpencil.select_circle", text="Circle Select", icon='META_EMPTY')
397                 col.operator("gpencil.select_lasso", text="Lasso Select", icon='BORDER_LASSO')
398                 col.operator("gpencil.select_alternate", text="Alternate Select", icon='BORDER_LASSO')
399
400                 # SW - Edit Tools
401                 col = pie.column()
402                 col.operator("gpencil.duplicate_move", icon='PARTICLE_PATH', text="Duplicate")
403                 col.operator("gpencil.delete", icon='X', text="Delete...")
404
405                 # SE - More Tools
406                 pie.operator("wm.call_menu_pie", text="More...").name = "GPENCIL_MT_pie_tools_more"
407             else:
408                 # Toggle Edit Mode
409                 pie.operator("gpencil.editmode_toggle", text="Enable Stroke Editing", icon='EDIT')
410
411
412 class GPENCIL_MT_pie_settings_palette(Menu):
413     """A pie menu for quick access to Grease Pencil settings"""
414     bl_label = "Grease Pencil Settings"
415
416     @classmethod
417     def poll(cls, context):
418         return bool(context.gpencil_data and context.active_gpencil_layer)
419
420     def draw(self, context):
421         layout = self.layout
422
423         pie = layout.menu_pie()
424         gpd = context.gpencil_data
425         gpl = context.active_gpencil_layer
426         palcolor = None  # context.active_gpencil_palettecolor
427
428         is_editmode = bool(gpd and gpd.use_stroke_edit_mode and context.editable_gpencil_strokes)
429
430         # W - Stroke draw settings
431         col = pie.column(align=True)
432         if palcolor is not None:
433             col.enabled = not palcolor.lock
434             col.label(text="Stroke")
435             col.prop(palcolor, "color", text="")
436             col.prop(palcolor, "alpha", text="", slider=True)
437
438         # E - Fill draw settings
439         col = pie.column(align=True)
440         if palcolor is not None:
441             col.enabled = not palcolor.lock
442             col.label(text="Fill")
443             col.prop(palcolor, "fill_color", text="")
444             col.prop(palcolor, "fill_alpha", text="", slider=True)
445
446         # S Brush settings
447         gpencil_active_brush_settings_simple(context, pie)
448
449         # N - Active Layer
450         col = pie.column()
451         col.label(text="Active Layer:      ")
452
453         row = col.row()
454         row.operator_context = 'EXEC_REGION_WIN'
455         row.operator_menu_enum("gpencil.layer_change", "layer", text="", icon='GREASEPENCIL')
456         row.prop(gpl, "info", text="")
457         row.operator("gpencil.layer_remove", text="", icon='X')
458
459         row = col.row()
460         row.prop(gpl, "lock")
461         row.prop(gpl, "hide")
462         col.prop(gpl, "use_onion_skinning")
463
464         # NW/NE/SW/SE - These operators are only available in editmode
465         # as they require strokes to be selected to work
466         if is_editmode:
467             # NW - Move stroke Down
468             col = pie.column(align=True)
469             col.label(text="Arrange Strokes")
470             col.operator("gpencil.stroke_arrange", text="Send to Back").direction = 'BOTTOM'
471             col.operator("gpencil.stroke_arrange", text="Send Backward").direction = 'DOWN'
472
473             # NE - Move stroke Up
474             col = pie.column(align=True)
475             col.label(text="Arrange Strokes")
476             col.operator("gpencil.stroke_arrange", text="Bring to Front").direction = 'TOP'
477             col.operator("gpencil.stroke_arrange", text="Bring Forward").direction = 'UP'
478
479             # SW - Move stroke to color
480             col = pie.column(align=True)
481             col.operator("gpencil.stroke_change_color", text="Move to Color")
482
483             # SE - Join strokes
484             col = pie.column(align=True)
485             col.label(text="Join Strokes")
486             row = col.row()
487             row.operator("gpencil.stroke_join", text="Join").type = 'JOIN'
488             row.operator("gpencil.stroke_join", text="Join & Copy").type = 'JOINCOPY'
489             col.operator("gpencil.stroke_flip", text="Flip Direction")
490
491             col.prop(gpd, "show_stroke_direction", text="Show Drawing Direction")
492
493
494 class GPENCIL_MT_pie_tools_more(Menu):
495     """A pie menu for accessing more Grease Pencil tools"""
496     bl_label = "More Grease Pencil Tools"
497
498     @classmethod
499     def poll(cls, context):
500         gpd = context.gpencil_data
501         return bool(gpd and gpd.use_stroke_edit_mode and context.editable_gpencil_strokes)
502
503     def draw(self, _context):
504         layout = self.layout
505
506         pie = layout.menu_pie()
507         # gpd = context.gpencil_data
508
509         col = pie.column(align=True)
510         col.operator("gpencil.copy", icon='COPYDOWN', text="Copy")
511         col.operator("gpencil.paste", icon='PASTEDOWN', text="Paste")
512
513         col = pie.column(align=True)
514         col.operator("gpencil.select_more", icon='ADD')
515         col.operator("gpencil.select_less", icon='REMOVE')
516
517         pie.operator("transform.mirror", icon='MOD_MIRROR')
518         pie.operator("transform.bend", icon='MOD_SIMPLEDEFORM')
519         pie.operator("transform.shear", icon='MOD_TRIANGULATE')
520         pie.operator("transform.tosphere", icon='MOD_MULTIRES')
521
522         pie.operator("gpencil.convert", icon='OUTLINER_OB_CURVE', text="Convert...")
523         pie.operator("wm.call_menu_pie", text="Back to Main Palette...").name = "GPENCIL_MT_pie_tool_palette"
524
525
526 class GPENCIL_MT_pie_sculpt(Menu):
527     """A pie menu for accessing Grease Pencil stroke sculpt settings"""
528     bl_label = "Grease Pencil Sculpt"
529
530     @classmethod
531     def poll(cls, context):
532         gpd = context.gpencil_data
533         return bool(gpd and gpd.use_stroke_edit_mode and context.editable_gpencil_strokes)
534
535     def draw(self, context):
536         layout = self.layout
537
538         pie = layout.menu_pie()
539
540         settings = context.tool_settings.gpencil_sculpt
541         brush = settings.brush
542
543         # W - Launch Sculpt Mode
544         col = pie.column()
545         # col.label(text="Tool:")
546         col.prop(settings, "sculpt_tool", text="")
547         col.operator("gpencil.sculpt_paint", text="Sculpt", icon='SCULPTMODE_HLT')
548
549         # E - Common Settings
550         col = pie.column(align=True)
551         col.prop(brush, "size", slider=True)
552         row = col.row(align=True)
553         row.prop(brush, "strength", slider=True)
554         # row.prop(brush, "use_pressure_strength", text="", icon_only=True)
555         col.prop(brush, "use_falloff")
556         if settings.sculpt_tool in {'SMOOTH', 'RANDOMIZE'}:
557             row = col.row(align=True)
558             row.prop(settings, "use_edit_position", text="Position", icon='MESH_DATA', toggle=True)
559             row.prop(settings, "use_edit_strength", text="Strength", icon='COLOR', toggle=True)
560             row.prop(settings, "use_edit_thickness", text="Thickness", icon='LINE_DATA', toggle=True)
561
562         # S - Change Brush Type Shortcuts
563         row = pie.row()
564         row.prop_enum(settings, "tool", value='GRAB')
565         row.prop_enum(settings, "tool", value='PUSH')
566         row.prop_enum(settings, "tool", value='CLONE')
567
568         # N - Change Brush Type Shortcuts
569         row = pie.row()
570         row.prop_enum(settings, "tool", value='SMOOTH')
571         row.prop_enum(settings, "tool", value='THICKNESS')
572         row.prop_enum(settings, "tool", value='STRENGTH')
573         row.prop_enum(settings, "tool", value='RANDOMIZE')
574
575
576 class GPENCIL_MT_snap(Menu):
577     bl_label = "Snap"
578
579     def draw(self, _context):
580         layout = self.layout
581
582         layout.operator("gpencil.snap_to_grid", text="Selection to Grid")
583         layout.operator("gpencil.snap_to_cursor", text="Selection to Cursor").use_offset = False
584         layout.operator("gpencil.snap_to_cursor", text="Selection to Cursor (Keep Offset)").use_offset = True
585
586         layout.separator()
587
588         layout.operator("gpencil.snap_cursor_to_selected", text="Cursor to Selected")
589         layout.operator("view3d.snap_cursor_to_center", text="Cursor to World Origin")
590         layout.operator("view3d.snap_cursor_to_grid", text="Cursor to Grid")
591
592
593 class GPENCIL_MT_separate(Menu):
594     bl_label = "Separate"
595
596     def draw(self, _context):
597         layout = self.layout
598         layout.operator("gpencil.stroke_separate", text="Selected Points").mode = 'POINT'
599         layout.operator("gpencil.stroke_separate", text="Selected Strokes").mode = 'STROKE'
600         layout.operator("gpencil.stroke_separate", text="Active Layer").mode = 'LAYER'
601
602
603 class GPENCIL_MT_gpencil_draw_delete(Menu):
604     bl_label = "GPencil Draw Delete"
605
606     def draw(self, _context):
607         layout = self.layout
608
609         layout.operator_context = 'INVOKE_REGION_WIN'
610
611         layout.operator("gpencil.active_frames_delete_all", text="Delete Frame")
612
613
614 class GPENCIL_MT_cleanup(Menu):
615     bl_label = "Clean Up"
616
617     def draw(self, _context):
618         layout = self.layout
619         layout.operator("gpencil.frame_clean_loose", text="Loose Points")
620         layout.separator()
621
622         layout.operator("gpencil.frame_clean_fill", text="Boundary Strokes").mode = 'ACTIVE'
623         layout.operator("gpencil.frame_clean_fill", text="Boundary Strokes all Frames").mode = 'ALL'
624         layout.separator()
625
626         layout.operator("gpencil.reproject")
627
628
629 class GPENCIL_UL_annotation_layer(UIList):
630     def draw_item(self, _context, layout, _data, item, icon, _active_data, _active_propname, _index):
631         # assert(isinstance(item, bpy.types.GPencilLayer)
632         gpl = item
633
634         if self.layout_type in {'DEFAULT', 'COMPACT'}:
635             if gpl.lock:
636                 layout.active = False
637
638             split = layout.split(factor=0.2)
639             split.prop(gpl, "color", text="", emboss=True)
640             split.prop(gpl, "info", text="", emboss=False)
641
642             row = layout.row(align=True)
643             row.prop(gpl, "annotation_hide", text="", emboss=False)
644         elif self.layout_type == 'GRID':
645             layout.alignment = 'CENTER'
646             layout.label(text="", icon_value=icon)
647
648
649 class AnnotationDataPanel:
650     bl_label = "Annotations"
651     bl_region_type = 'UI'
652     bl_options = {'DEFAULT_CLOSED'}
653
654     @classmethod
655     def poll(cls, context):
656         # Show this panel as long as someone that might own this exists
657         # AND the owner isn't an object (e.g. GP Object)
658         if context.gpencil_data_owner is None:
659             return False
660         elif type(context.gpencil_data_owner) is bpy.types.Object:
661             return False
662         else:
663             return True
664
665     def draw_header(self, context):
666         if context.space_data.type not in {'VIEW_3D', 'TOPBAR'}:
667             self.layout.prop(context.space_data, "show_annotation", text="")
668
669     def draw(self, context):
670         layout = self.layout
671         layout.use_property_decorate = False
672
673         # Grease Pencil owner.
674         gpd_owner = context.gpencil_data_owner
675         gpd = context.gpencil_data
676
677         # Owner selector.
678         if context.space_data.type == 'CLIP_EDITOR':
679             layout.row().prop(context.space_data, "grease_pencil_source", expand=True)
680
681         layout.template_ID(gpd_owner, "grease_pencil", new="gpencil.data_add", unlink="gpencil.data_unlink")
682
683         # List of layers/notes.
684         if gpd and gpd.layers:
685             self.draw_layers(context, layout, gpd)
686
687     def draw_layers(self, context, layout, gpd):
688         row = layout.row()
689
690         col = row.column()
691         if len(gpd.layers) >= 2:
692             layer_rows = 5
693         else:
694             layer_rows = 3
695         col.template_list("GPENCIL_UL_annotation_layer", "", gpd, "layers", gpd.layers, "active_index",
696                           rows=layer_rows, sort_reverse=True, sort_lock=True)
697
698         col = row.column()
699
700         sub = col.column(align=True)
701         sub.operator("gpencil.layer_add", icon='ADD', text="")
702         sub.operator("gpencil.layer_remove", icon='REMOVE', text="")
703
704         gpl = context.active_gpencil_layer
705         if gpl:
706             if len(gpd.layers) > 1:
707                 col.separator()
708
709                 sub = col.column(align=True)
710                 sub.operator("gpencil.layer_move", icon='TRIA_UP', text="").type = 'UP'
711                 sub.operator("gpencil.layer_move", icon='TRIA_DOWN', text="").type = 'DOWN'
712
713         tool_settings = context.tool_settings
714         if gpd and gpl:
715             layout.prop(gpl, "thickness")
716         else:
717             layout.prop(tool_settings, "annotation_thickness", text="Thickness")
718
719         if gpl:
720             # Full-Row - Frame Locking (and Delete Frame)
721             row = layout.row(align=True)
722             row.active = not gpl.lock
723
724             if gpl.active_frame:
725                 lock_status = iface_("Locked") if gpl.lock_frame else iface_("Unlocked")
726                 lock_label = iface_("Frame: %d (%s)") % (gpl.active_frame.frame_number, lock_status)
727             else:
728                 lock_label = iface_("Lock Frame")
729             row.prop(gpl, "lock_frame", text=lock_label, icon='UNLOCKED')
730             row.operator("gpencil.active_frame_delete", text="", icon='X')
731
732
733 class AnnotationOnionSkin:
734     bl_label = "Onion Skin"
735     bl_region_type = 'UI'
736     bl_options = {'DEFAULT_CLOSED'}
737
738     @classmethod
739     def poll(cls, context):
740         # Show this panel as long as someone that might own this exists
741         # AND the owner isn't an object (e.g. GP Object)
742         if context.gpencil_data_owner is None:
743             return False
744         elif type(context.gpencil_data_owner) is bpy.types.Object:
745             return False
746         else:
747             gpl = context.active_gpencil_layer
748             if gpl is None:
749                 return False
750
751             return True
752
753     def draw_header(self, context):
754         gpl = context.active_gpencil_layer
755         self.layout.prop(gpl, "use_annotation_onion_skinning", text="")
756
757     def draw(self, context):
758         layout = self.layout
759         layout.use_property_decorate = False
760
761         gpl = context.active_gpencil_layer
762         col = layout.column()
763         split = col.split(factor=0.5)
764         split.active = gpl.use_annotation_onion_skinning
765
766         # - Before Frames
767         sub = split.column(align=True)
768         row = sub.row(align=True)
769         row.prop(gpl, "annotation_onion_before_color", text="")
770         sub.prop(gpl, "annotation_onion_before_range", text="Before")
771
772         # - After Frames
773         sub = split.column(align=True)
774         row = sub.row(align=True)
775         row.prop(gpl, "annotation_onion_after_color", text="")
776         sub.prop(gpl, "annotation_onion_after_range", text="After")
777
778
779 class GreasePencilToolsPanel:
780     # For use in "2D" Editors without their own toolbar
781     # subclass must set
782     # bl_space_type = 'IMAGE_EDITOR'
783     bl_label = "Grease Pencil Settings"
784     bl_region_type = 'UI'
785     bl_options = {'DEFAULT_CLOSED'}
786
787     @classmethod
788     def poll(cls, context):
789         # XXX - disabled in 2.8 branch.
790         return False
791
792         return (context.gpencil_data is not None)
793
794     def draw(self, context):
795         layout = self.layout
796
797         gpd = context.gpencil_data
798
799         gpencil_active_brush_settings_simple(context, layout)
800
801         layout.separator()
802
803         gpencil_stroke_placement_settings(context, layout)
804
805
806 class GreasePencilMaterialsPanel:
807     # Mix-in, use for properties editor and top-bar.
808     def draw(self, context):
809         layout = self.layout
810         show_full_ui = (self.bl_space_type == 'PROPERTIES')
811
812         is_view3d = (self.bl_space_type == 'VIEW_3D')
813         tool_settings = context.scene.tool_settings
814         gpencil_paint = tool_settings.gpencil_paint
815         brush = gpencil_paint.brush
816
817         ob = context.object
818         row = layout.row()
819
820         if ob:
821             is_sortable = len(ob.material_slots) > 1
822             rows = 7
823
824             row.template_list("GPENCIL_UL_matslots", "", ob, "material_slots", ob, "active_material_index", rows=rows)
825
826             # if topbar popover and brush pinned, disable
827             if is_view3d and brush is not None:
828                 gp_settings = brush.gpencil_settings
829                 if gp_settings.use_material_pin:
830                     row.enabled = False
831
832             col = row.column(align=True)
833             if show_full_ui:
834                 col.operator("object.material_slot_add", icon='ADD', text="")
835                 col.operator("object.material_slot_remove", icon='REMOVE', text="")
836
837             col.menu("GPENCIL_MT_color_context_menu", icon='DOWNARROW_HLT', text="")
838
839             if is_sortable:
840                 col.separator()
841
842                 col.operator("object.material_slot_move", icon='TRIA_UP', text="").direction = 'UP'
843                 col.operator("object.material_slot_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
844
845                 col.separator()
846
847                 sub = col.column(align=True)
848                 sub.operator("gpencil.color_isolate", icon='LOCKED', text="").affect_visibility = False
849                 sub.operator("gpencil.color_isolate", icon='RESTRICT_VIEW_ON', text="").affect_visibility = True
850
851             if show_full_ui:
852                 row = layout.row()
853
854                 row.template_ID(ob, "active_material", new="material.new", live_icon=True)
855
856                 slot = context.material_slot
857                 if slot:
858                     icon_link = 'MESH_DATA' if slot.link == 'DATA' else 'OBJECT_DATA'
859                     row.prop(slot, "link", icon=icon_link, icon_only=True)
860
861                 if ob.data.use_stroke_edit_mode:
862                     row = layout.row(align=True)
863                     row.operator("gpencil.stroke_change_color", text="Assign")
864                     row.operator("gpencil.color_select", text="Select").deselect = False
865                     row.operator("gpencil.color_select", text="Deselect").deselect = True
866         # stroke color
867             ma = None
868             if is_view3d and brush is not None:
869                 gp_settings = brush.gpencil_settings
870                 if gp_settings.use_material_pin is False:
871                     ma = ob.material_slots[ob.active_material_index].material
872                 else:
873                     ma = gp_settings.material
874
875             if ma is not None and ma.grease_pencil is not None:
876                 gpcolor = ma.grease_pencil
877                 if (
878                         gpcolor.stroke_style == 'SOLID' or
879                         gpcolor.use_stroke_pattern or
880                         gpcolor.use_stroke_texture_mix
881                 ):
882                     row = layout.row()
883                     row.prop(gpcolor, "color", text="Stroke Color")
884
885         else:
886             space = context.space_data
887             row.template_ID(space, "pin_id")
888
889
890 class GPENCIL_UL_layer(UIList):
891     def draw_item(self, _context, layout, _data, item, icon, _active_data, _active_propname, _index):
892         # assert(isinstance(item, bpy.types.GPencilLayer)
893         gpl = item
894
895         if self.layout_type in {'DEFAULT', 'COMPACT'}:
896             if gpl.lock:
897                 layout.active = False
898
899             row = layout.row(align=True)
900             row.label(
901                 text="",
902                 icon='BONE_DATA' if gpl.is_parented else 'BLANK1',
903             )
904             row.prop(gpl, "info", text="", emboss=False)
905
906             row = layout.row(align=True)
907             row.prop(gpl, "clamp_layer", text="",
908                      icon='MOD_MASK' if gpl.clamp_layer else 'LAYER_ACTIVE',
909                      emboss=False)
910
911             row.prop(gpl, "lock", text="", emboss=False)
912             row.prop(gpl, "hide", text="", emboss=False)
913             subrow = row.row(align=True)
914             subrow.prop(
915                 gpl,
916                 "use_onion_skinning",
917                 text="",
918                 icon='ONIONSKIN_ON' if gpl.use_onion_skinning else 'ONIONSKIN_OFF',
919                 emboss=False,
920             )
921         elif self.layout_type == 'GRID':
922             layout.alignment = 'CENTER'
923             layout.label(
924                 text="",
925                 icon_value=icon,
926             )
927
928
929 classes = (
930     GPENCIL_MT_pie_tool_palette,
931     GPENCIL_MT_pie_settings_palette,
932     GPENCIL_MT_pie_tools_more,
933     GPENCIL_MT_pie_sculpt,
934
935     GPENCIL_MT_snap,
936     GPENCIL_MT_separate,
937     GPENCIL_MT_cleanup,
938
939     GPENCIL_MT_gpencil_draw_delete,
940
941     GPENCIL_UL_annotation_layer,
942     GPENCIL_UL_layer,
943 )
944
945 if __name__ == "__main__":  # only for live edit.
946     from bpy.utils import register_class
947     for cls in classes:
948         register_class(cls)