svn merge -r 21041:21301 https://svn.blender.org/svnroot/bf-blender/branches/blender2...
[blender.git] / release / ui / buttons_data_lamp.py
index 6cec1a0d09d8fa73bbd7e7eba4f3fa1ac63e121f..a556aceb98dd67319fd1ded437ab7c990e5a35a6 100644 (file)
@@ -7,48 +7,59 @@ class DataButtonsPanel(bpy.types.Panel):
        __context__ = "data"
        
        def poll(self, context):
-               ob = context.active_object
-               return (ob and ob.type == 'LAMP')
+               return (context.lamp != None)
+               
+class DATA_PT_preview(DataButtonsPanel):
+       __idname__= "DATA_PT_preview"
+       __label__ = "Preview"
+
+       def draw(self, context):
+               layout = self.layout
+
+               lamp = context.lamp
+               layout.template_preview(lamp)
        
 class DATA_PT_lamp(DataButtonsPanel):
        __idname__ = "DATA_PT_lamp"
        __label__ = "Lamp"
+       
+       def poll(self, context):
+               return ((context.object and context.object.type == 'LAMP') or context.lamp)
 
        def draw(self, context):
-               lamp = context.main.lamps[0]
                layout = self.layout
-
-               if not lamp:
-                       return
                
-               layout.row()
+               ob = context.object
+               lamp = context.lamp
+               space = context.space_data
+
+               split = layout.split(percentage=0.65)
+
+               if ob:
+                       split.template_ID(ob, "data")
+                       split.itemS()
+               elif lamp:
+                       split.template_ID(space, "pin_id")
+                       split.itemS()
+
+               layout.itemS()
+
                layout.itemR(lamp, "type", expand=True)
                
-               layout.split(number=2)
+               split = layout.split()
                
-               sub = layout.sub(0)
-               sub.column()
-               sub.itemL(text="LAMP DATABLOCKS")
+               sub = split.column()
+               sub.itemR(lamp, "color")
                sub.itemR(lamp, "energy")
                sub.itemR(lamp, "distance")
-       
-               sub = layout.sub(1)
-               sub.column()
-               sub.itemR(lamp, "color")
-               
-               layout.split(number=2)  
-               
-               sub = layout.sub(0)
-               sub.column()
-               sub.itemL(text="Illumination:")
-               sub.itemR(lamp, "layer")
                sub.itemR(lamp, "negative")
+       
+               sub = split.column()
+               sub.itemR(lamp, "layer", text="This Layer Only")
                sub.itemR(lamp, "specular")
                sub.itemR(lamp, "diffuse")
                
-               sub = layout.sub(1)
-               if (lamp.type in ('LOCAL', 'SPOT')):
-                       sub.column()
+               if lamp.type in ('POINT', 'SPOT'):
                        sub.itemR(lamp, "falloff_type")
                        sub.itemR(lamp, "sphere")
                        
@@ -56,7 +67,7 @@ class DATA_PT_lamp(DataButtonsPanel):
                                sub.itemR(lamp, "linear_attenuation")
                                sub.itemR(lamp, "quadratic_attenuation")
                        
-               if (lamp.type == 'AREA'):
+               if lamp.type == 'AREA':
                        sub.column()
                        sub.itemR(lamp, "gamma")
                        sub.itemR(lamp, "shape")
@@ -71,168 +82,171 @@ class DATA_PT_sunsky(DataButtonsPanel):
        __label__ = "Sun/Sky"
        
        def poll(self, context):
-               ob = context.active_object
-               lamp = context.main.lamps[0]
-               return (ob.type == 'LAMP' and lamp.type == 'SUN')
+               lamp = context.lamp
+               return (lamp and lamp.type == 'SUN')
 
        def draw(self, context):
-               lamp = context.main.lamps[0].sky
                layout = self.layout
+               lamp = context.lamp.sky
 
-               if not lamp:
-                       return
-               
-               layout.row()
-               layout.itemR(lamp, "sky")
-               layout.itemR(lamp, "atmosphere")
+               row = layout.row()
+               row.itemR(lamp, "sky")
+               row.itemR(lamp, "atmosphere")
                
