[Bf-blender-cvs] [a0acc64d35e] greasepencil-object: Palette Slots - File IO and Basic RNA support

Joshua Leung noreply at git.blender.org
Thu Sep 28 15:51:17 CEST 2017


Commit: a0acc64d35e26777746ae449b2ca81c296684676
Author: Joshua Leung
Date:   Fri Sep 29 02:37:51 2017 +1300
Branches: greasepencil-object
https://developer.blender.org/rBa0acc64d35e26777746ae449b2ca81c296684676

Palette Slots - File IO and Basic RNA support

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

M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_gpencil.c

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

diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 83701d684c6..a0722469473 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -6544,6 +6544,11 @@ static void lib_link_gpencil(FileData *fd, Main *main)
 					}
 				}
 			}
+			
+			/* Palette Slots */
+			for (bGPDpaletteref *gpref = gpd->palette_slots.first; gpref; gpref = gpref->next) {
+				gpref->palette = newlibadr_us(fd, gpd->id.lib, gpref->palette);
+			}
 
 			IDP_LibLinkProperty(gpd->id.properties, fd);
 			lib_link_animdata(fd, &gpd->id, gpd->adt);
@@ -6587,6 +6592,9 @@ static void direct_link_gpencil(FileData *fd, bGPdata *gpd)
 	for (palette = gpd->palettes.first; palette; palette = palette->next) {
 		link_list(fd, &palette->colors);
 	}
+	
+	/* relink palette slots */
+	link_list(fd, &gpd->palette_slots);
 
 	/* relink layers */
 	link_list(fd, &gpd->layers);
@@ -10076,6 +10084,10 @@ static void expand_gpencil(FileData *fd, Main *mainvar, bGPdata *gpd)
 			}
 		}
 	}
+	
+	for (bGPDpaletteref *gpref = gpd->palette_slots.first; gpref; gpref = gpref->next) {
+		expand_doit(fd, mainvar, gpref->palette);
+	}
 }
 
 static void expand_palette(FileData *fd, Main *mainvar, Palette *palette)
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index a0ed06c6a18..c2e22a45ccd 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -2830,14 +2830,9 @@ static void write_gpencil(WriteData *wd, bGPdata *gpd)
 				}
 			}
 		}
-#if 0       
-		/* since 2.8 the palettes uses BlenderPalettes, so do not save old palettes */
-		/* write grease-pencil palettes */
-		writelist(wd, DATA, bGPDpalette, &gpd->palettes);
-		for (bGPDpalette *palette = gpd->palettes.first; palette; palette = palette->next) {
-			writelist(wd, DATA, bGPDpalettecolor, &palette->colors);
-		}
-#endif
+       
+		/* write GP Palette Slots to file */
+		writelist(wd, DATA, bGPDpaletteref, &gpd->palette_slots);
 	}
 }
 
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index 416c5320937..6a6951e1662 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -269,6 +269,7 @@ extern StructRNA RNA_GPencilPalette;
 extern StructRNA RNA_GPencilPaletteColor;
 extern StructRNA RNA_GPencilBrush;
 extern StructRNA RNA_GPencilInterpolateSettings;
+extern StructRNA RNA_GPencilPaletteSlot;
 extern StructRNA RNA_GPencilStroke;
 extern StructRNA RNA_GPencilStrokePoint;
 extern StructRNA RNA_GPencilSculptSettings;
diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c
index a2f3c8679fc..1c569defef1 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -124,6 +124,34 @@ static void UNUSED_FUNCTION(rna_GPencil_onion_skinning_update)(Main *bmain, Scen
 	rna_GPencil_update(bmain, scene, ptr);
 }
 
