poll() as a python '@staticmethod' was too limiting and didnt allow useful base class...
[blender.git] / release / scripts / ui / properties_data_lamp.py
index c7ad5b1c8953acf36fdb6534c321eab0bb41294b..9a58622974e1dc8e470b8031a6f50f2a8e580508 100644 (file)
 #
 #  You should have received a copy of the GNU General Public License
 #  along with this program; if not, write to the Free Software Foundation,
-#  Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 #
 # ##### END GPL LICENSE BLOCK #####
 
 # <pep8 compliant>
 import bpy
+from rna_prop_ui import PropertyPanel
 
 
-class DataButtonsPanel(bpy.types.Panel):
+class LAMP_MT_sunsky_presets(bpy.types.Menu):
+    bl_label = "Sun & Sky Presets"
+    preset_subdir = "sunsky"
+    preset_operator = "script.execute_preset"
+    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
+    draw = bpy.types.Menu.draw_preset
+
+
+class DataButtonsPanel():
     bl_space_type = 'PROPERTIES'
     bl_region_type = 'WINDOW'
     bl_context = "data"
 
-    def poll(self, context):
-        return context.lamp
+    @classmethod
+    def poll(cls, context):
+        engine = context.scene.render.engine
+        return context.lamp and (engine in cls.COMPAT_ENGINES)
 
 
-class DATA_PT_preview(DataButtonsPanel):
+class DATA_PT_preview(DataButtonsPanel, bpy.types.Panel):
     bl_label = "Preview"
+    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
 
     def draw(self, context):
         self.layout.template_preview(context.lamp)
 
-
-class DATA_PT_context_lamp(DataButtonsPanel):
+class DATA_PT_context_lamp(DataButtonsPanel, bpy.types.Panel):
     bl_label = ""
     bl_show_header = False
+    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
 
     def draw(self, context):
         layout = self.layout
@@ -51,248 +63,287 @@ class DATA_PT_context_lamp(DataButtonsPanel):
 
         if ob:
             split.template_ID(ob, "data")
-            split.itemS()
+            split.separator()
         elif lamp:
             split.template_ID(space, "pin_id")
-            split.itemS()
+            split.separator()
+
+
+class DATA_PT_custom_props_lamp(DataButtonsPanel, PropertyPanel, bpy.types.Panel):
+    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
+    _context_path = "object.data"
 
 
-class DATA_PT_lamp(DataButtonsPanel):
+class DATA_PT_lamp(DataButtonsPanel, bpy.types.Panel):
     bl_label = "Lamp"
+    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
 
     def draw(self, context):
         layout = self.layout
 
         lamp = context.lamp
 
-        layout.itemR(lamp, "type", expand=True)
+        layout.prop(lamp, "type", expand=True)
 
         split = layout.split()
 
         col = split.column()
         sub = col.column()
-        sub.itemR(lamp, "color", text="")
-        sub.itemR(lamp, "energy")
+        sub.prop(lamp, "color", text="")
+        sub.prop(lamp, "energy")
 
         if lamp.type in ('POINT', 'SPOT'):
-            sub.itemL(text="Falloff:")
-            sub.itemR(lamp, "falloff_type", text="")
-            sub.itemR(lamp, "distance")
+            sub.label(text="Falloff:")
+            sub.prop(lamp, "falloff_type", text="")
+            sub.prop(lamp, "distance")
 
             if lamp.falloff_type == 'LINEAR_QUADRATIC_WEIGHTED':
-                col.itemL(text="Attenuation Factors:")
+                col.label(text="Attenuation Factors:")
                 sub = col.column(align=True)
-                sub.itemR(lamp, "linear_attenuation", slider=True, text="Linear")
-                sub.itemR(lamp, "quadratic_attenuation", slider=True, text="Quadratic")
+                sub.prop(lamp, "linear_attenuation", slider=True, text="Linear")
+                sub.prop(lamp, "quadratic_attenuation", slider=True, text="Quadratic")
 
-            col.itemR(lamp, "sphere")
+            col.prop(lamp, "sphere")
 
         if lamp.type == 'AREA':
-            col.itemR(lamp, "distance")
-            col.itemR(lamp, "gamma")
+            col.prop(lamp, "distance")
+            col.prop(lamp, "gamma")
 
         col = split.column()