-               if (lamp.sky or lamp.atmosphere):
-                       layout.row()
-                       layout.itemR(lamp, "atmosphere_turbidity", text="Turbidity")
+               row = layout.row()
+               row.active = lamp.sky or lamp.atmosphere
+               row.itemR(lamp, "atmosphere_turbidity", text="Turbidity")
                        
-                       layout.split(number=2)
-                       
-                       if (lamp.sky):
-                               sub = layout.sub(0)
-                               sub.column()
-                               sub.itemR(lamp, "sky_blend_type", text="Blend Type")
-                               sub.itemR(lamp, "sky_blend")
-                               sub.itemR(lamp, "sky_color_space", text="Color Space")
-                               sub.itemR(lamp, "sky_exposure")
-                               sub.column()
-                               sub.itemR(lamp, "horizon_brightness", text="Hor Bright")
-                               sub.itemR(lamp, "spread", text="Hor Spread")
-                               sub.itemR(lamp, "sun_brightness", text="Sun Bright")
-                               sub.itemR(lamp, "sun_size")
-                               sub.itemR(lamp, "backscattered_light", text="Back Light")
+               split = layout.split()
+
+               col = split.column()
+               sub = col.column()
+               sub.active = lamp.sky
+               sub.itemR(lamp, "sky_blend_type", text="Blend Type")
+               sub.itemR(lamp, "sky_blend")
+               sub.itemR(lamp, "sky_color_space", text="Color Space")
+               sub.itemR(lamp, "sky_exposure")
+               sub.itemR(lamp, "horizon_brightness", text="Hor Bright")
+               sub.itemR(lamp, "spread", text="Hor Spread")
+               sub.itemR(lamp, "sun_brightness", text="Sun Bright")
+               sub.itemR(lamp, "sun_size")
+               sub.itemR(lamp, "backscattered_light", text="Back Light")
                                
-                       if (lamp.atmosphere):
-                               sub = layout.sub(1)
-                               sub.column()
-                               sub.itemR(lamp, "sun_intensity", text="Sun Intens")
-                               sub.itemR(lamp, "atmosphere_inscattering", text="Inscattering")
-                               sub.itemR(lamp, "atmosphere_extinction", text="Extinction")
-                               sub.itemR(lamp, "atmosphere_distance_factor", text="Distance")
+               sub = split.column()
+               sub.active = lamp.atmosphere
+               sub.itemR(lamp, "sun_intensity", text="Sun Intens")
+               sub.itemR(lamp, "atmosphere_inscattering", text="Inscattering")
+               sub.itemR(lamp, "atmosphere_extinction", text="Extinction")
+               sub.itemR(lamp, "atmosphere_distance_factor", text="Distance")
                                
 class DATA_PT_shadow(DataButtonsPanel):
        __idname__ = "DATA_PT_shadow"
        __label__ = "Shadow"
        
        def poll(self, context):
-               ob = context.active_object
-               lamp = context.main.lamps[0]
-               return (ob.type == 'LAMP' and lamp.type in ('LOCAL','SUN', 'SPOT', 'AREA'))
+               lamp = context.lamp
+               return (lamp and lamp.type in ('POINT','SUN', 'SPOT', 'AREA'))
 
        def draw(self, context):
-               lamp = context.main.lamps[0]
                layout = self.layout
+               lamp = context.lamp
 
-               if not lamp:
-                       return
-               
-               layout.row()
                layout.itemR(lamp, "shadow_method", expand=True)
                
-               if (lamp.shadow_method in ('BUFFER_SHADOW', 'RAY_SHADOW')):
+               if lamp.shadow_method in ('BUFFER_SHADOW', 'RAY_SHADOW'):
                
-                       layout.split(number=2)
-                       
-                       sub = layout.sub(0)
-                       sub.column()
-                       sub.itemL(text="Options:")
-                       sub.itemR(lamp, "only_shadow")
-                       sub.itemR(lamp, "shadow_layer")
+                       split = layout.split()
                        
-                       sub = layout.sub(1)
-                       sub.column()
+                       sub = split.column()
                        sub.itemR(lamp, "shadow_color")
+                       
+                       sub = split.column()
+                       sub.itemR(lamp, "shadow_layer", text="This Layer Only")
+                       sub.itemR(lamp, "only_shadow")
                