+static char *rna_GPencilPaletteSlot_path(PointerRNA *ptr)
+{
+	bGPdata *gpd = (bGPdata *)ptr->id.data;
+	int index = BLI_findindex(&gpd->palette_slots, ptr->data);
+	
+	return BLI_sprintfN("palette_slots[%d]", index);
+}
+
+static int rna_GPencilPaletteSlot_name_length(PointerRNA *ptr)
+{
+	bGPDpaletteref *gpref = ptr->data;
+	
+	if (gpref->palette)
+		return strlen(gpref->palette->id.name + 2);
+	
+	return 0;
+}
+
+static void rna_GPencilPaletteSlot_name_get(PointerRNA *ptr, char *str)
+{
+	bGPDpaletteref *gpref = ptr->data;
+	
+	if (gpref->palette)
+		strcpy(str, gpref->palette->id.name + 2);
+	else
+		str[0] = '\0';
+}
+
 static char *rna_GPencilLayer_path(PointerRNA *ptr)
 {
 	bGPDlayer *gpl = (bGPDlayer *)ptr->data;
@@ -661,6 +689,45 @@ static int rna_GPencil_info_total_palettes(PointerRNA *ptr)
 
 #else
 
+static void rna_def_gpencil_palette_slot(BlenderRNA *brna)
+{
+	StructRNA *srna;
+	PropertyRNA *prop;
+	
+	srna = RNA_def_struct(brna, "GPencilPaletteSlot", NULL);
+	RNA_def_struct_sdna(srna, "bGPDpaletteref");
+	RNA_def_struct_path_func(srna, "rna_GPencilPaletteSlot_path");
+	RNA_def_struct_ui_text(srna, "Grease Pencil Palette Slot", "Reference for a Palette used in Grease Pencil datablock");
+	
+	prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
+	RNA_def_property_string_funcs(prop, "rna_GPencilPaletteSlot_name_get", "rna_GPencilPaletteSlot_name_length", NULL);
+	RNA_def_property_ui_text(prop, "Name", "Palette slot name");
+	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+	RNA_def_struct_name_property(srna, prop);
+	
+	prop = RNA_def_property(srna, "palette", PROP_POINTER, PROP_NONE);
+	RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT);
+	//RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_GPencilPalette_id_poll");
+	RNA_def_property_ui_text(prop, "Palette", "Palette data-block used by this palette slot");
+	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
+}
+
+static void rna_def_gpencil_palette_slots_api(BlenderRNA *brna, PropertyRNA *cprop)
+{
+	StructRNA *srna;
+	PropertyRNA *prop;
+
+	FunctionRNA *func;
+	PropertyRNA *parm;
+
+	RNA_def_property_srna(cprop, "GreasePencilPaletteSlots");
+	srna = RNA_def_struct(brna, "GreasePencilPaletteSlots", NULL);
+	RNA_def_struct_sdna(srna, "bGPdata");
+	RNA_def_struct_ui_text(srna, "Grease Pencil Palette Slots", "Collection of grease pencil palette slots");
+
+	/* TODO: API methods... new/remove/active */
+}
+
 /* information of vertex groups by point */
 static void rna_def_gpencil_point_weight(BlenderRNA *brna)
 {
@@ -1285,6 +1352,13 @@ static void rna_def_gpencil_data(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Layers", "");
 	rna_def_gpencil_layers_api(brna, prop);
 	
+	/* Palette Slots */
+	prop = RNA_def_property(srna, "palette_slots", PROP_COLLECTION, PROP_NONE);
+	RNA_def_property_collection_sdna(prop, NULL, "palette_slots", NULL);
+	RNA_def_property_struct_type(prop, "GPencilPaletteSlot");
+	RNA_def_property_ui_text(prop, "Palette Slots", "");
+	rna_def_gpencil_palette_slots_api(brna, prop);
+	
 	/* Animation Data */
 	rna_def_animdata_common(srna);
 	
@@ -1472,6 +1546,8 @@ void RNA_def_gpencil(BlenderRNA *brna)
 	rna_def_gpencil_stroke(brna);
 	rna_def_gpencil_stroke_point(brna);
 	rna_def_gpencil_point_weight(brna);
+	
+	rna_def_gpencil_palette_slot(brna);
 }
 
 #endif



More information about the Bf-blender-cvs mailing list