-        col.itemR(lamp, "negative")
-        col.itemR(lamp, "layer", text="This Layer Only")
-        col.itemR(lamp, "specular")
-        col.itemR(lamp, "diffuse")
+        col.prop(lamp, "negative")
+        col.prop(lamp, "layer", text="This Layer Only")
+        col.prop(lamp, "specular")
+        col.prop(lamp, "diffuse")
 
 
-class DATA_PT_sunsky(DataButtonsPanel):
+class DATA_PT_sunsky(DataButtonsPanel, bpy.types.Panel):
     bl_label = "Sky & Atmosphere"
+    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
 
-    def poll(self, context):
+    @classmethod
+    def poll(cls, context):
         lamp = context.lamp
-        return (lamp and lamp.type == 'SUN')
+        engine = context.scene.render.engine
+        return (lamp and lamp.type == 'SUN') and (engine in cls.COMPAT_ENGINES)
 
     def draw(self, context):
         layout = self.layout
 
         lamp = context.lamp.sky
 
-        layout.itemR(lamp, "sky")
+        row = layout.row(align=True)
+        row.prop(lamp, "use_sky")
+        row.menu("LAMP_MT_sunsky_presets", text=bpy.types.LAMP_MT_sunsky_presets.bl_label)
+        row.operator("lamp.sunsky_preset_add", text="", icon="ZOOMIN")
 
         row = layout.row()
-        row.active = lamp.sky or lamp.atmosphere
-        row.itemR(lamp, "atmosphere_turbidity", text="Turbidity")
+        row.active = lamp.use_sky or lamp.use_atmosphere
+        row.prop(lamp, "atmosphere_turbidity", text="Turbidity")
 
         split = layout.split()
 
         col = split.column()
-        col.active = lamp.sky
-        col.itemL(text="Blending:")
+        col.active = lamp.use_sky
+        col.label(text="Blending:")
         sub = col.column()
-        sub.itemR(lamp, "sky_blend_type", text="")
-        sub.itemR(lamp, "sky_blend", text="Factor")
+        sub.prop(lamp, "sky_blend_type", text="")
+        sub.prop(lamp, "sky_blend", text="Factor")
 
-        col.itemL(text="Color Space:")
+        col.label(text="Color Space:")
         sub = col.column()
-        sub.row().itemR(lamp, "sky_color_space", expand=True)
-        sub.itemR(lamp, "sky_exposure", text="Exposure")
+        sub.row().prop(lamp, "sky_color_space", expand=True)
+        sub.prop(lamp, "sky_exposure", text="Exposure")
 
         col = split.column()
-        col.active = lamp.sky
-        col.itemL(text="Horizon:")
+        col.active = lamp.use_sky
+        col.label(text="Horizon:")
         sub = col.column()
-        sub.itemR(lamp, "horizon_brightness", text="Brightness")
-        sub.itemR(lamp, "spread", text="Spread")
+        sub.prop(lamp, "horizon_brightness", text="Brightness")
+        sub.prop(lamp, "spread", text="Spread")
 
-        col.itemL(text="Sun:")
+        col.label(text="Sun:")
         sub = col.column()
-        sub.itemR(lamp, "sun_brightness", text="Brightness")
-        sub.itemR(lamp, "sun_size", text="Size")
-        sub.itemR(lamp, "backscattered_light", slider=True, text="Back Light")
+        sub.prop(lamp, "sun_brightness", text="Brightness")
+        sub.prop(lamp, "sun_size", text="Size")
+        sub.prop(lamp, "backscattered_light", slider=True, text="Back Light")
 
-        layout.itemS()
+        layout.separator()
 
-        layout.itemR(lamp, "atmosphere")
+        layout.prop(lamp, "use_atmosphere")
 
         split = layout.split()
 
         col = split.column()
-        col.active = lamp.atmosphere
-        col.itemL(text="Intensity:")
-        col.itemR(lamp, "sun_intensity", text="Sun")
-        col.itemR(lamp, "atmosphere_distance_factor", text="Distance")
+        col.active = lamp.use_atmosphere
+        col.label(text="Intensity:")
+        col.prop(lamp, "sun_intensity", text="Sun")
+        col.prop(lamp, "atmosphere_distance_factor", text="Distance")
 
         col = split.column()
