[Bf-blender-cvs] [7c9467ae1fd] greasepencil-object: Palette Slots - Add UI panel for Palette slots

Joshua Leung noreply at git.blender.org
Wed Oct 4 14:17:11 CEST 2017


Commit: 7c9467ae1fd0bfcf97dd5411fee0be60becb7325
Author: Joshua Leung
Date:   Wed Oct 4 12:27:02 2017 +1300
Branches: greasepencil-object
https://developer.blender.org/rB7c9467ae1fd0bfcf97dd5411fee0be60becb7325

Palette Slots - Add UI panel for Palette slots

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

M	release/scripts/startup/bl_ui/properties_material_gpencil.py
M	source/blender/makesrna/intern/rna_gpencil.c

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

diff --git a/release/scripts/startup/bl_ui/properties_material_gpencil.py b/release/scripts/startup/bl_ui/properties_material_gpencil.py
index d60264f33eb..6c0e541c79a 100644
--- a/release/scripts/startup/bl_ui/properties_material_gpencil.py
+++ b/release/scripts/startup/bl_ui/properties_material_gpencil.py
@@ -18,7 +18,23 @@
 
 # <pep8 compliant>
 import bpy
-from bpy.types import Panel
+from bpy.types import Panel, UIList
+
+
+class GPENCIL_UL_paletteslots(UIList):
+    def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
+        # assert(isinstance(item, bpy.types.GPencilPaletteSlot)
+        # ob = data
+        slot = item
+        palette = slot.palette
+        if self.layout_type in {'DEFAULT', 'COMPACT'}:
+            if palette:
+                layout.prop(palette, "name", text="", emboss=False, icon_value=icon)
+            else:
+                layout.label(text="", icon_value=icon)
+        elif self.layout_type == 'GRID':
+            layout.alignment = 'CENTER'
+            layout.label(text="", icon_value=icon)
 
 
 class MaterialButtonsPanel:
@@ -31,43 +47,63 @@ class MaterialButtonsPanel:
         return context.object and context.object.type == 'GPENCIL'
 
 
-class MATERIAL_PT_gpencil_palettecolor(Panel):
-    bl_label = "Grease Pencil Colors"
+class MATERIAL_PT_gpencil_palette_slots(Panel):
+    bl_label = "Palette Slots"
     bl_space_type = 'PROPERTIES'
     bl_region_type = 'WINDOW'
     bl_context = "material"
-    #bl_options = {'HIDE_HEADER'}
+    bl_options = {'HIDE_HEADER'}
 
     @classmethod
     def poll(cls, context):
         return context.object and context.object.type == 'GPENCIL'
-        
+
     @staticmethod
-    def paint_settings(context):
-        toolsettings = context.tool_settings
+    def draw(self, context):
+        layout = self.layout
+        gpd = context.gpencil_data
 
-        if context.sculpt_object:
-            return toolsettings.sculpt
-        elif context.vertex_paint_object:
-            return toolsettings.vertex_paint
-        elif context.weight_paint_object:
-            return toolsettings.weight_paint
-        elif context.image_paint_object:
-            if (toolsettings.image_paint and toolsettings.image_paint.detect_data()):
-                return toolsettings.image_paint
+        row = layout.row()
+        col = row.column()
+        if len(gpd.palette_slots) >= 2:
+            slot_rows = 5
+        else:
+            slot_rows = 2
+        col.template_list("GPENCIL_UL_paletteslots", "", gpd, "palette_slots", gpd, "active_palette_index",
+                          rows=slot_rows)
+
+        col = row.column()
+
+        sub = col.column(align=True)
+        sub.operator("palette.color_add", icon='ZOOMIN', text="").grease_pencil = True
+        sub.operator("palette.color_delete", icon='ZOOMOUT', text="")
 
-            return toolsettings.image_paint
+        sub = col.column(align=True)
+        sub.operator_menu_enum("gpencil.stroke_change_palette", text="", icon='ARROW_LEFTRIGHT', property="type")
 
-        return toolsettings.image_paint
 
