[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [38843] branches/soc-2011-onion: MyPaint BrushLib C wrapper is pretty much complete.

Jason Wilkins Jason.A.Wilkins at gmail.com
Sat Jul 30 06:36:47 CEST 2011


Revision: 38843
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38843
Author:   jwilkins
Date:     2011-07-30 04:36:40 +0000 (Sat, 30 Jul 2011)
Log Message:
-----------
MyPaint BrushLib C wrapper is pretty much complete.  Next step is to integrate it into paint_stroke

Modified Paths:
--------------
    branches/soc-2011-onion/extern/brushlib/CMakeLists.txt
    branches/soc-2011-onion/extern/brushlib/brush.hpp
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_brushlib.cpp
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_brushlib.h

Modified: branches/soc-2011-onion/extern/brushlib/CMakeLists.txt
===================================================================
--- branches/soc-2011-onion/extern/brushlib/CMakeLists.txt	2011-07-30 00:21:26 UTC (rev 38842)
+++ branches/soc-2011-onion/extern/brushlib/CMakeLists.txt	2011-07-30 04:36:40 UTC (rev 38843)
@@ -27,7 +27,6 @@
 ADD_CUSTOM_COMMAND(
 	OUTPUT brushsettings.hpp
 	COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/generate.py ${CMAKE_CURRENT_SOURCE_DIR}
-#	DEPENDS brushsettings.hpp ${CMAKE_CURRENT_SOURCE_DIR}/generate.py
 	)
 
 set(INC

Modified: branches/soc-2011-onion/extern/brushlib/brush.hpp
===================================================================
--- branches/soc-2011-onion/extern/brushlib/brush.hpp	2011-07-30 00:21:26 UTC (rev 38842)
+++ branches/soc-2011-onion/extern/brushlib/brush.hpp	2011-07-30 04:36:40 UTC (rev 38843)
@@ -23,7 +23,7 @@
 #endif
 
 #include <math.h>
-//#include "Python.h"
+#include "Python.h"
 
 #include "brushsettings.hpp"
 #include "mapping.hpp"

Modified: branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_brushlib.cpp
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_brushlib.cpp	2011-07-30 00:21:26 UTC (rev 38842)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_brushlib.cpp	2011-07-30 04:36:40 UTC (rev 38843)
@@ -34,7 +34,10 @@
  *  \ingroup edsculpt
  */
 
+#include "paint_brushlib.h"
+
 #include "MEM_sys_types.h"
+#include "BLI_rand.h"
 
 #include <stdio.h>
 #include <math.h>
@@ -42,21 +45,42 @@
 
 
 
-/* BrushLib uses glib, but Blender does not */
+/* BrushLib uses glib, but Blender does not,
+   so here is a thin wrapper so Blender can continue to not use glib */
 #if !WITH_GLIB
 
 typedef double gdouble;
 
 typedef int gint;
-
-struct GRand;
-GRand *g_rand_new();
-void g_rand_free(GRand *);
-int g_rand_int(GRand *);
-double g_rand_double(GRand *);
 typedef uint32_t guint32;
-void g_rand_set_seed(GRand *, guint32);
 
+typedef RNG GRand;
+
+static inline GRand *g_rand_new()
+{
+	return rng_new(BLI_rand());
+}
+
+static inline void g_rand_free(GRand *rng)
+{
+	rng_free(rng);
+}
+
+static inline int g_rand_int(GRand *rng)
+{
+	return rng_getInt(rng);
+}
+
+static inline double g_rand_double(GRand *rng)
+{
+	return rng_getDouble(rng);
+}
+
+static inline void g_rand_set_seed(GRand *rng, guint32 seed)
+{
+	rng_seed(rng, seed);
+}
+
 #define g_print printf
 
 template <typename A, typename B, typename C>
@@ -98,8 +122,10 @@
 #endif
 
 
+
 /* C99 stuff missing from MSVC */
-#ifdef MSVC
+#ifdef _MSC_VER
+
 #ifndef and
 #define and &&
 #endif
@@ -111,7 +137,6 @@
 #ifndef not
 #define not !
 #endif
-#endif
 
 float hypotf(float a, float b)
 {
@@ -122,8 +147,251 @@
 #define isfinite(A) ((A) < -DBL_MAX || (A) > DBL_MAX)
 #endif
 
+#endif // _MSC_VER
 
 
+
 #include <helpers.hpp>
 #include <surface.hpp>
 #include <brush.hpp>
+
+
+
+class BlenderSurface : public Surface {
+public:
+
+	void set_context(struct bContext *C, struct PaintStroke *stroke)
+	{
+		BlenderSurface::C= C;
+		BlenderSurface::stroke= stroke;
+	}
+
+protected:
+
+	struct bContext *C;
+	struct PaintStroke *stroke;
+
+};
+
+class VPaintSurface : public BlenderSurface {
+public:
+
+	bool draw_dab(
+		float x,
+		float y, 
+		float radius, 
+		float color_r,
+		float color_g,
+		float color_b,
+		float opaque,
+		float hardness = 0.5,
+		float alpha_eraser = 1.0,
+		float aspect_ratio = 1.0,
+		float angle = 0.0,
+		float lock_alpha = 0.0)
+	{
+		return
+			vpaint_draw_dab(
+				C,
+				stroke,
+				x,
+				y,
+				radius,
+				color_r,
+				color_g,
+				color_b,
+				opaque,
+				hardness,
+				alpha_eraser,
+				aspect_ratio,
+				angle,
+				lock_alpha);
+	}
+
+	void get_color(
+		float x,
+		float y, 
+		float radius, 
+		float * color_r,
+		float * color_g,
+		float * color_b,
+		float * color_a)
+	{
+		vpaint_get_color(
+			C,
+			stroke,
+			x,
+			y,
+			radius,
+			color_r,
+			color_g,
+			color_b,
+			color_a);
+	}
+};
+
+class SculptSurface : public BlenderSurface {
+public:
+
+	bool draw_dab(
+		float x,
+		float y, 
+		float radius, 
+		float color_r,
+		float color_g,
+		float color_b,
+		float opaque,
+		float hardness = 0.5,
+		float alpha_eraser = 1.0,
+		float aspect_ratio = 1.0,
+		float angle = 0.0,
+		float lock_alpha = 0.0)
+	{
+		return
+			sculpt_draw_dab(
+				C,
+				stroke,
+				x,
+				y,
+				radius,
+				color_r,
+				color_g,
+				color_b,
+				opaque,
+				hardness,
+				alpha_eraser,
+				aspect_ratio,
+				angle,
+				lock_alpha);
+	}
+
+	void get_color(
+		float x,
+		float y, 
+		float radius, 
+		float * color_r,
+		float * color_g,
+		float * color_b,
+		float * color_a)
+	{
+		sculpt_get_color(
+			C,
+			stroke,
+			x,
+			y,
+			radius,
+			color_r,
+			color_g,
+			color_b,
+			color_a);
+	}
+};
+
+class ImaPaintSurface : public BlenderSurface {
+public:
+
+	bool draw_dab(
+		float x,
+		float y, 
+		float radius, 
+		float color_r,
+		float color_g,
+		float color_b,
+		float opaque,
+		float hardness = 0.5,
+		float alpha_eraser = 1.0,
+		float aspect_ratio = 1.0,
+		float angle = 0.0,
+		float lock_alpha = 0.0)
+	{
+		return
+			imapaint_draw_dab(
+				C,
+				stroke,
+				x,
+				y,
+				radius,
+				color_r,
+				color_g,
+				color_b,
+				opaque,
+				hardness,
+				alpha_eraser,
+				aspect_ratio,
+				angle,
+				lock_alpha);
+	}
+
+	void get_color(
+		float x,
+		float y, 
+		float radius, 
+		float * color_r,
+		float * color_g,
+		float * color_b,
+		float * color_a)
+	{
+		imapaint_get_color(
+			C,
+			stroke,
+			x,
+			y,
+			radius,
+			color_r,
+			color_g,
+			color_b,
+			color_a);
+	}
+};
+
+struct BrushLibBrush *paint_brushlib_new_brush()
+{
+	return reinterpret_cast<BrushLibBrush *>(new Brush());
+}
+
+void paint_brushlib_free_brush(struct BrushLibBrush *brush)
+{
+	delete reinterpret_cast<Brush *>(brush);
+}
+
+int paint_brushlib_stroke_to(
+	struct BrushLibBrush *brushlib_brush,
+	struct BrushLibSurface *brushlib_surface,
+	float x,
+	float y,
+	float pressure,
+	float xtilt,
+	float ytilt,
+	float dtime)
+{
+	Brush   *brush=   reinterpret_cast<Brush *>   (brushlib_brush);
+	Surface *surface= reinterpret_cast<Surface *> (brushlib_surface);
+
+	return brush->stroke_to(surface, x, y, pressure, xtilt, ytilt, dtime);
+}
+
+struct BrushLibSurface *vpaint_brushlib_surface_new()
+{
+	return reinterpret_cast<BrushLibSurface *>(new VPaintSurface());
+}
+
+struct BrushLibSurface *sculpt_brushlib_surface_new()
+{
+	return reinterpret_cast<BrushLibSurface *>(new SculptSurface());
+}
+
+struct BrushLibSurface *imapaint_brushlib_surface_new()
+{
+	return reinterpret_cast<BrushLibSurface *>(new ImaPaintSurface());
+}
+
+void brushlib_surface_set_context(
+	struct BrushLibSurface *brushlib_surface,
+	bContext *C,
+	struct PaintStroke *stroke)
+{
+	BlenderSurface *blender_surface=
+		reinterpret_cast<BlenderSurface *>(brushlib_surface);
+
+	blender_surface->set_context(C, stroke);
+}

Modified: branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_brushlib.h
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_brushlib.h	2011-07-30 00:21:26 UTC (rev 38842)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_brushlib.h	2011-07-30 04:36:40 UTC (rev 38843)
@@ -37,4 +37,121 @@
 #ifndef PAINT_BRUSHLIB_H
 #define PAINT_BRUSHLIB_H
 
+#ifdef __cplusplus
+extern "C" {
 #endif
+
+int vpaint_draw_dab(
+	struct bContext *C,
+	struct PaintStroke *stroke,
+	float x,
+	float y, 
+	float radius, 
+	float color_r,
+	float color_g,
+	float color_b,
+	float opaque,
+	float hardness,
+	float alpha_eraser,
+	float aspect_ratio,
+	float angle,
+	float lock_alpha);
+
+void vpaint_get_color(
+	struct bContext *C,
+	struct PaintStroke *stroke,
+	float x,
+	float y, 
+	float radius, 
+	float * color_r,
+	float * color_g,
+	float * color_b,
+	float * color_a);
+
+int sculpt_draw_dab(
+	struct bContext *C,
+	struct PaintStroke *stroke,
+	float x,
+	float y, 
+	float radius, 
+	float color_r,
+	float color_g,
+	float color_b,
+	float opaque,
+	float hardness,
+	float alpha_eraser,
+	float aspect_ratio,
+	float angle,
+	float lock_alpha);
+
+void sculpt_get_color(
+	struct bContext *C,
+	struct PaintStroke *stroke,
+	float x,
+	float y, 
+	float radius, 
+	float * color_r,
+	float * color_g,
+	float * color_b,
+	float * color_a);
+
+int imapaint_draw_dab(
+	struct bContext *C,
+	struct PaintStroke *stroke,
+	float x,
+	float y, 
+	float radius, 
+	float color_r,
+	float color_g,
+	float color_b,
+	float opaque,
+	float hardness,
+	float alpha_eraser,
+	float aspect_ratio,
+	float angle,
+	float lock_alpha);
+
+void imapaint_get_color(
+	struct bContext *C,
+	struct PaintStroke *stroke,
+	float x,
+	float y, 
+	float radius, 
+	float * color_r,
+	float * color_g,
+	float * color_b,
+	float * color_a);
+
+/* BrushLibBrush and BrushLibSurface are opaque handles
+   There is no struct definition */
+
+struct BrushLibBrush *paint_brushlib_new_brush(void);
+
+void paint_brushlib_free_brush(struct BrushLibBrush *brush);
+
+int paint_brushlib_stroke_to(
+	struct BrushLibBrush *brushlib_brush,
+	struct BrushLibSurface *brushlib_surface,
+	float x,
+	float y,
+	float pressure,
+	float xtilt,
+	float ytilt,
+	float dtime);
+
+struct BrushLibSurface *vpaint_brushlib_surface_new(void);
+
+struct BrushLibSurface *sculpt_brushlib_surface_new(void);
+
+struct BrushLibSurface *imapaint_brushlib_surface_new(void);
+
+void paint_brushlib_surface_set_context(
+	struct BrushLibSurface *brushlib_surface,
+	bContext *C,
+	struct PaintStroke *stroke);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif




More information about the Bf-blender-cvs mailing list