*More single column stuff.
[blender.git] / release / scripts / ui / properties_data_lamp.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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21
22 narrowui = 180
23
24
25 class DataButtonsPanel(bpy.types.Panel):
26     bl_space_type = 'PROPERTIES'
27     bl_region_type = 'WINDOW'
28     bl_context = "data"
29
30     def poll(self, context):
31         return context.lamp
32
33
34 class DATA_PT_preview(DataButtonsPanel):
35     bl_label = "Preview"
36
37     def draw(self, context):
38         self.layout.template_preview(context.lamp)
39
40
41 class DATA_PT_context_lamp(DataButtonsPanel):
42     bl_label = ""
43     bl_show_header = False
44
45     def draw(self, context):
46         layout = self.layout
47
48         ob = context.object
49         lamp = context.lamp
50         space = context.space_data
51         col2 = context.region.width > narrowui
52
53
54         if col2:
55             split = layout.split(percentage=0.65)
56             if ob:
57                 split.template_ID(ob, "data")
58                 split.itemS()
59             elif lamp:
60                 split.template_ID(space, "pin_id")
61                 split.itemS()
62         else:
63             if ob:
64                 layout.template_ID(ob, "data")
65             elif lamp:
66                 layout.template_ID(space, "pin_id")
67
68
69 class DATA_PT_lamp(DataButtonsPanel):
70     bl_label = "Lamp"
71
72     def draw(self, context):
73         layout = self.layout
74
75         lamp = context.lamp
76         col2 = context.region.width > narrowui
77
78         if col2:
79             layout.itemR(lamp, "type", expand=True)
80         else:
81             layout.itemR(lamp, "type", text="")
82
83         split = layout.split()
84
85         col = split.column()
86         sub = col.column()
87         sub.itemR(lamp, "color", text="")
88         sub.itemR(lamp, "energy")
89
90         if lamp.type in ('POINT', 'SPOT'):
91             sub.itemL(text="Falloff:")
92             sub.itemR(lamp, "falloff_type", text="")
93             sub.itemR(lamp, "distance")
94
95             if lamp.falloff_type == 'LINEAR_QUADRATIC_WEIGHTED':
96                 col.itemL(text="Attenuation Factors:")
97                 sub = col.column(align=True)
98                 sub.itemR(lamp, "linear_attenuation", slider=True, text="Linear")
99                 sub.itemR(lamp, "quadratic_attenuation", slider=True, text="Quadratic")
100
101             col.itemR(lamp, "sphere")
102
103         if lamp.type == 'AREA':
104             col.itemR(lamp, "distance")
105             col.itemR(lamp, "gamma")
106
107         if col2:
108             col = split.column()
109         col.itemR(lamp, "negative")
110         col.itemR(lamp, "layer", text="This Layer Only")
111         col.itemR(lamp, "specular")
112         col.itemR(lamp, "diffuse")
113
114
115 class DATA_PT_sunsky(DataButtonsPanel):
116     bl_label = "Sky & Atmosphere"
117
118     def poll(self, context):
119         lamp = context.lamp
120         return (lamp and lamp.type == 'SUN')
121
122     def draw(self, context):
123         layout = self.layout
124
125         lamp = context.lamp.sky
126         col2 = context.region.width > narrowui
127
128         layout.itemR(lamp, "sky")
129
130         row = layout.row()
131         row.active = lamp.sky or lamp.atmosphere
132         row.itemR(lamp, "atmosphere_turbidity", text="Turbidity")
133
134         split = layout.split()
135
136         col = split.column()
137         col.active = lamp.sky
138         col.itemL(text="Blending:")
139         sub = col.column()
140         sub.itemR(lamp, "sky_blend_type", text="")
141         sub.itemR(lamp, "sky_blend", text="Factor")
142
143         col.itemL(text="Color Space:")
144         sub = col.column()
145         sub.row().itemR(lamp, "sky_color_space", expand=True)
146         sub.itemR(lamp, "sky_exposure", text="Exposure")
147
148         if col2:
149             col = split.column()
150         col.active = lamp.sky
151         col.itemL(text="Horizon:")
152         sub = col.column()
153         sub.itemR(lamp, "horizon_brightness", text="Brightness")
154         sub.itemR(lamp, "spread", text="Spread")
155
156         col.itemL(text="Sun:")
157         sub = col.column()
158         sub.itemR(lamp, "sun_brightness", text="Brightness")
159         sub.itemR(lamp, "sun_size", text="Size")
160         sub.itemR(lamp, "backscattered_light", slider=True, text="Back Light")
161
162         layout.itemS()
163
164         layout.itemR(lamp, "atmosphere")
165
166         split = layout.split()
167
168         col = split.column()
169         col.active = lamp.atmosphere
170         col.itemL(text="Intensity:")
171         col.itemR(lamp, "sun_intensity", text="Sun")
172         col.itemR(lamp, "atmosphere_distance_factor", text="Distance")
173
174         if col2:
175             col = split.column()
176         col.active = lamp.atmosphere
177         col.itemL(text="Scattering:")
178         sub = col.column(align=True)
179         sub.itemR(lamp, "atmosphere_inscattering", slider=True, text="Inscattering")
180         sub.itemR(lamp, "atmosphere_extinction", slider=True, text="Extinction")
181
182
183 class DATA_PT_shadow(DataButtonsPanel):
184     bl_label = "Shadow"
185
186     def poll(self, context):
187         lamp = context.lamp
188         return (lamp and lamp.type in ('POINT', 'SUN', 'SPOT', 'AREA'))
189
190     def draw(self, context):
191         layout = self.layout
192
193         lamp = context.lamp
194         col2 = context.region.width > narrowui
195
196         if col2:
197             layout.itemR(lamp, "shadow_method", expand=True)
198         else:
199             layout.itemR(lamp, "shadow_method", text="")
200
201         if lamp.shadow_method != 'NOSHADOW':
202             split = layout.split()
203
204             col = split.column()
205             col.itemR(lamp, "shadow_color", text="")
206
207             if col2:
208                 col = split.column()
209             col.itemR(lamp, "shadow_layer", text="This Layer Only")
210             col.itemR(lamp, "only_shadow")
211
212         if lamp.shadow_method == 'RAY_SHADOW':
213             col = layout.column()
214             col.itemL(text="Sampling:")
215             if col2:
216                 col.row().itemR(lamp, "shadow_ray_sampling_method", expand=True)
217             else:
218                 col.itemR(lamp, "shadow_ray_sampling_method", text="")
219
220             if lamp.type in ('POINT', 'SUN', 'SPOT'):
221                 split = layout.split()
222
223                 col = split.column()
224                 col.itemR(lamp, "shadow_soft_size", text="Soft Size")
225
226                 col.itemR(lamp, "shadow_ray_samples", text="Samples")
227                 if lamp.shadow_ray_sampling_method == 'ADAPTIVE_QMC':
228                     col.itemR(lamp, "shadow_adaptive_threshold", text="Threshold")
229                 if col2:
230                     col = split.column()
231
232             elif lamp.type == 'AREA':
233                 split = layout.split()
234
235                 col = split.column()
236
237                 if lamp.shape == 'SQUARE':
238                     col.itemR(lamp, "shadow_ray_samples_x", text="Samples")
239                 elif lamp.shape == 'RECTANGLE':
240                     col.itemR(lamp, "shadow_ray_samples_x", text="Samples X")
241                     col.itemR(lamp, "shadow_ray_samples_y", text="Samples Y")
242
243                 if lamp.shadow_ray_sampling_method == 'ADAPTIVE_QMC':
244                     col.itemR(lamp, "shadow_adaptive_threshold", text="Threshold")
245                     if col2:
246                         col = split.column()
247
248                 elif lamp.shadow_ray_sampling_method == 'CONSTANT_JITTERED':
249                     if col2:
250                         col = split.column()
251                     col.itemR(lamp, "umbra")
252                     col.itemR(lamp, "dither")
253                     col.itemR(lamp, "jitter")
254                 else:
255                     if col2:
256                         col = split.column()
257
258
259         elif lamp.shadow_method == 'BUFFER_SHADOW':
260             col = layout.column()
261             col.itemL(text="Buffer Type:")
262             if col2:
263                 col.row().itemR(lamp, "shadow_buffer_type", expand=True)
264             else:
265                 col.row().itemR(lamp, "shadow_buffer_type", text="")
266
267             if lamp.shadow_buffer_type in ('REGULAR', 'HALFWAY', 'DEEP'):
268                 split = layout.split()
269
270                 col = split.column()
271                 col.itemL(text="Filter Type:")
272                 col.itemR(lamp, "shadow_filter_type", text="")
273                 sub = col.column(align=True)
274                 sub.itemR(lamp, "shadow_buffer_soft", text="Soft")
275                 sub.itemR(lamp, "shadow_buffer_bias", text="Bias")
276
277                 if col2:
278                     col = split.column()
279                 col.itemL(text="Sample Buffers:")
280                 col.itemR(lamp, "shadow_sample_buffers", text="")
281                 sub = col.column(align=True)
282                 sub.itemR(lamp, "shadow_buffer_size", text="Size")
283                 sub.itemR(lamp, "shadow_buffer_samples", text="Samples")
284                 if lamp.shadow_buffer_type == 'DEEP':
285                     col.itemR(lamp, "compression_threshold")
286
287             elif lamp.shadow_buffer_type == 'IRREGULAR':
288                 layout.itemR(lamp, "shadow_buffer_bias", text="Bias")
289
290             split = layout.split()
291
292             col = split.column()
293             col.itemR(lamp, "auto_clip_start", text="Autoclip Start")
294             sub = col.column()
295             sub.active = not lamp.auto_clip_start
296             sub.itemR(lamp, "shadow_buffer_clip_start", text="Clip Start")
297
298             if col2:
299                 col = split.column()
300             col.itemR(lamp, "auto_clip_end", text="Autoclip End")
301             sub = col.column()
302             sub.active = not lamp.auto_clip_end
303             sub.itemR(lamp, "shadow_buffer_clip_end", text=" Clip End")
304
305
306 class DATA_PT_area(DataButtonsPanel):
307     bl_label = "Area Shape"
308
309     def poll(self, context):
310         lamp = context.lamp
311         return (lamp and lamp.type == 'AREA')
312
313     def draw(self, context):
314         layout = self.layout
315
316         lamp = context.lamp
317
318         split = layout.split()
319
320         col = split.column()
321         col.row().itemR(lamp, "shape", expand=True)
322
323         sub = col.column(align=True)
324         if (lamp.shape == 'SQUARE'):
325             sub.itemR(lamp, "size")
326         elif (lamp.shape == 'RECTANGLE'):
327             sub.itemR(lamp, "size", text="Size X")
328             sub.itemR(lamp, "size_y", text="Size Y")
329
330
331 class DATA_PT_spot(DataButtonsPanel):
332     bl_label = "Spot Shape"
333
334     def poll(self, context):
335         lamp = context.lamp
336         return (lamp and lamp.type == 'SPOT')
337
338     def draw(self, context):
339         layout = self.layout
340
341         lamp = context.lamp
342         col2 = context.region.width > narrowui
343
344         split = layout.split()
345
346         col = split.column()
347         sub = col.column()
348         sub.itemR(lamp, "spot_size", text="Size")
349         sub.itemR(lamp, "spot_blend", text="Blend", slider=True)
350         col.itemR(lamp, "square")
351
352         if col2:
353             col = split.column()
354         else:
355             col.itemS()
356         col.itemR(lamp, "halo")
357         sub = col.column(align=True)
358         sub.active = lamp.halo
359         sub.itemR(lamp, "halo_intensity", text="Intensity")
360         if lamp.shadow_method == 'BUFFER_SHADOW':
361             sub.itemR(lamp, "halo_step", text="Step")
362
363
364 class DATA_PT_falloff_curve(DataButtonsPanel):
365     bl_label = "Falloff Curve"
366     bl_default_closed = True
367
368     def poll(self, context):
369         lamp = context.lamp
370
371         return (lamp and lamp.type in ('POINT', 'SPOT') and lamp.falloff_type == 'CUSTOM_CURVE')
372
373     def draw(self, context):
374         lamp = context.lamp
375
376         self.layout.template_curve_mapping(lamp, "falloff_curve")
377
378 bpy.types.register(DATA_PT_context_lamp)
379 bpy.types.register(DATA_PT_preview)
380 bpy.types.register(DATA_PT_lamp)
381 bpy.types.register(DATA_PT_falloff_curve)
382 bpy.types.register(DATA_PT_area)
383 bpy.types.register(DATA_PT_spot)
384 bpy.types.register(DATA_PT_shadow)
385 bpy.types.register(DATA_PT_sunsky)