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>
20import bpy
21from bpy.types import Panel
22from rna_prop_ui import PropertyPanel
23
24
25class DataButtonsPanel:
26    bl_space_type = 'PROPERTIES'
27    bl_region_type = 'WINDOW'
28    bl_context = "data"
29
30    @classmethod
31    def poll(cls, context):
32        engine = context.engine
33        return context.speaker and (engine in cls.COMPAT_ENGINES)
34
35
36class DATA_PT_context_speaker(DataButtonsPanel, Panel):
37    bl_label = ""
38    bl_options = {'HIDE_HEADER'}
39    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
40
41    def draw(self, context):
42        layout = self.layout
43
44        ob = context.object
45        speaker = context.speaker
46        space = context.space_data
47
48        if ob:
49            layout.template_ID(ob, "data")
50        elif speaker:
51            layout.template_ID(space, "pin_id")
52
53
54class DATA_PT_speaker(DataButtonsPanel, Panel):
55    bl_label = "Sound"
56    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
57
58    def draw(self, context):
59        layout = self.layout
60
61        speaker = context.speaker
62
63        layout.template_ID(speaker, "sound", open="sound.open_mono")
64
65        layout.use_property_split = True
66
67        layout.prop(speaker, "muted")
68
69        col = layout.column()
70        col.active = not speaker.muted
71        col.prop(speaker, "volume", slider=True)
72        col.prop(speaker, "pitch")
73
74
75class DATA_PT_distance(DataButtonsPanel, Panel):
76    bl_label = "Distance"
77    bl_options = {'DEFAULT_CLOSED'}
78    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
79
80    def draw(self, context):
81        layout = self.layout
82
83        layout.use_property_split = True
84
85        speaker = context.speaker
86        layout.active = not speaker.muted
87
88        col = layout.column()
89        sub = col.column(align=True)
90        sub.prop(speaker, "volume_min", slider=True, text="Volume Min")
91        sub.prop(speaker, "volume_max", slider=True, text="Max")
92        col.prop(speaker, "attenuation")
93
94        col.separator()
95        col.prop(speaker, "distance_max", text="Max Distance")
96        col.prop(speaker, "distance_reference", text="Distance Reference")
97
98
99class DATA_PT_cone(DataButtonsPanel, Panel):
100    bl_label = "Cone"
101    bl_options = {'DEFAULT_CLOSED'}
102    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
103
104    def draw(self, context):
105        layout = self.layout
106
107        layout.use_property_split = True
108
109        speaker = context.speaker
110        layout.active = not speaker.muted
111
112        col = layout.column()
113
114        sub = col.column(align=True)
115        sub.prop(speaker, "cone_angle_outer", text="Angle Outer")
116        sub.prop(speaker, "cone_angle_inner", text="Inner")
117
118        col.separator()
119
120        col.prop(speaker, "cone_volume_outer", slider=True)
121
122
123class DATA_PT_custom_props_speaker(DataButtonsPanel, PropertyPanel, Panel):
124    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
125    _context_path = "object.data"
126    _property_type = bpy.types.Speaker
127
128
129classes = (
130    DATA_PT_context_speaker,
131    DATA_PT_speaker,
132    DATA_PT_distance,
133    DATA_PT_cone,
134    DATA_PT_custom_props_speaker,
135)
136
137if __name__ == "__main__":  # only for live edit.
138    from bpy.utils import register_class
139    for cls in classes:
140        register_class(cls)
141