[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58288] branches/soc-2013-paint/source/ blender: Some renames, operators for adding colours to palette, fixes to

Antony Riakiotakis kalast at gmail.com
Mon Jul 15 23:42:52 CEST 2013


Revision: 58288
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58288
Author:   psy-fi
Date:     2013-07-15 21:42:51 +0000 (Mon, 15 Jul 2013)
Log Message:
-----------
Some renames, operators for adding colours to palette, fixes to
read/write of palettes, RNA properties of colours.

Modified Paths:
--------------
    branches/soc-2013-paint/source/blender/blenkernel/BKE_paint.h
    branches/soc-2013-paint/source/blender/blenkernel/intern/library.c
    branches/soc-2013-paint/source/blender/blenkernel/intern/paint.c
    branches/soc-2013-paint/source/blender/blenloader/intern/readfile.c
    branches/soc-2013-paint/source/blender/blenloader/intern/writefile.c
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_ops.c
    branches/soc-2013-paint/source/blender/makesdna/DNA_brush_types.h
    branches/soc-2013-paint/source/blender/makesrna/intern/rna_sculpt_paint.c

Modified: branches/soc-2013-paint/source/blender/blenkernel/BKE_paint.h
===================================================================
--- branches/soc-2013-paint/source/blender/blenkernel/BKE_paint.h	2013-07-15 21:38:37 UTC (rev 58287)
+++ branches/soc-2013-paint/source/blender/blenkernel/BKE_paint.h	2013-07-15 21:42:51 UTC (rev 58288)
@@ -52,6 +52,7 @@
 struct ImagePool;
 struct UnifiedPaintSettings;
 struct Palette;
+struct PaletteColor;
 struct Main;
 
 enum OverlayFlags;
@@ -96,7 +97,9 @@
 void BKE_paint_free(struct Paint *p);
 void BKE_paint_copy(struct Paint *src, struct Paint *tar);
 
+void BKE_free_palette(struct Palette *palette);
 struct Palette *BKE_palette_add(struct Main *bmain, const char *name);
+struct PaletteColor *BKE_palette_color_add(struct Palette *palette);
 
 struct Paint *BKE_paint_get_active(struct Scene *sce);
 struct Paint *BKE_paint_get_active_from_context(const struct bContext *C);

Modified: branches/soc-2013-paint/source/blender/blenkernel/intern/library.c
===================================================================
--- branches/soc-2013-paint/source/blender/blenkernel/intern/library.c	2013-07-15 21:38:37 UTC (rev 58287)
+++ branches/soc-2013-paint/source/blender/blenkernel/intern/library.c	2013-07-15 21:42:51 UTC (rev 58288)
@@ -104,6 +104,7 @@
 #include "BKE_mask.h"
 #include "BKE_node.h"
 #include "BKE_object.h"
+#include "BKE_paint.h"
 #include "BKE_particle.h"
 #include "BKE_packedFile.h"
 #include "BKE_speaker.h"
@@ -980,6 +981,7 @@
 			BKE_free_linestyle((FreestyleLineStyle *)id);
 			break;
 		case ID_PAL:
+			BKE_free_palette((Palette *)id);
 			break;
 	}
 

Modified: branches/soc-2013-paint/source/blender/blenkernel/intern/paint.c
===================================================================
--- branches/soc-2013-paint/source/blender/blenkernel/intern/paint.c	2013-07-15 21:38:37 UTC (rev 58287)
+++ branches/soc-2013-paint/source/blender/blenkernel/intern/paint.c	2013-07-15 21:42:51 UTC (rev 58288)
@@ -44,6 +44,7 @@
 #include "BLI_bitmap.h"
 #include "BLI_utildefines.h"
 #include "BLI_math_vector.h"
+#include "BLI_listbase.h"
 
 #include "BKE_brush.h"
 #include "BKE_main.h"
@@ -294,7 +295,17 @@
 	return palette;
 }
 
+void BKE_free_palette (Palette *palette) {
+	BLI_freelistN(&palette->colors);
+}
 
