[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58221] branches/soc-2013-paint/source/ blender: Add new ID type for palettes.
Antony Riakiotakis
kalast at gmail.com
Sat Jul 13 21:05:15 CEST 2013
Revision: 58221
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58221
Author: psy-fi
Date: 2013-07-13 19:05:15 +0000 (Sat, 13 Jul 2013)
Log Message:
-----------
Add new ID type for palettes. Palette types are quite simple, an rgb
pointer, and a count of rgb values.
Modified Paths:
--------------
branches/soc-2013-paint/source/blender/blenkernel/BKE_main.h
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/editors/sculpt_paint/paint_ops.c
branches/soc-2013-paint/source/blender/makesdna/DNA_ID.h
branches/soc-2013-paint/source/blender/makesdna/DNA_brush_types.h
branches/soc-2013-paint/source/blender/makesdna/DNA_scene_types.h
Modified: branches/soc-2013-paint/source/blender/blenkernel/BKE_main.h
===================================================================
--- branches/soc-2013-paint/source/blender/blenkernel/BKE_main.h 2013-07-13 18:23:08 UTC (rev 58220)
+++ branches/soc-2013-paint/source/blender/blenkernel/BKE_main.h 2013-07-13 19:05:15 UTC (rev 58221)
@@ -84,6 +84,7 @@
ListBase nodetree;
ListBase brush;
ListBase particle;
+ ListBase palettes;
ListBase wm;
ListBase gpencil;
ListBase movieclip;
Modified: branches/soc-2013-paint/source/blender/blenkernel/BKE_paint.h
===================================================================
--- branches/soc-2013-paint/source/blender/blenkernel/BKE_paint.h 2013-07-13 18:23:08 UTC (rev 58220)
+++ branches/soc-2013-paint/source/blender/blenkernel/BKE_paint.h 2013-07-13 19:05:15 UTC (rev 58221)
@@ -51,6 +51,8 @@
struct Tex;
struct ImagePool;
struct UnifiedPaintSettings;
+struct Palette;
+struct Main;
enum OverlayFlags;
@@ -94,11 +96,15 @@
void BKE_paint_free(struct Paint *p);
void BKE_paint_copy(struct Paint *src, struct Paint *tar);
+struct Palette *BKE_palette_add(struct Main *bmain, const char *name);
+
struct Paint *BKE_paint_get_active(struct Scene *sce);
struct Paint *BKE_paint_get_active_from_context(const struct bContext *C);
PaintMode BKE_paintmode_get_active_from_context(const struct bContext *C);
struct Brush *BKE_paint_brush(struct Paint *paint);
void BKE_paint_brush_set(struct Paint *paint, struct Brush *br);
+struct Palette *BKE_paint_palette(struct Paint *paint);
+void BKE_paint_palette_set(struct Paint *p, struct Palette *palette);
/* testing face select mode
* Texture paint could be removed since selected faces are not used
Modified: branches/soc-2013-paint/source/blender/blenkernel/intern/library.c
===================================================================
--- branches/soc-2013-paint/source/blender/blenkernel/intern/library.c 2013-07-13 18:23:08 UTC (rev 58220)
+++ branches/soc-2013-paint/source/blender/blenkernel/intern/library.c 2013-07-13 19:05:15 UTC (rev 58221)
@@ -515,6 +515,8 @@
return &(mainlib->mask);
case ID_LS:
return &(mainlib->linestyle);
+ case ID_PALETTE:
+ return &(mainlib->palettes);
}
return NULL;
}
@@ -606,6 +608,7 @@
lb[a++] = &(main->wm);
lb[a++] = &(main->movieclip);
lb[a++] = &(main->mask);
+ lb[a++] = &(main->palettes);
lb[a] = NULL;
@@ -727,6 +730,9 @@
case ID_LS:
id = MEM_callocN(sizeof(FreestyleLineStyle), "Freestyle Line Style");
break;
+ case ID_PALETTE:
+ id = MEM_callocN(sizeof(Palette), "Palette");
+ break;
}
return id;
}
@@ -973,6 +979,8 @@
case ID_LS:
BKE_free_linestyle((FreestyleLineStyle *)id);
break;
+ case ID_PALETTE:
+ break;
}
/* avoid notifying on removed data */
Modified: branches/soc-2013-paint/source/blender/blenkernel/intern/paint.c
===================================================================
--- branches/soc-2013-paint/source/blender/blenkernel/intern/paint.c 2013-07-13 18:23:08 UTC (rev 58220)
+++ branches/soc-2013-paint/source/blender/blenkernel/intern/paint.c 2013-07-13 19:05:15 UTC (rev 58221)
@@ -46,6 +46,7 @@
#include "BLI_math_vector.h"
#include "BKE_brush.h"
+#include "BKE_main.h"
#include "BKE_context.h"
#include "BKE_depsgraph.h"
#include "BKE_global.h"
@@ -267,6 +268,33 @@
}
}
+Palette *BKE_paint_palette(Paint *p)
+{
+ return p ? p->palette : NULL;
+}
+
+void BKE_paint_palette_set(Paint *p, Palette *palette)
+{
+ if (p) {
+ id_us_min((ID *)p->palette);
+ id_us_plus((ID *)palette);
+ p->palette = palette;
+ }
+}
+
+Palette *BKE_palette_add(Main *bmain, const char *name)
+{
+ Palette *palette;
+
+ palette = BKE_libblock_alloc(&bmain->palettes, ID_PALETTE, name);
+
+ /* enable fake user by default */
+ palette->id.flag |= LIB_FAKEUSER;
+
+ return palette;
+}
+
+
/* are we in vertex paint or weight pain face select mode? */
int paint_facesel_test(Object *ob)
{
@@ -292,12 +320,18 @@
void BKE_paint_init(Paint *p, const char col[3])
{
Brush *brush;
+ Palette *palette;
/* If there's no brush, create one */
brush = BKE_paint_brush(p);
+ 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");
+
BKE_paint_brush_set(p, brush);
+ BKE_paint_palette_set(p, palette);
memcpy(p->paint_cursor_col, col, 3);
p->paint_cursor_col[3] = 128;
@@ -308,6 +342,7 @@
void BKE_paint_free(Paint *paint)
{
id_us_min((ID *)paint->brush);
+ id_us_min((ID *)paint->palette);
}
/* called when copying scene settings, so even if 'src' and 'tar' are the same
@@ -318,6 +353,7 @@
{
tar->brush = src->brush;
id_us_plus((ID *)tar->brush);
+ id_us_plus((ID *)tar->palette);
}
/* returns non-zero if any of the face's vertices
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-13 18:23:08 UTC (rev 58220)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_ops.c 2013-07-13 19:05:15 UTC (rev 58221)
@@ -92,7 +92,6 @@
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
-
static int brush_scale_size_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
@@ -150,6 +149,37 @@
RNA_def_float(ot->srna, "scalar", 1, 0, 2, "Scalar", "Factor to scale brush size by", 0, 2);
}
+/* Palette operators */
+
+static int palette_new_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ /*int type = RNA_enum_get(op->ptr, "type");*/
+ Paint *paint = BKE_paint_get_active_from_context(C);
+ Main *bmain = CTX_data_main(C);
+ Palette *palette;
+
+ palette = BKE_palette_add(bmain, "Palette");
+
+ BKE_paint_palette_set(paint, palette);
+
+ return OPERATOR_FINISHED;
+}
+
+static void PALETTE_OT_new(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Add New Palette";
+ ot->description = "Add New Palette";
+ ot->idname = "PALETTE_OT_new";
+
+ /* api callbacks */
+ ot->exec = palette_new_exec;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+
static int vertex_color_set_exec(bContext *C, wmOperator *UNUSED(op))
{
Scene *scene = CTX_data_scene(C);
@@ -924,6 +954,9 @@
void ED_operatortypes_paint(void)
{
+ /* palette */
+ WM_operatortype_append(PALETTE_OT_new);
+
/* brush */
WM_operatortype_append(BRUSH_OT_add);
WM_operatortype_append(BRUSH_OT_scale_size);
Modified: branches/soc-2013-paint/source/blender/makesdna/DNA_ID.h
===================================================================
--- branches/soc-2013-paint/source/blender/makesdna/DNA_ID.h 2013-07-13 18:23:08 UTC (rev 58220)
+++ branches/soc-2013-paint/source/blender/makesdna/DNA_ID.h 2013-07-13 19:05:15 UTC (rev 58221)
@@ -213,6 +213,7 @@
#define ID_MC MAKE_ID2('M', 'C') /* MovieClip */
#define ID_MSK MAKE_ID2('M', 'S') /* Mask */
#define ID_LS MAKE_ID2('L', 'S') /* FreestyleLineStyle */
+#define ID_PALETTE MAKE_ID2('P', 'L') /* Palette */
/* NOTE! Fake IDs, needed for g.sipo->blocktype or outliner */
#define ID_SEQ MAKE_ID2('S', 'Q')
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-13 18:23:08 UTC (rev 58220)
+++ branches/soc-2013-paint/source/blender/makesdna/DNA_brush_types.h 2013-07-13 19:05:15 UTC (rev 58221)
@@ -122,6 +122,18 @@
float mask_stencil_dimension[2];
} Brush;
+
+typedef struct Palette
+{
+ ID id;
+
+ /* pointer to individual colours */
+ float *colours[3];
+
+ int num_of_colours;
+ int pad;
+} Palette;
+
/* Brush.flag */
typedef enum BrushFlags {
BRUSH_AIRBRUSH = (1 << 0),
Modified: branches/soc-2013-paint/source/blender/makesdna/DNA_scene_types.h
===================================================================
--- branches/soc-2013-paint/source/blender/makesdna/DNA_scene_types.h 2013-07-13 18:23:08 UTC (rev 58220)
+++ branches/soc-2013-paint/source/blender/makesdna/DNA_scene_types.h 2013-07-13 19:05:15 UTC (rev 58221)
@@ -747,7 +747,8 @@
/* Paint Tool Base */
typedef struct Paint {
struct Brush *brush;
-
+ struct Palette *palette;
+
/* WM Paint cursor */
void *paint_cursor;
unsigned char paint_cursor_col[4];
More information about the Bf-blender-cvs
mailing list