-        col.active = lamp.atmosphere
-        col.itemL(text="Scattering:")
+        col.active = lamp.use_atmosphere
+        col.label(text="Scattering:")
         sub = col.column(align=True)
-        sub.itemR(lamp, "atmosphere_inscattering", slider=True, text="Inscattering")
-        sub.itemR(lamp, "atmosphere_extinction", slider=True, text="Extinction")
+        sub.prop(lamp, "atmosphere_inscattering", slider=True, text="Inscattering")
+        sub.prop(lamp, "atmosphere_extinction", slider=True, text="Extinction")
 
 
-class DATA_PT_shadow(DataButtonsPanel):
+class DATA_PT_shadow(DataButtonsPanel, bpy.types.Panel):
     bl_label = "Shadow"
+    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
 
-    def poll(self, context):
+    @classmethod
+    def poll(cls, context):
         lamp = context.lamp
-        return (lamp and lamp.type in ('POINT', 'SUN', 'SPOT', 'AREA'))
+        engine = context.scene.render.engine
+        return (lamp and lamp.type in ('POINT', 'SUN', 'SPOT', 'AREA')) and (engine in cls.COMPAT_ENGINES)
 
     def draw(self, context):
         layout = self.layout
 
         lamp = context.lamp
 
-        layout.itemR(lamp, "shadow_method", expand=True)
+        layout.prop(lamp, "shadow_method", expand=True)
+
+        if lamp.shadow_method == 'NOSHADOW' and lamp.type == 'AREA':
+            split = layout.split()
+
+            col= split.column()
+            col.label(text="Form factor sampling:")
+            
+            sub=col.row(align=True)
+
+            if lamp.shape == 'SQUARE':
+                sub.prop(lamp, "shadow_ray_samples_x", text="Samples")
+            elif lamp.shape == 'RECTANGLE':
+                sub.prop(lamp, "shadow_ray_samples_x", text="Samples X")
+                sub.prop(lamp, "shadow_ray_samples_y", text="Samples Y")
 
         if lamp.shadow_method != 'NOSHADOW':
             split = layout.split()
 
             col = split.column()
-            col.itemR(lamp, "shadow_color", text="")
+            col.prop(lamp, "shadow_color", text="")
 
             col = split.column()
-            col.itemR(lamp, "shadow_layer", text="This Layer Only")
-            col.itemR(lamp, "only_shadow")
+            col.prop(lamp, "shadow_layer", text="This Layer Only")
+            col.prop(lamp, "only_shadow")
 
         if lamp.shadow_method == 'RAY_SHADOW':
-            col = layout.column()
-            col.itemL(text="Sampling:")
-            col.row().itemR(lamp, "shadow_ray_sampling_method", expand=True)
-
+            split = layout.split()
+            
+            col = split.column()
+            col.label(text="Sampling:")
+            
             if lamp.type in ('POINT', 'SUN', 'SPOT'):
-                split = layout.split()
-
-                col = split.column()
-                col.itemR(lamp, "shadow_soft_size", text="Soft Size")
-
-                col.itemR(lamp, "shadow_ray_samples", text="Samples")
-                if lamp.shadow_ray_sampling_method == 'ADAPTIVE_QMC':
-                    col.itemR(lamp, "shadow_adaptive_threshold", text="Threshold")
-                col = split.column()
-
+                sub = col.row()
+                
+                sub.prop(lamp, "shadow_ray_samples", text="Samples")
+                sub.prop(lamp, "shadow_soft_size", text="Soft Size")
+                
             elif lamp.type == 'AREA':
-                split = layout.split()
-
-                col = split.column()
-                sub = split.column(align=True)
+                sub = col.row(align=True)
+                
                 if lamp.shape == 'SQUARE':
-                    col.itemR(lamp, "shadow_ray_samples_x", text="Samples")
+                    sub.prop(lamp, "shadow_ray_samples_x", text="Samples")
                 elif lamp.shape == 'RECTANGLE':
-                    col.itemR(lamp, "shadow_ray_samples_x", text="Samples X")
-                    col.itemR(lamp, "shadow_ray_samples_y", text="Samples Y")
+                    sub.prop(lamp, "shadow_ray_samples_x", text="Samples X")
+                    sub.prop(lamp, "shadow_ray_samples_y", text="Samples Y")
 
