patch from William, panel names need to be unique
[blender.git] / release / ui / buttons_data_lamp.py
1
2 import bpy
3
4 class DataButtonsPanel(bpy.types.Panel):
5         __space_type__ = "BUTTONS_WINDOW"
6         __region_type__ = "WINDOW"
7         __context__ = "data"
8         
9         def poll(self, context):
10                 return (context.lamp != None)
11                 
12 class DATA_PT_preview(DataButtonsPanel):
13         __idname__= "DATA_PT_preview"
14         __label__ = "Preview"
15
16         def draw(self, context):
17                 layout = self.layout
18
19                 lamp = context.lamp
20                 layout.template_preview(lamp)
21         
22 class DATA_PT_context_lamp(DataButtonsPanel):
23         __idname__ = "DATA_PT_context_lamp"
24         __label__ = " "
25         
26         def poll(self, context):
27                 return ((context.object and context.object.type == 'LAMP') or context.lamp)
28
29         def draw(self, context):
30                 layout = self.layout
31                 
32                 ob = context.object
33                 lamp = context.lamp
34                 space = context.space_data
35
36                 split = layout.split(percentage=0.65)
37
38                 if ob:
39                         split.template_ID(ob, "data")
40                         split.itemS()
41                 elif lamp:
42                         split.template_ID(space, "pin_id")
43                         split.itemS()
44
45
46 class DATA_PT_lamp(DataButtonsPanel):
47         __idname__ = "DATA_PT_lamp"
48         __label__ = "Lamp"
49         
50         def poll(self, context):
51                 return ((context.object and context.object.type == 'LAMP') or context.lamp)
52
53         def draw(self, context):
54                 layout = self.layout
55                 
56                 ob = context.object
57                 lamp = context.lamp
58                 space = context.space_data
59
60                 layout.itemR(lamp, "type", expand=True)
61                 
62                 split = layout.split()
63                 
64                 sub = split.column()
65                 sub.itemR(lamp, "color")
66                 sub.itemR(lamp, "energy")
67                 sub.itemR(lamp, "distance")
68                 sub.itemR(lamp, "negative")
69         
70                 sub = split.column()
71                 sub.itemR(lamp, "layer", text="This Layer Only")
72                 sub.itemR(lamp, "specular")
73                 sub.itemR(lamp, "diffuse")
74                 
75                 if lamp.type in ('POINT', 'SPOT'):
76                         sub.itemR(lamp, "falloff_type")
77                         sub.itemR(lamp, "sphere")
78                         
79                         if (lamp.falloff_type == 'LINEAR_QUADRATIC_WEIGHTED'):
80                                 sub.itemR(lamp, "linear_attenuation")
81                                 sub.itemR(lamp, "quadratic_attenuation")
82                         
83                 if lamp.type == 'AREA':
84                         sub.column()
85                         sub.itemR(lamp, "gamma")
86                         sub.itemR(lamp, "shape")
87                         if (lamp.shape == 'SQUARE'):
88                                 sub.itemR(lamp, "size")
89                         if (lamp.shape == 'RECTANGLE'):
90                                 sub.itemR(lamp, "size", text="Size X")
91                                 sub.itemR(lamp, "size_y")
92                                 
93 class DATA_PT_sunsky(DataButtonsPanel):
94         __idname__ = "DATA_PT_sunsky"
95         __label__ = "Sun/Sky"
96         
97         def poll(self, context):
98                 lamp = context.lamp
99                 return (lamp and lamp.type == 'SUN')
100
101         def draw(self, context):
102                 layout = self.layout
103                 lamp = context.lamp.sky
104
105                 row = layout.row()
106                 row.itemR(lamp, "sky")
107                 row.itemR(lamp, "atmosphere")
108                 
109                 row = layout.row()
110                 row.active = lamp.sky or lamp.atmosphere
111                 row.itemR(lamp, "atmosphere_turbidity", text="Turbidity")
112                         
113                 split = layout.split()
114
115                 col = split.column()
116                 sub = col.column()
117                 sub.active = lamp.sky
118                 sub.itemR(lamp, "sky_blend_type", text="Blend Type")
119                 sub.itemR(lamp, "sky_blend")
120                 sub.itemR(lamp, "sky_color_space", text="Color Space")
121                 sub.itemR(lamp, "sky_exposure")
122                 sub.itemR(lamp, "horizon_brightness", text="Hor Bright")
123                 sub.itemR(lamp, "spread", text="Hor Spread")
124                 sub.itemR(lamp, "sun_brightness", text="Sun Bright")
125                 sub.itemR(lamp, "sun_size")
126                 sub.itemR(lamp, "backscattered_light", text="Back Light")
127                                 
128                 sub = split.column()
129                 sub.active = lamp.atmosphere
130                 sub.itemR(lamp, "sun_intensity", text="Sun Intens")
131                 sub.itemR(lamp, "atmosphere_inscattering", text="Inscattering")
132                 sub.itemR(lamp, "atmosphere_extinction", text="Extinction")
133                 sub.itemR(lamp, "atmosphere_distance_factor", text="Distance")
134                                 
135 class DATA_PT_shadow(DataButtonsPanel):
136         __idname__ = "DATA_PT_shadow"
137         __label__ = "Shadow"
138         
139         def poll(self, context):
140                 lamp = context.lamp
141                 return (lamp and lamp.type in ('POINT','SUN', 'SPOT', 'AREA'))
142
143         def draw(self, context):
144                 layout = self.layout
145                 lamp = context.lamp
146
147                 layout.itemR(lamp, "shadow_method", expand=True)
148                 
149                 if lamp.shadow_method in ('BUFFER_SHADOW', 'RAY_SHADOW'):
150                 
151                         split = layout.split()
152                         
153                         sub = split.column()
154                         sub.itemR(lamp, "shadow_color")
155                         
156                         sub = split.column()
157                         sub.itemR(lamp, "shadow_layer", text="This Layer Only")
158                         sub.itemR(lamp, "only_shadow")
159                 
160                 if lamp.shadow_method == 'RAY_SHADOW':
161                 
162                         col = layout.column()
163                         col.itemL(text="Sampling:")
164                         col.row().itemR(lamp, "shadow_ray_sampling_method", expand=True)
165                                 
166                         if lamp.type in ('POINT', 'SUN', 'SPOT'):
167                                 flow = layout.column_flow()
168                                 flow.itemR(lamp, "shadow_soft_size", text="Soft Size")
169                                 flow.itemR(lamp, "shadow_ray_samples", text="Samples")
170                                 if lamp.shadow_ray_sampling_method == 'ADAPTIVE_QMC':
171                                         flow.itemR(lamp, "shadow_adaptive_threshold", text="Threshold")
172                                                 
173                         if lamp.type == 'AREA':
174                                 flow = layout.column_flow()
175                                 flow.itemR(lamp, "shadow_ray_samples_x", text="Samples")
176                                 if lamp.shadow_ray_sampling_method == 'ADAPTIVE_QMC':
177                                         flow.itemR(lamp, "shadow_adaptive_threshold", text="Threshold")
178                                 if lamp.shadow_ray_sampling_method == 'CONSTANT_JITTERED':
179                                         flow.itemR(lamp, "umbra")
180                                         flow.itemR(lamp, "dither")
181                                         flow.itemR(lamp, "jitter")      
182         
183                 if lamp.shadow_method == 'BUFFER_SHADOW':
184                         col = layout.column()
185                         col.itemL(text="Buffer Type:")
186                         col.row().itemR(lamp, "shadow_buffer_type", expand=True)
187
188                         if lamp.shadow_buffer_type in ('REGULAR', 'HALFWAY'):
189                                 flow = layout.column_flow()
190                                 flow.itemL(text="Sample Buffers:")
191                                 flow.itemR(lamp, "shadow_sample_buffers", text="")
192                                 flow.itemL(text="Filter Type:")
193                                 flow.itemR(lamp, "shadow_filter_type", text="")
194                                 
195                                 flow = layout.column_flow()
196                                 flow.itemR(lamp, "shadow_buffer_size", text="Size")
197                                 flow.itemR(lamp, "shadow_buffer_samples", text="Samples")
198                                 flow.itemR(lamp, "shadow_buffer_bias", text="Bias")
199                                 flow.itemR(lamp, "shadow_buffer_soft", text="Soft")
200                                 
201                         if (lamp.shadow_buffer_type == 'IRREGULAR'):
202                                 row = layout.row()
203                                 row.itemR(lamp, "shadow_buffer_bias", text="Bias")
204                         
205                         row = layout.row()
206                         row.itemR(lamp, "auto_clip_start", text="Autoclip Start")
207                         if not (lamp.auto_clip_start):
208                                 row.itemR(lamp, "shadow_buffer_clip_start", text="Clip Start")
209                         row = layout.row()
210                         row.itemR(lamp, "auto_clip_end", text="Autoclip End")
211                         if not (lamp.auto_clip_end):
212                                 row.itemR(lamp, "shadow_buffer_clip_end", text=" Clip End")
213
214 class DATA_PT_spot(DataButtonsPanel):
215         __idname__ = "DATA_PT_spot"
216         __label__ = "Spot"
217         
218         def poll(self, context):
219                 lamp = context.lamp
220                 return (lamp and lamp.type == 'SPOT')
221
222         def draw(self, context):
223                 layout = self.layout
224                 lamp = context.lamp
225
226                 split = layout.split()
227                 
228                 sub = split.column()
229                 sub.itemR(lamp, "spot_size", text="Size")
230                 sub.itemR(lamp, "spot_blend", text="Blend")
231                 sub.itemR(lamp, "square")
232                 
233                 col = split.column()
234                 col.itemR(lamp, "halo")
235                 colsub = col.column()
236                 colsub.active = lamp.halo
237                 colsub.itemR(lamp, "halo_intensity", text="Intensity")
238                 if lamp.shadow_method == 'BUFFER_SHADOW':
239                         colsub.itemR(lamp, "halo_step", text="Step")
240
241 class DATA_PT_falloff_curve(DataButtonsPanel):
242         __idname__ = "DATA_PT_falloff_curve"
243         __label__ = "Falloff Curve"
244         
245         def poll(self, context):
246                 lamp = context.lamp
247
248                 if lamp and lamp.type in ('POINT', 'SPOT'):
249                         if lamp.falloff_type == 'CUSTOM_CURVE':
250                                 return True
251
252                 return False
253
254         def draw(self, context):
255                 layout = self.layout
256                 lamp = context.lamp
257
258                 layout.template_curve_mapping(lamp.falloff_curve)
259
260 bpy.types.register(DATA_PT_context_lamp)
261 bpy.types.register(DATA_PT_preview)
262 bpy.types.register(DATA_PT_lamp)
263 bpy.types.register(DATA_PT_shadow)
264 bpy.types.register(DATA_PT_sunsky)
265 bpy.types.register(DATA_PT_spot)
266 bpy.types.register(DATA_PT_falloff_curve)