+PaletteColor *BKE_palette_color_add(Palette *palette)
+{
+	PaletteColor *color = MEM_callocN(sizeof(*color), "Pallete Color");
+	BLI_addtail(&palette->colors, color);
+	return color;
+}
+
 /* are we in vertex paint or weight pain face select mode? */
 int paint_facesel_test(Object *ob)
 {
@@ -327,8 +338,12 @@
 	palette = BKE_paint_palette(p);
 	if (brush == NULL)
 		brush = BKE_brush_add(G.main, "Brush");
-	if (palette == NULL)
-		palette = BKE_palette_add(G.main, "Palette");
+	if (palette == NULL) {
+		if (G.main->palettes.first)
+			palette = (Palette *) G.main->palettes.first;
+		else
+			palette = BKE_palette_add(G.main, "Palette");
+	}
 
 	BKE_paint_brush_set(p, brush);
 	BKE_paint_palette_set(p, palette);

Modified: branches/soc-2013-paint/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/soc-2013-paint/source/blender/blenloader/intern/readfile.c	2013-07-15 21:38:37 UTC (rev 58287)
+++ branches/soc-2013-paint/source/blender/blenloader/intern/readfile.c	2013-07-15 21:42:51 UTC (rev 58288)
@@ -1840,7 +1840,7 @@
 }
 
 /* ************ READ Palette *************** */
