4c77a6ad2c60382aa9a22fb00681e826ec22f98b
[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("wm.call_menu_pie", text="Settings...", icon='SCRIPTWIN').name = "GPENCIL_MT_pie_settings_palette"
365
366         # Editing tools
367         if gpd:
368             if gpd.use_stroke_edit_mode and context.editable_gpencil_strokes:
369                 # S - Exit Edit Mode
370                 pie.operator("gpencil.editmode_toggle", text="Exit Edit Mode", icon='EDIT')
371
372                 # N - Transforms
373                 col = pie.column()
374                 row = col.row(align=True)
375                 row.operator("transform.translate", icon='MAN_TRANS')
376                 row.operator("transform.rotate", icon='MAN_ROT')
377                 row.operator("transform.resize", text="Scale", icon='MAN_SCALE')
378                 row = col.row(align=True)
379                 row.label(text="Proportional Edit:")
380                 row.prop(context.tool_settings, "use_proportional_edit", text="", icon_only=True)
381                 row.prop(context.tool_settings, "proportional_edit_falloff", text="", icon_only=True)
382
383                 # NW - Select (Non-Modal)
384                 col = pie.column()
385                 col.operator("gpencil.select_all", text="Select All", icon='PARTICLE_POINT')
386                 col.operator("gpencil.select_all", text="Select Inverse", icon='BLANK1')
387                 col.operator("gpencil.select_linked", text="Select Linked", icon='LINKED')
388                 col.operator("gpencil.palettecolor_select", text="Select Color", icon='COLOR')
389
390                 # NE - Select (Modal)
391                 col = pie.column()
392                 col.operator("gpencil.select_box", text="Box Select", icon='BORDER_RECT')
393                 col.operator("gpencil.select_circle", text="Circle Select", icon='META_EMPTY')
394                 col.operator("gpencil.select_lasso", text="Lasso Select", icon='BORDER_LASSO')
395                 col.operator("gpencil.select_alternate", text="Alternate Select", icon='BORDER_LASSO')
396
397                 # SW - Edit Tools
398                 col = pie.column()
399                 col.operator("gpencil.duplicate_move", icon='PARTICLE_PATH', text="Duplicate")
400                 col.operator("gpencil.delete", icon='X', text="Delete...")
401
402                 # SE - More Tools
403                 pie.operator("wm.call_menu_pie", text="More...").name = "GPENCIL_MT_pie_tools_more"
404             else:
405                 # Toggle Edit Mode
406                 pie.operator("gpencil.editmode_toggle", text="Enable Stroke Editing", icon='EDIT')
407
408
409 class GPENCIL_MT_pie_settings_palette(Menu):
410     """A pie menu for quick access to Grease Pencil settings"""
411     bl_label = "Grease Pencil Settings"
412
413     @classmethod
414     def poll(cls, context):
415         return bool(context.gpencil_data and context.active_gpencil_layer)
416
417     def draw(self, context):
418         layout = self.layout
419
420         pie = layout.menu_pie()
421         gpd = context.gpencil_data
422         gpl = context.active_gpencil_layer
423         palcolor = None  # context.active_gpencil_palettecolor
424
425         is_editmode = bool(gpd and gpd.use_stroke_edit_mode and context.editable_gpencil_strokes)
426
427         # W - Stroke draw settings
428         col = pie.column(align=True)
429         if palcolor is not None:
430             col.enabled = not palcolor.lock
431             col.label(text="Stroke")
432             col.prop(palcolor, "color", text="")
433             col.prop(palcolor, "alpha", text="", slider=True)
434
435         # E - Fill draw settings
436         col = pie.column(align=True)
437         if palcolor is not None:
438             col.enabled = not palcolor.lock
439             col.label(text="Fill")
440             col.prop(palcolor, "fill_color", text="")
441             col.prop(palcolor, "fill_alpha", text="", slider=True)
442
443         # S Brush settings
444         gpencil_active_brush_settings_simple(context, pie)
445
446         # N - Active Layer
447         col = pie.column()
448         col.label(text="Active Layer:      ")
449
450         row = col.row()
451         row.operator_context = 'EXEC_REGION_WIN'
452         row.operator_menu_enum("gpencil.layer_change", "layer", text="", icon='GREASEPENCIL')
453         row.prop(gpl, "info", text="")
454         row.operator("gpencil.layer_remove", text="", icon='X')
455
456         row = col.row()
457         row.prop(gpl, "lock")
458         row.prop(gpl, "hide")
459         col.prop(gpl, "use_onion_skinning")
460
461         # NW/NE/SW/SE - These operators are only available in editmode
462         # as they require strokes to be selected to work
463         if is_editmode:
464             # NW - Move stroke Down
465             col = pie.column(align=True)
466             col.label(text="Arrange Strokes")
467             col.operator("gpencil.stroke_arrange", text="Send to Back").direction = 'BOTTOM'
468             col.operator("gpencil.stroke_arrange", text="Send Backward").direction = 'DOWN'
469
470             # NE - Move stroke Up
471             col = pie.column(align=True)
472             col.label(text="Arrange Strokes")
473             col.operator("gpencil.stroke_arrange", text="Bring to Front").direction = 'TOP'
474             col.operator("gpencil.stroke_arrange", text="Bring Forward").direction = 'UP'
475
476             # SW - Move stroke to color
477             col = pie.column(align=True)
478             col.operator("gpencil.stroke_change_color", text="Move to Color")
479
480             # SE - Join strokes
481             col = pie.column(align=True)
482             col.label(text="Join Strokes")
483             row = col.row()
484             row.operator("gpencil.stroke_join", text="Join").type = 'JOIN'
485             row.operator("gpencil.stroke_join", text="Join & Copy").type = 'JOINCOPY'
486             col.operator("gpencil.stroke_flip", text="Flip Direction")
487
488             col.prop(gpd, "show_stroke_direction", text="Show Drawing Direction")
489
490
491 class GPENCIL_MT_pie_tools_more(Menu):
492     """A pie menu for accessing more Grease Pencil tools"""
493     bl_label = "More Grease Pencil Tools"
494
495     @classmethod
496     def poll(cls, context):
497         gpd = context.gpencil_data
498         return bool(gpd and gpd.use_stroke_edit_mode and context.editable_gpencil_strokes)
499
500     def draw(self, _context):
501         layout = self.layout
502
503         pie = layout.menu_pie()
504         # gpd = context.gpencil_data
505
506         col = pie.column(align=True)
507         col.operator("gpencil.copy", icon='COPYDOWN', text="Copy")
508         col.operator("gpencil.paste", icon='PASTEDOWN', text="Paste")
509
510         col = pie.column(align=True)
511         col.operator("gpencil.select_more", icon='ADD')
512         col.operator("gpencil.select_less", icon='REMOVE')
513
514         pie.operator("transform.mirror", icon='MOD_MIRROR')
515         pie.operator("transform.bend", icon='MOD_SIMPLEDEFORM')
516         pie.operator("transform.shear", icon='MOD_TRIANGULATE')
517         pie.operator("transform.tosphere", icon='MOD_MULTIRES')
518
519         pie.operator("gpencil.convert", icon='OUTLINER_OB_CURVE', text="Convert...")
520         pie.operator("wm.call_menu_pie", text="Back to Main Palette...").name = "GPENCIL_MT_pie_tool_palette"
521
522
523 class GPENCIL_MT_pie_sculpt(Menu):
524     """A pie menu for accessing Grease Pencil stroke sculpt settings"""
525     bl_label = "Grease Pencil Sculpt"
526
527     @classmethod
528     def poll(cls, context):
529         gpd = context.gpencil_data
530         return bool(gpd and gpd.use_stroke_edit_mode and context.editable_gpencil_strokes)
531
532     def draw(self, context):
533         layout = self.layout
534
535         pie = layout.menu_pie()
536
537         settings = context.tool_settings.gpencil_sculpt
538         brush = settings.brush
539
540         # W - Launch Sculpt Mode
541         col = pie.column()
542         # col.label(text="Tool:")
543         col.prop(settings, "sculpt_tool", text="")
544         col.operator("gpencil.sculpt_paint", text="Sculpt", icon='SCULPTMODE_HLT')
545
546         # E - Common Settings
547         col = pie.column(align=True)
548         col.prop(brush, "size", slider=True)
549         row = col.row(align=True)
550         row.prop(brush, "strength", slider=True)
551         # row.prop(brush, "use_pressure_strength", text="", icon_only=True)
552         col.prop(brush, "use_falloff")
553         if settings.sculpt_tool in {'SMOOTH', 'RANDOMIZE'}:
554             row = col.row(align=True)
555             row.prop(settings, "use_edit_position", text="Position", icon='MESH_DATA', toggle=True)
556             row.prop(settings, "use_edit_strength", text="Strength", icon='COLOR', toggle=True)
557             row.prop(settings, "use_edit_thickness", text="Thickness", icon='LINE_DATA', toggle=True)
558
559         # S - Change Brush Type Shortcuts
560         row = pie.row()
561         row.prop_enum(settings, "tool", value='GRAB')
562         row.prop_enum(settings, "tool", value='PUSH')
563         row.prop_enum(settings, "tool", value='CLONE')
564
565         # N - Change Brush Type Shortcuts
566         row = pie.row()
567         row.prop_enum(settings, "tool", value='SMOOTH')
568         row.prop_enum(settings, "tool", value='THICKNESS')
569         row.prop_enum(settings, "tool", value='STRENGTH')
570         row.prop_enum(settings, "tool", value='RANDOMIZE')
571
572
573 class GPENCIL_MT_snap(Menu):
574     bl_label = "Snap"
575
576     def draw(self, _context):
577         layout = self.layout
578
579         layout.operator("gpencil.snap_to_grid", text="Selection to Grid")
580         layout.operator("gpencil.snap_to_cursor", text="Selection to Cursor").use_offset = False
581         layout.operator("gpencil.snap_to_cursor", text="Selection to Cursor (Keep Offset)").use_offset = True
582
583         layout.separator()
584
585         layout.operator("gpencil.snap_cursor_to_selected", text="Cursor to Selected")
586         layout.operator("view3d.snap_cursor_to_center", text="Cursor to World Origin")
587         layout.operator("view3d.snap_cursor_to_grid", text="Cursor to Grid")
588
589
590 class GPENCIL_MT_separate(Menu):
591     bl_label = "Separate"
592
593     def draw(self, _context):
594         layout = self.layout
595         layout.operator("gpencil.stroke_separate", text="Selected Points").mode = 'POINT'
596         layout.operator("gpencil.stroke_separate", text="Selected Strokes").mode = 'STROKE'
597         layout.operator("gpencil.stroke_separate", text="Active Layer").mode = 'LAYER'
598
599
600 class GPENCIL_MT_gpencil_draw_delete(Menu):
601     bl_label = "GPencil Draw Delete"
602
603     def draw(self, _context):
604         layout = self.layout
605
606         layout.operator_context = 'INVOKE_REGION_WIN'
607
608         layout.operator("gpencil.active_frames_delete_all", text="Delete Frame")
609
610
611 class GPENCIL_MT_cleanup(Menu):
612     bl_label = "Clean Up"
613
614     def draw(self, _context):
615         layout = self.layout
616         layout.operator("gpencil.frame_clean_loose", text="Loose Points")
617         layout.separator()
618
619         layout.operator("gpencil.frame_clean_fill", text="Boundary Strokes").mode = 'ACTIVE'
620         layout.operator("gpencil.frame_clean_fill", text="Boundary Strokes all Frames").mode = 'ALL'
621         layout.separator()
622
623         layout.operator("gpencil.reproject")
624
625
626 class GPENCIL_UL_annotation_layer(UIList):
627     def draw_item(self, _context, layout, _data, item, icon, _active_data, _active_propname, _index):
628         # assert(isinstance(item, bpy.types.GPencilLayer)
629         gpl = item
630
631         if self.layout_type in {'DEFAULT', 'COMPACT'}:
632             if gpl.lock:
633                 layout.active = False
634
635             split = layout.split(factor=0.2)
636             split.prop(gpl, "color", text="", emboss=True)
637             split.prop(gpl, "info", text="", emboss=False)
638
639             row = layout.row(align=True)
640             row.prop(gpl, "annotation_hide", text="", emboss=False)
641         elif self.layout_type == 'GRID':
642             layout.alignment = 'CENTER'
643             layout.label(text="", icon_value=icon)
644
645
646 class AnnotationDataPanel:
647     bl_label = "Annotations"
648     bl_region_type = 'UI'
649     bl_options = {'DEFAULT_CLOSED'}
650
651     @classmethod
652     def poll(cls, context):
653         # Show this panel as long as someone that might own this exists
654         # AND the owner isn't an object (e.g. GP Object)
655         if context.gpencil_data_owner is None:
656             return False
657         elif type(context.gpencil_data_owner) is bpy.types.Object:
658             return False
659         else:
660             return True
661
662     def draw_header(self, context):
663         if context.space_data.type not in {'VIEW_3D', 'TOPBAR'}:
664             self.layout.prop(context.space_data, "show_annotation", text="")
665
666     def draw(self, context):
667         layout = self.layout
668         layout.use_property_decorate = False
669
670         # Grease Pencil owner.
671         gpd_owner = context.gpencil_data_owner
672         gpd = context.gpencil_data
673
674         # Owner selector.
675         if context.space_data.type == 'CLIP_EDITOR':
676             layout.row().prop(context.space_data, "grease_pencil_source", expand=True)
677
678         layout.template_ID(gpd_owner, "grease_pencil", new="gpencil.data_add", unlink="gpencil.data_unlink")
679
680         # List of layers/notes.
681         if gpd and gpd.layers:
682             self.draw_layers(context, layout, gpd)
683
684     def draw_layers(self, context, layout, gpd):
685         row = layout.row()
686
687         col = row.column()
688         if len(gpd.layers) >= 2:
689             layer_rows = 5
690         else:
691             layer_rows = 3
692         col.template_list("GPENCIL_UL_annotation_layer", "", gpd, "layers", gpd.layers, "active_index",
693                           rows=layer_rows, sort_reverse=True, sort_lock=True)
694
695         col = row.column()
696
697         sub = col.column(align=True)
698         sub.operator("gpencil.layer_add", icon='ADD', text="")
699         sub.operator("gpencil.layer_remove", icon='REMOVE', text="")
700
701         gpl = context.active_gpencil_layer
702         if gpl:
703             if len(gpd.layers) > 1:
704                 col.separator()
705
706                 sub = col.column(align=True)
707                 sub.operator("gpencil.layer_move", icon='TRIA_UP', text="").type = 'UP'
708                 sub.operator("gpencil.layer_move", icon='TRIA_DOWN', text="").type = 'DOWN'
709
710         tool_settings = context.tool_settings
711         if gpd and gpl:
712             layout.prop(gpl, "thickness")
713         else:
714             layout.prop(tool_settings, "annotation_thickness", text="Thickness")
715
716         if gpl:
717             # Full-Row - Frame Locking (and Delete Frame)
718             row = layout.row(align=True)
719             row.active = not gpl.lock
720
721             if gpl.active_frame:
722                 lock_status = iface_("Locked") if gpl.lock_frame else iface_("Unlocked")
723                 lock_label = iface_("Frame: %d (%s)") % (gpl.active_frame.frame_number, lock_status)
724             else:
725                 lock_label = iface_("Lock Frame")
726             row.prop(gpl, "lock_frame", text=lock_label, icon='UNLOCKED')
727             row.operator("gpencil.active_frame_delete", text="", icon='X')
728
729
730 class AnnotationOnionSkin:
731     bl_label = "Onion Skin"
732     bl_region_type = 'UI'
733     bl_options = {'DEFAULT_CLOSED'}
734
735     @classmethod
736     def poll(cls, context):
737         # Show this panel as long as someone that might own this exists
738         # AND the owner isn't an object (e.g. GP Object)
739         if context.gpencil_data_owner is None:
740             return False
741         elif type(context.gpencil_data_owner) is bpy.types.Object:
742             return False
743         else:
744             gpl = context.active_gpencil_layer
745             if gpl is None:
746                 return False
747
748             return True
749
750     def draw_header(self, context):
751         gpl = context.active_gpencil_layer
752         self.layout.prop(gpl, "use_annotation_onion_skinning", text="")
753
754     def draw(self, context):
755         layout = self.layout
756         layout.use_property_decorate = False
757
758         gpl = context.active_gpencil_layer
759         col = layout.column()
760         split = col.split(factor=0.5)
761         split.active = gpl.use_annotation_onion_skinning
762
763         # - Before Frames
764         sub = split.column(align=True)
765         row = sub.row(align=True)
766         row.prop(gpl, "annotation_onion_before_color", text="")
767         sub.prop(gpl, "annotation_onion_before_range", text="Before")
768
769         # - After Frames
770         sub = split.column(align=True)
771         row = sub.row(align=True)
772         row.prop(gpl, "annotation_onion_after_color", text="")
773         sub.prop(gpl, "annotation_onion_after_range", text="After")
774
775
776 class GreasePencilToolsPanel:
777     # For use in "2D" Editors without their own toolbar
778     # subclass must set
779     # bl_space_type = 'IMAGE_EDITOR'
780     bl_label = "Grease Pencil Settings"
781     bl_region_type = 'UI'
782     bl_options = {'DEFAULT_CLOSED'}
783
784     @classmethod
785     def poll(cls, context):
786         # XXX - disabled in 2.8 branch.
787         return False
788
789         return (context.gpencil_data is not None)
790
791     def draw(self, context):
792         layout = self.layout
793
794         gpd = context.gpencil_data
795
796         gpencil_active_brush_settings_simple(context, layout)
797
798         layout.separator()
799
800         gpencil_stroke_placement_settings(context, layout)
801
802
803 class GreasePencilMaterialsPanel:
804     # Mix-in, use for properties editor and top-bar.
805     def draw(self, context):
806         layout = self.layout
807         show_full_ui = (self.bl_space_type == 'PROPERTIES')
808
809         is_view3d = (self.bl_space_type == 'VIEW_3D')
810         tool_settings = context.scene.tool_settings
811         gpencil_paint = tool_settings.gpencil_paint
812         brush = gpencil_paint.brush
813
814         ob = context.object
815         row = layout.row()
816
817         if ob:
818             is_sortable = len(ob.material_slots) > 1
819             rows = 7
820
821             row.template_list("GPENCIL_UL_matslots", "", ob, "material_slots", ob, "active_material_index", rows=rows)
822
823             # if topbar popover and brush pinned, disable
824             if is_view3d and brush is not None:
825                 gp_settings = brush.gpencil_settings
826                 if gp_settings.use_material_pin:
827                     row.enabled = False
828
829             col = row.column(align=True)
830             if show_full_ui:
831                 col.operator("object.material_slot_add", icon='ADD', text="")
832                 col.operator("object.material_slot_remove", icon='REMOVE', text="")
833
834             col.menu("GPENCIL_MT_color_context_menu", icon='DOWNARROW_HLT', text="")
835
836             if is_sortable:
837                 col.separator()
838
839                 col.operator("object.material_slot_move", icon='TRIA_UP', text="").direction = 'UP'
840                 col.operator("object.material_slot_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
841
842                 col.separator()
843
844                 sub = col.column(align=True)
845                 sub.operator("gpencil.color_isolate", icon='LOCKED', text="").affect_visibility = False
846                 sub.operator("gpencil.color_isolate", icon='RESTRICT_VIEW_ON', text="").affect_visibility = True
847
848             if show_full_ui:
849                 row = layout.row()
850
851                 row.template_ID(ob, "active_material", new="material.new", live_icon=True)
852
853                 slot = context.material_slot
854                 if slot:
855                     icon_link = 'MESH_DATA' if slot.link == 'DATA' else 'OBJECT_DATA'
856                     row.prop(slot, "link", icon=icon_link, icon_only=True)
857
858                 if ob.data.use_stroke_edit_mode:
859                     row = layout.row(align=True)
860                     row.operator("gpencil.stroke_change_color", text="Assign")
861                     row.operator("gpencil.color_select", text="Select").deselect = False
862                     row.operator("gpencil.color_select", text="Deselect").deselect = True
863         # stroke color
864             ma = None
865             if is_view3d and brush is not None:
866                 gp_settings = brush.gpencil_settings
867                 if gp_settings.use_material_pin is False:
868                     ma = ob.material_slots[ob.active_material_index].material
869                 else:
870                     ma = gp_settings.material
871
872             if ma is not None and ma.grease_pencil is not None:
873                 gpcolor = ma.grease_pencil
874                 if gpcolor.stroke_style == 'SOLID' or \
875                     gpcolor.use_stroke_pattern is True or \
876                     gpcolor.use_stroke_texture_mix is True:
877                     row = layout.row()
878                     row.prop(gpcolor, "color", text="Stroke Color")
879
880         else:
881             space = context.space_data
882             row.template_ID(space, "pin_id")
883
884
885 class GPENCIL_UL_layer(UIList):
886     def draw_item(self, _context, layout, _data, item, icon, _active_data, _active_propname, _index):
887         # assert(isinstance(item, bpy.types.GPencilLayer)
888         gpl = item
889
890         if self.layout_type in {'DEFAULT', 'COMPACT'}:
891             if gpl.lock:
892                 layout.active = False
893
894             row = layout.row(align=True)
895             row.label(
896                 text="",
897                 icon='BONE_DATA' if gpl.is_parented else 'BLANK1',
898             )
899             row.prop(gpl, "info", text="", emboss=False)
900
901             row = layout.row(align=True)
902             row.prop(gpl, "clamp_layer", text="",
903                      icon='MOD_MASK' if gpl.clamp_layer else 'LAYER_ACTIVE',
904                      emboss=False)
905
906             row.prop(gpl, "lock", text="", emboss=False)
907             row.prop(gpl, "hide", text="", emboss=False)
908             subrow = row.row(align=True)
909             subrow.prop(
910                 gpl,
911                 "use_onion_skinning",
912                 text="",
913                 icon='ONIONSKIN_ON' if gpl.use_onion_skinning else 'ONIONSKIN_OFF',
914                 emboss=False,
915             )
916         elif self.layout_type == 'GRID':
917             layout.alignment = 'CENTER'
918             layout.label(
919                 text="",
920                 icon_value=icon,
921             )
922
923
924 classes = (
925     GPENCIL_MT_pie_tool_palette,
926     GPENCIL_MT_pie_settings_palette,
927     GPENCIL_MT_pie_tools_more,
928     GPENCIL_MT_pie_sculpt,
929
930     GPENCIL_MT_snap,
931     GPENCIL_MT_separate,
932     GPENCIL_MT_cleanup,
933
934     GPENCIL_MT_gpencil_draw_delete,
935
936     GPENCIL_UL_annotation_layer,
937     GPENCIL_UL_layer,
938 )
939
940 if __name__ == "__main__":  # only for live edit.
941     from bpy.utils import register_class
942     for cls in classes:
943         register_class(cls)