-                if lamp.shadow_ray_sampling_method == 'ADAPTIVE_QMC':
-                    col.itemR(lamp, "shadow_adaptive_threshold", text="Threshold")
+            col.row().prop(lamp, "shadow_ray_sampling_method", expand=True)
 
-                elif lamp.shadow_ray_sampling_method == 'CONSTANT_JITTERED':
-                    sub.itemR(lamp, "umbra")
-                    sub.itemR(lamp, "dither")
-                    sub.itemR(lamp, "jitter")
+            split = layout.split()
+            col = split.column()
+            
+            if lamp.shadow_ray_sampling_method == 'ADAPTIVE_QMC':
+                col.prop(lamp, "shadow_adaptive_threshold", text="Threshold")
+                col = split.column()
+            
+            if lamp.type == 'AREA' and lamp.shadow_ray_sampling_method == 'CONSTANT_JITTERED':
+                col = split.column()
+                col = split.column()
+                col.prop(lamp, "umbra")
+                col.prop(lamp, "dither")
+                col.prop(lamp, "jitter")
 
         elif lamp.shadow_method == 'BUFFER_SHADOW':
             col = layout.column()
-            col.itemL(text="Buffer Type:")
-            col.row().itemR(lamp, "shadow_buffer_type", expand=True)
+            col.label(text="Buffer Type:")
+            col.row().prop(lamp, "shadow_buffer_type", expand=True)
 
             if lamp.shadow_buffer_type in ('REGULAR', 'HALFWAY', 'DEEP'):
                 split = layout.split()
 
                 col = split.column()
-                col.itemL(text="Filter Type:")
-                col.itemR(lamp, "shadow_filter_type", text="")
+                col.label(text="Filter Type:")
+                col.prop(lamp, "shadow_filter_type", text="")
                 sub = col.column(align=True)
-                sub.itemR(lamp, "shadow_buffer_soft", text="Soft")
-                sub.itemR(lamp, "shadow_buffer_bias", text="Bias")
+                sub.prop(lamp, "shadow_buffer_soft", text="Soft")
+                sub.prop(lamp, "shadow_buffer_bias", text="Bias")
 
                 col = split.column()
-                col.itemL(text="Sample Buffers:")
-                col.itemR(lamp, "shadow_sample_buffers", text="")
+                col.label(text="Sample Buffers:")
+                col.prop(lamp, "shadow_sample_buffers", text="")
                 sub = col.column(align=True)
-                sub.itemR(lamp, "shadow_buffer_size", text="Size")
-                sub.itemR(lamp, "shadow_buffer_samples", text="Samples")
+                sub.prop(lamp, "shadow_buffer_size", text="Size")
+                sub.prop(lamp, "shadow_buffer_samples", text="Samples")
                 if lamp.shadow_buffer_type == 'DEEP':
-                    col.itemR(lamp, "compression_threshold")
+                    col.prop(lamp, "compression_threshold")
 
             elif lamp.shadow_buffer_type == 'IRREGULAR':
-                layout.itemR(lamp, "shadow_buffer_bias", text="Bias")
+                layout.prop(lamp, "shadow_buffer_bias", text="Bias")
 
-            row = layout.row()
-            row.itemR(lamp, "auto_clip_start", text="Autoclip Start")
-            sub = row.row()
+            split = layout.split()
+
+            col = split.column()
+            col.prop(lamp, "auto_clip_start", text="Autoclip Start")
+            sub = col.column()
             sub.active = not lamp.auto_clip_start
-            sub.itemR(lamp, "shadow_buffer_clip_start", text="Clip Start")
+            sub.prop(lamp, "shadow_buffer_clip_start", text="Clip Start")
 
-            row = layout.row()
-            row.itemR(lamp, "auto_clip_end", text="Autoclip End")
-            sub = row.row()
+            col = split.column()
+            col.prop(lamp, "auto_clip_end", text="Autoclip End")
+            sub = col.column()
             sub.active = not lamp.auto_clip_end
-            sub.itemR(lamp, "shadow_buffer_clip_end", text=" Clip End")
+            sub.prop(lamp, "shadow_buffer_clip_end", text=" Clip End")
 
 
-class DATA_PT_area(DataButtonsPanel):
+class DATA_PT_area(DataButtonsPanel, bpy.types.Panel):
     bl_label = "Area Shape"