-static void lib_link_palette(FileData *UNUSED(fd), Main *main)
+static void lib_link_palette(FileData *fd, Main *main)
 {
 	Palette *palette;
 
@@ -1848,6 +1848,8 @@
 	for (palette = main->palettes.first; palette; palette = palette->id.next) {
 		if (palette->id.flag & LIB_NEED_LINK) {
 			palette->id.flag -= LIB_NEED_LINK;
+
+			if (palette->id.properties) IDP_LibLinkProperty(palette->id.properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
 		}
 	}
 }
@@ -1855,7 +1857,7 @@
 static void direct_link_palette(FileData *fd, Palette *palette)
 {
 	/* palette itself has been read */
-	palette->colours = newdataadr(fd, palette->colours);
+	link_list(fd, &palette->colors);
 }
 
 

Modified: branches/soc-2013-paint/source/blender/blenloader/intern/writefile.c
===================================================================
--- branches/soc-2013-paint/source/blender/blenloader/intern/writefile.c	2013-07-15 21:38:37 UTC (rev 58287)
+++ branches/soc-2013-paint/source/blender/blenloader/intern/writefile.c	2013-07-15 21:42:51 UTC (rev 58288)
@@ -2861,11 +2861,12 @@
 
 	for (palette = idbase->first; palette; palette= palette->id.next) {
 		if (palette->id.us > 0 || wd->current) {
+			PaletteColor *color;
 			writestruct(wd, ID_PAL, "Palette", 1, palette);
 			if (palette->id.properties) IDP_WriteProperty(palette->id.properties, wd);
 
-			if (palette->colours)
-				writedata(wd, DATA, palette->num_of_colours, palette->colours);
+			for (color = palette->colors.first; color; color= color->next)
+				writestruct(wd, DATA, "PaletteColor", 1, color);
 		}
 	}
 }

Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_ops.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_ops.c	2013-07-15 21:38:37 UTC (rev 58287)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_ops.c	2013-07-15 21:42:51 UTC (rev 58288)
@@ -169,7 +169,7 @@
 {
 	/* identifiers */
 	ot->name = "Add New Palette";
-	ot->description = "Add New Palette";
+	ot->description = "Add new palette";
 	ot->idname = "PALETTE_OT_new";
 
 	/* api callbacks */
@@ -179,7 +179,56 @@
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
+static int palette_color_add_exec(bContext *C, wmOperator *UNUSED(op))
+{
+	/*int type = RNA_enum_get(op->ptr, "type");*/
+	Paint *paint = BKE_paint_get_active_from_context(C);
+	Brush *brush = paint->brush;
+	PaintMode mode = BKE_paintmode_get_active_from_context(C);
+	Palette *palette = paint->palette;
+	PaletteColor *color = BKE_palette_color_add(palette);
 
+	if (ELEM3(mode, PAINT_TEXTURE_PROJECTIVE, PAINT_TEXTURE_2D, PAINT_VERTEX)) {
+		copy_v3_v3(color->rgb, brush->rgb);
+		color->value = 0.0;
+	}
+	else if (mode == PAINT_WEIGHT) {
+		zero_v3(color->rgb);
+		color->value = brush->weight;
+	}
+	else if (mode == PAINT_WEIGHT) {
+		zero_v3(color->rgb);
+		color->value = brush->alpha;
+	}
+
+	return OPERATOR_FINISHED;
+}
+
+static int palette_color_add_poll(bContext *C)
+{
+	Paint *paint = BKE_paint_get_active_from_context(C);
+
+	if (paint && paint->palette != NULL)
+		return TRUE;
+
+	return FALSE;
+}
+
+static void PALETTE_OT_color_add(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "New Palette Color";
+	ot->description = "Add new color to active palette";
+	ot->idname = "PALETTE_OT_color_add";
+
+	/* api callbacks */
+	ot->exec = palette_color_add_exec;
+	ot->poll = palette_color_add_poll;
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+
 static int vertex_color_set_exec(bContext *C, wmOperator *UNUSED(op))
 {
 	Scene *scene = CTX_data_scene(C);
@@ -957,7 +1006,7 @@
 {
 	/* palette */
 	WM_operatortype_append(PALETTE_OT_new);
-
+	WM_operatortype_append(PALETTE_OT_color_add);
 	/* brush */
 	WM_operatortype_append(BRUSH_OT_add);
 	WM_operatortype_append(BRUSH_OT_scale_size);

Modified: branches/soc-2013-paint/source/blender/makesdna/DNA_brush_types.h
===================================================================
--- branches/soc-2013-paint/source/blender/makesdna/DNA_brush_types.h	2013-07-15 21:38:37 UTC (rev 58287)
+++ branches/soc-2013-paint/source/blender/makesdna/DNA_brush_types.h	2013-07-15 21:42:51 UTC (rev 58288)
@@ -122,13 +122,20 @@
 	float mask_stencil_dimension[2];
 } Brush;
 
+typedef struct PaletteColor
+{
+	struct PaletteColor *next, *prev;
+	/* two values, one to store rgb, other to store values for sculpt/weight */
+	float rgb[3];
+	float value;
+} PaletteColor;
 
 typedef struct Palette
 {
 	ID id;
 
 	/* pointer to individual colours */
-	float (*colours)[3];
+	ListBase colors;
 
 	int num_of_colours;
 	int pad;

Modified: branches/soc-2013-paint/source/blender/makesrna/intern/rna_sculpt_paint.c
===================================================================
--- branches/soc-2013-paint/source/blender/makesrna/intern/rna_sculpt_paint.c	2013-07-15 21:38:37 UTC (rev 58287)
+++ branches/soc-2013-paint/source/blender/makesrna/intern/rna_sculpt_paint.c	2013-07-15 21:42:51 UTC (rev 58288)
@@ -287,13 +287,43 @@
 }
 #else
 
+static void rna_def_palettecolor(BlenderRNA *brna)
+{
+	StructRNA *srna;
+	PropertyRNA *prop;
+
+	srna = RNA_def_struct(brna, "PaletteColor", NULL);
+	RNA_def_struct_ui_text(srna, "Palette Color", "");
+
+	prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR_GAMMA);
+	RNA_def_property_range(prop, 0.0, 1.0);
+	RNA_def_property_float_sdna(prop, NULL, "rgb");
+	RNA_def_property_ui_text(prop, "Color", "");
+
+	prop = RNA_def_property(srna, "strength", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_range(prop, 0.0, 1.0);
+	RNA_def_property_float_sdna(prop, NULL, "value");
+	RNA_def_property_ui_text(prop, "Value", "");
+
+	prop = RNA_def_property(srna, "weight", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_range(prop, 0.0, 1.0);
+	RNA_def_property_float_sdna(prop, NULL, "value");
+	RNA_def_property_ui_text(prop, "Weight", "");
+}
+
+
 static void rna_def_palette(BlenderRNA *brna)
 {
 	StructRNA *srna;
+	PropertyRNA *prop;
 
 	srna = RNA_def_struct(brna, "Palette", "ID");
 	RNA_def_struct_ui_text(srna, "Palette", "");
 	RNA_def_struct_ui_icon(srna, ICON_COLOR);
+
+	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");
 }
 
 
@@ -694,6 +724,7 @@
 {
 	/* *** Non-Animated *** */
 	RNA_define_animate_sdna(false);
+	rna_def_palettecolor(brna);
 	rna_def_palette(brna);
 	rna_def_paint(brna);
 	rna_def_sculpt(brna);




More information about the Bf-blender-cvs mailing list