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