Merged changes in the trunk up to revision 53584.
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>
Sat, 5 Jan 2013 22:24:05 +0000 (22:24 +0000)
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>
Sat, 5 Jan 2013 22:24:05 +0000 (22:24 +0000)
Conflicts resolved:
release/scripts/startup/bl_ui/properties_render.py
source/blender/blenloader/intern/readfile.c
source/blender/editors/interface/interface_templates.c
source/blender/makesrna/RNA_enum_types.h

Also made additional code updates for:
r53355 UIList - Python-extendable list of UI items
r53460 Alpha premul pipeline cleanup

51 files changed:
1  2 
CMakeLists.txt
SConstruct
doc/python_api/sphinx_doc_gen.py
intern/cycles/blender/addon/ui.py
release/scripts/startup/bl_operators/__init__.py
release/scripts/startup/bl_ui/__init__.py
release/scripts/startup/bl_ui/properties_render.py
release/scripts/startup/bl_ui/properties_render_layer.py
release/scripts/startup/bl_ui/space_view3d.py
source/blender/blenkernel/CMakeLists.txt
source/blender/blenkernel/intern/bpath.c
source/blender/blenkernel/intern/material.c
source/blender/blenkernel/intern/object.c
source/blender/blenkernel/intern/scene.c
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/blenlib/CMakeLists.txt
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/bmesh/CMakeLists.txt
source/blender/bmesh/SConscript
source/blender/bmesh/intern/bmesh_construct.c
source/blender/editors/include/UI_resources.h
source/blender/editors/interface/interface_templates.c
source/blender/editors/interface/resources.c
source/blender/editors/mesh/editmesh_tools.c
source/blender/editors/render/render_shading.c
source/blender/editors/space_view3d/drawobject.c
source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
source/blender/makesdna/DNA_ID.h
source/blender/makesdna/DNA_mesh_types.h
source/blender/makesdna/DNA_scene_types.h
source/blender/makesdna/DNA_userdef_types.h
source/blender/makesrna/RNA_access.h
source/blender/makesrna/RNA_enum_types.h
source/blender/makesrna/intern/makesrna.c
source/blender/makesrna/intern/rna_color.c
source/blender/makesrna/intern/rna_mesh.c
source/blender/makesrna/intern/rna_scene.c
source/blender/makesrna/intern/rna_space.c
source/blender/makesrna/intern/rna_userdef.c
source/blender/python/SConscript
source/blender/python/intern/CMakeLists.txt
source/blender/python/intern/bpy_app_build_options.c
source/blender/render/intern/include/render_types.h
source/blender/render/intern/source/convertblender.c
source/blender/render/intern/source/pipeline.c
source/blender/render/intern/source/render_result.c
source/blender/windowmanager/intern/wm_files.c
source/blenderplayer/bad_level_call_stubs/stubs.c
source/creator/CMakeLists.txt
source/creator/creator.c

diff --cc CMakeLists.txt
Simple merge
diff --cc SConstruct
Simple merge
Simple merge
Simple merge
@@@ -43,15 -43,10 +43,15 @@@ _modules = 
      "vertexpaint_dirt",
      "view3d",
      "wm",
 -)
 +]
 +
 +import bpy
 +
- if 'FREESTYLE' in bpy.app.build_options:
++if bpy.app.build_options.freestyle:
 +    _modules.append("freestyle")
  __import__(name=__name__, fromlist=_modules)
  _namespace = globals()
 -_modules_loaded = {name: _namespace[name] for name in _modules}
 +_modules_loaded = {name: _namespace[name] for name in _modules if name != 'bpy'}
  del _namespace
  
  
@@@ -51,19 -68,8 +51,18 @@@ class RenderButtonsPanel()
  
      @classmethod
      def poll(cls, context):
 -        rd = context.scene.render
 -        return context.scene and (rd.engine in cls.COMPAT_ENGINES)
 +        scene = context.scene
 +        return scene and (scene.render.engine in cls.COMPAT_ENGINES)
 +
 +
 +class RenderFreestyleButtonsPanel(RenderButtonsPanel):
 +    # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here
 +
 +    @classmethod
 +    def poll(cls, context):
 +        if not super().poll(context):
 +            return False
-         rd = context.scene.render
-         return 'FREESTYLE' in bpy.app.build_options
++        return bpy.app.build_options.freestyle
  
  
  class RENDER_PT_render(RenderButtonsPanel, Panel):
index 20fc080,0000000..61750f6
mode 100644,000000..100644
--- /dev/null
@@@ -1,743 -1,0 +1,782 @@@
- from bpy.types import Menu, Panel
 +# ##### BEGIN GPL LICENSE BLOCK #####
 +#
 +#  This program is free software; you can redistribute it and/or
 +#  modify it under the terms of the GNU General Public License
 +#  as published by the Free Software Foundation; either version 2
 +#  of the License, or (at your option) any later version.
 +#
 +#  This program is distributed in the hope that it will be useful,
 +#  but WITHOUT ANY WARRANTY; without even the implied warranty of
 +#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 +#  GNU General Public License for more details.
 +#
 +#  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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 +#
 +# ##### END GPL LICENSE BLOCK #####
 +
 +# <pep8 compliant>
 +import bpy
-         return 'FREESTYLE' in bpy.app.build_options and rd.use_freestyle and rd.layers.active
++from bpy.types import Menu, Panel, UIList
 +
 +
 +class RenderLayerButtonsPanel():
 +    bl_space_type = 'PROPERTIES'
 +    bl_region_type = 'WINDOW'
 +    bl_context = "render_layer"
 +    # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here
 +
 +    @classmethod
 +    def poll(cls, context):
 +        scene = context.scene
 +        return scene and (scene.render.engine in cls.COMPAT_ENGINES)
 +
 +
 +class RenderLayerFreestyleButtonsPanel(RenderLayerButtonsPanel):
 +    # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here
 +
 +    @classmethod
 +    def poll(cls, context):
 +        if not super().poll(context):
 +            return False
 +        rd = context.scene.render
-         row.template_list(rd, "layers", rd.layers, "active_index", rows=2)
++        return bpy.app.build_options.freestyle and rd.use_freestyle and rd.layers.active
 +
 +
 +class RenderLayerFreestyleEditorButtonsPanel(RenderLayerFreestyleButtonsPanel):
 +    # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here
 +
 +    @classmethod
 +    def poll(cls, context):
 +        if not super().poll(context):
 +            return False
 +        rl = context.scene.render.layers.active
 +        return rl and rl.freestyle_settings.mode == 'EDITOR'
 +
 +
++class RENDERLAYER_UL_renderlayers(UIList):
++    def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
++        # assert(isinstance(item, bpy.types.SceneRenderLayer)
++        layer = item
++        if self.layout_type in {'DEFAULT', 'COMPACT'}:
++            layout.label(layer.name, icon_value=icon)
++            layout.prop(layer, "use", text="", index=index)
++        elif self.layout_type in {'GRID'}:
++            layout.alignment = 'CENTER'
++            layout.label("", icon_value=icon)
++
++#     else if (RNA_struct_is_a(itemptr->type, &RNA_SceneRenderLayer)) {
++#             uiItemL(sub, name, icon);
++#             uiBlockSetEmboss(block, UI_EMBOSS);
++#             uiDefButR(block, OPTION, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, itemptr, "use", 0, 0, 0, 0, 0,  NULL);
++#     }
++
++
++class RENDERLAYER_UL_linesets(UIList):
++    def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
++        lineset = item
++        if self.layout_type in {'DEFAULT', 'COMPACT'}:
++            layout.label(lineset.name, icon_value=icon)
++            layout.prop(lineset, "use", text="", index=index)
++        elif self.layout_type in {'GRID'}:
++            layout.alignment = 'CENTER'
++            layout.label("", icon_value=icon)
++
++##ifdef WITH_FREESTYLE
++#     else if (RNA_struct_is_a(itemptr->type, &RNA_SceneRenderLayer) || 
++#              RNA_struct_is_a(itemptr->type, &RNA_FreestyleLineSet)) {
++##else
++#     else if (RNA_struct_is_a(itemptr->type, &RNA_SceneRenderLayer)) {
++##endif
++#             uiItemL(sub, name, icon);
++#             uiBlockSetEmboss(block, UI_EMBOSS);
++#             uiDefButR(block, OPTION, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, itemptr, "use", 0, 0, 0, 0, 0,  NULL);
++#     }
++
++
 +class RENDERLAYER_PT_layers(RenderLayerButtonsPanel, Panel):
 +    bl_label = "Layers"
 +    bl_options = {'HIDE_HEADER'}
 +    COMPAT_ENGINES = {'BLENDER_RENDER'}
 +
 +    def draw(self, context):
 +        layout = self.layout
 +
 +        scene = context.scene
 +        rd = scene.render
 +
 +        row = layout.row()
- #        col.label(text="")
++        row.template_list("RENDERLAYER_UL_renderlayers", "", rd, "layers", rd.layers, "active_index", rows=2)
 +
 +        col = row.column(align=True)
 +        col.operator("scene.render_layer_add", icon='ZOOMIN', text="")
 +        col.operator("scene.render_layer_remove", icon='ZOOMOUT', text="")
 +
 +        row = layout.row()
 +        rl = rd.layers.active
 +        if rl:
 +            row.prop(rl, "name")
 +        row.prop(rd, "use_single_layer", text="", icon_only=True)
 +
 +
 +class RENDERLAYER_PT_layer_options(RenderLayerButtonsPanel, Panel):
 +    bl_label = "Layer"
 +    bl_options = {'DEFAULT_CLOSED'}
 +    COMPAT_ENGINES = {'BLENDER_RENDER'}
 +
 +    def draw(self, context):
 +        layout = self.layout
 +
 +        scene = context.scene
 +        rd = scene.render
 +        rl = rd.layers.active
 +
 +        split = layout.split()
 +
 +        col = split.column()
 +        col.prop(scene, "layers", text="Scene")
-         row = col.row(align=True)
-         row.prop(rl, "use_zmask")
-         sub = row.row(align=True)
-         sub.prop(rl, "invert_zmask", text="", icon='ZOOMOUT')
-         sub.active = rl.use_zmask
++        col.label(text="")
 +        col.prop(rl, "light_override", text="Light")
 +        col.prop(rl, "material_override", text="Material")
 +
 +        col = split.column()
 +        col.prop(rl, "layers", text="Layer")
 +        col.label(text="Mask Layers:")
 +        col.prop(rl, "layers_zmask", text="")
 +
 +        layout.separator()
 +        layout.label(text="Include:")
 +
 +        split = layout.split()
 +
 +        col = split.column()
-         col.prop(rl, "use_ztransp")
++        col.prop(rl, "use_zmask")
++        row = col.row()
++        row.prop(rl, "invert_zmask", text="Negate")
++        row.active = rl.use_zmask
 +        col.prop(rl, "use_all_z")
-         col.prop(rl, "use_strand")
 +
 +        col = split.column()
 +        col.prop(rl, "use_solid")
 +        col.prop(rl, "use_halo")
-         if 'FREESTYLE' in bpy.app.build_options:
++        col.prop(rl, "use_ztransp")
 +
 +        col = split.column()
 +        col.prop(rl, "use_sky")
 +        col.prop(rl, "use_edge_enhance")