+    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
 
-    def poll(self, context):
+    @classmethod
+    def poll(cls, context):
         lamp = context.lamp
-        return (lamp and lamp.type == 'AREA')
+        engine = context.scene.render.engine
+        return (lamp and lamp.type == 'AREA') and (engine in cls.COMPAT_ENGINES)
 
     def draw(self, context):
-        layout = self.layout
-
         lamp = context.lamp
 
+        layout = self.layout
         split = layout.split()
 
         col = split.column()
-        col.row().itemR(lamp, "shape", expand=True)
+        
+        col.row().prop(lamp, "shape", expand=True)
+        sub = col.row(align=True)
 
-        sub = col.column(align=True)
         if (lamp.shape == 'SQUARE'):
-            sub.itemR(lamp, "size")
+            sub.prop(lamp, "size")
         elif (lamp.shape == 'RECTANGLE'):
-            sub.itemR(lamp, "size", text="Size X")
-            sub.itemR(lamp, "size_y", text="Size Y")
+            sub.prop(lamp, "size", text="Size X")
+            sub.prop(lamp, "size_y", text="Size Y")
 
 
-class DATA_PT_spot(DataButtonsPanel):
+class DATA_PT_spot(DataButtonsPanel, bpy.types.Panel):
     bl_label = "Spot Shape"
+    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
 
-    def poll(self, context):
+    @classmethod
+    def poll(cls, context):
         lamp = context.lamp
-        return (lamp and lamp.type == 'SPOT')
+        engine = context.scene.render.engine
+        return (lamp and lamp.type == 'SPOT') and (engine in cls.COMPAT_ENGINES)
 
     def draw(self, context):
         layout = self.layout
@@ -303,38 +354,45 @@ class DATA_PT_spot(DataButtonsPanel):
 
         col = split.column()
         sub = col.column()
-        sub.itemR(lamp, "spot_size", text="Size")
-        sub.itemR(lamp, "spot_blend", text="Blend", slider=True)
-        col.itemR(lamp, "square")
+        sub.prop(lamp, "spot_size", text="Size")
+        sub.prop(lamp, "spot_blend", text="Blend", slider=True)
+        col.prop(lamp, "square")
+        col.prop(lamp, "show_cone")
 
         col = split.column()
-        col.itemR(lamp, "halo")
+
+        col.prop(lamp, "halo")
         sub = col.column(align=True)
         sub.active = lamp.halo
-        sub.itemR(lamp, "halo_intensity", text="Intensity")
+        sub.prop(lamp, "halo_intensity", text="Intensity")
         if lamp.shadow_method == 'BUFFER_SHADOW':
-            sub.itemR(lamp, "halo_step", text="Step")
+            sub.prop(lamp, "halo_step", text="Step")
 
 
-class DATA_PT_falloff_curve(DataButtonsPanel):
+class DATA_PT_falloff_curve(DataButtonsPanel, bpy.types.Panel):
     bl_label = "Falloff Curve"
     bl_default_closed = True
+    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
 
-    def poll(self, context):
+    @classmethod
+    def poll(cls, context):
         lamp = context.lamp
+        engine = context.scene.render.engine
 
-        return (lamp and lamp.type in ('POINT', 'SPOT') and lamp.falloff_type == 'CUSTOM_CURVE')
+        return (lamp and lamp.type in ('POINT', 'SPOT') and lamp.falloff_type == 'CUSTOM_CURVE') and (engine in cls.COMPAT_ENGINES)
 
     def draw(self, context):
         lamp = context.lamp
 
         self.layout.template_curve_mapping(lamp, "falloff_curve")
 
-bpy.types.register(DATA_PT_context_lamp)
-bpy.types.register(DATA_PT_preview)
-bpy.types.register(DATA_PT_lamp)
-bpy.types.register(DATA_PT_falloff_curve)
-bpy.types.register(DATA_PT_area)
-bpy.types.register(DATA_PT_spot)
-bpy.types.register(DATA_PT_shadow)
-bpy.types.register(DATA_PT_sunsky)
+
+def register():
+    pass
+
+
+def unregister():
+    pass
+
+if __name__ == "__main__":
+    register()