+class MATERIAL_PT_gpencil_palette_colors(Panel):
+    bl_label = "Active Palette"
+    bl_space_type = 'PROPERTIES'
+    bl_region_type = 'WINDOW'
+    bl_context = "material"
+
+    @classmethod
+    def poll(cls, context):
+        return context.object and context.object.type == 'GPENCIL'
+    
     @staticmethod
     def draw(self, context):
         layout = self.layout
-        palette = context.active_palette
-        paint = self.paint_settings(context)
+        
+        gpd = context.gpencil_data
+        slot = gpd.palette_slots[gpd.active_palette_index] # XXX
+        
+        #palette = context.active_palette
+        palette = slot.palette if slot else None
 
         row = layout.row()
-        row.template_ID(paint, "palette", new="palette.new_gpencil")
+        row.template_ID(slot, "palette", new="palette.new_gpencil")
 
         if palette:
             row = layout.row()
@@ -102,9 +138,6 @@ class MATERIAL_PT_gpencil_palettecolor(Panel):
                 sub.operator("palette.palettecolor_isolate", icon='LOCKED', text="").affect_visibility = False
                 sub.operator("palette.palettecolor_isolate", icon='RESTRICT_VIEW_OFF', text="").affect_visibility = True
 
-            row = layout.row()
-            row.operator_menu_enum("gpencil.stroke_change_palette", text="Change Palette...", property="type")
-
 
 class MATERIAL_PT_gpencil_palette_strokecolor(Panel):
     bl_label = "Stroke"
@@ -227,7 +260,9 @@ class MATERIAL_PT_gpencil_palette_fillcolor(Panel):
 
 
 classes = (
-    MATERIAL_PT_gpencil_palettecolor,
+    GPENCIL_UL_paletteslots,
+    MATERIAL_PT_gpencil_palette_slots,
+    MATERIAL_PT_gpencil_palette_colors,
     MATERIAL_PT_gpencil_palette_strokecolor,
     MATERIAL_PT_gpencil_palette_fillcolor,
 )
diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c
index 94cb5f65429..5c27c2e3b4b 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -162,6 +162,14 @@ static void rna_GPencilPaletteSlot_palette_set(PointerRNA *ptr, PointerRNA value
 	BKE_gpencil_paletteslot_set_palette(gpd, palslot, palette);
 }
 
+static void rna_GPencil_active_palette_index_range(PointerRNA *ptr, int *min, int *max,
+                                                   int *UNUSED(softmin), int *UNUSED(softmax))
+{
+	bGPdata *gpd = (bGPdata *)ptr->id.data;
+	*min = 0;
+	*max = BLI_listbase_count(&gpd->palette_slots) - 1;
+}
+
 static char *rna_GPencilLayer_path(PointerRNA *ptr)
 {
 	bGPDlayer *gpl = (bGPDlayer *)ptr->data;
@@ -1366,6 +1374,9 @@ static void rna_def_gpencil_data(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Layers", "");
 	rna_def_gpencil_layers_api(brna, prop);
 	
+	/* Animation Data */
+	rna_def_animdata_common(srna);
+	
 	/* Palette Slots */
 	prop = RNA_def_property(srna, "palette_slots", PROP_COLLECTION, PROP_NONE);
 	RNA_def_property_collection_sdna(prop, NULL, "palette_slots", NULL);
@@ -1373,8 +1384,15 @@ static void rna_def_gpencil_data(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Palette Slots", "");
 	rna_def_gpencil_palette_slots_api(brna, prop);
 	
-	/* Animation Data */
-	rna_def_animdata_common(srna);
+	prop = RNA_def_property(srna, "active_palette_index", PROP_INT, PROP_UNSIGNED);
+	RNA_def_property_int_sdna(prop, NULL, "active_palette_slot");
+	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+	RNA_def_property_int_funcs(prop, NULL, NULL,
+	                           "rna_GPencil_active_palette_index_range");
+	RNA_def_property_ui_text(prop, "Active Palette Index", "Index of active palette slot");
+	RNA_def_property_update(prop, NC_MATERIAL, NULL);
+	
+	
 	
 	/* xray modes */
 	prop = RNA_def_property(srna, "xray_mode", PROP_ENUM, PROP_NONE);



More information about the Bf-blender-cvs mailing list