[Bf-blender-cvs] [ec8ad8d] GPencil_EditStrokes: Grease Pencil Layers UI: Ported properties panel to Python and UI Lists

Joshua Leung noreply at git.blender.org
Sun Oct 12 13:54:04 CEST 2014


Commit: ec8ad8d0c47af5e3550f625614a5c3933e9438e3
Author: Joshua Leung
Date:   Mon Oct 13 00:53:45 2014 +1300
Branches: GPencil_EditStrokes
https://developer.blender.org/rBec8ad8d0c47af5e3550f625614a5c3933e9438e3

Grease Pencil Layers UI: Ported properties panel to Python and UI Lists

This commit ports the Grease Pencil properties panel (which displayed the layers info)
to Python, and simplifies the design by using UI Lists instead of listing out the
contents of each layer inline. The resulting design is a lot more compact, and should
also be more easily scannable, especially when you have lots of layers.

For now, I've left all the old C-based layers code alone, but just commented out
in case we need to roll back this commit. So far, all the editors seem to be behaving
correctly, but I may have glossed over some details.

===================================================================

M	release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M	release/scripts/startup/bl_ui/space_clip.py
M	release/scripts/startup/bl_ui/space_image.py
M	release/scripts/startup/bl_ui/space_node.py
M	release/scripts/startup/bl_ui/space_sequencer.py
M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/editors/space_clip/clip_buttons.c
M	source/blender/editors/space_image/image_buttons.c
M	source/blender/editors/space_node/node_buttons.c
M	source/blender/editors/space_sequencer/sequencer_buttons.c
M	source/blender/editors/space_view3d/view3d_buttons.c
M	source/blender/makesrna/intern/rna_gpencil.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
index c2870cf..d5333c9 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -20,13 +20,31 @@
 
 
 import bpy
-from bpy.types import Menu
+from bpy.types import Menu, UIList
+
+
+def gpencil_stroke_placement_settings(context, layout, gpd):
+    col = layout.column(align=True)
+
+    col.label(text="Stroke Placement:")
+
+    row = col.row(align=True)
+    row.prop_enum(gpd, "draw_mode", 'VIEW')
+    row.prop_enum(gpd, "draw_mode", 'CURSOR')
+
+    if context.space_data.type == 'VIEW_3D':
+        row = col.row(align=True)
+        row.prop_enum(gpd, "draw_mode", 'SURFACE')
+        row.prop_enum(gpd, "draw_mode", 'STROKE')
+
+        row = col.row(align=False)
+        row.active = gpd.draw_mode in ('SURFACE', 'STROKE')
+        row.prop(gpd, "use_stroke_endpoints")
 
 
 class GreasePencilDrawingToolsPanel():
     # subclass must set
     # bl_space_type = 'IMAGE_EDITOR'
-    # bl_region_type = 'TOOLS'
     bl_label = "Grease Pencil"
     bl_category = "Grease Pencil"
     bl_region_type = 'TOOLS'
@@ -53,21 +71,8 @@ class GreasePencilDrawingToolsPanel():
         gpd = context.gpencil_data
         if gpd:
             col.separator()
+            gpencil_stroke_placement_settings(context, col, gpd)
 
-            col.label(text="Stroke Placement:")
-
-            row = col.row(align=True)
-            row.prop_enum(gpd, "draw_mode", 'VIEW')
-            row.prop_enum(gpd, "draw_mode", 'CURSOR')
-
-            if context.space_data.type == 'VIEW_3D':
-                row = col.row(align=True)
-                row.prop_enum(gpd, "draw_mode", 'SURFACE')
-                row.prop_enum(gpd, "draw_mode", 'STROKE')
-
-                row = col.row(align=False)
-                row.active = gpd.draw_mode in ('SURFACE', 'STROKE')
-                row.prop(gpd, "use_stroke_endpoints")
 
         if context.space_data.type == 'VIEW_3D':
             col.separator()
@@ -115,7 +120,6 @@ class GreasePencilStrokeEditPanel():
 
 ###############################
 
-
 class GPENCIL_PIE_tool_palette(Menu):
     """A pie menu for quick access to Grease Pencil tools"""
     bl_label = "Grease Pencil Tools"
@@ -157,3 +161,127 @@ class GPENCIL_PIE_tool_palette(Menu):
 
             # SE - Mirror?  (Best would be to do Settings here...)
             pie.operator("transform.mirror", text="Mirror", icon='MOD_MIRROR').gpencil_strokes = True
