Workbench: clean up the viewport shading code
[blender.git] / release / scripts / startup / bl_ui / properties_collection.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 Panel
22
23
24 class CollectionButtonsPanel:
25     bl_space_type = 'PROPERTIES'
26     bl_region_type = 'WINDOW'
27     bl_context = "collection"
28
29
30 def get_collection_from_context(context):
31     active_object = context.active_object
32
33     if active_object and active_object.dupli_group and context.space_data.collection_context == 'GROUP':
34         group = active_object.dupli_group
35         return group.view_layer.collections.active
36     else:
37         return context.layer_collection
38
39
40 class COLLECTION_PT_context_collection(CollectionButtonsPanel, Panel):
41     bl_label = ""
42     bl_options = {'HIDE_HEADER'}
43
44     def draw(self, context):
45         layout = self.layout
46         space = context.space_data
47         active_object = context.active_object
48
49         if active_object and active_object.dupli_group:
50             split = layout.split(percentage=0.2)
51             split.row().prop(space, "collection_context", expand=True)
52             layout = split
53
54         collection = get_collection_from_context(context)
55         name = collection.name
56         if name == 'Master Collection':
57             layout.label(text=name, icon='COLLAPSEMENU')
58         else:
59             layout.prop(collection, "name", text="", icon='COLLAPSEMENU')
60
61
62 class COLLECTION_PT_clay_settings(CollectionButtonsPanel, Panel):
63     bl_label = "Render Settings"
64     COMPAT_ENGINES = {'BLENDER_CLAY'}
65
66     @classmethod
67     def poll(cls, context):
68         return context.view_render.engine in cls.COMPAT_ENGINES
69
70     def draw(self, context):
71         layout = self.layout
72         scene_props = context.scene.collection_properties['BLENDER_CLAY']
73         collection = get_collection_from_context(context)
74         collection_props = collection.engine_overrides['BLENDER_CLAY']
75
76         col = layout.column()
77         col.template_override_property(collection_props, scene_props, "matcap_icon", custom_template="icon_view")
78         col.template_override_property(collection_props, scene_props, "matcap_rotation")
79         col.template_override_property(collection_props, scene_props, "matcap_hue")
80         col.template_override_property(collection_props, scene_props, "matcap_saturation")
81         col.template_override_property(collection_props, scene_props, "matcap_value")
82         col.template_override_property(collection_props, scene_props, "ssao_factor_cavity")
83         col.template_override_property(collection_props, scene_props, "ssao_factor_edge")
84         col.template_override_property(collection_props, scene_props, "ssao_distance")
85         col.template_override_property(collection_props, scene_props, "ssao_attenuation")
86         col.template_override_property(collection_props, scene_props, "hair_brightness_randomness")
87
88
89 class COLLECTION_PT_workbench_settings(CollectionButtonsPanel, Panel):
90     bl_label = "Workbench Settings"
91
92     def draw(self, context):
93         layout = self.layout
94         scene_props = context.scene.collection_properties['BLENDER_WORKBENCH']
95         collection = get_collection_from_context(context)
96         collection_props = collection.engine_overrides['BLENDER_WORKBENCH']
97
98         col = layout.column()
99         col.template_override_property(collection_props, scene_props, "object_color")
100
101
102 class COLLECTION_PT_object_mode_settings(CollectionButtonsPanel, Panel):
103     bl_label = "Object Mode Settings"
104
105     @classmethod
106     def poll(cls, context):
107         ob = context.object
108         return ob and ob.mode == 'OBJECT'
109
110     def draw(self, context):
111         layout = self.layout
112         scene_props = context.scene.collection_properties['ObjectMode']
113         collection = get_collection_from_context(context)
114         collection_props = collection.engine_overrides['ObjectMode']
115
116         col = layout.column()
117         col.template_override_property(collection_props, scene_props, "show_wire")
118         col.template_override_property(collection_props, scene_props, "show_backface_culling")
119
120
121 class COLLECTION_PT_edit_mode_settings(CollectionButtonsPanel, Panel):
122     bl_label = "Edit Mode Settings"
123
124     @classmethod
125     def poll(cls, context):
126         ob = context.object
127         return ob and ob.mode == 'EDIT'
128
129     def draw(self, context):
130         layout = self.layout
131         scene_props = context.scene.collection_properties['EditMode']
132         collection = get_collection_from_context(context)
133         collection_props = collection.engine_overrides['EditMode']
134
135         col = layout.column()
136         col.template_override_property(collection_props, scene_props, "show_occlude_wire")
137         col.template_override_property(collection_props, scene_props, "backwire_opacity")
138         col.template_override_property(collection_props, scene_props, "face_normals_show")
139         col.template_override_property(collection_props, scene_props, "vert_normals_show")
140         col.template_override_property(collection_props, scene_props, "loop_normals_show")
141         col.template_override_property(collection_props, scene_props, "normals_length")
142         col.template_override_property(collection_props, scene_props, "show_weight")
143
144
145 class COLLECTION_PT_paint_weight_mode_settings(CollectionButtonsPanel, Panel):
146     bl_label = "Weight Paint Mode Settings"
147
148     @classmethod
149     def poll(cls, context):
150         ob = context.object
151         return ob and ob.mode == 'WEIGHT_PAINT'
152
153     def draw(self, context):
154         layout = self.layout
155         scene_props = context.scene.collection_properties['WeightPaintMode']
156         collection = get_collection_from_context(context)
157         collection_props = collection.engine_overrides['WeightPaintMode']
158
159         col = layout.column()
160         col.template_override_property(collection_props, scene_props, "use_shading")
161         col.template_override_property(collection_props, scene_props, "use_wire")
162
163
164 class COLLECTION_PT_paint_vertex_mode_settings(CollectionButtonsPanel, Panel):
165     bl_label = "Vertex Paint Mode Settings"
166
167     @classmethod
168     def poll(cls, context):
169         ob = context.object
170         return ob and ob.mode == 'VERTEX_PAINT'
171
172     def draw(self, context):
173         layout = self.layout
174         scene_props = context.scene.collection_properties['VertexPaintMode']
175         collection = get_collection_from_context(context)
176         collection_props = collection.engine_overrides['VertexPaintMode']
177
178         col = layout.column()
179         col.template_override_property(collection_props, scene_props, "use_shading")
180         col.template_override_property(collection_props, scene_props, "use_wire")
181
182
183 classes = (
184     COLLECTION_PT_context_collection,
185     COLLECTION_PT_clay_settings,
186     COLLECTION_PT_workbench_settings,
187     COLLECTION_PT_object_mode_settings,
188     COLLECTION_PT_edit_mode_settings,
189     COLLECTION_PT_paint_weight_mode_settings,
190     COLLECTION_PT_paint_vertex_mode_settings,
191 )
192
193 if __name__ == "__main__":  # only for live edit.
194     from bpy.utils import register_class
195     for cls in classes:
196         register_class(cls)