-               if (lamp.shadow_method == 'RAY_SHADOW'):
+               if lamp.shadow_method == 'RAY_SHADOW':
                
-                       layout.column()
-                       layout.itemL(text="Sampling:")
-                       layout.itemR(lamp, "shadow_ray_sampling_method", expand=True)
+                       col = layout.column()
+                       col.itemL(text="Sampling:")
+                       col.row().itemR(lamp, "shadow_ray_sampling_method", expand=True)
                                
-                       if (lamp.type in ('LOCAL', 'SUN', 'SPOT') and lamp.shadow_ray_sampling_method in ('CONSTANT_QMC', 'ADAPTIVE_QMC')):
-                               layout.column_flow()
-                               layout.itemR(lamp, "shadow_soft_size", text="Soft Size")
-                               layout.itemR(lamp, "shadow_ray_samples", text="Samples")
-                               if (lamp.shadow_ray_sampling_method == 'ADAPTIVE_QMC'):
-                                       layout.itemR(lamp, "shadow_adaptive_threshold", text="Threshold")
+                       if lamp.type in ('POINT', 'SUN', 'SPOT'):
+                               flow = layout.column_flow()
+                               flow.itemR(lamp, "shadow_soft_size", text="Soft Size")
+                               flow.itemR(lamp, "shadow_ray_samples", text="Samples")
+                               if lamp.shadow_ray_sampling_method == 'ADAPTIVE_QMC':
+                                       flow.itemR(lamp, "shadow_adaptive_threshold", text="Threshold")
                                                
-                       if (lamp.type == 'AREA'):
-                               layout.column_flow()
-                               layout.itemR(lamp, "shadow_ray_samples_x", text="Samples")
-                               if (lamp.shadow_ray_sampling_method == 'ADAPTIVE_QMC'):
-                                       layout.itemR(lamp, "shadow_adaptive_threshold", text="Threshold")
-                               if (lamp.shadow_ray_sampling_method == 'CONSTANT_JITTERED'):
-                                       layout.itemR(lamp, "umbra")
-                                       layout.itemR(lamp, "dither")
-                                       layout.itemR(lamp, "jitter")    
-               
-               if (lamp.shadow_method == 'BUFFER_SHADOW'):
-                       layout.column()
-                       layout.itemL(text="Buffer Type:")
-                       layout.itemR(lamp, "shadow_buffer_type", expand=True)
-
-                       if (lamp.shadow_buffer_type in ('REGULAR', 'HALFWAY')):
-                               layout.column_flow()
-                               layout.itemL(text="Sample Buffers:")
-                               layout.itemR(lamp, "shadow_sample_buffers", expand=True)
-                               layout.itemL(text="Filter Type:")
-                               layout.itemR(lamp, "shadow_filter_type", expand=True)
-                               layout.column_flow()
-                               layout.itemR(lamp, "shadow_buffer_size", text="Size")
-                               layout.itemR(lamp, "shadow_buffer_samples", text="Samples")
-                               layout.itemR(lamp, "shadow_buffer_bias", text="Bias")
-                               layout.itemR(lamp, "shadow_buffer_soft", text="Soft")
+                       if lamp.type == 'AREA':
+                               flow = layout.column_flow()
+                               flow.itemR(lamp, "shadow_ray_samples_x", text="Samples")
+                               if lamp.shadow_ray_sampling_method == 'ADAPTIVE_QMC':
+                                       flow.itemR(lamp, "shadow_adaptive_threshold", text="Threshold")
+                               if lamp.shadow_ray_sampling_method == 'CONSTANT_JITTERED':
+                                       flow.itemR(lamp, "umbra")
+                                       flow.itemR(lamp, "dither")
+                                       flow.itemR(lamp, "jitter")      
+       
+               if lamp.shadow_method == 'BUFFER_SHADOW':
+                       col = layout.column()
+                       col.itemL(text="Buffer Type:")
+                       col.row().itemR(lamp, "shadow_buffer_type", expand=True)
+
+                       if lamp.shadow_buffer_type in ('REGULAR', 'HALFWAY'):
+                               flow = layout.column_flow()
+                               flow.itemL(text="Sample Buffers:")
+                               flow.itemR(lamp, "shadow_sample_buffers", text="")
+                               flow.itemL(text="Filter Type:")
+                               flow.itemR(lamp, "shadow_filter_type", text="")
+                               
+                               flow = layout.column_flow()
+                               flow.itemR(lamp, "shadow_buffer_size", text="Size")
+                               flow.itemR(lamp, "shadow_buffer_samples", text="Samples")
+                               flow.itemR(lamp, "shadow_buffer_bias", text="Bias")
+                               flow.itemR(lamp, "shadow_buffer_soft", text="Soft")
                                
                        if (lamp.shadow_buffer_type == 'IRREGULAR'):