-         row.template_list(freestyle, "linesets", freestyle.linesets, "active_index", rows=rows)
++        col.prop(rl, "use_strand")
++        if bpy.app.build_options.freestyle:
 +            row = col.row()
 +            row.prop(rl, "use_freestyle")
 +            row.active = rd.use_freestyle
 +
 +
 +class RENDERLAYER_PT_layer_passes(RenderLayerButtonsPanel, Panel):
 +    bl_label = "Render Passes"
 +    bl_options = {'DEFAULT_CLOSED'}
 +    COMPAT_ENGINES = {'BLENDER_RENDER'}
 +
 +    def draw_pass_type_buttons(self, box, rl, pass_type):
 +        # property names
 +        use_pass_type = "use_pass_" + pass_type
 +        exclude_pass_type = "exclude_" + pass_type
 +        # draw pass type buttons
 +        row = box.row()
 +        row.prop(rl, use_pass_type)
 +        row.prop(rl, exclude_pass_type, text="")
 +
 +    def draw(self, context):
 +        layout = self.layout
 +
 +        scene = context.scene
 +        rd = scene.render
 +        rl = rd.layers.active
 +
 +        split = layout.split()
 +
 +        col = split.column()
 +        col.prop(rl, "use_pass_combined")
 +        col.prop(rl, "use_pass_z")
 +        col.prop(rl, "use_pass_vector")
 +        col.prop(rl, "use_pass_normal")
 +        col.prop(rl, "use_pass_uv")
 +        col.prop(rl, "use_pass_mist")
 +        col.prop(rl, "use_pass_object_index")
 +        col.prop(rl, "use_pass_material_index")
 +        col.prop(rl, "use_pass_color")
 +
 +        col = split.column()
 +        col.prop(rl, "use_pass_diffuse")
 +        self.draw_pass_type_buttons(col, rl, "specular")
 +        self.draw_pass_type_buttons(col, rl, "shadow")
 +        self.draw_pass_type_buttons(col, rl, "emit")
 +        self.draw_pass_type_buttons(col, rl, "ambient_occlusion")
 +        self.draw_pass_type_buttons(col, rl, "environment")
 +        self.draw_pass_type_buttons(col, rl, "indirect")
 +        self.draw_pass_type_buttons(col, rl, "reflection")
 +        self.draw_pass_type_buttons(col, rl, "refraction")
 +
 +
 +class RENDER_MT_lineset_specials(Menu):
 +    bl_label = "Lineset Specials"
 +
 +    def draw(self, context):
 +        layout = self.layout
 +        layout.operator("scene.freestyle_lineset_copy", icon='COPYDOWN')
 +        layout.operator("scene.freestyle_lineset_paste", icon='PASTEDOWN')
 +
 +
 +class RENDERLAYER_PT_freestyle(RenderLayerFreestyleButtonsPanel, Panel):
 +    bl_label = "Freestyle"
 +    COMPAT_ENGINES = {'BLENDER_RENDER'}
 +
 +    def draw(self, context):
 +        rd = context.scene.render
 +        rl = rd.layers.active
 +        freestyle = rl.freestyle_settings
 +
 +        layout = self.layout
 +        layout.active = rl.use_freestyle
 +        layout.prop(freestyle, "mode", text="Control mode")
 +
 +        col = layout.column()
 +        col.label(text="Edge Detection Options:")
 +        split = col.split()
 +        sub = split.column()
 +        sub.prop(freestyle, "crease_angle")
 +        sub.prop(freestyle, "use_culling")
 +        sub = split.column()
 +        sub.prop(freestyle, "use_smoothness")
 +        sub.prop(freestyle, "use_material_boundaries")
 +        col.prop(freestyle, "use_advanced_options")
 +        # Advanced options are hidden by default to warn new users
 +        if freestyle.use_advanced_options:
 +            split = col.split()
 +            sub = split.column()
 +            sub.active = freestyle.use_advanced_options
 +            if freestyle.mode == 'SCRIPT':
 +                sub.prop(freestyle, "use_ridges_and_valleys")
 +            sub.prop(freestyle, "sphere_radius")
 +            sub = split.column()
 +            sub.active = freestyle.use_advanced_options
 +            if freestyle.mode == 'SCRIPT':
 +                sub.prop(freestyle, "use_suggestive_contours")
 +            sub.prop(freestyle, "kr_derivative_epsilon")
 +
 +        if freestyle.mode == 'SCRIPT':
 +            split = layout.split()
 +            split.label("Style modules:")
 +            split.operator("scene.freestyle_module_add", text="Add")
 +            for i, module in enumerate(freestyle.modules):
 +                box = layout.box()
 +                box.context_pointer_set("freestyle_module", module)
 +                row = box.row(align=True)
 +                row.prop(module, "use", text="")
 +                row.prop(module, "module_path", text="")
 +                row.operator("scene.freestyle_module_remove", icon='X', text="")
 +                row.operator("scene.freestyle_module_move", icon='TRIA_UP', text="").direction = 'UP'
 +                row.operator("scene.freestyle_module_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
 +
 +
 +class RENDERLAYER_PT_freestyle_lineset(RenderLayerFreestyleEditorButtonsPanel, Panel):
 +    bl_label = "Freestyle Line Set"
 +    COMPAT_ENGINES = {'BLENDER_RENDER'}
 +
 +    def draw_edge_type_buttons(self, box, lineset, edge_type):
 +        # property names
 +        select_edge_type = "select_" + edge_type
 +        exclude_edge_type = "exclude_" + edge_type
 +        # draw edge type buttons
 +        row = box.row(align=True)
 +        row.prop(lineset, select_edge_type)
 +        sub = row.column()
 +        sub.prop(lineset, exclude_edge_type, text="")
 +        sub.active = getattr(lineset, select_edge_type)
 +
 +    def draw(self, context):
 +        rd = context.scene.render
 +        rl = rd.layers.active
 +        freestyle = rl.freestyle_settings
 +        lineset = freestyle.linesets.active
 +
 +        layout = self.layout
 +        layout.active = rl.use_freestyle
 +
 +        col = layout.column()
 +        row = col.row()
 +        rows = 5 if lineset else 2
++        row.template_list("RENDERLAYER_UL_linesets", "", freestyle, "linesets", freestyle.linesets, "active_index", rows=rows)
 +
 +        sub = row.column()
 +        subsub = sub.column(align=True)
 +        subsub.operator("scene.freestyle_lineset_add", icon='ZOOMIN', text="")
 +        subsub.operator("scene.freestyle_lineset_remove", icon='ZOOMOUT', text="")
 +        subsub.menu("RENDER_MT_lineset_specials", icon='DOWNARROW_HLT', text="")
 +        if lineset:
 +            sub.separator()
 +            subsub = sub.column(align=True)
 +            subsub.operator("scene.freestyle_lineset_move", icon='TRIA_UP', text="").direction = 'UP'
 +            subsub.operator("scene.freestyle_lineset_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
 +
 +            col.prop(lineset, "name")
 +
 +            col = layout.column()
 +            col.label(text="Selection By:")
 +            row = col.row(align=True)
 +            row.prop(lineset, "select_by_visibility", text="Visibility", toggle=True)
 +            row.prop(lineset, "select_by_edge_types", text="Edge Types", toggle=True)
 +            row.prop(lineset, "select_by_face_marks", text="Face Marks", toggle=True)
 +            row.prop(lineset, "select_by_group", text="Group", toggle=True)
 +            row.prop(lineset, "select_by_image_border", text="Image Border", toggle=True)
 +
 +            if lineset.select_by_visibility:
 +                col.label(text="Visibility:")
 +                row = col.row(align=True)
 +                row.prop(lineset, "visibility", expand=True)
 +                if lineset.visibility == 'RANGE':
 +                    row = col.row(align=True)
 +                    row.prop(lineset, "qi_start")
 +                    row.prop(lineset, "qi_end")
 +
 +            if lineset.select_by_edge_types:
 +                col.label(text="Edge Types:")
 +                row = col.row()
 +                row.prop(lineset, "edge_type_negation", expand=True)
 +                row.prop(lineset, "edge_type_combination", expand=True)
 +
 +                split = col.split()
 +                sub = split.column()
 +                self.draw_edge_type_buttons(sub, lineset, "silhouette")
 +                self.draw_edge_type_buttons(sub, lineset, "border")
 +                self.draw_edge_type_buttons(sub, lineset, "contour")
 +                self.draw_edge_type_buttons(sub, lineset, "suggestive_contour")
 +                self.draw_edge_type_buttons(sub, lineset, "ridge_valley")
 +                sub = split.column()
 +                self.draw_edge_type_buttons(sub, lineset, "crease")
 +                self.draw_edge_type_buttons(sub, lineset, "edge_mark")
 +                self.draw_edge_type_buttons(sub, lineset, "external_contour")
 +                self.draw_edge_type_buttons(sub, lineset, "material_boundary")
 +
 +            if lineset.select_by_face_marks:
 +                col.label(text="Face Marks:")
 +                row = col.row()
 +                row.prop(lineset, "face_mark_negation", expand=True)
 +                row.prop(lineset, "face_mark_condition", expand=True)
 +
 +            if lineset.select_by_group:
 +                col.label(text="Group:")
 +                row = col.row()
 +                row.prop(lineset, "group", text="")
 +                row.prop(lineset, "group_negation", expand=True)
 +
 +
 +class RENDERLAYER_PT_freestyle_linestyle(RenderLayerFreestyleEditorButtonsPanel, Panel):
 +    bl_label = "Freestyle Line Style"
 +    bl_options = {'DEFAULT_CLOSED'}
 +    COMPAT_ENGINES = {'BLENDER_RENDER'}
 +
 +    def draw_modifier_box_header(self, box, modifier):
 +        row = box.row()
 +        row.context_pointer_set("modifier", modifier)
 +        if modifier.expanded:
 +            icon = 'TRIA_DOWN'
 +        else:
 +            icon = 'TRIA_RIGHT'
 +        row.prop(modifier, "expanded", text="", icon=icon, emboss=False)
 +        # TODO: Use icons rather than text label, would save some room!
 +        row.label(text=modifier.rna_type.name)
 +        row.prop(modifier, "name", text="")
 +        if modifier.use:
 +            icon = 'RESTRICT_RENDER_OFF'
 +        else:
 +            icon = 'RESTRICT_RENDER_ON'
 +        row.prop(modifier, "use", text="", icon=icon)
 +        sub = row.row(align=True)
 +        sub.operator("scene.freestyle_modifier_copy", icon='NONE', text="Copy")
 +        sub.operator("scene.freestyle_modifier_move", icon='TRIA_UP', text="").direction = 'UP'
 +        sub.operator("scene.freestyle_modifier_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
 +        sub.operator("scene.freestyle_modifier_remove", icon='X', text="")
 +
 +    def draw_modifier_common(self, box, modifier):
 +        row = box.row()
 +        row.prop(modifier, "blend", text="")
 +        row.prop(modifier, "influence")
 +
 +    def draw_modifier_color_ramp_common(self, box, modifier, has_range):
 +        box.template_color_ramp(modifier, "color_ramp", expand=True)
 +        if has_range:
 +            row = box.row(align=True)
 +            row.prop(modifier, "range_min")
 +            row.prop(modifier, "range_max")
 +
 +    def draw_modifier_curve_common(self, box, modifier, has_range, has_value):
 +        row = box.row()
 +        row.prop(modifier, "mapping", text="")
 +        sub = row.column()
 +        sub.prop(modifier, "invert")
 +        if modifier.mapping == 'CURVE':
 +            sub.active = False
 +            box.template_curve_mapping(modifier, "curve")
 +        if has_range:
 +            row = box.row(align=True)
 +            row.prop(modifier, "range_min")
 +            row.prop(modifier, "range_max")
 +        if has_value:
 +            row = box.row(align=True)
 +            row.prop(modifier, "value_min")
 +            row.prop(modifier, "value_max")
 +
 +    def draw_color_modifier(self, context, modifier):
 +        layout = self.layout
 +
 +        col = layout.column(align=True)
 +        self.draw_modifier_box_header(col.box(), modifier)
 +        if modifier.expanded:
 +            box = col.box()
 +            self.draw_modifier_common(box, modifier)
 +
 +            if modifier.type == 'ALONG_STROKE':
 +                self.draw_modifier_color_ramp_common(box, modifier, False)
 +
 +            elif modifier.type == 'DISTANCE_FROM_OBJECT':
 +                box.prop(modifier, "target")
 +                self.draw_modifier_color_ramp_common(box, modifier, True)
 +                prop = box.operator("scene.freestyle_fill_range_by_selection")
 +                prop.type = 'COLOR'
 +                prop.name = modifier.name
 +
 +            elif modifier.type == 'DISTANCE_FROM_CAMERA':
 +                self.draw_modifier_color_ramp_common(box, modifier, True)
 +                prop = box.operator("scene.freestyle_fill_range_by_selection")
 +                prop.type = 'COLOR'
 +                prop.name = modifier.name
 +
 +            elif modifier.type == 'MATERIAL':
 +                row = box.row()
 +                row.prop(modifier, "material_attr", text="")
 +                sub = row.column()
 +                sub.prop(modifier, "use_ramp")
 +                if modifier.material_attr in {'DIFF', 'SPEC'}:
 +                    sub.active = True
 +                    show_ramp = modifier.use_ramp
 +                else:
 +                    sub.active = False
 +                    show_ramp = True
 +                if show_ramp:
 +                    self.draw_modifier_color_ramp_common(box, modifier, False)
 +
 +    def draw_alpha_modifier(self, context, modifier):
 +        layout = self.layout
 +
 +        col = layout.column(align=True)
 +        self.draw_modifier_box_header(col.box(), modifier)
 +        if modifier.expanded:
 +            box = col.box()
 +            self.draw_modifier_common(box, modifier)
 +
 +            if modifier.type == 'ALONG_STROKE':
 +                self.draw_modifier_curve_common(box, modifier, False, False)
 +
 +            elif modifier.type == 'DISTANCE_FROM_OBJECT':
 +                box.prop(modifier, "target")
 +                self.draw_modifier_curve_common(box, modifier, True, False)
 +                prop = box.operator("scene.freestyle_fill_range_by_selection")
 +                prop.type = 'ALPHA'
 +                prop.name = modifier.name
 +
 +            elif modifier.type == 'DISTANCE_FROM_CAMERA':
 +                self.draw_modifier_curve_common(box, modifier, True, False)
 +                prop = box.operator("scene.freestyle_fill_range_by_selection")
 +                prop.type = 'ALPHA'
 +                prop.name = modifier.name
 +
 +            elif modifier.type == 'MATERIAL':
 +                box.prop(modifier, "material_attr", text="")
 +                self.draw_modifier_curve_common(box, modifier, False, False)
 +
 +    def draw_thickness_modifier(self, context, modifier):
 +        layout = self.layout
 +
 +        col = layout.column(align=True)
 +        self.draw_modifier_box_header(col.box(), modifier)
 +        if modifier.expanded:
 +            box = col.box()
 +            self.draw_modifier_common(box, modifier)
 +
 +            if modifier.type == 'ALONG_STROKE':
 +                self.draw_modifier_curve_common(box, modifier, False, True)
 +
 +            elif modifier.type == 'DISTANCE_FROM_OBJECT':
 +                box.prop(modifier, "target")
 +                self.draw_modifier_curve_common(box, modifier, True, True)
 +                prop = box.operator("scene.freestyle_fill_range_by_selection")
 +                prop.type = 'THICKNESS'
 +                prop.name = modifier.name
 +
 +            elif modifier.type == 'DISTANCE_FROM_CAMERA':
 +                self.draw_modifier_curve_common(box, modifier, True, True)
 +                prop = box.operator("scene.freestyle_fill_range_by_selection")
 +                prop.type = 'THICKNESS'
 +                prop.name = modifier.name
 +
 +            elif modifier.type == 'MATERIAL':
 +                box.prop(modifier, "material_attr", text="")
 +                self.draw_modifier_curve_common(box, modifier, False, True)
 +
 +            elif modifier.type == 'CALLIGRAPHY':
 +                box.prop(modifier, "orientation")
 +                row = box.row(align=True)
 +                row.prop(modifier, "min_thickness")
 +                row.prop(modifier, "max_thickness")
 +
 +    def draw_geometry_modifier(self, context, modifier):
 +        layout = self.layout
 +
 +        col = layout.column(align=True)
 +        self.draw_modifier_box_header(col.box(), modifier)
 +        if modifier.expanded:
 +            box = col.box()
 +
 +            if modifier.type == 'SAMPLING':
 +                box.prop(modifier, "sampling")
 +
 +            elif modifier.type == 'BEZIER_CURVE':
 +                box.prop(modifier, "error")
 +
 +            elif modifier.type == 'SINUS_DISPLACEMENT':
 +                split = box.split()
 +                col = split.column()
 +                col.prop(modifier, "wavelength")
 +                col.prop(modifier, "amplitude")
 +                col = split.column()
 +                col.prop(modifier, "phase")
 +
 +            elif modifier.type == 'SPATIAL_NOISE':
 +                split = box.split()
 +                col = split.column()
 +                col.prop(modifier, "amplitude")
 +                col.prop(modifier, "scale")
 +                col.prop(modifier, "octaves")
 +                col = split.column()
 +                col.prop(modifier, "smooth")
 +                col.prop(modifier, "pure_random")
 +
 +            elif modifier.type == 'PERLIN_NOISE_1D':
 +                split = box.split()
 +                col = split.column()
 +                col.prop(modifier, "frequency")
 +                col.prop(modifier, "amplitude")
 +                col.prop(modifier, "seed")
 +                col = split.column()
 +                col.prop(modifier, "octaves")
 +                col.prop(modifier, "angle")
 +
 +            elif modifier.type == 'PERLIN_NOISE_2D':
 +                split = box.split()
 +                col = split.column()
 +                col.prop(modifier, "frequency")
 +                col.prop(modifier, "amplitude")
 +                col.prop(modifier, "seed")
 +                col = split.column()
 +                col.prop(modifier, "octaves")
 +                col.prop(modifier, "angle")
 +
 +            elif modifier.type == 'BACKBONE_STRETCHER':
 +                box.prop(modifier, "backbone_length")
 +
 +            elif modifier.type == 'TIP_REMOVER':
 +                box.prop(modifier, "tip_length")
 +
 +            elif modifier.type == 'POLYGONIZATION':
 +                box.prop(modifier, "error")
 +
 +            elif modifier.type == 'GUIDING_LINES':
 +                box.prop(modifier, "offset")
 +
 +            elif modifier.type == 'BLUEPRINT':
 +                row = box.row()
 +                row.prop(modifier, "shape", expand=True)
 +                box.prop(modifier, "rounds")
 +                row = box.row()
 +                if modifier.shape in {'CIRCLES', 'ELLIPSES'}:
 +                    row.prop(modifier, "random_radius")
 +                    row.prop(modifier, "random_center")
 +                elif modifier.shape == 'SQUARES':
 +                    row.prop(modifier, "backbone_length")
 +                    row.prop(modifier, "random_backbone")
 +
 +            elif modifier.type == '2D_OFFSET':
 +                row = box.row(align=True)
 +                row.prop(modifier, "start")
 +                row.prop(modifier, "end")
 +                row = box.row(align=True)
 +                row.prop(modifier, "x")
 +                row.prop(modifier, "y")
 +
 +            elif modifier.type == '2D_TRANSFORM':
 +                box.prop(modifier, "pivot")
 +                if modifier.pivot == 'PARAM':
 +                    box.prop(modifier, "pivot_u")
 +                elif modifier.pivot == 'ABSOLUTE':
 +                    row = box.row(align=True)
 +                    row.prop(modifier, "pivot_x")
 +                    row.prop(modifier, "pivot_y")
 +                row = box.row(align=True)
 +                row.prop(modifier, "scale_x")
 +                row.prop(modifier, "scale_y")
 +                box.prop(modifier, "angle")
 +
 +    def draw(self, context):
 +        rd = context.scene.render
 +        rl = rd.layers.active
 +        lineset = rl.freestyle_settings.linesets.active
 +
 +        layout = self.layout
 +        layout.active = rl.use_freestyle
 +
 +        if lineset is None:
 +            return
 +        linestyle = lineset.linestyle
 +
 +        layout.template_ID(lineset, "linestyle", new="scene.freestyle_linestyle_new")
 +        row = layout.row(align=True)
 +        row.prop(linestyle, "panel", expand=True)
 +        if linestyle.panel == 'STROKES':
 +            ## Chaining
 +            layout.label(text="Chaining:")
 +            split = layout.split(align=True)
 +            # First column
 +            col = split.column()
 +            col.prop(linestyle, "use_chaining", text="Enable Chaining")
 +            sub = col.row()
 +            sub.active = linestyle.use_chaining
 +            sub.prop(linestyle, "same_object")
 +            # Second column
 +            col = split.column()
 +            col.active = linestyle.use_chaining
 +            col.prop(linestyle, "chaining", text="")
 +            if linestyle.chaining == 'SKETCHY':
 +                col.prop(linestyle, "rounds")
 +
 +            ## Splitting
 +            layout.label(text="Splitting:")
 +            split = layout.split(align=True)
 +            # First column
 +            col = split.column()
 +            row = col.row(align=True)
 +            row.prop(linestyle, "use_min_angle", text="")
 +            sub = row.row()
 +            sub.active = linestyle.use_min_angle
 +            sub.prop(linestyle, "min_angle")
 +            row = col.row(align=True)
 +            row.prop(linestyle, "use_max_angle", text="")
 +            sub = row.row()
 +            sub.active = linestyle.use_max_angle
 +            sub.prop(linestyle, "max_angle")
 +            # Second column
 +            col = split.column()
 +            row = col.row(align=True)
 +            row.prop(linestyle, "use_split_length", text="")
 +            sub = row.row()
 +            sub.active = linestyle.use_split_length
 +            sub.prop(linestyle, "split_length", text="2D Length")
 +            row = col.row(align=True)
 +            row.prop(linestyle, "material_boundary")
 +            # End of columns
 +            row = layout.row(align=True)
 +            row.prop(linestyle, "use_split_pattern", text="")
 +            sub = row.row()
 +            sub.active = linestyle.use_split_pattern
 +            sub.prop(linestyle, "split_dash1", text="D1")
 +            sub.prop(linestyle, "split_gap1", text="G1")
 +            sub.prop(linestyle, "split_dash2", text="D2")
 +            sub.prop(linestyle, "split_gap2", text="G2")
 +            sub.prop(linestyle, "split_dash3", text="D3")
 +            sub.prop(linestyle, "split_gap3", text="G3")
 +
 +            ## Selection
 +            layout.label(text="Selection:")
 +            split = layout.split(align=True)
 +            # First column
 +            col = split.column()
 +            row = col.row(align=True)
 +            row.prop(linestyle, "use_min_length", text="")
 +            sub = row.row()
 +            sub.active = linestyle.use_min_length
 +            sub.prop(linestyle, "min_length")
 +            # Second column
 +            col = split.column()
 +            row = col.row(align=True)
 +            row.prop(linestyle, "use_max_length", text="")
 +            sub = row.row()
 +            sub.active = linestyle.use_max_length
 +            sub.prop(linestyle, "max_length")
 +
 +            ## Caps
 +            layout.label(text="Caps:")
 +            row = layout.row(align=True)
 +            row.prop(linestyle, "caps", expand=True)
 +
 +            ## Dashed lines
 +            layout.label(text="Dashed Line:")
 +            row = layout.row(align=True)
 +            row.prop(linestyle, "use_dashed_line", text="")
 +            sub = row.row()
 +            sub.active = linestyle.use_dashed_line
 +            sub.prop(linestyle, "dash1", text="D1")
 +            sub.prop(linestyle, "gap1", text="G1")
 +            sub.prop(linestyle, "dash2", text="D2")
 +            sub.prop(linestyle, "gap2", text="G2")
 +            sub.prop(linestyle, "dash3", text="D3")
 +            sub.prop(linestyle, "gap3", text="G3")
 +
 +        elif linestyle.panel == 'COLOR':
 +            col = layout.column()
 +            row = col.row()
 +            row.label(text="Base Color:")
 +            row.prop(linestyle, "color", text="")
 +            col.label(text="Modifiers:")
 +            col.operator_menu_enum("scene.freestyle_color_modifier_add", "type", text="Add Modifier")
 +            for modifier in linestyle.color_modifiers:
 +                self.draw_color_modifier(context, modifier)
 +
 +        elif linestyle.panel == 'ALPHA':
 +            col = layout.column()
 +            row = col.row()
 +            row.label(text="Base Transparency:")
 +            row.prop(linestyle, "alpha")
 +            col.label(text="Modifiers:")
 +            col.operator_menu_enum("scene.freestyle_alpha_modifier_add", "type", text="Add Modifier")
 +            for modifier in linestyle.alpha_modifiers:
 +                self.draw_alpha_modifier(context, modifier)
 +
 +        elif linestyle.panel == 'THICKNESS':
 +            col = layout.column()
 +            row = col.row()
 +            row.label(text="Base Thickness:")
 +            row.prop(linestyle, "thickness")
 +            row = col.row()
 +            row.prop(linestyle, "thickness_position", expand=True)
 +            row = col.row()
 +            row.prop(linestyle, "thickness_ratio")
 +            row.active = (linestyle.thickness_position == 'RELATIVE')
 +            col = layout.column()
 +            col.label(text="Modifiers:")
 +            col.operator_menu_enum("scene.freestyle_thickness_modifier_add", "type", text="Add Modifier")
 +            for modifier in linestyle.thickness_modifiers:
 +                self.draw_thickness_modifier(context, modifier)
 +
 +        elif linestyle.panel == 'GEOMETRY':
 +            col = layout.column()
 +            col.label(text="Modifiers:")
 +            col.operator_menu_enum("scene.freestyle_geometry_modifier_add", "type", text="Add Modifier")
 +            for modifier in linestyle.geometry_modifiers:
 +                self.draw_geometry_modifier(context, modifier)
 +
 +        elif linestyle.panel == 'MISC':
 +            pass
 +
 +
 +if __name__ == "__main__":  # only for live edit.
 +    bpy.utils.register_module(__name__)
@@@ -1838,12 -1839,6 +1839,12 @@@ class VIEW3D_MT_edit_mesh_edges(Menu)
  
          layout.separator()
  
-         if context.scene and 'FREESTYLE' in bpy.app.build_options:
++        if context.scene and bpy.app.build_options.freestyle:
 +            layout.operator("mesh.mark_freestyle_edge").clear = False
 +            layout.operator("mesh.mark_freestyle_edge", text="Clear Freestyle Edge").clear = True
 +
 +        layout.separator()
 +
          layout.operator("mesh.edge_rotate", text="Rotate Edge CW").use_ccw = False
          layout.operator("mesh.edge_rotate", text="Rotate Edge CCW").use_ccw = True
  
@@@ -1884,12 -1879,6 +1885,12 @@@ class VIEW3D_MT_edit_mesh_faces(Menu)
  
          layout.separator()
  
-         if context.scene and 'FREESTYLE' in bpy.app.build_options:
++        if context.scene and bpy.app.build_options.freestyle:
 +            layout.operator("mesh.mark_freestyle_face").clear = False
 +            layout.operator("mesh.mark_freestyle_face", text="Clear Freestyle Face").clear = True
 +
 +        layout.separator()
 +
          layout.operator("mesh.quads_convert_to_tris")
          layout.operator("mesh.tris_convert_to_quads")
  
@@@ -2493,9 -2482,6 +2494,9 @@@ class VIEW3D_PT_view3d_meshdisplay(Pane
          col.prop(mesh, "show_edge_bevel_weight", text="Bevel Weights")
          col.prop(mesh, "show_edge_seams", text="Seams")
          col.prop(mesh, "show_edge_sharp", text="Sharp")
-         if context.scene and 'FREESTYLE' in bpy.app.build_options:
++        if context.scene and bpy.app.build_options.freestyle:
 +            col.prop(mesh, "show_freestyle_edge_marks", text="Freestyle Edge Marks")
 +            col.prop(mesh, "show_freestyle_face_marks", text="Freestyle Face Marks")
  
          col.separator()
          col.label(text="Normals:")
@@@ -149,9 -151,10 +151,10 @@@ set(SR
        intern/world.c
        intern/writeavi.c
        intern/writeframeserver.c
 -
 +      
        BKE_DerivedMesh.h
        BKE_action.h
+       BKE_addon.h
        BKE_anim.h
        BKE_animsys.h
        BKE_armature.h
Simple merge
@@@ -1031,11 -1070,23 +1073,23 @@@ FileData *blo_openblendermemory(void *m
        }
        else {
                FileData *fd = filedata_new();
+               char *cp = mem;
+               
                fd->buffer = mem;
                fd->buffersize = memsize;
 -                      fd->read = fd_read_from_memory;
+               
+               /* test if gzip */
+               if (cp[0] == 0x1f && cp[1] == 0x8b) {
+                       if (0 == fd_read_gzip_from_memory_init(fd)) {
+                               blo_freefiledata(fd);
+                               return NULL;
+                       }
+               }
+               else
 +              fd->read = fd_read_from_memory;
+                       
                fd->flags |= FD_FLAGS_NOT_MY_BUFFER;
 -
 +              
                return blo_decode_and_check(fd, reports);
        }
  }
@@@ -1176,6 -1235,14 +1238,14 @@@ static void *newmclipadr(FileData *fd, 
        return NULL;
  }
  
 -      
+ static void *newpackedadr(FileData *fd, void *adr)      /* used to restore packed data after undo */
+ {
+       if (fd->packedmap && adr)
+               return oldnewmap_lookup_and_inc(fd->packedmap, adr);
++
+       return oldnewmap_lookup_and_inc(fd->datamap, adr);
+ }
  
  static void *newlibadr(FileData *fd, void *lib, void *adr)            /* only lib data */
  {
@@@ -5734,7 -5842,13 +5868,13 @@@ static void direct_link_region(FileDat
                pa->activedata = NULL;
                pa->type = NULL;
        }
 -
 +      
+       link_list(fd, &ar->ui_lists);
+       for (ui_list = ar->ui_lists.first; ui_list; ui_list = ui_list->next) {
+               ui_list->type = NULL;
+       }
        ar->regiondata = newdataadr(fd, ar->regiondata);
        if (ar->regiondata) {
                if (spacetype == SPACE_VIEW3D) {
@@@ -8636,56 -8568,40 +8777,82 @@@ static void do_versions(FileData *fd, L
                }
        }
  
-       {
+       if (main->versionfile < 265 || (main->versionfile == 265 && main->subversionfile < 5)) {
                Scene *scene;
+               Image *image;
+               Tex *tex;
  
                for (scene = main->scene.first; scene; scene = scene->id.next) {
+                       Sequence *seq;
+                       SEQ_BEGIN (scene->ed, seq)
+                       {
+                               if (seq->flag & SEQ_MAKE_PREMUL)
+                                       seq->alpha_mode = SEQ_ALPHA_STRAIGHT;
+                       }
+                       SEQ_END
                        if (scene->r.bake_samples == 0)
 -                      scene->r.bake_samples = 256;
 +                              scene->r.bake_samples = 256;
                }
 -              }
+               for (image = main->image.first; image; image = image->id.next) {
+                       if (image->flag & IMA_DO_PREMUL)
+                               image->alpha_mode = IMA_ALPHA_STRAIGHT;
 +      }
  
+               for (tex = main->tex.first; tex; tex = tex->id.next) {
+                       if (tex->type == TEX_IMAGE && (tex->imaflag & TEX_USEALPHA) == 0) {
+                               image = blo_do_versions_newlibadr(fd, tex->id.lib, tex->ima);
+                               if (image)
+                                       image->flag |= IMA_IGNORE_ALPHA;
+                       }
+               }
+       }
++
 +#ifdef WITH_FREESTYLE
 +      /* default values in Freestyle settings */
 +      {
 +              Scene *sce;
 +              SceneRenderLayer *srl;
 +              FreestyleLineStyle *linestyle;
 +
 +              for(sce = main->scene.first; sce; sce = sce->id.next) {
 +                      if (sce->r.line_thickness_mode == 0) {
 +                              sce->r.line_thickness_mode = R_LINE_THICKNESS_ABSOLUTE;
 +                              sce->r.unit_line_thickness = 1.0f;
 +                      }
 +                      for(srl = sce->r.layers.first; srl; srl = srl->next) {
 +                              if (srl->freestyleConfig.mode == 0)
 +                                      srl->freestyleConfig.mode = FREESTYLE_CONTROL_EDITOR_MODE;
 +                              if (srl->freestyleConfig.raycasting_algorithm == FREESTYLE_ALGO_CULLED_ADAPTIVE_CUMULATIVE ||
 +                                  srl->freestyleConfig.raycasting_algorithm == FREESTYLE_ALGO_CULLED_ADAPTIVE_TRADITIONAL) {
 +                                      srl->freestyleConfig.raycasting_algorithm = 0; /* deprecated */
 +                                      srl->freestyleConfig.flags |= FREESTYLE_CULLING;
 +                              }
 +                      }
 +              }
 +              for(linestyle = main->linestyle.first; linestyle; linestyle = linestyle->id.next) {
 +#if 1
 +                      /* disable the Misc panel for now */
 +                      if (linestyle->panel == LS_PANEL_MISC) {
 +                              linestyle->panel = LS_PANEL_STROKES;
 +                      }
 +#endif
 +                      if (linestyle->thickness_position == 0) {
 +                              linestyle->thickness_position = LS_THICKNESS_CENTER;
 +                              linestyle->thickness_ratio = 0.5f;
 +                      }
 +                      if (linestyle->chaining == 0)
 +                              linestyle->chaining = LS_CHAINING_PLAIN;
 +                      if (linestyle->rounds == 0)
 +                              linestyle->rounds = 3;
 +              }
 +      }
 +#endif
 +
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
        /* WATCH IT 2!: Userdef struct init has to be in editors/interface/resources.c! */
  
@@@ -8796,7 -8710,14 +8964,14 @@@ static BHead *read_userdef(BlendFileDat
                for (kmi=keymap->items.first; kmi; kmi=kmi->next)
                        direct_link_keymapitem(fd, kmi);
        }
 -
 +      
+       for (addon = user->addons.first; addon; addon = addon->next) {
+               addon->prop = newdataadr(fd, addon->prop);
+               if (addon->prop) {
+                       IDP_DirectLinkProperty(addon->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
+               }
+       }
        // XXX
        user->uifonts.first = user->uifonts.last= NULL;
        
@@@ -9001,7 -8922,15 +9176,15 @@@ static void expand_doit_library(void *f
                                Library *lib = read_struct(fd, bheadlib, "Library");
                                Main *ptr = blo_find_main(fd, lib->name, fd->relabase);
                                
 -                                      id = is_yet_read(fd, ptr, bhead);
+                               if (ptr->curlib == NULL) {
+                                       const char *idname= bhead_id_name(fd, bhead);
+                                       
+                                       BKE_reportf_wrap(fd->reports, RPT_WARNING, TIP_("LIB ERROR: Data refers to main .blend file: '%s' from %s"),
+                                                        idname, mainvar->curlib->filepath);
+                                       return;
+                               }
+                               else
 +                              id = is_yet_read(fd, ptr, bhead);
                                
                                if (id == NULL) {
                                        read_libblock(fd, ptr, bhead, LIB_READ+LIB_INDIRECT, NULL);
@@@ -10299,12 -10189,26 +10482,26 @@@ static void read_libraries(FileData *ba
                                FileData *fd = mainptr->curlib->filedata;
                                
                                if (fd == NULL) {
+                                       
                                        /* printf and reports for now... its important users know this */
 -                                              BKE_reportf_wrap(basefd->reports, RPT_INFO, TIP_("Read library:  '%s', '%s'"),
 -                                                                               mainptr->curlib->filepath, mainptr->curlib->name);
 -                                              fd = blo_openblenderfile(mainptr->curlib->filepath, basefd->reports);
+                                       
+                                       /* if packed file... */
+                                       if (mainptr->curlib->packedfile) {
+                                               PackedFile *pf = mainptr->curlib->packedfile;
+                                               
+                                               BKE_reportf_wrap(basefd->reports, RPT_INFO, TIP_("Read packed library:  '%s'"),
+                                                                                mainptr->curlib->name);
+                                               fd = blo_openblendermemory(pf->data, pf->size, basefd->reports);
+                                               
+                                               
+                                               /* needed for library_append and read_libraries */
+                                               BLI_strncpy(fd->relabase, mainptr->curlib->filepath, sizeof(fd->relabase));
+                                       }
+                                       else {
-                                       
 +                                      BKE_reportf_wrap(basefd->reports, RPT_INFO, TIP_("Read library:  '%s', '%s'"),
 +                                                       mainptr->curlib->filepath, mainptr->curlib->name);
 +                                      fd = blo_openblenderfile(mainptr->curlib->filepath, basefd->reports);
+                                       }
                                        /* allow typing in a new lib path */
                                        if (G.debug_value == -666) {
                                                while (fd == NULL) {
Simple merge
Simple merge
@@@ -2408,193 -2339,18 +2349,18 @@@ static void uilist_draw_item_default(st
        namebuf = RNA_struct_name_get_alloc(itemptr, NULL, 0, NULL);
        name = (namebuf) ? namebuf : "";
  
-       /* hardcoded types */
-       if (itemptr->type == &RNA_MeshTexturePolyLayer || itemptr->type == &RNA_MeshLoopColorLayer) {
-               uiItemL(sub, name, icon);
-               uiBlockSetEmboss(block, UI_EMBOSSN);
-               uiDefIconButR(block, TOG, 0, ICON_SCENE, 0, 0, UI_UNIT_X, UI_UNIT_Y, itemptr, "active_render",
-                             0, 0, 0, 0, 0, NULL);
-               uiBlockSetEmboss(block, UI_EMBOSS);
+       /* Simplest one! */
+       switch (ui_list->layout_type) {
+       case UILST_LAYOUT_GRID:
+               uiItemL(layout, "", icon);
+               break;
+       case UILST_LAYOUT_DEFAULT:
+       case UILST_LAYOUT_COMPACT:
+       default:
+               uiItemL(layout, name, icon);
+               break;
        }
-       else if (RNA_struct_is_a(itemptr->type, &RNA_MaterialTextureSlot)) {
-               uiItemL(sub, name, icon);
-               uiBlockSetEmboss(block, UI_EMBOSS);
-               uiDefButR(block, OPTION, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, ptr, "use_textures", i, 0, 0, 0, 0,  NULL);
-       }
- #ifdef WITH_FREESTYLE
-       else if (RNA_struct_is_a(itemptr->type, &RNA_SceneRenderLayer) || 
-                RNA_struct_is_a(itemptr->type, &RNA_FreestyleLineSet)) {
- #else
-       else if (RNA_struct_is_a(itemptr->type, &RNA_SceneRenderLayer)) {
- #endif
-               uiItemL(sub, name, icon);
-               uiBlockSetEmboss(block, UI_EMBOSS);
-               uiDefButR(block, OPTION, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, itemptr, "use", 0, 0, 0, 0, 0,  NULL);
-       }
-       else if (RNA_struct_is_a(itemptr->type, &RNA_MaterialSlot)) {
-               /* provision to draw active node name */
-               Material *ma, *manode;
-               Scene *scene = CTX_data_scene(C);
-               Object *ob = (Object *)ptr->id.data;
-               int index = (Material **)itemptr->data - ob->mat;
-               
-               /* default item with material base name */
-               uiItemL(sub, name, icon);
 -
 +              
-               ma = give_current_material(ob, index + 1);
-               if (ma && !BKE_scene_use_new_shading_nodes(scene)) {
-                       manode = give_node_material(ma);
-                       if (manode) {
-                               char str[MAX_ID_NAME + 12];
-                               BLI_snprintf(str, sizeof(str), IFACE_("Node %s"), manode->id.name + 2);
-                               uiItemL(sub, str, ui_id_icon_get(C, &manode->id, 1));
-                       }
-                       else if (ma->use_nodes) {
-                               uiItemL(sub, IFACE_("Node <none>"), ICON_NONE);
-                       }
-               }
-       }
-       else if (itemptr->type == &RNA_ShapeKey) {
-               Object *ob = (Object *)activeptr->data;
-               Key *key = (Key *)itemptr->id.data;
-               KeyBlock *kb = (KeyBlock *)itemptr->data;
-               split = uiLayoutSplit(sub, 0.66f, FALSE);
-               uiItemL(split, name, icon);
-               uiBlockSetEmboss(block, UI_EMBOSSN);
-               row = uiLayoutRow(split, TRUE);
-               if (i == 0 || (key->type != KEY_RELATIVE)) uiItemL(row, "", ICON_NONE);
-               else uiItemR(row, itemptr, "value", 0, "", ICON_NONE);
-               uiItemR(row, itemptr, "mute", 0, "", ICON_NONE);
-               if ((kb->flag & KEYBLOCK_MUTE) ||
-                   (ob->mode == OB_MODE_EDIT && !((ob->shapeflag & OB_SHAPE_EDIT_MODE) && ob->type == OB_MESH)))
-               {
-                       uiLayoutSetActive(row, FALSE);
-               }
-               uiBlockSetEmboss(block, UI_EMBOSS);
-       }
-       else if (itemptr->type == &RNA_VertexGroup) {
-               bDeformGroup *dg = (bDeformGroup *)itemptr->data;
-               uiItemL(sub, name, icon);
-               /* RNA does not allow nice lock icons, use lower level buttons */
- #if 0
-               uiDefButR(block, OPTION, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, itemptr, "lock_weight", 0, 0, 0, 0, 0,  NULL);
- #else
-               uiBlockSetEmboss(block, UI_EMBOSSN);
-               uiDefIconButBitC(block, TOG, DG_LOCK_WEIGHT, 0, (dg->flag & DG_LOCK_WEIGHT) ? ICON_LOCKED : ICON_UNLOCKED,
-                                0, 0, UI_UNIT_X, UI_UNIT_Y, &dg->flag, 0, 0, 0, 0,
-                                TIP_("Maintain relative weights while painting"));
-               uiBlockSetEmboss(block, UI_EMBOSS);
- #endif
-       }
-       else if (itemptr->type == &RNA_KeyingSetPath) {
-               KS_Path *ksp = (KS_Path *)itemptr->data;
-               
-               /* icon needs to be the type of ID which is currently active */
-               RNA_enum_icon_from_value(id_type_items, ksp->idtype, &icon);
-               
-               /* nothing else special to do... */
-               uiItemL(sub, name, icon); /* fails, backdrop LISTROW... */
-       }
-       else if (itemptr->type == &RNA_DynamicPaintSurface) {
-               char name_final[96];
-               const char *enum_name;
-               PropertyRNA *prop = RNA_struct_find_property(itemptr, "surface_type");
-               DynamicPaintSurface *surface = (DynamicPaintSurface *)itemptr->data;
-               RNA_property_enum_name(C, itemptr, prop, RNA_property_enum_get(itemptr, prop), &enum_name);
-               BLI_snprintf(name_final, sizeof(name_final), "%s (%s)", name, enum_name);
-               uiItemL(sub, name_final, icon);
-               if (dynamicPaint_surfaceHasColorPreview(surface)) {
-                       uiBlockSetEmboss(block, UI_EMBOSSN);
-                       uiDefIconButR(block, OPTION, 0,
-                                     (surface->flags & MOD_DPAINT_PREVIEW) ? ICON_RESTRICT_VIEW_OFF : ICON_RESTRICT_VIEW_ON,
-                                     0, 0, UI_UNIT_X, UI_UNIT_Y, itemptr, "show_preview", 0, 0, 0, 0, 0, NULL);
-                       uiBlockSetEmboss(block, UI_EMBOSS);
-               }
-               uiDefButR(block, OPTION, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, itemptr, "is_active", i, 0, 0, 0, 0,  NULL);
-       }
-       else if (itemptr->type == &RNA_MovieTrackingObject) {
-               MovieTrackingObject *tracking_object = (MovieTrackingObject *)itemptr->data;
-               split = uiLayoutSplit(sub, 0.75f, FALSE);
-               if (tracking_object->flag & TRACKING_OBJECT_CAMERA) {
-                       uiItemL(split, name, ICON_CAMERA_DATA);
-               }
-               else {
-                       uiItemL(split, name, ICON_OBJECT_DATA);
-               }
-       }
-       else if (itemptr->type == &RNA_MaskLayer) {
-               split = uiLayoutRow(sub, FALSE);
-               uiItemL(split, name, icon);
-               uiBlockSetEmboss(block, UI_EMBOSSN);
-               row = uiLayoutRow(split, TRUE);
-               uiItemR(row, itemptr, "alpha", 0, "", ICON_NONE);
-               uiItemR(row, itemptr, "hide", 0, "", ICON_NONE);
-               uiItemR(row, itemptr, "hide_select", 0, "", ICON_NONE);
-               uiItemR(row, itemptr, "hide_render", 0, "", ICON_NONE);
-               uiBlockSetEmboss(block, UI_EMBOSS);
-       }
-       /* There is a last chance to display custom controls (in addition to the name/label):
-        * If the given item property group features a string property named as prop_list,
-        * this tries to add controls for all properties of the item listed in that string property.
-        * (colon-separated names).
-        *
-        * This is especially useful for python. E.g., if you list a collection of this property
-        * group:
-        *
-        * class TestPropertyGroup(bpy.types.PropertyGroup):
-        *     bool    = BoolProperty(default=False)
-        *     integer = IntProperty()
-        *     string  = StringProperty()
-        * 
-        *     # A string of all identifiers (colon-separated) which property's controls should be
-        *     # displayed in a template_list.
-        *     template_list_controls = StringProperty(default="integer:bool:string", options={"HIDDEN"})
-        *
-        * ... you'll get a numfield for the integer prop, a check box for the bool prop, and a textfield
-        * for the string prop, after the name of each item of the collection.
-        */
-       else if (prop_list_id) {
-               row = uiLayoutRow(sub, TRUE);
-               uiItemL(row, name, icon);
-               /* XXX: Check, as sometimes we get an itemptr looking like
-                *      {id = {data = 0x0}, type = 0x0, data = 0x0}
-                *      which would obviously produce a sigsev... */
-               if (itemptr->type) {
-                       /* If the special property is set for the item, and it is a collection... */
-                       PropertyRNA *prop_list = RNA_struct_find_property(itemptr, prop_list_id);
-                       if (prop_list && RNA_property_type(prop_list) == PROP_STRING) {
-                               int prop_names_len;
-                               char *prop_names = RNA_property_string_get_alloc(itemptr, prop_list, NULL, 0, &prop_names_len);
-                               char *prop_names_end = prop_names + prop_names_len;
-                               char *id = prop_names;
-                               char *id_next;
-                               while (id < prop_names_end) {
-                                       if ((id_next = strchr(id, ':'))) *id_next++ = '\0';
-                                       else id_next = prop_names_end;
-                                       uiItemR(row, itemptr, id, 0, NULL, ICON_NONE);
-                                       id = id_next;
-                               }
-                               MEM_freeN(prop_names);
-                       }
-               }
-       }
-       else
-               uiItemL(sub, name, icon);  /* fails, backdrop LISTROW... */
        /* free name */
        if (namebuf) {
                MEM_freeN(namebuf);
@@@ -2662,71 -2425,37 +2435,37 @@@ void uiTemplateList(uiLayout *layout, b
        }
  
        /* get active data */
-       activei = RNA_property_int_get(activeptr, activeprop);
-       if (listtype == 'i') {
-               box = uiLayoutListBox(layout, ptr, prop, activeptr, activeprop);
-               col = uiLayoutColumn(box, TRUE);
-               row = uiLayoutRow(col, FALSE);
+       activei = RNA_property_int_get(active_dataptr, activeprop);
  
-               if (ptr->data && prop) {
-                       /* create list items */
-                       RNA_PROP_BEGIN (ptr, itemptr, prop)
-                       {
-                               /* create button */
-                               if (!(i % 9))
-                                       row = uiLayoutRow(col, FALSE);
+       /* Find the uiList type. */
+       ui_list_type = WM_uilisttype_find(listtype_name, FALSE);
  
-                               icon = list_item_icon_get(C, &itemptr, rnaicon, 1);
-                               but = uiDefIconButR_prop(block, LISTROW, 0, icon, 0, 0, UI_UNIT_X * 10, UI_UNIT_Y, activeptr,
-                                                        activeprop, 0, 0, i, 0, 0, "");
-                               uiButSetFlag(but, UI_BUT_NO_TOOLTIP);
-                               
-                               i++;
+       if (ui_list_type == NULL) {
+               RNA_warning("List type %s not found", listtype_name);
+               return;
 -      }
 +                      }
-                       RNA_PROP_END;
-               }
-       }
-       else if (listtype == 'c') {
-               /* compact layout */
  
-               row = uiLayoutRow(layout, TRUE);
+       draw_item = ui_list_type->draw_item ? ui_list_type->draw_item : uilist_draw_item_default;
  
-               if (ptr->data && prop) {
-                       /* create list items */
-                       RNA_PROP_BEGIN (ptr, itemptr, prop)
-                       {
-                               found = (activei == i);
+       /* Find or add the uiList to the current Region. */
+       /* We tag the list id with the list type... */
+       BLI_snprintf(ui_list_id, sizeof(ui_list_id), "%s_%s", ui_list_type->idname, list_id ? list_id : "");
  
-                               if (found) {
-                                       /* create button */
-                                       name = RNA_struct_name_get_alloc(&itemptr, NULL, 0, NULL);
-                                       icon = list_item_icon_get(C, &itemptr, rnaicon, 0);
-                                       uiItemL(row, (name) ? name : "", icon);
+       ar = CTX_wm_region(C);
+       ui_list = BLI_findstring(&ar->ui_lists, ui_list_id, offsetof(uiList, list_id));
  
-                                       if (name) {
-                                               MEM_freeN((void *)name);
+       if (!ui_list) {
+               ui_list = MEM_callocN(sizeof(uiList), __func__);
+               BLI_strncpy(ui_list->list_id, ui_list_id, sizeof(ui_list->list_id));
+               BLI_addtail(&ar->ui_lists, ui_list);
 -      }
 +                                      }
-                               }
  
-                               i++;
-                       }
-                       RNA_PROP_END;
-               }
-               /* if not found, add in dummy button */
-               if (i == 0)
-                       uiItemL(row, "", ICON_NONE);
+       /* Because we can't actually pass type across save&load... */
+       ui_list->type = ui_list_type;
+       ui_list->layout_type = layout_type;
  
-               /* next/prev button */
-               BLI_snprintf(numstr, sizeof(numstr), "%d :", i);
-               but = uiDefIconTextButR_prop(block, NUM, 0, 0, numstr, 0, 0, UI_UNIT_X * 5, UI_UNIT_Y, activeptr,
-                                            activeprop, 0, 0, 0, 0, 0, "");
-               if (i == 0)
-                       uiButSetFlag(but, UI_BUT_DISABLED);
-       }
-       else {
+       switch (layout_type) {
+       case UILST_LAYOUT_DEFAULT:
                /* default rows */
                if (rows == 0)
                        rows = 5;
                /* add scrollbar */
                if (len > items) {
                        col = uiLayoutColumn(row, FALSE);
-                       uiDefButI(block, SCROLL, 0, "", 0, 0, UI_UNIT_X * 0.75, UI_UNIT_Y * items, &pa->list_scroll,
+                       uiDefButI(block, SCROLL, 0, "", 0, 0, UI_UNIT_X * 0.75, UI_UNIT_Y * items, &ui_list->list_scroll,
                                  0, len - items, items, 0, "");
                }
 -                              }
+               break;
+       case UILST_LAYOUT_COMPACT:
+               row = uiLayoutRow(layout, TRUE);
+               if (dataptr->data && prop) {
+                       /* create list items */
+                       RNA_PROP_BEGIN (dataptr, itemptr, prop)
+                       {
+                               found = (activei == i);
+                               if (found) {
+                                       icon = UI_rnaptr_icon_get(C, &itemptr, rnaicon, FALSE);
+                                       if (icon == ICON_DOT)
+                                               icon = ICON_NONE;
+                                       draw_item(ui_list, C, row, dataptr, &itemptr, icon, active_dataptr, active_propname, i);
 -                      }
++      }
+                               i++;
++}
+                       RNA_PROP_END;
+               }
+               /* if list is empty, add in dummy button */
+               if (i == 0)
+                       uiItemL(row, "", ICON_NONE);
+               /* next/prev button */
+               BLI_snprintf(numstr, sizeof(numstr), "%d :", i);
+               but = uiDefIconTextButR_prop(block, NUM, 0, 0, numstr, 0, 0, UI_UNIT_X * 5, UI_UNIT_Y,
+                                            active_dataptr, activeprop, 0, 0, 0, 0, 0, "");
+               if (i == 0)
+                       uiButSetFlag(but, UI_BUT_DISABLED);
+               break;
+       case UILST_LAYOUT_GRID:
+               box = uiLayoutListBox(layout, ui_list, dataptr, prop, active_dataptr, activeprop);
+               col = uiLayoutColumn(box, TRUE);
+               row = uiLayoutRow(col, FALSE);
+               if (dataptr->data && prop) {
+                       /* create list items */
+                       RNA_PROP_BEGIN (dataptr, itemptr, prop)
+                       {
+                               /* create button */
+                               if (!(i % 9))
+                                       row = uiLayoutRow(col, FALSE);
+                               subblock = uiLayoutGetBlock(row);
+                               overlap = uiLayoutOverlap(row);
+                               /* list item behind label & other buttons */
+                               sub = uiLayoutRow(overlap, FALSE);
+                               but = uiDefButR_prop(subblock, LISTROW, 0, "", 0, 0, UI_UNIT_X * 10, UI_UNIT_Y,
+                                                    active_dataptr, activeprop, 0, 0, i, 0, 0, "");
+                               uiButSetFlag(but, UI_BUT_NO_TOOLTIP);
+                               sub = uiLayoutRow(overlap, FALSE);
+                               icon = UI_rnaptr_icon_get(C, &itemptr, rnaicon, FALSE);
+                               draw_item(ui_list, C, sub, dataptr, &itemptr, icon, active_dataptr, active_propname, i);
+                               i++;
+                       }
+                       RNA_PROP_END;
+               }
+               break;
        }
  }
  
@@@ -126,14 -126,10 +126,14 @@@ typedef struct drawDMEdgesSel_userData 
  } drawDMEdgesSel_userData;
  
  typedef struct drawDMFacesSel_userData {
 +#ifdef WITH_FREESTYLE
 +      unsigned char *cols[4];
 +#else
        unsigned char *cols[3];
 +#endif
  
-       DerivedMesh *dm; /* BMESH BRANCH ONLY */
-       BMEditMesh *em;  /* BMESH BRANCH ONLY */
+       DerivedMesh *dm;
+       BMEditMesh *em;
  
        BMFace *efa_act;
        int *orig_index_mf_to_mpoly;
index 356b752,0000000..f80761c
mode 100644,000000..100644
--- /dev/null
@@@ -1,503 -1,0 +1,507 @@@
 +/*
 + * ***** BEGIN GPL LICENSE BLOCK *****
 + *
 + * This program is free software; you can redistribute it and/or
 + * modify it under the terms of the GNU General Public License
 + * as published by the Free Software Foundation; either version 2
 + * of the License, or (at your option) any later version.
 + *
 + * This program is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + * GNU General Public License for more details.
 + *
 + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 + *
 + * The Original Code is Copyright (C) 2010 Blender Foundation.
 + * All rights reserved.
 + *
 + * The Original Code is: all of this file.
 + *
 + * Contributor(s): none yet.
 + *
 + * ***** END GPL LICENSE BLOCK *****
 + */
 +
 +/** \file blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
 + *  \ingroup freestyle
 + */
 +
 +#include "BlenderStrokeRenderer.h"
 +#include "BlenderTextureManager.h"
 +
 +#include "../application/AppConfig.h"
 +#include "../stroke/Canvas.h"
 +
 +#include "BKE_global.h"
 +
 +// XXX Are those "ifdef __cplusplus" useful here?
 +#ifdef __cplusplus
 +extern "C" {
 +#endif
 +
 +#include "MEM_guardedalloc.h"
 +
 +#include "DNA_camera_types.h"
 +#include "DNA_customdata_types.h"
 +#include "DNA_listBase.h"
 +#include "DNA_meshdata_types.h"
 +#include "DNA_mesh_types.h"
 +#include "DNA_object_types.h"
 +#include "DNA_screen_types.h"
 +
 +#include "BKE_customdata.h"
 +#include "BKE_global.h"
 +#include "BKE_library.h" /* free_libblock */
 +#include "BKE_main.h" /* struct Main */
 +#include "BKE_material.h"
 +#include "BKE_mesh.h"
 +#include "BKE_object.h"
 +#include "BKE_scene.h"
 +
 +#include "RE_pipeline.h"
 +
 +#ifdef __cplusplus
 +}
 +#endif
 +
 +BlenderStrokeRenderer::BlenderStrokeRenderer(Render* re, int render_count) : StrokeRenderer()
 +{
 +      // TEMPORARY - need a  texture manager
 +      _textureManager = new BlenderTextureManager;
 +      _textureManager->load();
 +
 +      // for stroke mesh generation
 +      _width = re->winx;
 +      _height = re->winy;
 +
 +      //Scene.New("FreestyleStrokes")
 +      old_scene = re->scene;
 +
 +      char name[22];
 +      BLI_snprintf(name, sizeof(name), "FRS%d_%s", render_count, re->scene->id.name + 2);
 +      freestyle_scene = BKE_scene_add(G.main, name);
 +      freestyle_scene->r.cfra = old_scene->r.cfra;
 +      freestyle_scene->r.mode = old_scene->r.mode &
 +                                ~(R_EDGE_FRS | R_SHADOW | R_SSS | R_PANORAMA | R_ENVMAP | R_MBLUR | R_BORDER);
 +      freestyle_scene->r.xsch = re->rectx; // old_scene->r.xsch
 +      freestyle_scene->r.ysch = re->recty; // old_scene->r.ysch
 +      freestyle_scene->r.xasp = 1.0f; // old_scene->r.xasp;
 +      freestyle_scene->r.yasp = 1.0f; // old_scene->r.yasp;
 +      freestyle_scene->r.tilex = old_scene->r.tilex;
 +      freestyle_scene->r.tiley = old_scene->r.tiley;
 +      freestyle_scene->r.size = 100; // old_scene->r.size
 +      freestyle_scene->r.maximsize = old_scene->r.maximsize;
 +      freestyle_scene->r.ocres = old_scene->r.ocres;
 +      freestyle_scene->r.color_mgt_flag = 0; // old_scene->r.color_mgt_flag;
 +      freestyle_scene->r.scemode = old_scene->r.scemode & ~(R_SINGLE_LAYER);
 +      freestyle_scene->r.flag = old_scene->r.flag;
 +      freestyle_scene->r.threads = old_scene->r.threads;
 +      freestyle_scene->r.border.xmin = old_scene->r.border.xmin;
 +      freestyle_scene->r.border.ymin = old_scene->r.border.ymin;
 +      freestyle_scene->r.border.xmax = old_scene->r.border.xmax;
 +      freestyle_scene->r.border.ymax = old_scene->r.border.ymax;
 +      strcpy(freestyle_scene->r.pic, old_scene->r.pic);
 +      freestyle_scene->r.safety.xmin = old_scene->r.safety.xmin;
 +      freestyle_scene->r.safety.ymin = old_scene->r.safety.ymin;
 +      freestyle_scene->r.safety.xmax = old_scene->r.safety.xmax;
 +      freestyle_scene->r.safety.ymax = old_scene->r.safety.ymax;
 +      freestyle_scene->r.osa = old_scene->r.osa;
 +      freestyle_scene->r.filtertype = old_scene->r.filtertype;
 +      freestyle_scene->r.gauss = old_scene->r.gauss;
 +      freestyle_scene->r.dither_intensity = old_scene->r.dither_intensity;
 +      BLI_strncpy(freestyle_scene->r.engine, old_scene->r.engine, sizeof(freestyle_scene->r.engine));
 +      freestyle_scene->r.im_format.planes = R_IMF_PLANES_RGBA; 
 +      freestyle_scene->r.im_format.imtype = R_IMF_IMTYPE_PNG;
 +      BKE_scene_disable_color_management(freestyle_scene);
 +
++      // Render layer
++      SceneRenderLayer *srl = (SceneRenderLayer *)freestyle_scene->r.layers.first;
++      srl->layflag = SCE_LAY_SOLID | SCE_LAY_ZTRA;
++
 +      BKE_scene_set_background(G.main, freestyle_scene);
 +
 +      // Camera
 +      Object* object_camera = BKE_object_add(freestyle_scene, OB_CAMERA);
 +
 +      Camera* camera = (Camera *)object_camera->data;
 +      camera->type = CAM_ORTHO;
 +      camera->ortho_scale = max(re->rectx, re->recty);
 +      camera->clipsta = 0.1f;
 +      camera->clipend = 100.0f;
 +
 +      _z_delta = 0.00001f;
 +      _z = camera->clipsta + _z_delta;
 +
 +      // test
 +      //_z = 999.90f; _z_delta = 0.01f;
 +
 +      object_camera->loc[0] = re->disprect.xmin + 0.5f * re->rectx;
 +      object_camera->loc[1] = re->disprect.ymin + 0.5f * re->recty;
 +      object_camera->loc[2] = 1.0f;
 +
 +      freestyle_scene->camera = object_camera;
 +
 +      // Material
 +      material = BKE_material_add("stroke_material");
 +      material->mode |= MA_VERTEXCOLP;
 +      material->mode |= MA_TRANSP;
 +      material->mode |= MA_SHLESS;
 +      material->vcol_alpha = 1;
 +}
 +
 +BlenderStrokeRenderer::~BlenderStrokeRenderer()
 +{
 +      if (0 != _textureManager) {
 +              delete _textureManager;
 +              _textureManager = NULL;
 +      }
 +
 +      // The freestyle_scene object is not released here.  Instead,
 +      // the scene is released in free_all_freestyle_renders() in
 +      // source/blender/render/intern/source/pipeline.c, after the
 +      // compositor has finished.
 +
 +      // release objects and data blocks
 +      for (Base *b = (Base*)freestyle_scene->base.first; b; b = b->next) {
 +              Object *ob = b->object;
 +              void *data = ob->data;
 +              char name[24];
 +              strcpy(name, ob->id.name);
 +#if 0
 +              if (G.debug & G_DEBUG_FREESTYLE) {
 +                      cout << "removing " << name[0] << name[1] << ":" << (name+2) << endl;
 +              }
 +#endif
 +              switch (ob->type) {
 +              case OB_MESH:
 +                      BKE_libblock_free(&G.main->object, ob);
 +                      BKE_libblock_free(&G.main->mesh, data);
 +                      break;
 +              case OB_CAMERA:
 +                      BKE_libblock_free(&G.main->object, ob);
 +                      BKE_libblock_free(&G.main->camera, data);
 +                      freestyle_scene->camera = NULL;
 +                      break;
 +              default:
 +                      cerr << "Warning: unexpected object in the scene: " << name[0] << name[1] << ":" << (name+2) << endl;
 +              }
 +      }
 +      BLI_freelistN(&freestyle_scene->base);
 +
 +      // release material
 +      BKE_libblock_free(&G.main->mat, material);
 +
 +      BKE_scene_set_background(G.main, old_scene);
 +}
 +
 +float BlenderStrokeRenderer::get_stroke_vertex_z(void) const
 +{
 +      float z = _z;
 +      BlenderStrokeRenderer *self = const_cast<BlenderStrokeRenderer *>(this);
 +      if (!(_z < _z_delta * 100000.0f))
 +              self->_z_delta *= 10.0f;
 +      self->_z += _z_delta;
 +      return -z;
 +}
 +
 +void BlenderStrokeRenderer::RenderStrokeRep(StrokeRep *iStrokeRep) const
 +{
 +      RenderStrokeRepBasic(iStrokeRep);
 +}
 +
 +void BlenderStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const
 +{
 +      ////////////////////
 +      //  Build up scene
 +      ////////////////////
 +
 +      vector<Strip*>& strips = iStrokeRep->getStrips();
 +      Strip::vertex_container::iterator v[3];
 +      StrokeVertexRep *svRep[3];
 +      Vec3r color[3];
 +      unsigned int vertex_index, edge_index, loop_index;
 +      Vec2r p;
 +
 +      for (vector<Strip*>::iterator s = strips.begin(), send = strips.end();
 +           s != send;
 +           ++s){
 +              Strip::vertex_container& strip_vertices = (*s)->vertices();
 +              int strip_vertex_count = (*s)->sizeStrip();
 +              int xl, xu, yl, yu, n, visible_faces, visible_segments;
 +              bool visible;
 +
 +              // iterate over all vertices and count visible faces and strip segments
 +              // (note: a strip segment is a series of visible faces, while two strip
 +              // segments are separated by one or more invisible faces)
 +              v[0] = strip_vertices.begin();
 +              v[1] = v[0] + 1;
 +              v[2] = v[0] + 2;
 +              visible_faces = visible_segments = 0;
 +              visible = false;
 +              for (n = 2; n < strip_vertex_count; n++, v[0]++, v[1]++, v[2]++) {
 +                      svRep[0] = *(v[0]);
 +                      svRep[1] = *(v[1]);
 +                      svRep[2] = *(v[2]);
 +                      xl = xu = yl = yu = 0;
 +                      for (int j = 0; j < 3; j++) {
 +                              p = svRep[j]->point2d();
 +                              if (p[0] < 0.0)
 +                                      xl++;
 +                              else if (p[0] > _width)
 +                                      xu++;
 +                              if (p[1] < 0.0)
 +                                      yl++;
 +                              else if (p[1] > _height)
 +                                      yu++;
 +                      }
 +                      if (xl == 3 || xu == 3 || yl == 3 || yu == 3) {
 +                              visible = false;
 +                      }
 +                      else {
 +                              visible_faces++;
 +                              if (!visible)
 +                                      visible_segments++;
 +                              visible = true;
 +                      }
 +              }
 +              if (visible_faces == 0)
 +                      continue;
 +
 +              //me = Mesh.New()
 +#if 0
 +              Object* object_mesh = BKE_object_add(freestyle_scene, OB_MESH);
 +#else
 +              Object* object_mesh = NewMesh();
 +#endif
 +              Mesh* mesh = (Mesh*)object_mesh->data;
 +#if 0
 +              MEM_freeN(mesh->bb);
 +              mesh->bb = NULL;
 +              mesh->id.us = 0;
 +#endif
 +#if 1
 +              //me.materials = [mat]
 +              mesh->mat = (Material**)MEM_mallocN(1 * sizeof(Material*), "MaterialList");
 +              mesh->mat[0] = material;
 +              mesh->totcol = 1;
 +              test_object_materials((ID*)mesh);
 +#else
 +              assign_material(object_mesh, material, object_mesh->totcol + 1);
 +              object_mesh->actcol = object_mesh->totcol;
 +#endif
 +
 +              // vertices allocation
 +              mesh->totvert = visible_faces + visible_segments * 2;
 +              mesh->mvert = (MVert*)CustomData_add_layer(&mesh->vdata, CD_MVERT, CD_CALLOC, NULL, mesh->totvert);
 +
 +              // edges allocation
 +              mesh->totedge = visible_faces * 2 + visible_segments;
 +              mesh->medge = (MEdge*)CustomData_add_layer(&mesh->edata, CD_MEDGE, CD_CALLOC, NULL, mesh->totedge);
 +
 +              // faces allocation
 +              mesh->totpoly = visible_faces;
 +              mesh->mpoly = (MPoly*)CustomData_add_layer(&mesh->pdata, CD_MPOLY, CD_CALLOC, NULL, mesh->totpoly);
 +
 +              // loops allocation
 +              mesh->totloop = visible_faces * 3;
 +              mesh->mloop = (MLoop*)CustomData_add_layer(&mesh->ldata, CD_MLOOP, CD_CALLOC, NULL, mesh->totloop);
 +
 +              // colors allocation
 +              mesh->mloopcol = (MLoopCol*)CustomData_add_layer(&mesh->ldata, CD_MLOOPCOL, CD_CALLOC, NULL, mesh->totloop);
 +
 +              ////////////////////
 +              //  Data copy
 +              ////////////////////
 +
 +              MVert *vertices = mesh->mvert;
 +              MEdge *edges = mesh->medge;
 +              MPoly *polys = mesh->mpoly;
 +              MLoop *loops = mesh->mloop;
 +              MLoopCol *colors = mesh->mloopcol;
 +
 +              v[0] = strip_vertices.begin();
 +              v[1] = v[0] + 1;
 +              v[2] = v[0] + 2;
 +
 +              vertex_index = edge_index = loop_index = 0;
 +              visible = false;
 +
 +              // Note: Mesh generation in the following loop assumes stroke strips
 +              // to be triangle strips.
 +              for (n = 2; n < strip_vertex_count; n++, v[0]++, v[1]++, v[2]++) {
 +                      svRep[0] = *(v[0]);
 +                      svRep[1] = *(v[1]);
 +                      svRep[2] = *(v[2]);
 +                      xl = xu = yl = yu = 0;
 +                      for (int j = 0; j < 3; j++) {
 +                              p = svRep[j]->point2d();
 +                              if (p[0] < 0.0)
 +                                      xl++;
 +                              else if (p[0] > _width)
 +                                      xu++;
 +                              if (p[1] < 0.0)
 +                                      yl++;
 +                              else if (p[1] > _height)
 +                                      yu++;
 +                      }
 +                      if (xl == 3 || xu == 3 || yl == 3 || yu == 3) {
 +                              visible = false;
 +                      }
 +                      else {
 +                              if (!visible) {
 +                                      // first vertex
 +                                      vertices->co[0] = svRep[0]->point2d()[0];
 +                                      vertices->co[1] = svRep[0]->point2d()[1];
 +                                      vertices->co[2] = get_stroke_vertex_z();
 +                                      ++vertices;
 +                                      ++vertex_index;
 +
 +                                      // second vertex
 +                                      vertices->co[0] = svRep[1]->point2d()[0];
 +                                      vertices->co[1] = svRep[1]->point2d()[1];
 +                                      vertices->co[2] = get_stroke_vertex_z();
 +                                      ++vertices;
 +                                      ++vertex_index;
 +
 +                                      // first edge
 +                                      edges->v1 = vertex_index - 2;
 +                                      edges->v2 = vertex_index - 1;
 +                                      ++edges;
 +                                      ++edge_index;
 +                              }
 +                              visible = true;
 +
 +                              // vertex
 +                              vertices->co[0] = svRep[2]->point2d()[0];
 +                              vertices->co[1] = svRep[2]->point2d()[1];
 +                              vertices->co[2] = get_stroke_vertex_z();
 +                              ++vertices;
 +                              ++vertex_index;
 +
 +                              // edges
 +                              edges->v1 = vertex_index - 1;
 +                              edges->v2 = vertex_index - 3;
 +                              ++edges;
 +                              ++edge_index;
 +
 +                              edges->v1 = vertex_index - 1;
 +                              edges->v2 = vertex_index - 2;
 +                              ++edges;
 +                              ++edge_index;
 +
 +                              // poly
 +                              polys->loopstart = loop_index;
 +                              polys->totloop = 3;
 +                              ++polys;
 +
 +                              // loops
 +                              if (n % 2 == 0) {
 +                                      loops[0].v = vertex_index - 1;
 +                                      loops[0].e = edge_index - 1;
 +
 +                                      loops[1].v = vertex_index - 2;
 +                                      loops[1].e = edge_index - 3;
 +
 +                                      loops[2].v = vertex_index - 3;
 +                                      loops[2].e = edge_index - 2;
 +                              }
 +                              else {
 +                                      loops[0].v = vertex_index - 1;
 +                                      loops[0].e = edge_index - 2;
 +
 +                                      loops[1].v = vertex_index - 3;
 +                                      loops[1].e = edge_index - 3;
 +
 +                                      loops[2].v = vertex_index - 2;
 +                                      loops[2].e = edge_index - 1;
 +                              }
 +                              loops += 3;
 +                              loop_index += 3;
 +
 +                              // colors
 +                              if (n % 2 == 0) {
 +                                      colors[0].r = (short)(255.0f * svRep[2]->color()[0]);
 +                                      colors[0].g = (short)(255.0f * svRep[2]->color()[1]);
 +                                      colors[0].b = (short)(255.0f * svRep[2]->color()[2]);
 +                                      colors[0].a = (short)(255.0f * svRep[2]->alpha());
 +
 +                                      colors[1].r = (short)(255.0f * svRep[1]->color()[0]);
 +                                      colors[1].g = (short)(255.0f * svRep[1]->color()[1]);
 +                                      colors[1].b = (short)(255.0f * svRep[1]->color()[2]);
 +                                      colors[1].a = (short)(255.0f * svRep[1]->alpha());
 +
 +                                      colors[2].r = (short)(255.0f * svRep[0]->color()[0]);
 +                                      colors[2].g = (short)(255.0f * svRep[0]->color()[1]);
 +                                      colors[2].b = (short)(255.0f * svRep[0]->color()[2]);
 +                                      colors[2].a = (short)(255.0f * svRep[0]->alpha());
 +                              }
 +                              else {
 +                                      colors[0].r = (short)(255.0f * svRep[2]->color()[0]);
 +                                      colors[0].g = (short)(255.0f * svRep[2]->color()[1]);
 +                                      colors[0].b = (short)(255.0f * svRep[2]->color()[2]);
 +                                      colors[0].a = (short)(255.0f * svRep[2]->alpha());
 +
 +                                      colors[1].r = (short)(255.0f * svRep[0]->color()[0]);
 +                                      colors[1].g = (short)(255.0f * svRep[0]->color()[1]);
 +                                      colors[1].b = (short)(255.0f * svRep[0]->color()[2]);
 +                                      colors[1].a = (short)(255.0f * svRep[0]->alpha());
 +
 +                                      colors[2].r = (short)(255.0f * svRep[1]->color()[0]);
 +                                      colors[2].g = (short)(255.0f * svRep[1]->color()[1]);
 +                                      colors[2].b = (short)(255.0f * svRep[1]->color()[2]);
 +                                      colors[2].a = (short)(255.0f * svRep[1]->alpha());
 +                              }
 +                              colors += 3;
 +                      }
 +              } // loop over strip vertices
 +#if 0
 +              BKE_mesh_validate(mesh, TRUE);
 +#endif
 +      } // loop over strips
 +}
 +
 +// A replacement of BKE_object_add() for better performance.
 +Object *BlenderStrokeRenderer::NewMesh() const
 +{
 +      Object *ob;
 +      Base *base;
 +      char name[MAX_ID_NAME];
 +      static unsigned int mesh_id = 0xffffffff;
 +
 +      BLI_snprintf(name, MAX_ID_NAME, "0%08xOB", mesh_id);
 +      ob = BKE_object_add_only_object(OB_MESH, name);
 +      BLI_snprintf(name, MAX_ID_NAME, "0%08xME", mesh_id);
 +      ob->data = BKE_mesh_add(name);
 +      ob->lay = 1;
 +
 +      base = BKE_scene_base_add(freestyle_scene, ob);
 +#if 0
 +      BKE_scene_base_deselect_all(scene);
 +      BKE_scene_base_select(scene, base);
 +#endif
 +      ob->recalc |= OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME;
 +
 +      --mesh_id;
 +
 +      return ob;
 +}
 +
 +Render* BlenderStrokeRenderer::RenderScene(Render *re)
 +{
 +      Camera *camera = (Camera*)freestyle_scene->camera->data;
 +      if (camera->clipend < _z)
 +              camera->clipend = _z + _z_delta * 100.0f;
 +#if 0
 +      if (G.debug & G_DEBUG_FREESTYLE) {
 +              cout << "clipsta " << camera->clipsta << ", clipend " << camera->clipend << endl;
 +      }
 +#endif
 +
 +      Render *freestyle_render = RE_NewRender(freestyle_scene->id.name);
 +
 +      RE_RenderFreestyleStrokes(freestyle_render, G.main, freestyle_scene);
 +      return freestyle_render;
 +}
Simple merge
Simple merge
@@@ -132,13 -135,9 +135,16 @@@ extern EnumPropertyItem prop_dynamicpai
  
  extern EnumPropertyItem clip_editor_mode_items[];
  
+ extern EnumPropertyItem icon_items[];
+ extern EnumPropertyItem uilist_layout_type_items[];
 +#ifdef WITH_FREESTYLE
 +extern EnumPropertyItem linestyle_color_modifier_type_items[];
 +extern EnumPropertyItem linestyle_alpha_modifier_type_items[];
 +extern EnumPropertyItem linestyle_thickness_modifier_type_items[];
 +extern EnumPropertyItem linestyle_geometry_modifier_type_items[];
 +#endif
 +
  struct bContext;
  struct PointerRNA;
  struct PropertyRNA;
Simple merge
  
  #include "bpy_app_build_options.h"
  
- static PyObject *make_build_options(void)
+ static PyTypeObject BlenderAppBuildOptionsType;
+ static PyStructSequence_Field app_builtopts_info_fields[] = {
+       /* names mostly follow CMake options, lowecases, after WITH_ */
+       {(char *)"bullet", NULL},
+       {(char *)"codec_avi", NULL},
+       {(char *)"codec_ffmpeg", NULL},
+       {(char *)"codec_quicktime", NULL},
+       {(char *)"codec_sndfile", NULL},
+       {(char *)"compositor", NULL},
+       {(char *)"cycles", NULL},
+       {(char *)"cycles_osl", NULL},
++      {(char *)"freestyle", NULL},
+       {(char *)"gameengine", NULL},
+       {(char *)"image_cineon", NULL},
+       {(char *)"image_dds", NULL},
+       {(char *)"image_frameserver", NULL},
+       {(char *)"image_hdr", NULL},
+       {(char *)"image_openexr", NULL},
+       {(char *)"image_openjpeg", NULL},
+       {(char *)"image_redcode", NULL},
+       {(char *)"image_tiff", NULL},
+       {(char *)"input_ndof", NULL},
+       {(char *)"audaspace", NULL},
+       {(char *)"international", NULL},
+       {(char *)"openal", NULL},
+       {(char *)"sdl", NULL},
+       {(char *)"jack", NULL},
+       {(char *)"libmv", NULL},
+       {(char *)"mod_boolean", NULL},
+       {(char *)"mod_fluid", NULL},
+       {(char *)"mod_oceansim", NULL},
+       {(char *)"mod_remesh", NULL},
+       {(char *)"mod_smoke", NULL},
+       {(char *)"collada", NULL},
+       {(char *)"opencolorio", NULL},
+       {(char *)"player", NULL},
+       {NULL}
+ };
+ static PyStructSequence_Desc app_builtopts_info_desc = {
+       (char *)"bpy.app.build_options",     /* name */
+       (char *)"This module contains information about FFmpeg blender is linked against",    /* doc */
+       app_builtopts_info_fields,    /* fields */
+       (sizeof(app_builtopts_info_fields) / sizeof(PyStructSequence_Field)) - 1
+ };
+ static PyObject *make_builtopts_info(void)
  {
-       PyObject *build_options = PyFrozenSet_New(NULL);
+       PyObject *builtopts_info;
+       int pos = 0;
  
- #define SetStrItem(str) \
-       PySet_Add(build_options, PyUnicode_FromString(str));
+       builtopts_info = PyStructSequence_New(&BlenderAppBuildOptionsType);
+       if (builtopts_info == NULL) {
+               return NULL;
+       }
  
- #ifdef WITH_AUDASPACE
-       SetStrItem("AUDASPACE");
- #endif
+ #define SetObjIncref(item) \
+       PyStructSequence_SET_ITEM(builtopts_info, pos++, (Py_IncRef(item), item))
  
  #ifdef WITH_BULLET
-       SetStrItem("BULLET");
+       SetObjIncref(Py_True);
+ #else
+       SetObjIncref(Py_False);
  #endif
  
  #ifdef WITH_AVI
  #endif
  
  #ifdef WITH_CYCLES_OSL
-       SetStrItem("CYCLES_OSL");
+       SetObjIncref(Py_True);
+ #else
+       SetObjIncref(Py_False);
  #endif
  
-       SetStrItem("FREESTYLE");
 +#ifdef WITH_FREESTYLE
++      SetObjIncref(Py_True);
++#else
++      SetObjIncref(Py_False);
 +#endif
 +
  #ifdef WITH_GAMEENGINE
-       SetStrItem("GAMEENGINE");
+       SetObjIncref(Py_True);
+ #else
+       SetObjIncref(Py_False);
  #endif
  
  #ifdef WITH_CINEON
Simple merge
Simple merge