+
+
+###############################
+
+class GPENCIL_UL_layer(UIList):
+    def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
+        # assert(isinstance(item, bpy.types.GPencilLayer)
+        gpl = item
+
+        if self.layout_type in {'DEFAULT', 'COMPACT'}:
+            if gpl.lock:
+                layout.active = False
+
+            split = layout.split(percentage=0.2)
+            split.prop(gpl, "color", text="")
+            split.prop(gpl, "info", text="", emboss=False)
+
+            row = layout.row(align=True)
+            row.prop(gpl, "lock", text="", emboss=False)
+            row.prop(gpl, "hide", text="", emboss=False)
+        elif self.layout_type in {'GRID'}:
+            layout.alignment = 'CENTER'
+            layout.label(text="", icon_value=icon)
+
+
+class GPENCIL_MT_layer_specials(Menu):
+    bl_label = "Grease Pencil Layer Specials"
+    #COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
+
+    def draw(self, context):
+        layout = self.layout
+
+        layout.operator("gpencil.convert", text='Convert', icon='OUTLINER_OB_CURVE')  # icon is not ideal
+        layout.operator("gpencil.active_frame_delete", text="Delete Frame", icon='X')  # icon is not ideal
+
+
+class GreasePencilDataPanel():
+    # subclass must set
+    # bl_space_type = 'IMAGE_EDITOR'
+    bl_label = "Grease Pencil"
+    bl_region_type = 'UI'
+
+    @staticmethod
+    def draw_header(self, context):
+        self.layout.prop(context.space_data, "show_grease_pencil", text="")
+
+
+    @staticmethod
+    def draw(self, context):
+        layout = self.layout
+
+        # owner of Grease Pencil data
+        # TODO: owner selector
+        gpd_owner = context.gpencil_data_owner
+        gpd = context.gpencil_data
+
+        # Grease Pencil data selector
+        layout.template_ID(gpd_owner, "grease_pencil", new="gpencil.data_add", unlink="gpencil.data_unlink")
+
+        # Grease Pencil data...
+        if gpd is None:
+            # even with no data, this operator will still work, as it makes gpd too
+            layout.operator("gpencil.layer_add", text="New Layer", icon='ZOOMIN')
+        else:
+            self.draw_layers(context, layout, gpd)
+
+            layout.separator()
+            layout.separator()
+
+            gpencil_stroke_placement_settings(context, layout, gpd)
+
+
+    def draw_layers(self, context, layout, gpd):
+        row = layout.row()
+
+        col = row.column()
+        col.template_list("GPENCIL_UL_layer", "", gpd, "layers", gpd.layers, "active_index", rows=5)
+
+        col = row.column()
+
+        sub = col.column(align=True)
+        sub.operator("gpencil.layer_add", icon='ZOOMIN', text="")
+        sub.operator("gpencil.layer_remove", icon='ZOOMOUT', text="")
+        sub.menu("GPENCIL_MT_layer_specials", icon='DOWNARROW_HLT', text="")
+
+        gpl = context.active_gpencil_layer
+        if gpl:
+            col.separator()
+
+            sub = col.column(align=True)
+            sub.operator("gpencil.layer_move", icon='TRIA_UP', text="").type = 'UP'
+            sub.operator("gpencil.layer_move", icon='TRIA_DOWN', text="").type = 'DOWN'
+
+
+            # layer settings
+            split = layout.split(percentage=0.5)
+            split.active = not gpl.lock
+
+            # Column 1 - Appearance
+            col = split.column()
+
+            subcol = col.column(align=True)
+            subcol.prop(gpl, "color", text="")
+            subcol.prop(gpl, "alpha", slider=True)
+
+            col.prop(gpl, "line_width", slider=True)
+
+            #if debug:
+            #   col.prop(gpl, "show_points")
+
+            # Column 2 - Options (& Current Frame)
+            col = split.column(align=True)
+            # Onion skinning
+            col.prop(gpl, "use_onion_skinning")
+            col.prop(gpl, "ghost_range_max", text="Frames")
+
+            col.prop(gpl, "show_x_ray")
+
+            if gpl.active_frame:
+                lock_status = "Locked" if gpl.lock_frame else "Unlocked"
+                lock_label = "Frame: %d (%s)" % (gpl.active_frame.frame_number, lock_status)
+            else:
+                lock_label = "Lock Frame"
+            layout.prop(gpl, "lock_frame", text=lock_label, icon='UNLOCKED')
diff --git a/release/scripts/startup/bl_ui/space_clip.py b/release/scripts/startup/bl_ui/space_clip.py
index 371f210..64190a8 100644
--- a/release/scripts/startup/bl_ui/space_clip.py
+++ b/release/scripts/startup/bl_ui/space_clip.py
@@ -23,7 +23,8 @@ from bpy.types import Panel, Header, Menu, UIList
 from bpy.app.translations import pgettext_iface as iface_
 from bl_ui.properties_grease_pencil_common import (
         GreasePencilDrawingToolsPanel,
-        GreasePencilStrokeEditPanel
+        GreasePencilStrokeEditPanel,
+        GreasePencilDataPanel
         )
 
 
