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