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