@@ -1053,16 +1054,6 @@ class CLIP_PT_tools_mask(MASK_PT_tools, Panel):
 # --- end mask ---
 
 
-# Grease Pencil drawing tools
-class CLIP_PT_tools_grease_pencil_draw(GreasePencilDrawingToolsPanel, Panel):
-    bl_space_type = 'CLIP_EDITOR'
-
-
-# Grease Pencil stroke editing tools
-class CLIP_PT_tools_grease_pencil_edit(GreasePencilStrokeEditPanel, Panel):
-    bl_space_type = 'CLIP_EDITOR'
-
-
 class CLIP_PT_footage(CLIP_PT_clip_view_panel, Panel):
     bl_space_type = 'CLIP_EDITOR'
     bl_region_type = 'UI'
@@ -1117,6 +1108,26 @@ class CLIP_PT_tools_scenesetup(Panel):
         layout.operator("clip.setup_tracking_scene")
 
 
+# Grease Pencil properties
+class CLIP_PT_grease_pencil(GreasePencilDataPanel, CLIP_PT_clip_view_panel, Panel):
+    bl_space_type = 'CLIP_EDITOR'
+    bl_region_type = 'UI'
+    bl_options = {'DEFAULT_CLOSED'}
+
+    # NOTE: this is just a wrapper around the generic GP Panel
+    # But, this should only be visible in "clip" view
+
+
+# Grease Pencil drawing tools
+class CLIP_PT_tools_grease_pencil_draw(GreasePencilDrawingToolsPanel, Panel):
+    bl_space_type = 'CLIP_EDITOR'
+
+
+# Grease Pencil stroke editing tools
+class CLIP_PT_tools_grease_pencil_edit(GreasePencilStrokeEditPanel, Panel):
+    bl_space_type = 'CLIP_EDITOR'
+
+
 class CLIP_MT_view(Menu):
     bl_label = "View"
 
diff --git a/release/scripts/startup/bl_ui/space_image.py b/release/scripts/startup/bl_ui/space_image.py
index 83cfd8c..2944ef0 100644
--- a/release/scripts/startup/bl_ui/space_image.py
+++ b/release/scripts/startup/bl_ui/space_image.py
@@ -27,7 +27,8 @@ from bl_ui.properties_paint_common import (
         )
 from bl_ui.properties_grease_pencil_common import (
         GreasePencilDrawingToolsPanel,
-        GreasePencilStrokeEditPanel
+        GreasePencilStrokeEditPanel,
+        GreasePencilDataPanel
         )
 from bpy.app.translations import pgettext_iface as iface_
 
@@ -1145,6 +1146,13 @@ class IMAGE_PT_scope_sample(Panel):
         sub.prop(sima.scopes, "accuracy")
 
 
+# Grease Pencil properties
+class IMAGE_PT_grease_pencil(GreasePencilDataPanel, Panel):
+    bl_space_type = 'IMAGE_EDITOR'
+    bl_region_type = 'UI'
+
+    # NOTE: this is just a wrapper around the generic GP Panel
+
 # Grease Pencil drawing tools
 class IMAGE_PT_tools_grease_pencil_draw(GreasePencilDrawingToolsPanel, Panel):
     bl_space_type = 'IMAGE_EDITOR'
diff --git a/release/scripts/startup/bl_ui/space_node.py b/release/scripts/startup/bl_ui/space_node.py
index 0c844af..6495196 100644
--- a/release/scripts/startup/bl_ui/space_node.py
+++ b/release/scripts/startup/bl_ui/space_node.py
@@ -21,7 +21,8 @@ import bpy
 from bpy.types import Header, Menu, Panel
 from bl_ui.properties_grease_pencil_common import (
         GreasePencilDrawingToolsPanel,
-      

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list