Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2015-03-18 07:09:04 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-03-18 08:10:43 +0300
commit29195197147a882849859ea963cae42484dfeaba (patch)
treeb45cf4a573fda9a1ff45c1eb2dd158cb5e15e1ff /source/blender/makesrna/intern/rna_palette.c
parenta975a3ca63d155e9ee1f0ba96fd451c330885aaa (diff)
RNA: palette colors api
Methods so Python can manage colors. palette.colors.new()/remove()/clear()/active
Diffstat (limited to 'source/blender/makesrna/intern/rna_palette.c')
-rw-r--r--source/blender/makesrna/intern/rna_palette.c92
1 files changed, 90 insertions, 2 deletions
diff --git a/source/blender/makesrna/intern/rna_palette.c b/source/blender/makesrna/intern/rna_palette.c
index 54e5881a44c..7405df967a0 100644
--- a/source/blender/makesrna/intern/rna_palette.c
+++ b/source/blender/makesrna/intern/rna_palette.c
@@ -27,6 +27,7 @@
#include "BLI_utildefines.h"
#include "RNA_define.h"
+#include "RNA_access.h"
#include "rna_internal.h"
@@ -36,8 +37,96 @@
#include "DNA_brush_types.h"
+#include "BKE_paint.h"
+#include "BKE_report.h"
+
+static PaletteColor *rna_Palette_color_new(Palette *palette)
+{
+ PaletteColor *color = BKE_palette_color_add(palette);
+ return color;
+}
+
+static void rna_Palette_color_remove(Palette *palette, ReportList *reports, PointerRNA *color_ptr)
+{
+ PaletteColor *color = color_ptr->data;
+
+ if (BLI_findindex(&palette->colors, color) == -1) {
+ BKE_reportf(reports, RPT_ERROR, "Palette '%s' does not contain color given", palette->id.name + 2);
+ return;
+ }
+
+ BKE_palette_color_remove_ex(palette, color, true);
+
+ RNA_POINTER_INVALIDATE(color_ptr);
+}
+
+static void rna_Palette_color_clear(Palette *palette)
+{
+ BKE_palette_clear(palette);
+}
+
+static PointerRNA rna_Palette_active_color_get(PointerRNA *ptr)
+{
+ Palette *palette = ptr->data;
+ PaletteColor *color;
+
+ color = BLI_findlink(&palette->colors, palette->active_color);
+
+ if (color)
+ return rna_pointer_inherit_refine(ptr, &RNA_PaletteColor, color);
+
+ return rna_pointer_inherit_refine(ptr, NULL, NULL);
+}
+
+static void rna_Palette_active_color_set(PointerRNA *ptr, PointerRNA value)
+{
+ Palette *palette = ptr->data;
+ PaletteColor *color = value.data;
+
+ /* -1 is ok for an unset index */
+ if (color == NULL)
+ palette->active_color = -1;
+ else
+ palette->active_color = BLI_findindex(&palette->colors, color);
+}
+
#else
+/* palette.colors */
+static void rna_def_palettecolors(BlenderRNA *brna, PropertyRNA *cprop)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ FunctionRNA *func;
+ PropertyRNA *parm;
+
+ RNA_def_property_srna(cprop, "PaletteColors");
+ srna = RNA_def_struct(brna, "PaletteColors", NULL);
+ RNA_def_struct_sdna(srna, "Palette");
+ RNA_def_struct_ui_text(srna, "Palette Splines", "Collection of palette colors");
+
+ func = RNA_def_function(srna, "new", "rna_Palette_color_new");
+ RNA_def_function_ui_description(func, "Add a new color to the palette");
+ parm = RNA_def_pointer(func, "color", "PaletteColor", "", "The newly created color");
+ RNA_def_function_return(func, parm);
+
+ func = RNA_def_function(srna, "remove", "rna_Palette_color_remove");
+ RNA_def_function_ui_description(func, "Remove a color from the palette");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ parm = RNA_def_pointer(func, "color", "PaletteColor", "", "The color to remove");
+ RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR);
+ RNA_def_property_clear_flag(parm, PROP_THICK_WRAP);
+
+ func = RNA_def_function(srna, "clear", "rna_Palette_color_clear");
+ RNA_def_function_ui_description(func, "Remove all colors from the palette");
+
+ prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
+ RNA_def_property_struct_type(prop, "PaletteColor");
+ RNA_def_property_pointer_funcs(prop, "rna_Palette_active_color_get", "rna_Palette_active_color_set", NULL, NULL);
+ RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_ui_text(prop, "Active Palette Color", "");
+}
static void rna_def_palettecolor(BlenderRNA *brna)
{
@@ -77,8 +166,7 @@ static void rna_def_palette(BlenderRNA *brna)
prop = RNA_def_property(srna, "colors", PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_type(prop, "PaletteColor");
- RNA_def_property_ui_text(prop, "Palette Color", "Colors that are part of this palette");
- RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
+ rna_def_palettecolors(brna, prop);
}
void RNA_def_palette(BlenderRNA *brna)