Moving classes to separate listing broke panel order
[blender-staging.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
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 = "gpencil_stroke_placement_view3d"
29     elif context.space_data.type == 'SEQUENCE_EDITOR':
30         propname = "gpencil_stroke_placement_sequencer_preview"
31     elif context.space_data.type == 'IMAGE_EDITOR':
32         propname = "gpencil_stroke_placement_image_editor"
33     else:
34         propname = "gpencil_stroke_placement_view2d"
35
36     ts = context.tool_settings
37
38     col = layout.column(align=True)
39
40     col.label(text="Stroke Placement:")
41
42     row = col.row(align=True)
43     row.prop_enum(ts, propname, 'VIEW')
44     row.prop_enum(ts, propname, 'CURSOR')
45
46     if context.space_data.type == 'VIEW_3D':
47         row = col.row(align=True)
48         row.prop_enum(ts, propname, 'SURFACE')
49         row.prop_enum(ts, propname, 'STROKE')
50
51         row = col.row(align=False)
52         row.active = getattr(ts, propname) in {'SURFACE', 'STROKE'}
53         row.prop(ts, "use_gpencil_stroke_endpoints")
54
55         if context.scene.tool_settings.gpencil_stroke_placement_view3d == 'CURSOR':
56             row = col.row(align=True)
57             row.label("Lock axis:")
58             row = col.row(align=True)
59             row.prop(ts.gpencil_sculpt, "lockaxis", expand=True)
60
61
62 def gpencil_active_brush_settings_simple(context, layout):
63     brush = context.active_gpencil_brush
64     if brush is None:
65         layout.label("No Active Brush")
66         return
67
68     col = layout.column()
69     col.label("Active Brush:      ")
70
71     row = col.row(align=True)
72     row.operator_context = 'EXEC_REGION_WIN'
73     row.operator_menu_enum("gpencil.brush_change", "brush", text="", icon='BRUSH_DATA')
74     row.prop(brush, "name", text="")
75
76     col.prop(brush, "line_width", slider=True)
77     row = col.row(align=True)
78     row.prop(brush, "use_random_pressure", text='', icon='RNDCURVE')
79     row.prop(brush, "pen_sensitivity_factor", slider=True)
80     row.prop(brush, "use_pressure", text='', icon='STYLUS_PRESSURE')
81     row = col.row(align=True)
82     row.prop(brush, "use_random_strength", text='', icon='RNDCURVE')
83     row.prop(brush, "strength", slider=True)
84     row.prop(brush, "use_strength_pressure", text='', icon='STYLUS_PRESSURE')
85     row = col.row(align=True)
86     row.prop(brush, "jitter", slider=True)
87     row.prop(brush, "use_jitter_pressure", text='', icon='STYLUS_PRESSURE')
88     row = col.row()
89     row.prop(brush, "angle", slider=True)
90     row.prop(brush, "angle_factor", text="Factor", slider=True)
91
92
93 class GreasePencilDrawingToolsPanel:
94     # subclass must set
95     # bl_space_type = 'IMAGE_EDITOR'
96     bl_label = "Grease Pencil"
97     bl_category = "Grease Pencil"
98     bl_region_type = 'TOOLS'
99
100     @staticmethod
101     def draw(self, context):
102         layout = self.layout
103
104         is_3d_view = context.space_data.type == 'VIEW_3D'
105         is_clip_editor = context.space_data.type == 'CLIP_EDITOR'
106
107         col = layout.column(align=True)
108
109         col.label(text="Draw:")
110         row = col.row(align=True)
111         row.operator("gpencil.draw", icon='GREASEPENCIL', text="Draw").mode = 'DRAW'
112         row.operator("gpencil.draw", icon='FORCE_CURVE', text="Erase").mode = 'ERASER'  # XXX: Needs a dedicated icon
113
114         row = col.row(align=True)
115         row.operator("gpencil.draw", icon='LINE_DATA', text="Line").mode = 'DRAW_STRAIGHT'
116         row.operator("gpencil.draw", icon='MESH_DATA', text="Poly").mode = 'DRAW_POLY'
117
118         col.separator()
119
120         sub = col.column(align=True)
121         sub.operator("gpencil.blank_frame_add", icon='NEW')
122         sub.operator("gpencil.active_frames_delete_all", icon='X', text="Delete Frame(s)")
123
124         sub = col.column(align=True)
125         sub.prop(context.tool_settings, "use_gpencil_additive_drawing", text="Additive Drawing")
126         sub.prop(context.tool_settings, "use_gpencil_continuous_drawing", text="Continuous Drawing")
127         sub.prop(context.tool_settings, "use_gpencil_draw_onback", text="Draw on Back")
128
129         col.separator()
130         col.separator()
131
132         if context.space_data.type in {'VIEW_3D', 'CLIP_EDITOR'}:
133             col.separator()
134             col.label("Data Source:")
135             row = col.row(align=True)
136             if is_3d_view:
137                 row.prop(context.tool_settings, "grease_pencil_source", expand=True)
138             elif is_clip_editor:
139                 row.prop(context.space_data, "grease_pencil_source", expand=True)
140
141         col.separator()
142         col.separator()
143
144         gpencil_stroke_placement_settings(context, col)
145
146         gpd = context.gpencil_data
147
148         if gpd and not is_3d_view:
149             layout.separator()
150             layout.separator()
151
152             col = layout.column(align=True)
153             col.prop(gpd, "use_stroke_edit_mode", text="Enable Editing", icon='EDIT', toggle=True)
154
155         if is_3d_view:
156             col.separator()
157             col.separator()
158
159             col.label(text="Tools:")
160             col.operator_menu_enum("gpencil.convert", text="Convert to Geometry...", property="type")
161             col.operator("view3d.ruler")
162
163
164 class GreasePencilStrokeEditPanel:
165     # subclass must set
166     # bl_space_type = 'IMAGE_EDITOR'
167     bl_label = "Edit Strokes"
168     bl_category = "Grease Pencil"
169     bl_region_type = 'TOOLS'
170     bl_options = {'DEFAULT_CLOSED'}
171
172     @classmethod
173     def poll(cls, context):
174         if context.gpencil_data is None:
175             return False
176
177         gpd = context.gpencil_data
178         return bool(context.editable_gpencil_strokes) and bool(gpd.use_stroke_edit_mode)
179
180     @staticmethod
181     def draw(self, context):
182         layout = self.layout
183
184         is_3d_view = context.space_data.type == 'VIEW_3D'
185
186         if not is_3d_view:
187             layout.label(text="Select:")
188             col = layout.column(align=True)
189             col.operator("gpencil.select_all", text="Select All")
190             col.operator("gpencil.select_border")
191             col.operator("gpencil.select_circle")
192
193             layout.separator()
194
195             col = layout.column(align=True)
196             col.operator("gpencil.select_linked")
197             col.operator("gpencil.select_more")
198             col.operator("gpencil.select_less")
199             col.operator("gpencil.palettecolor_select")
200
201         layout.label(text="Edit:")
202         row = layout.row(align=True)
203         row.operator("gpencil.copy", text="Copy")
204         row.operator("gpencil.paste", text="Paste").type = 'COPY'
205         row.operator("gpencil.paste", text="Paste & Merge").type = 'MERGE'
206
207         col = layout.column(align=True)
208         col.operator("gpencil.delete")
209         col.operator("gpencil.duplicate_move", text="Duplicate")
210         if is_3d_view:
211             col.operator("gpencil.stroke_cyclical_set", text="Toggle Cyclic").type = 'TOGGLE'
212
213         layout.separator()
214
215         if not is_3d_view:
216             col = layout.column(align=True)
217             col.operator("transform.translate")                # icon='MAN_TRANS'
218             col.operator("transform.rotate")                   # icon='MAN_ROT'
219             col.operator("transform.resize", text="Scale")     # icon='MAN_SCALE'
220
221             layout.separator()
222
223         col = layout.column(align=True)
224         col.operator("transform.bend", text="Bend")
225         col.operator("transform.mirror", text="Mirror")
226         col.operator("transform.shear", text="Shear")
227         col.operator("transform.tosphere", text="To Sphere")
228
229         layout.separator()
230         col = layout.column(align=True)
231         col.operator_menu_enum("gpencil.stroke_arrange", text="Arrange Strokes...", property="direction")
232         col.operator("gpencil.stroke_change_color", text="Move to Color")
233
234         if is_3d_view:
235             layout.separator()
236             
237
238         layout.separator()
239         col = layout.column(align=True)
240         col.operator("gpencil.stroke_subdivide", text="Subdivide")
241         col.operator("gpencil.stroke_join", text="Join").type = 'JOIN'
242         col.operator("gpencil.stroke_join", text="Join & Copy").type = 'JOINCOPY'
243         col.operator("gpencil.stroke_flip", text="Flip Direction")
244
245         gpd = context.gpencil_data
246         if gpd:
247             col.prop(gpd, "show_stroke_direction", text="Show Directions")
248
249         if is_3d_view:
250             layout.separator()
251             layout.operator_menu_enum("gpencil.reproject", text="Reproject Strokes...", property="type")
252
253
254 class GreasePencilInterpolatePanel:
255     bl_space_type = 'VIEW_3D'
256     bl_label = "Interpolate"
257     bl_category = "Grease Pencil"
258     bl_region_type = 'TOOLS'
259     bl_options = {'DEFAULT_CLOSED'}
260
261     @classmethod
262     def poll(cls, context):
263         if context.gpencil_data is None:
264             return False
265         elif context.space_data.type != 'VIEW_3D':
266             return False
267
268         gpd = context.gpencil_data
269         return bool(context.editable_gpencil_strokes) and bool(gpd.use_stroke_edit_mode)
270
271     @staticmethod
272     def draw(self, context):
273         layout = self.layout
274         settings = context.tool_settings.gpencil_interpolate
275
276         col = layout.column(align=True)
277         col.operator("gpencil.interpolate", text="Interpolate")
278         col.operator("gpencil.interpolate_sequence", text="Sequence")
279         col.operator("gpencil.interpolate_reverse", text="Remove Breakdowns")
280
281         col = layout.column(align=True)
282         col.label(text="Options:")
283         col.prop(settings, "interpolate_all_layers")
284         col.prop(settings, "interpolate_selected_only")
285
286         col = layout.column(align=True)
287         col.label(text="Sequence Options:")
288         col.prop(settings, "type")
289         if settings.type == 'CUSTOM':
290             box = layout.box()
291             # TODO: Options for loading/saving curve presets?
292             box.template_curve_mapping(settings, "interpolation_curve", brush=True)
293         elif settings.type != 'LINEAR':
294             col.prop(settings, "easing")
295
296             if settings.type == 'BACK':
297                 layout.prop(settings, "back")
298             elif setting.type == 'ELASTIC':
299                 sub = layout.column(align=True)
300                 sub.prop(settings, "amplitude")
301                 sub.prop(settings, "period")
302
303
304 class GreasePencilBrushPanel:
305     # subclass must set
306     # bl_space_type = 'IMAGE_EDITOR'
307     bl_label = "Drawing Brushes"
308     bl_category = "Grease Pencil"
309     bl_region_type = 'TOOLS'
310
311     @staticmethod
312     def draw(self, context):
313         layout = self.layout
314
315         row = layout.row()
316         col = row.column()
317         ts = context.scene.tool_settings
318         if len(ts.gpencil_brushes) >= 2:
319             brows = 3
320         else:
321             brows = 2
322         col.template_list("GPENCIL_UL_brush", "", ts, "gpencil_brushes", ts.gpencil_brushes, "active_index", rows=brows)
323
324         col = row.column()
325
326         sub = col.column(align=True)
327         sub.operator("gpencil.brush_add", icon='ZOOMIN', text="")
328         sub.operator("gpencil.brush_remove", icon='ZOOMOUT', text="")
329         sub.menu("GPENCIL_MT_brush_specials", icon='DOWNARROW_HLT', text="")
330         brush = context.active_gpencil_brush
331         if brush:
332             if len(ts.gpencil_brushes) > 1:
333                 col.separator()
334                 sub = col.column(align=True)
335                 sub.operator("gpencil.brush_move", icon='TRIA_UP', text="").type = 'UP'
336                 sub.operator("gpencil.brush_move", icon='TRIA_DOWN', text="").type = 'DOWN'
337
338         # Brush details
339         if brush is not None:
340             row = layout.row()
341             row.prop(brush, "line_width")
342             row = layout.row(align=True)
343             row.prop(brush, "use_random_pressure", text='', icon='RNDCURVE')
344             row.prop(brush, "pen_sensitivity_factor", slider=True)
345             row.prop(brush, "use_pressure", text='', icon='STYLUS_PRESSURE')
346             row = layout.row(align=True)
347             row.prop(brush, "use_random_strength", text='', icon='RNDCURVE')
348             row.prop(brush, "strength", slider=True)
349             row.prop(brush, "use_strength_pressure", text='', icon='STYLUS_PRESSURE')
350             row = layout.row(align=True)
351             row.prop(brush, "random_press", slider=True)
352
353             row = layout.row(align=True)
354             row.prop(brush, "jitter", slider=True)
355             row.prop(brush, "use_jitter_pressure", text='', icon='STYLUS_PRESSURE')
356             row = layout.row()
357             row.prop(brush, "angle", slider=True)
358             row.prop(brush, "angle_factor", text="Factor", slider=True)
359
360             box = layout.box()
361             col = box.column(align=True)
362             col.label(text="Stroke Quality:")
363             col.prop(brush, "pen_smooth_factor")
364             col.prop(brush, "pen_smooth_steps")
365             col.separator()
366             row = col.row(align=False)
367             row.prop(brush, "pen_subdivision_steps")
368             row.prop(brush, "random_subdiv", text='Randomness', slider=True)
369
370
371 class GreasePencilStrokeSculptPanel:
372     # subclass must set
373     # bl_space_type = 'IMAGE_EDITOR'
374     bl_label = "Sculpt Strokes"
375     bl_category = "Grease Pencil"
376     bl_region_type = 'TOOLS'
377
378     @classmethod
379     def poll(cls, context):
380         if context.gpencil_data is None:
381             return False
382
383         gpd = context.gpencil_data
384         return bool(context.editable_gpencil_strokes) and bool(gpd.use_stroke_edit_mode)
385
386     @staticmethod
387     def draw(self, context):
388         layout = self.layout
389
390         settings = context.tool_settings.gpencil_sculpt
391         tool = settings.tool
392         brush = settings.brush
393
394         layout.column().prop(settings, "tool")
395
396         col = layout.column()
397         col.prop(brush, "size", slider=True)
398         row = col.row(align=True)
399         row.prop(brush, "strength", slider=True)
400         row.prop(brush, "use_pressure_strength", text="")
401         col.prop(brush, "use_falloff")
402         if tool in {'SMOOTH', 'RANDOMIZE'}:
403             row = layout.row(align=True)
404             row.prop(settings, "affect_position", text="Position", icon='MESH_DATA', toggle=True)
405             row.prop(settings, "affect_strength", text="Strength", icon='COLOR', toggle=True)
406             row.prop(settings, "affect_thickness", text="Thickness", icon='LINE_DATA', toggle=True)
407
408         layout.separator()
409
410         if tool == 'THICKNESS':
411             layout.row().prop(brush, "direction", expand=True)
412         elif tool == 'PINCH':
413             row = layout.row(align=True)
414             row.prop_enum(brush, "direction", 'ADD', text="Pinch")
415             row.prop_enum(brush, "direction", 'SUBTRACT', text="Inflate")
416         elif settings.tool == 'TWIST':
417             row = layout.row(align=True)
418             row.prop_enum(brush, "direction", 'SUBTRACT', text="CW")
419             row.prop_enum(brush, "direction", 'ADD', text="CCW")
420
421         row = layout.row(align=True)
422         row.prop(settings, "use_select_mask")
423         row = layout.row(align=True)
424         row.prop(settings, "selection_alpha", slider=True)
425
426         if tool == 'SMOOTH':
427             layout.prop(brush, "affect_pressure")
428
429
430 class GreasePencilBrushCurvesPanel:
431     # subclass must set
432     # bl_space_type = 'IMAGE_EDITOR'
433     bl_label = "Brush Curves"
434     bl_category = "Grease Pencil"
435     bl_region_type = 'TOOLS'
436     bl_options = {'DEFAULT_CLOSED'}
437
438     @classmethod
439     def poll(cls, context):
440         if context.active_gpencil_brush is None:
441             return False
442
443         brush = context.active_gpencil_brush
444         return bool(brush)
445
446     @staticmethod
447     def draw(self, context):
448         layout = self.layout
449         brush = context.active_gpencil_brush
450         # Brush
451         layout.label("Sensitivity")
452         box = layout.box()
453         box.template_curve_mapping(brush, "curve_sensitivity", brush=True)
454
455         layout.label("Strength")
456         box = layout.box()
457         box.template_curve_mapping(brush, "curve_strength", brush=True)
458
459         layout.label("Jitter")
460         box = layout.box()
461         box.template_curve_mapping(brush, "curve_jitter", brush=True)
462
463
464 ###############################
465
466 class GPENCIL_PIE_tool_palette(Menu):
467     """A pie menu for quick access to Grease Pencil tools"""
468     bl_label = "Grease Pencil Tools"
469
470     def draw(self, context):
471         layout = self.layout
472
473         pie = layout.menu_pie()
474         gpd = context.gpencil_data
475
476         # W - Drawing Types
477         col = pie.column()
478         col.operator("gpencil.draw", text="Draw", icon='GREASEPENCIL').mode = 'DRAW'
479         col.operator("gpencil.draw", text="Straight Lines", icon='LINE_DATA').mode = 'DRAW_STRAIGHT'
480         col.operator("gpencil.draw", text="Poly", icon='MESH_DATA').mode = 'DRAW_POLY'
481
482         # E - Eraser
483         # XXX: needs a dedicated icon...
484         col = pie.column()
485         col.operator("gpencil.draw", text="Eraser", icon='FORCE_CURVE').mode = 'ERASER'
486
487         # E - "Settings" Palette is included here too, since it needs to be in a stable position...
488         if gpd and gpd.layers.active:
489             col.separator()
490             col.operator("wm.call_menu_pie", text="Settings...", icon='SCRIPTWIN').name = "GPENCIL_PIE_settings_palette"
491
492         # Editing tools
493         if gpd:
494             if gpd.use_stroke_edit_mode and context.editable_gpencil_strokes:
495                 # S - Exit Edit Mode
496                 pie.operator("gpencil.editmode_toggle", text="Exit Edit Mode", icon='EDIT')
497
498                 # N - Transforms
499                 col = pie.column()
500                 row = col.row(align=True)
501                 row.operator("transform.translate", icon='MAN_TRANS')
502                 row.operator("transform.rotate", icon='MAN_ROT')
503                 row.operator("transform.resize", text="Scale", icon='MAN_SCALE')
504                 row = col.row(align=True)
505                 row.label("Proportional Edit:")
506                 row.prop(context.tool_settings, "proportional_edit", text="", icon_only=True)
507                 row.prop(context.tool_settings, "proportional_edit_falloff", text="", icon_only=True)
508
509                 # NW - Select (Non-Modal)
510                 col = pie.column()
511                 col.operator("gpencil.select_all", text="Select All", icon='PARTICLE_POINT')
512                 col.operator("gpencil.select_all", text="Select Inverse", icon='BLANK1')
513                 col.operator("gpencil.select_linked", text="Select Linked", icon='LINKED')
514                 col.operator("gpencil.palettecolor_select", text="Select Color", icon='COLOR')
515
516                 # NE - Select (Modal)
517                 col = pie.column()
518                 col.operator("gpencil.select_border", text="Border Select", icon='BORDER_RECT')
519                 col.operator("gpencil.select_circle", text="Circle Select", icon='META_EMPTY')
520                 col.operator("gpencil.select_lasso", text="Lasso Select", icon='BORDER_LASSO')
521
522                 # SW - Edit Tools
523                 col = pie.column()
524                 col.operator("gpencil.duplicate_move", icon='PARTICLE_PATH', text="Duplicate")
525                 col.operator("gpencil.delete", icon='X', text="Delete...")
526
527                 # SE - More Tools
528                 pie.operator("wm.call_menu_pie", text="More...").name = "GPENCIL_PIE_tools_more"
529             else:
530                 # Toggle Edit Mode
531                 pie.operator("gpencil.editmode_toggle", text="Enable Stroke Editing", icon='EDIT')
532
533
534 class GPENCIL_PIE_settings_palette(Menu):
535     """A pie menu for quick access to Grease Pencil settings"""
536     bl_label = "Grease Pencil Settings"
537
538     @classmethod
539     def poll(cls, context):
540         return bool(context.gpencil_data and context.active_gpencil_layer)
541
542     def draw(self, context):
543         layout = self.layout
544
545         pie = layout.menu_pie()
546         gpd = context.gpencil_data
547         gpl = context.active_gpencil_layer
548         palcolor = context.active_gpencil_palettecolor
549         brush = context.active_gpencil_brush
550
551         is_editmode = bool(gpd and gpd.use_stroke_edit_mode and context.editable_gpencil_strokes)
552
553         # W - Stroke draw settings
554         col = pie.column(align=True)
555         if palcolor is not None:
556             col.enabled = not palcolor.lock
557             col.label(text="Stroke")
558             col.prop(palcolor, "color", text="")
559             col.prop(palcolor, "alpha", text="", slider=True)
560
561         # E - Fill draw settings
562         col = pie.column(align=True)
563         if palcolor is not None:
564             col.enabled = not palcolor.lock
565             col.label(text="Fill")
566             col.prop(palcolor, "fill_color", text="")
567             col.prop(palcolor, "fill_alpha", text="", slider=True)
568
569         # S Brush settings
570         gpencil_active_brush_settings_simple(context, pie)
571
572         # N - Active Layer
573         col = pie.column()
574         col.label("Active Layer:      ")
575
576         row = col.row()
577         row.operator_context = 'EXEC_REGION_WIN'
578         row.operator_menu_enum("gpencil.layer_change", "layer", text="", icon='GREASEPENCIL')
579         row.prop(gpl, "info", text="")
580         row.operator("gpencil.layer_remove", text="", icon='X')
581
582         row = col.row()
583         row.prop(gpl, "lock")
584         row.prop(gpl, "hide")
585         col.prop(gpl, "use_onion_skinning")
586
587         # NW/NE/SW/SE - These operators are only available in editmode
588         # as they require strokes to be selected to work
589         if is_editmode:
590             # NW - Move stroke Down
591             col = pie.column(align=True)
592             col.label("Arrange Strokes")
593             col.operator("gpencil.stroke_arrange", text="Send to Back").direction = 'BOTTOM'
594             col.operator("gpencil.stroke_arrange", text="Send Backward").direction = 'DOWN'
595
596             # NE - Move stroke Up
597             col = pie.column(align=True)
598             col.label("Arrange Strokes")
599             col.operator("gpencil.stroke_arrange", text="Bring to Front").direction = 'TOP'
600             col.operator("gpencil.stroke_arrange", text="Bring Forward").direction = 'UP'
601
602             # SW - Move stroke to color
603             col = pie.column(align=True)
604             col.operator("gpencil.stroke_change_color", text="Move to Color")
605
606             # SE - Join strokes
607             col = pie.column(align=True)
608             col.label("Join Strokes")
609             row = col.row()
610             row.operator("gpencil.stroke_join", text="Join").type = 'JOIN'
611             row.operator("gpencil.stroke_join", text="Join & Copy").type = 'JOINCOPY'
612             col.operator("gpencil.stroke_flip", text="Flip direction")
613
614             col.prop(gpd, "show_stroke_direction", text="Show drawing direction")
615
616
617 class GPENCIL_PIE_tools_more(Menu):
618     """A pie menu for accessing more Grease Pencil tools"""
619     bl_label = "More Grease Pencil Tools"
620
621     @classmethod
622     def poll(cls, context):
623         gpd = context.gpencil_data
624         return bool(gpd and gpd.use_stroke_edit_mode and context.editable_gpencil_strokes)
625
626     def draw(self, context):
627         layout = self.layout
628
629         pie = layout.menu_pie()
630         # gpd = context.gpencil_data
631
632         col = pie.column(align=True)
633         col.operator("gpencil.copy", icon='COPYDOWN', text="Copy")
634         col.operator("gpencil.paste", icon='PASTEDOWN', text="Paste")
635
636         col = pie.column(align=True)
637         col.operator("gpencil.select_more", icon='ZOOMIN')
638         col.operator("gpencil.select_less", icon='ZOOMOUT')
639
640         pie.operator("transform.mirror", icon='MOD_MIRROR')
641         pie.operator("transform.bend", icon='MOD_SIMPLEDEFORM')
642         pie.operator("transform.shear", icon='MOD_TRIANGULATE')
643         pie.operator("transform.tosphere", icon='MOD_MULTIRES')
644
645         pie.operator("gpencil.convert", icon='OUTLINER_OB_CURVE', text="Convert...")
646         pie.operator("wm.call_menu_pie", text="Back to Main Palette...").name = "GPENCIL_PIE_tool_palette"
647
648
649 class GPENCIL_PIE_sculpt(Menu):
650     """A pie menu for accessing Grease Pencil stroke sculpting settings"""
651     bl_label = "Grease Pencil Sculpt"
652
653     @classmethod
654     def poll(cls, context):
655         gpd = context.gpencil_data
656         return bool(gpd and gpd.use_stroke_edit_mode and context.editable_gpencil_strokes)
657
658     def draw(self, context):
659         layout = self.layout
660
661         pie = layout.menu_pie()
662
663         settings = context.tool_settings.gpencil_sculpt
664         brush = settings.brush
665
666         # W - Launch Sculpt Mode
667         col = pie.column()
668         # col.label("Tool:")
669         col.prop(settings, "tool", text="")
670         col.operator("gpencil.brush_paint", text="Sculpt", icon='SCULPTMODE_HLT')
671
672         # E - Common Settings
673         col = pie.column(align=True)
674         col.prop(brush, "size", slider=True)
675         row = col.row(align=True)
676         row.prop(brush, "strength", slider=True)
677         # row.prop(brush, "use_pressure_strength", text="", icon_only=True)
678         col.prop(brush, "use_falloff")
679         if settings.tool in {'SMOOTH', 'RANDOMIZE'}:
680             row = col.row(align=True)
681             row.prop(settings, "affect_position", text="Position", icon='MESH_DATA', toggle=True)
682             row.prop(settings, "affect_strength", text="Strength", icon='COLOR', toggle=True)
683             row.prop(settings, "affect_thickness", text="Thickness", icon='LINE_DATA', toggle=True)
684
685         # S - Change Brush Type Shortcuts
686         row = pie.row()
687         row.prop_enum(settings, "tool", value='GRAB')
688         row.prop_enum(settings, "tool", value='PUSH')
689         row.prop_enum(settings, "tool", value='CLONE')
690
691         # N - Change Brush Type Shortcuts
692         row = pie.row()
693         row.prop_enum(settings, "tool", value='SMOOTH')
694         row.prop_enum(settings, "tool", value='THICKNESS')
695         row.prop_enum(settings, "tool", value='STRENGTH')
696         row.prop_enum(settings, "tool", value='RANDOMIZE')
697
698
699 ###############################
700
701
702 class GPENCIL_MT_snap(Menu):
703     bl_label = "Snap"
704
705     def draw(self, context):
706         layout = self.layout
707
708         layout.operator("gpencil.snap_to_grid", text="Selection to Grid")
709         layout.operator("gpencil.snap_to_cursor", text="Selection to Cursor").use_offset = False
710         layout.operator("gpencil.snap_to_cursor", text="Selection to Cursor (Offset)").use_offset = True
711
712         layout.separator()
713
714         layout.operator("gpencil.snap_cursor_to_selected", text="Cursor to Selected")
715         layout.operator("view3d.snap_cursor_to_center", text="Cursor to Center")
716         layout.operator("view3d.snap_cursor_to_grid", text="Cursor to Grid")
717
718
719 class GPENCIL_MT_gpencil_edit_specials(Menu):
720     bl_label = "GPencil Specials"
721
722     def draw(self, context):
723         layout = self.layout
724         is_3d_view = context.space_data.type == 'VIEW_3D'
725
726         layout.operator_context = 'INVOKE_REGION_WIN'
727
728         layout.operator("gpencil.stroke_subdivide", text="Subdivide")
729
730         layout.separator()
731
732         layout.operator("gpencil.stroke_join", text="Join").type = 'JOIN'
733         layout.operator("gpencil.stroke_join", text="Join & Copy").type = 'JOINCOPY'
734         layout.operator("gpencil.stroke_flip", text="Flip Direction")
735
736         if is_3d_view:
737             layout.separator()
738             layout.operator("gpencil.reproject")
739
740
741 ###############################
742
743
744 class GPENCIL_UL_brush(UIList):
745     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
746         # assert(isinstance(item, bpy.types.GPencilBrush)
747         brush = item
748
749         if self.layout_type in {'DEFAULT', 'COMPACT'}:
750             row = layout.row(align=True)
751             row.prop(brush, "name", text="", emboss=False, icon='BRUSH_DATA')
752         elif self.layout_type == 'GRID':
753             layout.alignment = 'CENTER'
754             layout.label(text="", icon_value=icon)
755
756
757 class GPENCIL_UL_palettecolor(UIList):
758     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
759         # assert(isinstance(item, bpy.types.PaletteColor)
760         palcolor = item
761
762         if self.layout_type in {'DEFAULT', 'COMPACT'}:
763             if palcolor.lock:
764                 layout.active = False
765
766             split = layout.split(percentage=0.25)
767             row = split.row(align=True)
768             row.enabled = not palcolor.lock
769             row.prop(palcolor, "color", text="", emboss=palcolor.is_stroke_visible)
770             row.prop(palcolor, "fill_color", text="", emboss=palcolor.is_fill_visible)
771             split.prop(palcolor, "name", text="", emboss=False)
772
773             row = layout.row(align=True)
774             row.prop(palcolor, "lock", text="", emboss=False)
775             row.prop(palcolor, "hide", text="", emboss=False)
776             if palcolor.ghost is True:
777                 icon = 'GHOST_DISABLED'
778             else:
779                 icon = 'GHOST_ENABLED'
780             row.prop(palcolor, "ghost", text="", icon=icon, emboss=False)
781
782         elif self.layout_type == 'GRID':
783             layout.alignment = 'CENTER'
784             layout.label(text="", icon_value=icon)
785
786
787 class GPENCIL_UL_layer(UIList):
788     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
789         # assert(isinstance(item, bpy.types.GPencilLayer)
790         gpl = item
791
792         if self.layout_type in {'DEFAULT', 'COMPACT'}:
793             if gpl.lock:
794                 layout.active = False
795
796             row = layout.row(align=True)
797             if gpl.is_parented:
798                 icon = 'BONE_DATA'
799             else:
800                 icon = 'BLANK1'
801
802             row.label(text="", icon=icon)
803             row.prop(gpl, "info", text="", emboss=False)
804
805             row = layout.row(align=True)
806             row.prop(gpl, "lock", text="", emboss=False)
807             row.prop(gpl, "hide", text="", emboss=False)
808             row.prop(gpl, "unlock_color", text="", emboss=False)
809         elif self.layout_type == 'GRID':
810             layout.alignment = 'CENTER'
811             layout.label(text="", icon_value=icon)
812
813
814 class GPENCIL_MT_layer_specials(Menu):
815     bl_label = "Layer"
816
817     def draw(self, context):
818         layout = self.layout
819
820         layout.operator("gpencil.layer_duplicate", icon='COPY_ID')  # XXX: needs a dedicated icon
821
822         layout.separator()
823
824         layout.operator("gpencil.reveal", icon='RESTRICT_VIEW_OFF', text="Show All")
825         layout.operator("gpencil.hide", icon='RESTRICT_VIEW_ON', text="Hide Others").unselected = True
826
827         layout.separator()
828
829         layout.operator("gpencil.lock_all", icon='LOCKED', text="Lock All")
830         layout.operator("gpencil.unlock_all", icon='UNLOCKED', text="UnLock All")
831
832         layout.separator()
833
834         layout.operator("gpencil.layer_merge", icon='NLA', text="Merge Down")
835
836
837 class GPENCIL_MT_brush_specials(Menu):
838     bl_label = "Layer"
839
840     def draw(self, context):
841         layout = self.layout
842         layout.operator("gpencil.brush_copy", icon='PASTEDOWN', text="Copy current drawing brush")
843         layout.operator("gpencil.brush_presets_create", icon='HELP', text="Create a set of predefined brushes")
844
845
846 class GPENCIL_MT_palettecolor_specials(Menu):
847     bl_label = "Layer"
848
849     def draw(self, context):
850         layout = self.layout
851
852         layout.operator("gpencil.palettecolor_reveal", icon='RESTRICT_VIEW_OFF', text="Show All")
853         layout.operator("gpencil.palettecolor_hide", icon='RESTRICT_VIEW_ON', text="Hide Others").unselected = True
854
855         layout.separator()
856
857         layout.operator("gpencil.palettecolor_lock_all", icon='LOCKED', text="Lock All")
858         layout.operator("gpencil.palettecolor_unlock_all", icon='UNLOCKED', text="UnLock All")
859         layout.operator("gpencil.palettecolor_copy", icon='PASTEDOWN', text="Copy Color")
860
861         layout.separator()
862
863         layout.operator("gpencil.palettecolor_select", icon='COLOR', text="Select Strokes")
864         layout.operator("gpencil.stroke_change_color", icon='MAN_TRANS', text="Move to Color")
865
866
867 class GreasePencilDataPanel:
868     # subclass must set
869     # bl_space_type = 'IMAGE_EDITOR'
870     bl_label = "Grease Pencil Layers"
871     bl_region_type = 'UI'
872
873     @staticmethod
874     def draw_header(self, context):
875         self.layout.prop(context.space_data, "show_grease_pencil", text="")
876
877     @staticmethod
878     def draw(self, context):
879         layout = self.layout
880
881         # owner of Grease Pencil data
882         gpd_owner = context.gpencil_data_owner
883         gpd = context.gpencil_data
884
885         # Owner Selector
886         if context.space_data.type == 'VIEW_3D':
887             layout.prop(context.tool_settings, "grease_pencil_source", expand=True)
888         elif context.space_data.type == 'CLIP_EDITOR':
889             layout.prop(context.space_data, "grease_pencil_source", expand=True)
890
891         # Grease Pencil data selector
892         layout.template_ID(gpd_owner, "grease_pencil", new="gpencil.data_add", unlink="gpencil.data_unlink")
893
894         # Grease Pencil data...
895         if (gpd is None) or (not gpd.layers):
896             layout.operator("gpencil.layer_add", text="New Layer")
897         else:
898             self.draw_layers(context, layout, gpd)
899
900     def draw_layers(self, context, layout, gpd):
901         row = layout.row()
902
903         col = row.column()
904         if len(gpd.layers) >= 2:
905             layer_rows = 5
906         else:
907             layer_rows = 2
908         col.template_list("GPENCIL_UL_layer", "", gpd, "layers", gpd.layers, "active_index", rows=layer_rows)
909
910         col = row.column()
911
912         sub = col.column(align=True)
913         sub.operator("gpencil.layer_add", icon='ZOOMIN', text="")
914         sub.operator("gpencil.layer_remove", icon='ZOOMOUT', text="")
915
916         gpl = context.active_gpencil_layer
917         if gpl:
918             sub.menu("GPENCIL_MT_layer_specials", icon='DOWNARROW_HLT', text="")
919
920             if len(gpd.layers) > 1:
921                 col.separator()
922
923                 sub = col.column(align=True)
924                 sub.operator("gpencil.layer_move", icon='TRIA_UP', text="").type = 'UP'
925                 sub.operator("gpencil.layer_move", icon='TRIA_DOWN', text="").type = 'DOWN'
926
927                 col.separator()
928
929                 sub = col.column(align=True)
930                 sub.operator("gpencil.layer_isolate", icon='LOCKED', text="").affect_visibility = False
931                 sub.operator("gpencil.layer_isolate", icon='RESTRICT_VIEW_OFF', text="").affect_visibility = True
932
933         if gpl:
934             self.draw_layer(context, layout, gpl)
935
936     def draw_layer(self, context, layout, gpl):
937         row = layout.row(align=True)
938         row.prop(gpl, "opacity", text="Opacity", slider=True)
939
940         # Layer options
941         split = layout.split(percentage=0.5)
942         split.active = not gpl.lock
943         split.prop(gpl, "show_x_ray")
944         split.prop(gpl, "show_points")
945
946         # Offsets + Parenting (where available)
947         if context.space_data.type == 'VIEW_3D':
948             split = layout.split(percentage=0.5)
949         else:
950             split = layout.column()  # parenting is not available in 2D editors...
951         split.active = not gpl.lock
952
953         # Offsets - Color Tint
954         col = split.column()
955         subcol = col.column(align=True)
956         subcol.label("Tint")
957         subcol.enabled = not gpl.lock
958         subcol.prop(gpl, "tint_color", text="")
959         subcol.prop(gpl, "tint_factor", text="Factor", slider=True)
960
961         # Offsets - Thickness
962         row = col.row(align=True)
963         row.prop(gpl, "line_change", text="Thickness Change", slider=True)
964         row.operator("gpencil.stroke_apply_thickness", icon='STYLUS_PRESSURE', text="")
965
966         # Parenting 
967         if context.space_data.type == 'VIEW_3D':
968             col = split.column(align=True)
969             col.label(text="Parent:")
970             col.prop(gpl, "parent", text="")
971
972             sub = col.column()
973             sub.prop(gpl, "parent_type", text="")
974             parent = gpl.parent
975             if parent and gpl.parent_type == 'BONE' and parent.type == 'ARMATURE':
976                 sub.prop_search(gpl, "parent_bone", parent.data, "bones", text="")
977
978         layout.separator()
979
980         # Full-Row - Frame Locking (and Delete Frame)
981         row = layout.row(align=True)
982         row.active = not gpl.lock
983
984         if gpl.active_frame:
985             lock_status = iface_("Locked") if gpl.lock_frame else iface_("Unlocked")
986             lock_label = iface_("Frame: %d (%s)") % (gpl.active_frame.frame_number, lock_status)
987         else:
988             lock_label = iface_("Lock Frame")
989         row.prop(gpl, "lock_frame", text=lock_label, icon='UNLOCKED')
990         row.operator("gpencil.active_frame_delete", text="", icon='X')
991
992         layout.separator()
993
994         # Onion skinning
995         col = layout.column(align=True)
996         col.active = not gpl.lock
997
998         row = col.row()
999         row.prop(gpl, "use_onion_skinning")
1000         sub = row.row(align=True)
1001         icon = 'RESTRICT_RENDER_OFF' if gpl.use_ghosts_always else 'RESTRICT_RENDER_ON'
1002         sub.prop(gpl, "use_ghosts_always", text="", icon=icon)
1003         sub.prop(gpl, "use_ghost_custom_colors", text="", icon='COLOR')
1004
1005         split = col.split(percentage=0.5)
1006         split.active = gpl.use_onion_skinning
1007
1008         # - Before Frames
1009         sub = split.column(align=True)
1010         row = sub.row(align=True)
1011         row.active = gpl.use_ghost_custom_colors
1012         row.prop(gpl, "before_color", text="")
1013         sub.prop(gpl, "ghost_before_range", text="Before")
1014
1015         # - After Frames
1016         sub = split.column(align=True)
1017         row = sub.row(align=True)
1018         row.active = gpl.use_ghost_custom_colors
1019         row.prop(gpl, "after_color", text="")
1020         sub.prop(gpl, "ghost_after_range", text="After")
1021
1022
1023 class GreasePencilPaletteColorPanel:
1024     # subclass must set
1025     bl_label = "Grease Pencil Colors"
1026     bl_region_type = 'UI'
1027
1028     @classmethod
1029     def poll(cls, context):
1030         if context.gpencil_data is None:
1031             return False
1032
1033         gpd = context.gpencil_data
1034         return bool(gpd.layers.active)
1035
1036     @staticmethod
1037     def draw(self, context):
1038         layout = self.layout
1039         palette = context.active_gpencil_palette
1040
1041         if palette:
1042             row = layout.row(align=True)
1043             row.operator_context = 'EXEC_REGION_WIN'
1044             row.operator_menu_enum("gpencil.palette_change", "palette", text="", icon='COLOR')
1045             row.prop(palette, "name", text="")
1046             row.operator("gpencil.palette_add", icon='ZOOMIN', text="")
1047             row.operator("gpencil.palette_remove", icon='X', text="")
1048
1049             # Palette colors
1050             row = layout.row()
1051             col = row.column()
1052             if len(palette.colors) >= 2:
1053                 color_rows = 5
1054             else:
1055                 color_rows = 2
1056             col.template_list("GPENCIL_UL_palettecolor", "", palette, "colors", palette.colors, "active_index",
1057                               rows=color_rows)
1058
1059             col = row.column()
1060
1061             sub = col.column(align=True)
1062             sub.operator("gpencil.palettecolor_add", icon='ZOOMIN', text="")
1063             sub.operator("gpencil.palettecolor_remove", icon='ZOOMOUT', text="")
1064
1065             palcol = context.active_gpencil_palettecolor
1066             if palcol:
1067                 sub.menu("GPENCIL_MT_palettecolor_specials", icon='DOWNARROW_HLT', text="")
1068
1069             if len(palette.colors) > 1:
1070                 col.separator()
1071
1072                 sub = col.column(align=True)
1073                 sub.operator("gpencil.palettecolor_move", icon='TRIA_UP', text="").direction = 'UP'
1074                 sub.operator("gpencil.palettecolor_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
1075
1076                 row = layout.row()
1077                 sub = row.row(align=True)
1078                 sub.label(text="Isolate:") # based on active color only
1079                 sub.operator("gpencil.palettecolor_isolate", icon='LOCKED', text="").affect_visibility = False
1080                 sub.operator("gpencil.palettecolor_isolate", icon='RESTRICT_VIEW_OFF', text="").affect_visibility = True
1081                 sub = row.row(align=True)
1082                 sub.label(text="Lock:") # based on other stuff...
1083                 sub.operator("gpencil.stroke_lock_color", icon='BORDER_RECT', text="")
1084                 sub.operator("gpencil.palette_lock_layer", icon='COLOR', text="")
1085
1086             pcolor = palette.colors.active
1087             if pcolor:
1088                 self.draw_palettecolors(layout, pcolor)
1089
1090     # Draw palette colors
1091     def draw_palettecolors(self, layout, pcolor):
1092         # color settings
1093         split = layout.split(percentage=0.5)
1094         split.active = not pcolor.lock
1095
1096         # Column 1 - Stroke
1097         col = split.column(align=True)
1098         col.enabled = not pcolor.lock
1099         col.label(text="Stroke:")
1100         col.prop(pcolor, "color", text="")
1101         col.prop(pcolor, "alpha", slider=True)
1102
1103         # Column 2 - Fill
1104         col = split.column(align=True)
1105         col.enabled = not pcolor.lock
1106         col.label(text="Fill:")
1107         col.prop(pcolor, "fill_color", text="")
1108         col.prop(pcolor, "fill_alpha", text="Opacity", slider=True)
1109
1110         # Options
1111         split = layout.split(percentage=0.5)
1112         split.active = not pcolor.lock
1113
1114         col = split.column(align=True)
1115         col.active = not pcolor.lock
1116         col.prop(pcolor, "use_volumetric_strokes")
1117         col = split.column(align=True)
1118         col.active = not pcolor.lock
1119         col.prop(pcolor, "use_hq_fill")
1120
1121
1122 class GreasePencilToolsPanel:
1123     # For use in "2D" Editors without their own toolbar
1124     # subclass must set
1125     # bl_space_type = 'IMAGE_EDITOR'
1126     # bl_options = {'DEFAULT_CLOSED'}
1127     bl_label = "Grease Pencil Settings"
1128     bl_region_type = 'UI'
1129
1130     @classmethod
1131     def poll(cls, context):
1132         return (context.gpencil_data is not None)
1133
1134     @staticmethod
1135     def draw(self, context):
1136         layout = self.layout
1137
1138         # gpd_owner = context.gpencil_data_owner
1139         gpd = context.gpencil_data
1140
1141         layout.prop(gpd, "use_stroke_edit_mode", text="Enable Editing", icon='EDIT', toggle=True)
1142
1143         layout.separator()
1144
1145         layout.label("Proportional Edit:")
1146         row = layout.row()
1147         row.prop(context.tool_settings, "proportional_edit", text="")
1148         row.prop(context.tool_settings, "proportional_edit_falloff", text="")
1149
1150         layout.separator()
1151         layout.separator()
1152
1153         gpencil_active_brush_settings_simple(context, layout)
1154
1155         layout.separator()
1156
1157         gpencil_stroke_placement_settings(context, layout)
1158
1159
1160 classes = (
1161     GPENCIL_PIE_tool_palette,
1162     GPENCIL_PIE_settings_palette,
1163     GPENCIL_PIE_tools_more,
1164     GPENCIL_PIE_sculpt,
1165     GPENCIL_MT_snap,
1166     GPENCIL_MT_gpencil_edit_specials,
1167     GPENCIL_UL_brush,
1168     GPENCIL_UL_palettecolor,
1169     GPENCIL_UL_layer,
1170     GPENCIL_MT_layer_specials,
1171     GPENCIL_MT_brush_specials,
1172     GPENCIL_MT_palettecolor_specials,
1173 )
1174
1175 if __name__ == "__main__":  # only for live edit.
1176     from bpy.utils import register_class
1177     for cls in classes:
1178         register_class(cls)