GPencil: Changes in Fill and new 3D Cursor View Plane
[blender.git] / release / scripts / startup / bl_ui / space_topbar.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 Header, Menu, Panel
22
23
24 class TOPBAR_HT_upper_bar(Header):
25     bl_space_type = 'TOPBAR'
26
27     def draw(self, context):
28         region = context.region
29
30         if region.alignment == 'RIGHT':
31             self.draw_right(context)
32         else:
33             self.draw_left(context)
34
35     def draw_left(self, context):
36         layout = self.layout
37
38         window = context.window
39         screen = context.screen
40
41         layout.operator("wm.splash", text="", icon='BLENDER', emboss=False)
42
43         TOPBAR_MT_editor_menus.draw_collapsible(context, layout)
44
45         layout.separator()
46
47         if not screen.show_fullscreen:
48             layout.template_ID_tabs(
49                 window, "workspace",
50                 new="workspace.add",
51                 menu="TOPBAR_MT_workspace_menu",
52             )
53         else:
54             layout.operator(
55                 "screen.back_to_previous",
56                 icon='SCREEN_BACK',
57                 text="Back to Previous",
58             )
59
60     def draw_right(self, context):
61         layout = self.layout
62
63         window = context.window
64         screen = context.screen
65         scene = window.scene
66
67         # If statusbar is hidden, still show messages at the top
68         if not screen.show_statusbar:
69             layout.template_reports_banner()
70             layout.template_running_jobs()
71
72         # Active workspace view-layer is retrieved through window, not through workspace.
73         layout.template_ID(window, "scene", new="scene.new", unlink="scene.delete")
74
75         row = layout.row(align=True)
76         row.template_search(
77             window, "view_layer",
78             scene, "view_layers",
79             new="scene.view_layer_add",
80             unlink="scene.view_layer_remove")
81
82
83 class TOPBAR_HT_lower_bar(Header):
84     bl_space_type = 'TOPBAR'
85     bl_region_type = 'WINDOW'
86
87     def draw(self, context):
88         region = context.region
89
90         if region.alignment == 'RIGHT':
91             self.draw_right(context)
92         else:
93             self.draw_left(context)
94
95     def draw_left(self, context):
96         layout = self.layout
97
98         # Active Tool
99         # -----------
100         from .space_toolsystem_common import ToolSelectPanelHelper
101         tool = ToolSelectPanelHelper.draw_active_tool_header(context, layout)
102         tool_space_type = 'VIEW_3D' if tool is None else tool.space_type
103         tool_mode = context.mode if tool is None else tool.mode
104
105         # Object Mode Options
106         # -------------------
107
108         # Example of how tool_settings can be accessed as pop-overs.
109
110         # TODO(campbell): editing options should be after active tool options
111         # (obviously separated for from the users POV)
112         draw_fn = getattr(getattr(_draw_left_context_mode, tool_space_type, None), tool_mode, None)
113         if draw_fn is not None:
114             draw_fn(context, layout, tool)
115
116         if tool_space_type == 'VIEW_3D':
117             # Note: general mode options should be added to 'draw_right'.
118             if tool_mode == 'SCULPT':
119                 if (tool is not None) and tool.has_datablock:
120                     layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".paint_common", category="")
121             elif tool_mode == 'PAINT_VERTEX':
122                 if (tool is not None) and tool.has_datablock:
123                     layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".paint_common", category="")
124             elif tool_mode == 'PAINT_WEIGHT':
125                 if (tool is not None) and tool.has_datablock:
126                     layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".paint_common", category="")
127             elif tool_mode == 'PAINT_TEXTURE':
128                 if (tool is not None) and tool.has_datablock:
129                     layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".paint_common", category="")
130             elif tool_mode == 'EDIT_ARMATURE':
131                 pass
132             elif tool_mode == 'EDIT_CURVE':
133                 pass
134             elif tool_mode == 'EDIT_MESH':
135                 pass
136             elif tool_mode == 'POSE':
137                 pass
138             elif tool_mode == 'PARTICLE':
139                 # Disable, only shows "Brush" panel, which is already in the top-bar.
140                 # if tool.has_datablock:
141                 #     layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".paint_common", category="")
142                 pass
143             elif tool_mode == 'PAINT_GPENCIL':
144                 if (tool is not None) and tool.has_datablock:
145                     layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".greasepencil_paint", category="")
146             elif tool_mode == 'SCULPT_GPENCIL':
147                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".greasepencil_sculpt", category="")
148             elif tool_mode == 'WEIGHT_GPENCIL':
149                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".greasepencil_weight", category="")
150         elif tool_space_type == 'IMAGE_EDITOR':
151             if tool_mode == 'PAINT':
152                 if (tool is not None) and tool.has_datablock:
153                     layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".paint_common_2d", category="")
154             elif context.uv_sculpt_object is not None:
155                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".uv_sculpt", category="")
156
157     def draw_right(self, context):
158         layout = self.layout
159
160         # Active Tool
161         # -----------
162         from .space_toolsystem_common import ToolSelectPanelHelper
163         tool = ToolSelectPanelHelper.tool_active_from_context(context)
164         tool_space_type = 'VIEW_3D' if tool is None else tool.space_type
165         tool_mode = context.mode if tool is None else tool.mode
166
167         if tool_space_type == 'VIEW_3D':
168             if tool_mode == 'SCULPT':
169                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".sculpt_mode", category="")
170             elif tool_mode == 'PAINT_VERTEX':
171                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".vertexpaint", category="")
172             elif tool_mode == 'PAINT_WEIGHT':
173                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".weightpaint", category="")
174             elif tool_mode == 'PAINT_TEXTURE':
175                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".imagepaint", category="")
176             elif tool_mode == 'EDIT_TEXT':
177                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".text_edit", category="")
178             elif tool_mode == 'EDIT_ARMATURE':
179                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".armature_edit", category="")
180             elif tool_mode == 'EDIT_METABALL':
181                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".mball_edit", category="")
182             elif tool_mode == 'EDIT_LATTICE':
183                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".lattice_edit", category="")
184             elif tool_mode == 'EDIT_CURVE':
185                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".curve_edit", category="")
186             elif tool_mode == 'EDIT_MESH':
187                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".mesh_edit", category="")
188             elif tool_mode == 'POSE':
189                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".posemode", category="")
190             elif tool_mode == 'PARTICLE':
191                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".particlemode", category="")
192             elif tool_mode == 'OBJECT':
193                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".objectmode", category="")
194             elif tool_mode in {'PAINT_GPENCIL', 'EDIT_GPENCIL', 'SCULPT_GPENCIL', 'WEIGHT_GPENCIL'}:
195                 # Grease pencil layer.
196                 gpl = context.active_gpencil_layer
197                 if gpl and gpl.info is not None:
198                     text = gpl.info
199                     maxw = 25
200                     if len(text) > maxw:
201                         text = text[:maxw - 5] + '..' + text[-3:]
202                 else:
203                     text = ""
204
205                 layout.label(text="Layer:")
206                 sub = layout.row()
207                 sub.ui_units_x = 8
208                 sub.popover(
209                     panel="TOPBAR_PT_gpencil_layers",
210                     text=text,
211                 )
212         elif tool_space_type == 'IMAGE_EDITOR':
213             if tool_mode == 'PAINT':
214                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".imagepaint_2d", category="")
215
216
217 class _draw_left_context_mode:
218     class VIEW_3D:
219         @staticmethod
220         def SCULPT(context, layout, tool):
221             if (tool is None) or (not tool.has_datablock):
222                 return
223
224             paint = context.tool_settings.sculpt
225             layout.template_ID_preview(paint, "brush", rows=3, cols=8, hide_buttons=True)
226
227             brush = paint.brush
228             if brush is None:
229                 return
230
231             from .properties_paint_common import (
232                 brush_basic_sculpt_settings,
233             )
234             brush_basic_sculpt_settings(layout, context, brush, compact=True)
235
236         @staticmethod
237         def PAINT_TEXTURE(context, layout, tool):
238             if (tool is None) or (not tool.has_datablock):
239                 return
240
241             paint = context.tool_settings.image_paint
242             layout.template_ID_preview(paint, "brush", rows=3, cols=8, hide_buttons=True)
243
244             brush = paint.brush
245             if brush is None:
246                 return
247
248             from .properties_paint_common import (
249                 UnifiedPaintPanel,
250                 brush_basic_texpaint_settings,
251             )
252             capabilities = brush.image_paint_capabilities
253             if capabilities.has_color:
254                 UnifiedPaintPanel.prop_unified_color(layout, context, brush, "color", text="")
255             brush_basic_texpaint_settings(layout, context, brush, compact=True)
256
257         @staticmethod
258         def PAINT_VERTEX(context, layout, tool):
259             if (tool is None) or (not tool.has_datablock):
260                 return
261
262             paint = context.tool_settings.vertex_paint
263             layout.template_ID_preview(paint, "brush", rows=3, cols=8, hide_buttons=True)
264
265             brush = paint.brush
266             if brush is None:
267                 return
268
269             from .properties_paint_common import (
270                 UnifiedPaintPanel,
271                 brush_basic_vpaint_settings,
272             )
273             capabilities = brush.vertex_paint_capabilities
274             if capabilities.has_color:
275                 UnifiedPaintPanel.prop_unified_color(layout, context, brush, "color", text="")
276             brush_basic_vpaint_settings(layout, context, brush, compact=True)
277
278         @staticmethod
279         def PAINT_WEIGHT(context, layout, tool):
280             if (tool is None) or (not tool.has_datablock):
281                 return
282
283             paint = context.tool_settings.weight_paint
284             layout.template_ID_preview(paint, "brush", rows=3, cols=8, hide_buttons=True)
285             brush = paint.brush
286             if brush is None:
287                 return
288
289             from .properties_paint_common import brush_basic_wpaint_settings
290             brush_basic_wpaint_settings(layout, context, brush, compact=True)
291
292         @staticmethod
293         def PAINT_GPENCIL(context, layout, tool):
294             if tool is None:
295                 return
296
297             # is_paint = True
298             # FIXME: tools must use their own UI drawing!
299             if tool.idname in {"builtin.line", "builtin.box", "builtin.circle", "builtin.arc", "builtin.curve"}:
300                 # is_paint = False
301                 pass
302             elif tool.idname == "Cutter":
303                 row = layout.row(align=True)
304                 row.prop(context.tool_settings.gpencil_sculpt, "intersection_threshold")
305                 return
306             elif not tool.has_datablock:
307                 return
308
309             paint = context.tool_settings.gpencil_paint
310             brush = paint.brush
311             if brush is None:
312                 return
313
314             gp_settings = brush.gpencil_settings
315
316             def draw_color_selector():
317                 ma = gp_settings.material
318                 row = layout.row(align=True)
319
320                 icon_id = 0
321                 if ma:
322                     icon_id = ma.id_data.preview.icon_id
323                     txt_ma = ma.name
324                     maxw = 25
325                     if len(txt_ma) > maxw:
326                         txt_ma = txt_ma[:maxw - 5] + '..' + txt_ma[-3:]
327                 else:
328                     txt_ma = ""
329
330                 row.label(text="Material:")
331                 sub = row.row()
332                 sub.ui_units_x = 8
333                 sub.popover(
334                     panel="TOPBAR_PT_gpencil_materials",
335                     text=txt_ma,
336                     icon_value=icon_id,
337                 )
338
339                 row.prop(gp_settings, "use_material_pin", text="")
340
341             row = layout.row(align=True)
342             tool_settings = context.scene.tool_settings
343             settings = tool_settings.gpencil_paint
344             row.template_ID_preview(settings, "brush", rows=3, cols=8, hide_buttons=True)
345
346             if brush.gpencil_tool in {'FILL', 'DRAW'}:
347                 draw_color_selector()
348
349             from .properties_paint_common import (
350                 brush_basic_gpencil_paint_settings,
351             )
352             brush_basic_gpencil_paint_settings(layout, context, brush, compact=True)
353
354             # FIXME: tools must use their own UI drawing!
355             if tool.idname in {"builtin.arc", "builtin.curve", "builtin.line", "builtin.box", "builtin.circle"}:
356                 settings = context.tool_settings.gpencil_sculpt
357                 row = layout.row(align=True)
358                 row.prop(settings, "use_thickness_curve", text="", icon='CURVE_DATA')
359                 sub = row.row(align=True)
360                 sub.active = settings.use_thickness_curve
361                 sub.popover(
362                     panel="TOPBAR_PT_gpencil_primitive",
363                     text="Thickness Profile"
364                 )
365                 
366             if brush.gpencil_tool == 'FILL':
367                 settings = context.tool_settings.gpencil_sculpt
368                 row = layout.row(align=True)
369                 sub = row.row(align=True)
370                 sub.popover(
371                     panel="TOPBAR_PT_gpencil_fill",
372                     text="Fill Options"
373                 )
374
375         @staticmethod
376         def SCULPT_GPENCIL(context, layout, tool):
377             if (tool is None) or (not tool.has_datablock):
378                 return
379             tool_settings = context.tool_settings
380             settings = tool_settings.gpencil_sculpt
381             brush = settings.brush
382
383             from .properties_paint_common import (
384                 brush_basic_gpencil_sculpt_settings,
385             )
386             brush_basic_gpencil_sculpt_settings(layout, context, brush, compact=True)
387
388         @staticmethod
389         def WEIGHT_GPENCIL(context, layout, tool):
390             if (tool is None) or (not tool.has_datablock):
391                 return
392             tool_settings = context.tool_settings
393             settings = tool_settings.gpencil_sculpt
394             brush = settings.brush
395
396             from .properties_paint_common import (
397                 brush_basic_gpencil_weight_settings,
398             )
399             brush_basic_gpencil_weight_settings(layout, context, brush, compact=True)
400
401         @staticmethod
402         def PARTICLE(context, layout, tool):
403             if (tool is None) or (not tool.has_datablock):
404                 return
405
406             # See: 'VIEW3D_PT_tools_brush', basically a duplicate
407             settings = context.tool_settings.particle_edit
408             brush = settings.brush
409             tool = settings.tool
410             if tool != 'NONE':
411                 layout.prop(brush, "size", slider=True)
412                 if tool == 'ADD':
413                     layout.prop(brush, "count")
414
415                     layout.prop(settings, "use_default_interpolate")
416                     layout.prop(brush, "steps", slider=True)
417                     layout.prop(settings, "default_key_count", slider=True)
418                 else:
419                     layout.prop(brush, "strength", slider=True)
420
421                     if tool == 'LENGTH':
422                         layout.row().prop(brush, "length_mode", expand=True)
423                     elif tool == 'PUFF':
424                         layout.row().prop(brush, "puff_mode", expand=True)
425                         layout.prop(brush, "use_puff_volume")
426                     elif tool == 'COMB':
427                         # Note: actually in 'Options' panel,
428                         # disabled when used in popover.
429                         row = layout.row()
430                         row.active = settings.is_editable
431                         row.prop(settings, "use_emitter_deflect", text="Deflect Emitter")
432                         sub = row.row(align=True)
433                         sub.active = settings.use_emitter_deflect
434                         sub.prop(settings, "emitter_distance", text="Distance")
435
436     class IMAGE_EDITOR:
437         @staticmethod
438         def VIEW(context, layout, tool):
439             tool_settings = context.tool_settings
440             if tool_settings.use_uv_sculpt:
441                 if context.mode == 'EDIT_MESH':
442                     uv_sculpt = tool_settings.uv_sculpt
443                     brush = uv_sculpt.brush
444                     if brush:
445                         from .properties_paint_common import UnifiedPaintPanel
446
447                         row = layout.row(align=True)
448                         UnifiedPaintPanel.prop_unified_size(row, context, brush, "size", slider=True)
449                         UnifiedPaintPanel.prop_unified_size(row, context, brush, "use_pressure_size", text="")
450
451                         row = layout.row(align=True)
452                         UnifiedPaintPanel.prop_unified_strength(row, context, brush, "strength", slider=True)
453                         UnifiedPaintPanel.prop_unified_strength(row, context, brush, "use_pressure_strength", text="")
454
455         @staticmethod
456         def PAINT(context, layout, tool):
457             if (tool is None) or (not tool.has_datablock):
458                 return
459
460             paint = context.tool_settings.image_paint
461             layout.template_ID_preview(paint, "brush", rows=3, cols=8, hide_buttons=True)
462
463             brush = paint.brush
464             if brush is None:
465                 return
466
467             from .properties_paint_common import (
468                 UnifiedPaintPanel,
469                 brush_basic_texpaint_settings,
470             )
471             capabilities = brush.image_paint_capabilities
472             if capabilities.has_color:
473                 UnifiedPaintPanel.prop_unified_color(layout, context, brush, "color", text="")
474             brush_basic_texpaint_settings(layout, context, brush, compact=True)
475
476
477 class TOPBAR_PT_gpencil_layers(Panel):
478     bl_space_type = 'VIEW_3D'
479     bl_region_type = 'HEADER'
480     bl_label = "Layers"
481     bl_ui_units_x = 14
482
483     @classmethod
484     def poll(cls, context):
485         if context.gpencil_data is None:
486             return False
487
488         ob = context.object
489         if ob is not None and ob.type == 'GPENCIL':
490             return True
491
492         return False
493
494     def draw(self, context):
495         layout = self.layout
496         gpd = context.gpencil_data
497
498         # Grease Pencil data...
499         if (gpd is None) or (not gpd.layers):
500             layout.operator("gpencil.layer_add", text="New Layer")
501         else:
502             self.draw_layers(context, layout, gpd)
503
504     def draw_layers(self, context, layout, gpd):
505         row = layout.row()
506
507         col = row.column()
508         layer_rows = 10
509         col.template_list("GPENCIL_UL_layer", "", gpd, "layers", gpd.layers, "active_index",
510                           rows=layer_rows, sort_reverse=True, sort_lock=True)
511
512         gpl = context.active_gpencil_layer
513         if gpl:
514             srow = col.row(align=True)
515             srow.prop(gpl, "blend_mode", text="Blend")
516
517             srow = col.row(align=True)
518             srow.prop(gpl, "opacity", text="Opacity", slider=True)
519             srow.prop(gpl, "clamp_layer", text="",
520                       icon='MOD_MASK' if gpl.clamp_layer else 'LAYER_ACTIVE')
521
522             srow = col.row(align=True)
523             srow.prop(gpl, "use_solo_mode", text="Show Only On Keyframed")
524
525         col = row.column()
526
527         sub = col.column(align=True)
528         sub.operator("gpencil.layer_add", icon='ADD', text="")
529         sub.operator("gpencil.layer_remove", icon='REMOVE', text="")
530
531         gpl = context.active_gpencil_layer
532         if gpl:
533             sub.menu("GPENCIL_MT_layer_context_menu", icon='DOWNARROW_HLT', text="")
534
535             if len(gpd.layers) > 1:
536                 col.separator()
537
538                 sub = col.column(align=True)
539                 sub.operator("gpencil.layer_move", icon='TRIA_UP', text="").type = 'UP'
540                 sub.operator("gpencil.layer_move", icon='TRIA_DOWN', text="").type = 'DOWN'
541
542                 col.separator()
543
544                 sub = col.column(align=True)
545                 sub.operator("gpencil.layer_isolate", icon='LOCKED', text="").affect_visibility = False
546                 sub.operator("gpencil.layer_isolate", icon='HIDE_OFF', text="").affect_visibility = True
547
548
549 class TOPBAR_MT_editor_menus(Menu):
550     bl_idname = "TOPBAR_MT_editor_menus"
551     bl_label = ""
552
553     def draw(self, context):
554         layout = self.layout
555         layout.menu("TOPBAR_MT_file")
556         layout.menu("TOPBAR_MT_edit")
557
558         layout.menu("TOPBAR_MT_render")
559
560         layout.menu("TOPBAR_MT_window")
561         layout.menu("TOPBAR_MT_help")
562
563
564 class TOPBAR_MT_file(Menu):
565     bl_label = "File"
566
567     def draw(self, context):
568         layout = self.layout
569
570         layout.operator_context = 'INVOKE_AREA'
571         layout.menu("TOPBAR_MT_file_new", text="New", icon='FILE_NEW')
572         layout.operator("wm.open_mainfile", text="Open...", icon='FILE_FOLDER')
573         layout.menu("TOPBAR_MT_file_open_recent")
574         layout.operator("wm.revert_mainfile")
575         layout.operator("wm.recover_last_session")
576         layout.operator("wm.recover_auto_save", text="Recover Auto Save...")
577
578         layout.separator()
579
580         layout.operator_context = 'EXEC_AREA' if context.blend_data.is_saved else 'INVOKE_AREA'
581         layout.operator("wm.save_mainfile", text="Save", icon='FILE_TICK')
582
583         layout.operator_context = 'INVOKE_AREA'
584         layout.operator("wm.save_as_mainfile", text="Save As...")
585         layout.operator_context = 'INVOKE_AREA'
586         layout.operator("wm.save_as_mainfile", text="Save Copy...").copy = True
587
588         layout.separator()
589         layout.operator_context = 'INVOKE_AREA'
590
591         if any(bpy.utils.app_template_paths()):
592             app_template = context.preferences.app_template
593         else:
594             app_template = None
595
596         if app_template:
597             layout.label(text=bpy.path.display_name(app_template, has_ext=False))
598             layout.operator("wm.save_homefile")
599             layout.operator(
600                 "wm.read_factory_settings",
601                 text="Load Factory Settings",
602             ).app_template = app_template
603         else:
604             layout.operator("wm.save_homefile")
605             layout.operator("wm.read_factory_settings")
606
607         layout.separator()
608
609         layout.operator("preferences.app_template_install", text="Install Application Template...")
610
611         layout.separator()
612
613         layout.operator_context = 'INVOKE_AREA'
614         layout.operator("wm.link", text="Link...", icon='LINK_BLEND')
615         layout.operator("wm.append", text="Append...", icon='APPEND_BLEND')
616         layout.menu("TOPBAR_MT_file_previews")
617
618         layout.separator()
619
620         layout.menu("TOPBAR_MT_file_import", icon='IMPORT')
621         layout.menu("TOPBAR_MT_file_export", icon='EXPORT')
622
623         layout.separator()
624
625         layout.menu("TOPBAR_MT_file_external_data")
626
627         layout.separator()
628
629         layout.operator_context = 'EXEC_AREA'
630         if bpy.data.is_dirty:
631             layout.operator_context = 'INVOKE_SCREEN'  # quit dialog
632         layout.operator("wm.quit_blender", text="Quit", icon='QUIT')
633
634
635 class TOPBAR_MT_file_new(Menu):
636     bl_label = "New File"
637
638     @staticmethod
639     def app_template_paths():
640         import os
641
642         template_paths = bpy.utils.app_template_paths()
643
644         # expand template paths
645         app_templates = []
646         for path in template_paths:
647             for d in os.listdir(path):
648                 if d.startswith(("__", ".")):
649                     continue
650                 template = os.path.join(path, d)
651                 if os.path.isdir(template):
652                     # template_paths_expand.append(template)
653                     app_templates.append(d)
654
655         return sorted(app_templates)
656
657     def draw_ex(layout, context, *, use_splash=False, use_more=False):
658         layout.operator_context = 'EXEC_DEFAULT'
659
660         # Limit number of templates in splash screen, spill over into more menu.
661         paths = TOPBAR_MT_file_new.app_template_paths()
662         splash_limit = 5
663
664         if use_splash:
665             icon = 'FILE_NEW'
666             show_more = len(paths) > (splash_limit - 1)
667             if show_more:
668                 paths = paths[:splash_limit - 2]
669         elif use_more:
670             icon = 'FILE_NEW'
671             paths = paths[splash_limit - 2:]
672             show_more = False
673         else:
674             icon = 'NONE'
675             show_more = False
676
677         # Draw application templates.
678         if not use_more:
679             props = layout.operator("wm.read_homefile", text="General", icon=icon)
680             props.app_template = ""
681
682         for d in paths:
683             props = layout.operator(
684                 "wm.read_homefile",
685                 text=bpy.path.display_name(d),
686                 icon=icon,
687             )
688             props.app_template = d
689
690         if show_more:
691             layout.menu("TOPBAR_MT_templates_more", text="...")
692
693     def draw(self, context):
694         TOPBAR_MT_file_new.draw_ex(self.layout, context)
695
696
697 class TOPBAR_MT_templates_more(Menu):
698     bl_label = "Templates"
699
700     def draw(self, context):
701         bpy.types.TOPBAR_MT_file_new.draw_ex(self.layout, context, use_more=True)
702
703
704 class TOPBAR_MT_file_import(Menu):
705     bl_idname = "TOPBAR_MT_file_import"
706     bl_label = "Import"
707
708     def draw(self, context):
709         if bpy.app.build_options.collada:
710             self.layout.operator("wm.collada_import", text="Collada (Default) (.dae)")
711         if bpy.app.build_options.alembic:
712             self.layout.operator("wm.alembic_import", text="Alembic (.abc)")
713
714
715 class TOPBAR_MT_file_export(Menu):
716     bl_idname = "TOPBAR_MT_file_export"
717     bl_label = "Export"
718
719     def draw(self, context):
720         if bpy.app.build_options.collada:
721             self.layout.operator("wm.collada_export", text="Collada (Default) (.dae)")
722         if bpy.app.build_options.alembic:
723             self.layout.operator("wm.alembic_export", text="Alembic (.abc)")
724
725
726 class TOPBAR_MT_file_external_data(Menu):
727     bl_label = "External Data"
728
729     def draw(self, context):
730         layout = self.layout
731
732         icon = 'CHECKBOX_HLT' if bpy.data.use_autopack else 'CHECKBOX_DEHLT'
733         layout.operator("file.autopack_toggle", icon=icon)
734
735         layout.separator()
736
737         pack_all = layout.row()
738         pack_all.operator("file.pack_all")
739         pack_all.active = not bpy.data.use_autopack
740
741         unpack_all = layout.row()
742         unpack_all.operator("file.unpack_all")
743         unpack_all.active = not bpy.data.use_autopack
744
745         layout.separator()
746
747         layout.operator("file.make_paths_relative")
748         layout.operator("file.make_paths_absolute")
749         layout.operator("file.report_missing_files")
750         layout.operator("file.find_missing_files")
751
752
753 class TOPBAR_MT_file_previews(Menu):
754     bl_label = "Data Previews"
755
756     def draw(self, context):
757         layout = self.layout
758
759         layout.operator("wm.previews_ensure")
760         layout.operator("wm.previews_batch_generate")
761
762         layout.separator()
763
764         layout.operator("wm.previews_clear")
765         layout.operator("wm.previews_batch_clear")
766
767
768 class TOPBAR_MT_render(Menu):
769     bl_label = "Render"
770
771     def draw(self, context):
772         layout = self.layout
773
774         rd = context.scene.render
775
776         layout.operator("render.render", text="Render Image", icon='RENDER_STILL').use_viewport = True
777         props = layout.operator("render.render", text="Render Animation", icon='RENDER_ANIMATION')
778         props.animation = True
779         props.use_viewport = True
780
781         layout.separator()
782
783         layout.operator("sound.mixdown", text="Render Audio...")
784
785         layout.separator()
786
787         layout.operator("render.view_show", text="View Render")
788         layout.operator("render.play_rendered_anim", text="View Animation")
789         layout.prop_menu_enum(rd, "display_mode", text="Display Mode")
790
791         layout.separator()
792
793         layout.prop(rd, "use_lock_interface", text="Lock Interface")
794
795
796 class TOPBAR_MT_edit(Menu):
797     bl_label = "Edit"
798
799     def draw(self, context):
800         layout = self.layout
801
802         layout.operator("ed.undo")
803         layout.operator("ed.redo")
804
805         layout.separator()
806
807         layout.operator("ed.undo_history", text="Undo History...")
808
809         layout.separator()
810
811         layout.operator("screen.repeat_last")
812         layout.operator("screen.repeat_history", text="Repeat History...")
813
814         layout.separator()
815
816         layout.operator("screen.redo_last", text="Adjust Last Operation...")
817
818         layout.separator()
819
820         layout.operator("wm.search_menu", text="Operator Search...", icon='VIEWZOOM')
821
822         layout.separator()
823
824         # Should move elsewhere (impacts outliner & 3D view).
825         tool_settings = context.tool_settings
826         layout.prop(tool_settings, "lock_object_mode")
827
828         layout.separator()
829
830         layout.operator("screen.userpref_show", text="Preferences...", icon='PREFERENCES')
831
832
833 class TOPBAR_MT_window(Menu):
834     bl_label = "Window"
835
836     def draw(self, context):
837         import sys
838
839         layout = self.layout
840
841         layout.operator("wm.window_new")
842         layout.operator("wm.window_new_main")
843
844         layout.separator()
845
846         layout.operator("wm.window_fullscreen_toggle", icon='FULLSCREEN_ENTER')
847
848         layout.separator()
849
850         layout.operator("screen.workspace_cycle", text="Next Workspace").direction = 'NEXT'
851         layout.operator("screen.workspace_cycle", text="Previous Workspace").direction = 'PREV'
852
853         layout.separator()
854
855         layout.prop(context.screen, "show_topbar")
856         layout.prop(context.screen, "show_statusbar")
857
858         layout.separator()
859
860         layout.operator("screen.screenshot")
861
862         if sys.platform[:3] == "win":
863             layout.separator()
864             layout.operator("wm.console_toggle", icon='CONSOLE')
865
866         if context.scene.render.use_multiview:
867             layout.separator()
868             layout.operator("wm.set_stereo_3d")
869
870
871 class TOPBAR_MT_help(Menu):
872     bl_label = "Help"
873
874     def draw(self, context):
875         # If 'url_prefill_from_blender' becomes slow it could be made into a separate operator
876         # to avoid constructing the bug report just to show this menu.
877         from bl_ui_utils.bug_report_url import url_prefill_from_blender
878
879         layout = self.layout
880
881         show_developer = context.preferences.view.show_developer_ui
882
883         layout.operator(
884             "wm.url_open", text="Manual", icon='HELP',
885         ).url = "https://docs.blender.org/manual/en/dev/"
886
887         layout.operator(
888             "wm.url_open", text="Report a Bug", icon='URL',
889         ).url = url_prefill_from_blender()
890
891         layout.separator()
892
893         layout.operator(
894             "wm.url_open", text="User Communities", icon='URL',
895         ).url = "https://www.blender.org/community/"
896         layout.operator(
897             "wm.url_open", text="Developer Community", icon='URL',
898         ).url = "https://www.blender.org/get-involved/developers/"
899
900         layout.separator()
901
902         layout.operator(
903             "wm.url_open", text="Blender Website", icon='URL',
904         ).url = "https://www.blender.org"
905         layout.operator(
906             "wm.url_open", text="Release Notes", icon='URL',
907         ).url = "https://www.blender.org/download/releases/%d-%d/" % bpy.app.version[:2]
908         layout.operator(
909             "wm.url_open", text="Credits", icon='URL',
910         ).url = "https://www.blender.org/about/credits/"
911
912         layout.separator()
913
914         layout.operator(
915             "wm.url_open", text="Blender Store", icon='URL',
916         ).url = "https://store.blender.org"
917         layout.operator(
918             "wm.url_open", text="Development Fund", icon='URL'
919         ).url = "https://fund.blender.org"
920         layout.operator(
921             "wm.url_open", text="Donate", icon='URL',
922         ).url = "https://www.blender.org/foundation/donation-payment/"
923
924         layout.separator()
925
926         if show_developer:
927             layout.operator(
928                 "wm.url_open", text="Python API Reference", icon='URL',
929             ).url = bpy.types.WM_OT_doc_view._prefix
930
931             layout.operator("wm.operator_cheat_sheet", icon='TEXT')
932
933         layout.operator("wm.sysinfo")
934
935         layout.separator()
936
937         layout.operator("wm.splash", icon='BLENDER')
938
939
940 class TOPBAR_MT_file_context_menu(Menu):
941     bl_label = "File Context Menu"
942
943     def draw(self, context):
944         layout = self.layout
945
946         layout.operator_context = 'INVOKE_AREA'
947         layout.operator("wm.read_homefile", text="New", icon='FILE_NEW')
948         layout.operator("wm.open_mainfile", text="Open...", icon='FILE_FOLDER')
949
950         layout.separator()
951
952         layout.operator("wm.link", text="Link...", icon='LINK_BLEND')
953         layout.operator("wm.append", text="Append...", icon='APPEND_BLEND')
954
955         layout.separator()
956
957         layout.menu("TOPBAR_MT_file_import", icon='IMPORT')
958         layout.menu("TOPBAR_MT_file_export", icon='EXPORT')
959
960
961 class TOPBAR_MT_window_context_menu(Menu):
962     bl_label = "Window Context Menu"
963
964     def draw(self, context):
965         layout = self.layout
966
967         layout.operator_context = 'EXEC_AREA'
968
969         layout.operator("wm.window_new")
970         layout.operator("wm.window_new_main")
971
972         layout.operator_context = 'INVOKE_AREA'
973
974         layout.operator("screen.area_dupli", icon='DUPLICATE')
975
976         layout.separator()
977
978         layout.operator("screen.area_split", text="Horizontal Split").direction = 'HORIZONTAL'
979         layout.operator("screen.area_split", text="Vertical Split").direction = 'VERTICAL'
980
981         layout.separator()
982
983         layout.operator("wm.window_fullscreen_toggle", icon='FULLSCREEN_ENTER')
984
985         layout.separator()
986
987         layout.operator("screen.userpref_show", text="Preferences...", icon='PREFERENCES')
988
989
990 class TOPBAR_MT_workspace_menu(Menu):
991     bl_label = "Workspace"
992
993     def draw(self, context):
994         layout = self.layout
995
996         layout.operator("workspace.duplicate", text="Duplicate", icon='DUPLICATE')
997         if len(bpy.data.workspaces) > 1:
998             layout.operator("workspace.delete", text="Delete", icon='REMOVE')
999
1000         layout.separator()
1001
1002         layout.operator("workspace.reorder_to_front", text="Reorder to Front", icon='TRIA_LEFT_BAR')
1003         layout.operator("workspace.reorder_to_back", text="Reorder to Back", icon='TRIA_RIGHT_BAR')
1004
1005         layout.separator()
1006
1007         # For key binding discoverability.
1008         props = layout.operator("screen.workspace_cycle", text="Previous Workspace")
1009         props.direction = 'PREV'
1010         props = layout.operator("screen.workspace_cycle", text="Next Workspace")
1011         props.direction = 'NEXT'
1012
1013
1014 class TOPBAR_PT_active_tool(Panel):
1015     bl_space_type = 'PROPERTIES'
1016     bl_region_type = 'WINDOW'
1017     bl_category = ""
1018     bl_context = ".active_tool"  # dot on purpose (access from tool settings)
1019     bl_label = "Active Tool"
1020     bl_options = {'HIDE_HEADER'}
1021
1022     def draw(self, context):
1023         layout = self.layout
1024
1025         # Panel display of topbar tool settings.
1026         # currently displays in tool settings, keep here since the same functionality is used for the topbar.
1027
1028         layout.use_property_split = True
1029         layout.use_property_decorate = False
1030
1031         from .space_toolsystem_common import ToolSelectPanelHelper
1032         ToolSelectPanelHelper.draw_active_tool_header(context, layout, show_tool_name=True)
1033
1034
1035 # Grease Pencil Object - Primitive curve
1036 class TOPBAR_PT_gpencil_primitive(Panel):
1037     bl_space_type = 'VIEW_3D'
1038     bl_region_type = 'HEADER'
1039     bl_label = "Primitives"
1040
1041     def draw(self, context):
1042         settings = context.tool_settings.gpencil_sculpt
1043
1044         layout = self.layout
1045         # Curve
1046         layout.template_curve_mapping(settings, "thickness_primitive_curve", brush=True)
1047
1048 # Grease Pencil Fill
1049 class TOPBAR_PT_gpencil_fill(Panel):
1050     bl_space_type = 'VIEW_3D'
1051     bl_region_type = 'HEADER'
1052     bl_label = "Advanced"
1053
1054     @staticmethod
1055     def draw(self, context):
1056         paint = context.tool_settings.gpencil_paint
1057         brush = paint.brush
1058         gp_settings = brush.gpencil_settings
1059
1060         layout = self.layout
1061         # Fill
1062         row = layout.row(align=True)
1063         row.prop(gp_settings, "fill_factor", text="Resolution")
1064         if gp_settings.fill_draw_mode != 'STROKE':
1065             row = layout.row(align=True)
1066             row.prop(gp_settings, "show_fill", text="Ignore Transparent Strokes")
1067             row = layout.row(align=True)
1068             row.prop(gp_settings, "fill_threshold", text="Threshold")
1069
1070
1071 classes = (
1072     TOPBAR_HT_upper_bar,
1073     TOPBAR_HT_lower_bar,
1074     TOPBAR_MT_file_context_menu,
1075     TOPBAR_MT_window_context_menu,
1076     TOPBAR_MT_workspace_menu,
1077     TOPBAR_MT_editor_menus,
1078     TOPBAR_MT_file,
1079     TOPBAR_MT_file_new,
1080     TOPBAR_MT_templates_more,
1081     TOPBAR_MT_file_import,
1082     TOPBAR_MT_file_export,
1083     TOPBAR_MT_file_external_data,
1084     TOPBAR_MT_file_previews,
1085     TOPBAR_MT_edit,
1086     TOPBAR_MT_render,
1087     TOPBAR_MT_window,
1088     TOPBAR_MT_help,
1089     TOPBAR_PT_active_tool,
1090     TOPBAR_PT_gpencil_layers,
1091     TOPBAR_PT_gpencil_primitive,
1092     TOPBAR_PT_gpencil_fill,
1093 )
1094
1095 if __name__ == "__main__":  # only for live edit.
1096     from bpy.utils import register_class
1097     for cls in classes:
1098         register_class(cls)