Cleanup: unused imports
[blender.git] / release / scripts / startup / bl_ui / properties_data_gpencil.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 import bpy
21 from bpy.types import Menu, Panel, UIList
22 from rna_prop_ui import PropertyPanel
23
24 ###############################
25 # Base-Classes (for shared stuff - e.g. poll, attributes, etc.)
26
27
28 class DataButtonsPanel:
29     bl_space_type = 'PROPERTIES'
30     bl_region_type = 'WINDOW'
31     bl_context = "data"
32
33     @classmethod
34     def poll(cls, context):
35         return context.gpencil
36
37
38 class ObjectButtonsPanel:
39     bl_space_type = 'PROPERTIES'
40     bl_region_type = 'WINDOW'
41     bl_context = "data"
42
43     @classmethod
44     def poll(cls, context):
45         ob = context.object
46         return ob and ob.type == 'GPENCIL'
47
48
49 class LayerDataButtonsPanel:
50     bl_space_type = 'PROPERTIES'
51     bl_region_type = 'WINDOW'
52     bl_context = "data"
53
54     @classmethod
55     def poll(cls, context):
56         gpencil = context.gpencil
57         return gpencil and gpencil.layers.active
58
59
60 ###############################
61 # GP Object Properties Panels and Helper Classes
62
63 class DATA_PT_context_gpencil(DataButtonsPanel, Panel):
64     bl_label = ""
65     bl_options = {'HIDE_HEADER'}
66
67     def draw(self, context):
68         layout = self.layout
69
70         ob = context.object
71         gpencil = context.gpencil
72         space = context.space_data
73
74         if ob:
75             layout.template_ID(ob, "data")
76         else:
77             layout.template_ID(space, "pin_id")
78
79
80 class GPENCIL_MT_layer_context_menu(Menu):
81     bl_label = "Layer"
82
83     def draw(self, context):
84         layout = self.layout
85         gpd = context.gpencil
86
87         layout.operator("gpencil.layer_duplicate", icon='ADD')  # XXX: needs a dedicated icon
88
89         layout.separator()
90
91         layout.operator("gpencil.reveal", icon='RESTRICT_VIEW_OFF', text="Show All")
92         layout.operator("gpencil.hide", icon='RESTRICT_VIEW_ON', text="Hide Others").unselected = True
93
94         layout.separator()
95
96         layout.operator("gpencil.lock_all", icon='LOCKED', text="Lock All")
97         layout.operator("gpencil.unlock_all", icon='UNLOCKED', text="UnLock All")
98         layout.prop(gpd, "use_autolock_layers", text="Autolock Inactive Layers")
99
100         layout.separator()
101
102         layout.operator("gpencil.layer_merge", icon='SORT_ASC', text="Merge Down")
103
104         layout.separator()
105         layout.menu("VIEW3D_MT_gpencil_copy_layer")
106
107
108 class DATA_PT_gpencil_layers(DataButtonsPanel, Panel):
109     bl_label = "Layers"
110
111     def draw(self, context):
112         layout = self.layout
113         #layout.use_property_split = True
114         layout.use_property_decorate = False
115
116         gpd = context.gpencil
117
118         # Grease Pencil data...
119         if (gpd is None) or (not gpd.layers):
120             layout.operator("gpencil.layer_add", text="New Layer")
121         else:
122             self.draw_layers(context, layout, gpd)
123
124     def draw_layers(self, context, layout, gpd):
125
126         row = layout.row()
127
128         col = row.column()
129         layer_rows = 7
130         col.template_list("GPENCIL_UL_layer", "", gpd, "layers", gpd.layers, "active_index",
131                           rows=layer_rows, sort_reverse=True, sort_lock=True)
132
133         gpl = gpd.layers.active
134
135         if gpl:
136             srow = col.row(align=True)
137             srow.prop(gpl, "blend_mode", text="Blend")
138
139             srow = col.row(align=True)
140             srow.prop(gpl, "opacity", text="Opacity", slider=True)
141             srow.prop(gpl, "clamp_layer", text="",
142                       icon='MOD_MASK' if gpl.clamp_layer else 'LAYER_ACTIVE')
143
144             srow = col.row(align=True)
145             srow.prop(gpl, "use_solo_mode", text="Show Only On Keyframed")
146
147         col = row.column()
148
149         sub = col.column(align=True)
150         sub.operator("gpencil.layer_add", icon='ADD', text="")
151         sub.operator("gpencil.layer_remove", icon='REMOVE', text="")
152
153         if gpl:
154             sub.menu("GPENCIL_MT_layer_context_menu", icon='DOWNARROW_HLT', text="")
155
156             if len(gpd.layers) > 1:
157                 col.separator()
158
159                 sub = col.column(align=True)
160                 sub.operator("gpencil.layer_move", icon='TRIA_UP', text="").type = 'UP'
161                 sub.operator("gpencil.layer_move", icon='TRIA_DOWN', text="").type = 'DOWN'
162
163                 col.separator()
164
165                 sub = col.column(align=True)
166                 sub.operator("gpencil.layer_isolate", icon='LOCKED', text="").affect_visibility = False
167                 sub.operator("gpencil.layer_isolate", icon='RESTRICT_VIEW_ON', text="").affect_visibility = True
168
169
170 class DATA_PT_gpencil_layer_adjustments(LayerDataButtonsPanel, Panel):
171     bl_label = "Adjustments"
172     bl_parent_id = 'DATA_PT_gpencil_layers'
173     bl_options = {'DEFAULT_CLOSED'}
174
175     def draw(self, context):
176         layout = self.layout
177         layout.use_property_split = True
178         scene = context.scene
179
180         gpd = context.gpencil
181         gpl = gpd.layers.active
182         layout.active = not gpl.lock
183
184         # Layer options
185         # Offsets - Color Tint
186         layout.enabled = not gpl.lock
187         col = layout.column(align=True)
188         col.prop(gpl, "tint_color")
189         col.prop(gpl, "tint_factor", text="Factor", slider=True)
190
191         # Offsets - Thickness
192         col = layout.row(align=True)
193         col.prop(gpl, "line_change", text="Stroke Thickness")
194
195         col = layout.row(align=True)
196         col.prop(gpl, "pass_index")
197
198         col = layout.row(align=True)
199         col.prop_search(gpl, "viewlayer_render", scene, "view_layers", text="View Layer")
200
201         col = layout.row(align=True)
202         col.prop(gpl, "lock_material")
203
204
205 class DATA_PT_gpencil_layer_relations(LayerDataButtonsPanel, Panel):
206     bl_label = "Relations"
207     bl_parent_id = 'DATA_PT_gpencil_layers'
208     bl_options = {'DEFAULT_CLOSED'}
209
210     def draw(self, context):
211         layout = self.layout
212         layout.use_property_split = True
213         layout.use_property_decorate = False
214
215         gpd = context.gpencil
216         gpl = gpd.layers.active
217
218         col = layout.column()
219         col.active = not gpl.lock
220         col.prop(gpl, "parent")
221         col.prop(gpl, "parent_type", text="Type")
222         parent = gpl.parent
223
224         if parent and gpl.parent_type == 'BONE' and parent.type == 'ARMATURE':
225             col.prop_search(gpl, "parent_bone", parent.data, "bones", text="Bone")
226
227
228 class DATA_PT_gpencil_onion_skinning(DataButtonsPanel, Panel):
229     bl_label = "Onion Skinning"
230     bl_options = {'DEFAULT_CLOSED'}
231
232     def draw(self, context):
233         gpd = context.gpencil
234
235         layout = self.layout
236         layout.use_property_split = True
237         layout.enabled = gpd.users <= 1
238
239         if gpd.users > 1:
240             layout.label(text="Multiuser datablock not supported", icon='ERROR')
241
242         col = layout.column()
243         col.prop(gpd, "onion_mode")
244         col.prop(gpd, "onion_factor", text="Opacity", slider=True)
245
246         if gpd.onion_mode == 'ABSOLUTE':
247             col = layout.column(align=True)
248             col.prop(gpd, "ghost_before_range", text="Frames Before")
249             col.prop(gpd, "ghost_after_range", text="Frames After")
250         elif gpd.onion_mode == 'RELATIVE':
251             col = layout.column(align=True)
252             col.prop(gpd, "ghost_before_range", text="Keyframes Before")
253             col.prop(gpd, "ghost_after_range", text="Keyframes After")
254
255
256 class DATA_PT_gpencil_onion_skinning_custom_colors(DataButtonsPanel, Panel):
257     bl_parent_id = "DATA_PT_gpencil_onion_skinning"
258     bl_label = "Custom Colors"
259     bl_options = {'DEFAULT_CLOSED'}
260
261     def draw_header(self, context):
262         gpd = context.gpencil
263
264         self.layout.prop(gpd, "use_ghost_custom_colors", text="")
265
266     def draw(self, context):
267         gpd = context.gpencil
268
269         layout = self.layout
270         layout.use_property_split = True
271         layout.enabled = gpd.users <= 1 and gpd.use_ghost_custom_colors
272
273         layout.prop(gpd, "before_color", text="Before")
274         layout.prop(gpd, "after_color", text="After")
275
276
277 class DATA_PT_gpencil_onion_skinning_display(DataButtonsPanel, Panel):
278     bl_parent_id = "DATA_PT_gpencil_onion_skinning"
279     bl_label = "Display"
280     bl_options = {'DEFAULT_CLOSED'}
281
282     def draw(self, context):
283         gpd = context.gpencil
284
285         layout = self.layout
286         layout.use_property_split = True
287         layout.enabled = gpd.users <= 1
288
289         layout.prop(gpd, "use_ghosts_always", text="View In Render")
290
291         col = layout.column(align=True)
292         col.prop(gpd, "use_onion_fade", text="Fade")
293         sub = layout.column()
294         sub.active = gpd.onion_mode in {'RELATIVE', 'SELECTED'}
295         sub.prop(gpd, "use_onion_loop", text="Loop")
296
297
298 class GPENCIL_MT_gpencil_vertex_group(Menu):
299     bl_label = "GP Vertex Groups"
300
301     def draw(self, context):
302         layout = self.layout
303
304         layout.operator_context = 'EXEC_AREA'
305         layout.operator("object.vertex_group_add")
306
307         ob = context.active_object
308         if ob.vertex_groups.active:
309             layout.separator()
310
311             layout.operator("gpencil.vertex_group_assign", text="Assign to Active Group")
312             layout.operator("gpencil.vertex_group_remove_from", text="Remove from Active Group")
313
314             layout.separator()
315             layout.operator_menu_enum("object.vertex_group_set_active", "group", text="Set Active Group")
316             layout.operator("object.vertex_group_remove", text="Remove Active Group").all = False
317             layout.operator("object.vertex_group_remove", text="Remove All Groups").all = True
318
319             layout.separator()
320             layout.operator("gpencil.vertex_group_select", text="Select Points")
321             layout.operator("gpencil.vertex_group_deselect", text="Deselect Points")
322
323
324 class GPENCIL_UL_vgroups(UIList):
325     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
326         vgroup = item
327         if self.layout_type in {'DEFAULT', 'COMPACT'}:
328             layout.prop(vgroup, "name", text="", emboss=False, icon_value=icon)
329             # icon = 'LOCKED' if vgroup.lock_weight else 'UNLOCKED'
330             # layout.prop(vgroup, "lock_weight", text="", icon=icon, emboss=False)
331         elif self.layout_type == 'GRID':
332             layout.alignment = 'CENTER'
333             layout.label(text="", icon_value=icon)
334
335
336 class DATA_PT_gpencil_vertex_groups(ObjectButtonsPanel, Panel):
337     bl_label = "Vertex Groups"
338     bl_options = {'DEFAULT_CLOSED'}
339
340     def draw(self, context):
341         layout = self.layout
342
343         ob = context.object
344         group = ob.vertex_groups.active
345
346         rows = 2
347         if group:
348             rows = 4
349
350         row = layout.row()
351         row.template_list("GPENCIL_UL_vgroups", "", ob, "vertex_groups", ob.vertex_groups, "active_index", rows=rows)
352
353         col = row.column(align=True)
354         col.operator("object.vertex_group_add", icon='ADD', text="")
355         col.operator("object.vertex_group_remove", icon='REMOVE', text="").all = False
356
357         if ob.vertex_groups:
358             row = layout.row()
359
360             sub = row.row(align=True)
361             sub.operator("gpencil.vertex_group_assign", text="Assign")
362             sub.operator("gpencil.vertex_group_remove_from", text="Remove")
363
364             sub = row.row(align=True)
365             sub.operator("gpencil.vertex_group_select", text="Select")
366             sub.operator("gpencil.vertex_group_deselect", text="Deselect")
367
368             layout.prop(context.tool_settings, "vertex_group_weight", text="Weight")
369
370
371 class DATA_PT_gpencil_strokes(DataButtonsPanel, Panel):
372     bl_label = "Strokes"
373     bl_options = {'DEFAULT_CLOSED'}
374
375     def draw(self, context):
376         layout = self.layout
377         layout.use_property_split = True
378         layout.use_property_decorate = False
379
380         ob = context.object
381         gpd = context.gpencil
382
383         col = layout.column(align=True)
384         col.prop(gpd, "stroke_depth_order")
385
386         if ob:
387             col.enabled = not ob.show_in_front
388
389         col = layout.column(align=True)
390         col.prop(gpd, "stroke_thickness_space")
391         sub = col.column()
392         sub.active = gpd.stroke_thickness_space == 'WORLDSPACE'
393         sub.prop(gpd, "pixel_factor", text="Thickness Scale")
394
395         layout.prop(gpd, "use_force_fill_recalc", text="Force Fill Update")
396         layout.prop(gpd, "use_adaptive_uv", text="Adaptive UVs")
397
398
399 class DATA_PT_gpencil_display(DataButtonsPanel, Panel):
400     bl_label = "Viewport Display"
401     bl_options = {'DEFAULT_CLOSED'}
402
403     def draw(self, context):
404         layout = self.layout
405         layout.use_property_split = True
406         layout.use_property_decorate = False
407
408         gpd = context.gpencil
409         gpl = gpd.layers.active
410
411         layout.prop(gpd, "edit_line_color", text="Edit Line Color")
412         if gpl:
413             layout.prop(gpd, "show_stroke_direction", text="Show Stroke Directions")
414
415
416 class DATA_PT_gpencil_canvas(DataButtonsPanel, Panel):
417     bl_label = "Canvas"
418     bl_parent_id = 'DATA_PT_gpencil_display'
419     bl_options = {'DEFAULT_CLOSED'}
420
421     def draw(self, context):
422         layout = self.layout
423         layout.use_property_split = True
424         layout.use_property_decorate = False
425         gpd = context.gpencil
426         grid = gpd.grid
427
428         row = layout.row(align=True)
429         col = row.column()
430         col.prop(grid, "color", text="Color")
431         col.prop(grid, "scale", text="Scale")
432         col.prop(grid, "offset")
433         row = layout.row(align=True)
434         col = row.column()
435         col.prop(grid, "lines", text="Subdivisions")
436
437
438 class DATA_PT_custom_props_gpencil(DataButtonsPanel, PropertyPanel, Panel):
439     _context_path = "object.data"
440     _property_type = bpy.types.GreasePencil
441
442 ###############################
443
444
445 classes = (
446     DATA_PT_context_gpencil,
447     DATA_PT_gpencil_layers,
448     DATA_PT_gpencil_onion_skinning,
449     DATA_PT_gpencil_onion_skinning_custom_colors,
450     DATA_PT_gpencil_onion_skinning_display,
451     DATA_PT_gpencil_layer_adjustments,
452     DATA_PT_gpencil_layer_relations,
453     DATA_PT_gpencil_vertex_groups,
454     DATA_PT_gpencil_strokes,
455     DATA_PT_gpencil_display,
456     DATA_PT_gpencil_canvas,
457     DATA_PT_custom_props_gpencil,
458
459     GPENCIL_UL_vgroups,
460
461     GPENCIL_MT_layer_context_menu,
462     GPENCIL_MT_gpencil_vertex_group,
463 )
464
465 if __name__ == "__main__":  # only for live edit.
466     from bpy.utils import register_class
467     for cls in classes:
468         register_class(cls)