-                               layout.row()
-                               layout.itemR(lamp, "shadow_buffer_bias", text="Bias")
+                               row = layout.row()
+                               row.itemR(lamp, "shadow_buffer_bias", text="Bias")
                        
-                       layout.row()
-                       layout.itemR(lamp, "auto_clip_start", text="Autoclip Start")
+                       row = layout.row()
+                       row.itemR(lamp, "auto_clip_start", text="Autoclip Start")
                        if not (lamp.auto_clip_start):
-                               layout.itemR(lamp, "shadow_buffer_clip_start", text="Clip Start")
-                       layout.row()
-                       layout.itemR(lamp, "auto_clip_end", text="Autoclip End")
+                               row.itemR(lamp, "shadow_buffer_clip_start", text="Clip Start")
+                       row = layout.row()
+                       row.itemR(lamp, "auto_clip_end", text="Autoclip End")
                        if not (lamp.auto_clip_end):
-                               layout.itemR(lamp, "shadow_buffer_clip_end", text=" Clip End")
+                               row.itemR(lamp, "shadow_buffer_clip_end", text=" Clip End")
 
 class DATA_PT_spot(DataButtonsPanel):
        __idname__ = "DATA_PT_spot"
        __label__ = "Spot"
        
        def poll(self, context):
-               ob = context.active_object
-               lamp = context.main.lamps[0]
-               return (ob.type == 'LAMP' and lamp.type == 'SPOT')
+               lamp = context.lamp
+               return (lamp and lamp.type == 'SPOT')
 
        def draw(self, context):
-               lamp = context.main.lamps[0]
                layout = self.layout
+               lamp = context.lamp
 
-               if not lamp:
-                       return
+               split = layout.split()
                
-               layout.split(number=2)
-               
-               sub = layout.sub(0)
-               sub.column()
+               sub = split.column()
+               sub.itemR(lamp, "spot_size", text="Size")
+               sub.itemR(lamp, "spot_blend", text="Blend")
                sub.itemR(lamp, "square")
-               sub.itemR(lamp, "spot_size")
-               sub.itemR(lamp, "spot_blend")
                
-               sub = layout.sub(1)
-               sub.column()
-               sub.itemR(lamp, "halo")
-               if (lamp.halo):
-                       sub.itemR(lamp, "halo_intensity")
-                       if (lamp.shadow_method == 'BUFFER_SHADOW'):
-                               sub.itemR(lamp, "halo_step")
+               col = split.column()
+               col.itemR(lamp, "halo")
+               colsub = col.column()
+               colsub.active = lamp.halo
+               colsub.itemR(lamp, "halo_intensity", text="Intensity")
+               if lamp.shadow_method == 'BUFFER_SHADOW':
+                       colsub.itemR(lamp, "halo_step", text="Step")
+
+class DATA_PT_falloff_curve(DataButtonsPanel):
+       __idname__ = "DATA_PT_falloff_curve"
+       __label__ = "Falloff Curve"
+       
+       def poll(self, context):
+               lamp = context.lamp
+
+               if lamp and lamp.type in ('POINT', 'SPOT'):
+                       if lamp.falloff_type == 'CUSTOM_CURVE':
+                               return True
+
+               return False
+
+       def draw(self, context):
+               layout = self.layout
+               lamp = context.lamp
+
+               layout.template_curve_mapping(lamp.falloff_curve)
 
+bpy.types.register(DATA_PT_preview)
 bpy.types.register(DATA_PT_lamp)
 bpy.types.register(DATA_PT_shadow)
 bpy.types.register(DATA_PT_sunsky)
 bpy.types.register(DATA_PT_spot)
+bpy.types.register(DATA_PT_falloff_curve)