app: connect the MyPaint brush core with the new brush container
and remove all hackish temp code that did the same. Remove quite some #ifdefs around code that doesn't depend on libmypaint.
This commit is contained in:
@ -16,6 +16,7 @@ AM_CPPFLAGS = \
|
|||||||
$(CAIRO_CFLAGS) \
|
$(CAIRO_CFLAGS) \
|
||||||
$(GEGL_CFLAGS) \
|
$(GEGL_CFLAGS) \
|
||||||
$(GDK_PIXBUF_CFLAGS) \
|
$(GDK_PIXBUF_CFLAGS) \
|
||||||
|
$(LIBMYPAINTGEGL_CFLAGS) \
|
||||||
$(GEXIV2_CFLAGS) \
|
$(GEXIV2_CFLAGS) \
|
||||||
$(LCMS_CFLAGS) \
|
$(LCMS_CFLAGS) \
|
||||||
-I$(includedir) \
|
-I$(includedir) \
|
||||||
|
@ -21,6 +21,10 @@
|
|||||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||||
#include <gegl.h>
|
#include <gegl.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBMYPAINT
|
||||||
|
#include <mypaint-brush.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "core-types.h"
|
#include "core-types.h"
|
||||||
|
|
||||||
#include "gimpmybrush.h"
|
#include "gimpmybrush.h"
|
||||||
@ -32,7 +36,12 @@
|
|||||||
|
|
||||||
struct _GimpMybrushPrivate
|
struct _GimpMybrushPrivate
|
||||||
{
|
{
|
||||||
gpointer dummy;
|
gboolean json_loaded;
|
||||||
|
|
||||||
|
gchar *brush_json;
|
||||||
|
gdouble radius;
|
||||||
|
gdouble opaque;
|
||||||
|
gdouble hardness;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -102,6 +111,10 @@ gimp_mybrush_init (GimpMybrush *brush)
|
|||||||
brush->priv = G_TYPE_INSTANCE_GET_PRIVATE (brush,
|
brush->priv = G_TYPE_INSTANCE_GET_PRIVATE (brush,
|
||||||
GIMP_TYPE_MYBRUSH,
|
GIMP_TYPE_MYBRUSH,
|
||||||
GimpMybrushPrivate);
|
GimpMybrushPrivate);
|
||||||
|
|
||||||
|
brush->priv->radius = 1.0;
|
||||||
|
brush->priv->opaque = 1.0;
|
||||||
|
brush->priv->hardness = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -109,6 +122,12 @@ gimp_mybrush_finalize (GObject *object)
|
|||||||
{
|
{
|
||||||
GimpMybrush *brush = GIMP_MYBRUSH (object);
|
GimpMybrush *brush = GIMP_MYBRUSH (object);
|
||||||
|
|
||||||
|
if (brush->priv->brush_json)
|
||||||
|
{
|
||||||
|
g_free (brush->priv->brush_json);
|
||||||
|
brush->priv->brush_json = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,3 +239,96 @@ gimp_mybrush_get_standard (GimpContext *context)
|
|||||||
|
|
||||||
return standard_mybrush;
|
return standard_mybrush;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gimp_mybrush_load_json (GimpMybrush *brush)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_LIBMYPAINT
|
||||||
|
|
||||||
|
GFile *file = gimp_data_get_file (GIMP_DATA (brush));
|
||||||
|
MyPaintBrush *mypaint_brush = mypaint_brush_new ();
|
||||||
|
|
||||||
|
mypaint_brush_from_defaults (mypaint_brush);
|
||||||
|
|
||||||
|
if (file)
|
||||||
|
{
|
||||||
|
gchar *path = g_file_get_path (file);
|
||||||
|
|
||||||
|
if (g_file_get_contents (path, &brush->priv->brush_json, NULL, NULL))
|
||||||
|
{
|
||||||
|
if (! mypaint_brush_from_string (mypaint_brush,
|
||||||
|
brush->priv->brush_json))
|
||||||
|
{
|
||||||
|
g_printerr ("Failed to deserialize MyPaint brush\n");
|
||||||
|
g_free (brush->priv->brush_json);
|
||||||
|
brush->priv->brush_json = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_printerr ("Failed to load MyPaint brush\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
brush->priv->radius =
|
||||||
|
mypaint_brush_get_base_value (mypaint_brush,
|
||||||
|
MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC);
|
||||||
|
|
||||||
|
brush->priv->opaque =
|
||||||
|
mypaint_brush_get_base_value (mypaint_brush,
|
||||||
|
MYPAINT_BRUSH_SETTING_OPAQUE);
|
||||||
|
|
||||||
|
brush->priv->hardness =
|
||||||
|
mypaint_brush_get_base_value (mypaint_brush,
|
||||||
|
MYPAINT_BRUSH_SETTING_HARDNESS);
|
||||||
|
|
||||||
|
mypaint_brush_unref (mypaint_brush);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
brush->priv->json_loaded = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
const gchar *
|
||||||
|
gimp_mybrush_get_brush_json (GimpMybrush *brush)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (GIMP_IS_MYBRUSH (brush), NULL);
|
||||||
|
|
||||||
|
if (! brush->priv->json_loaded)
|
||||||
|
gimp_mybrush_load_json (brush);
|
||||||
|
|
||||||
|
return brush->priv->brush_json;
|
||||||
|
}
|
||||||
|
|
||||||
|
gdouble
|
||||||
|
gimp_mybrush_get_radius (GimpMybrush *brush)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (GIMP_IS_MYBRUSH (brush), 1.0);
|
||||||
|
|
||||||
|
if (! brush->priv->json_loaded)
|
||||||
|
gimp_mybrush_load_json (brush);
|
||||||
|
|
||||||
|
return brush->priv->radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
gdouble
|
||||||
|
gimp_mybrush_get_opaque (GimpMybrush *brush)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (GIMP_IS_MYBRUSH (brush), 1.0);
|
||||||
|
|
||||||
|
if (! brush->priv->json_loaded)
|
||||||
|
gimp_mybrush_load_json (brush);
|
||||||
|
|
||||||
|
return brush->priv->opaque;
|
||||||
|
}
|
||||||
|
|
||||||
|
gdouble
|
||||||
|
gimp_mybrush_get_hardness (GimpMybrush *brush)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (GIMP_IS_MYBRUSH (brush), 1.0);
|
||||||
|
|
||||||
|
if (! brush->priv->json_loaded)
|
||||||
|
gimp_mybrush_load_json (brush);
|
||||||
|
|
||||||
|
return brush->priv->hardness;
|
||||||
|
}
|
||||||
|
@ -46,11 +46,17 @@ struct _GimpMybrushClass
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
GType gimp_mybrush_get_type (void) G_GNUC_CONST;
|
GType gimp_mybrush_get_type (void) G_GNUC_CONST;
|
||||||
|
|
||||||
GimpData * gimp_mybrush_new (GimpContext *context,
|
GimpData * gimp_mybrush_new (GimpContext *context,
|
||||||
const gchar *name);
|
const gchar *name);
|
||||||
GimpData * gimp_mybrush_get_standard (GimpContext *context);
|
GimpData * gimp_mybrush_get_standard (GimpContext *context);
|
||||||
|
|
||||||
|
const gchar * gimp_mybrush_get_brush_json (GimpMybrush *brush);
|
||||||
|
|
||||||
|
gdouble gimp_mybrush_get_radius (GimpMybrush *brush);
|
||||||
|
gdouble gimp_mybrush_get_opaque (GimpMybrush *brush);
|
||||||
|
gdouble gimp_mybrush_get_hardness (GimpMybrush *brush);
|
||||||
|
|
||||||
|
|
||||||
#endif /* __GIMP_MYBRUSH_H__ */
|
#endif /* __GIMP_MYBRUSH_H__ */
|
||||||
|
@ -43,9 +43,8 @@
|
|||||||
#include "core/gimp.h"
|
#include "core/gimp.h"
|
||||||
#include "core/gimp-palettes.h"
|
#include "core/gimp-palettes.h"
|
||||||
#include "core/gimpdrawable.h"
|
#include "core/gimpdrawable.h"
|
||||||
#include "core/gimpimage.h"
|
#include "core/gimperror.h"
|
||||||
#include "core/gimpimage-undo.h"
|
#include "core/gimpmybrush.h"
|
||||||
#include "core/gimptempbuf.h"
|
|
||||||
|
|
||||||
#include "gimpmybrushcore.h"
|
#include "gimpmybrushcore.h"
|
||||||
#include "gimpmybrushsurface.h"
|
#include "gimpmybrushsurface.h"
|
||||||
@ -56,6 +55,7 @@
|
|||||||
|
|
||||||
struct _GimpMybrushCorePrivate
|
struct _GimpMybrushCorePrivate
|
||||||
{
|
{
|
||||||
|
GimpMybrush *mybrush;
|
||||||
#if 0
|
#if 0
|
||||||
MyPaintGeglTiledSurface *surface;
|
MyPaintGeglTiledSurface *surface;
|
||||||
#else
|
#else
|
||||||
@ -68,17 +68,22 @@ struct _GimpMybrushCorePrivate
|
|||||||
|
|
||||||
/* local function prototypes */
|
/* local function prototypes */
|
||||||
|
|
||||||
static void gimp_mybrush_core_paint (GimpPaintCore *paint_core,
|
static gboolean gimp_mybrush_core_start (GimpPaintCore *paint_core,
|
||||||
GimpDrawable *drawable,
|
GimpDrawable *drawable,
|
||||||
GimpPaintOptions *paint_options,
|
GimpPaintOptions *paint_options,
|
||||||
const GimpCoords *coords,
|
const GimpCoords *coords,
|
||||||
GimpPaintState paint_state,
|
GError **error);
|
||||||
guint32 time);
|
static void gimp_mybrush_core_paint (GimpPaintCore *paint_core,
|
||||||
static void gimp_mybrush_core_motion (GimpPaintCore *paint_core,
|
GimpDrawable *drawable,
|
||||||
GimpDrawable *drawable,
|
GimpPaintOptions *paint_options,
|
||||||
GimpPaintOptions *paint_options,
|
const GimpCoords *coords,
|
||||||
const GimpCoords *coords,
|
GimpPaintState paint_state,
|
||||||
guint32 time);
|
guint32 time);
|
||||||
|
static void gimp_mybrush_core_motion (GimpPaintCore *paint_core,
|
||||||
|
GimpDrawable *drawable,
|
||||||
|
GimpPaintOptions *paint_options,
|
||||||
|
const GimpCoords *coords,
|
||||||
|
guint32 time);
|
||||||
|
|
||||||
|
|
||||||
G_DEFINE_TYPE (GimpMybrushCore, gimp_mybrush_core, GIMP_TYPE_PAINT_CORE)
|
G_DEFINE_TYPE (GimpMybrushCore, gimp_mybrush_core, GIMP_TYPE_PAINT_CORE)
|
||||||
@ -104,6 +109,7 @@ gimp_mybrush_core_class_init (GimpMybrushCoreClass *klass)
|
|||||||
{
|
{
|
||||||
GimpPaintCoreClass *paint_core_class = GIMP_PAINT_CORE_CLASS (klass);
|
GimpPaintCoreClass *paint_core_class = GIMP_PAINT_CORE_CLASS (klass);
|
||||||
|
|
||||||
|
paint_core_class->start = gimp_mybrush_core_start;
|
||||||
paint_core_class->paint = gimp_mybrush_core_paint;
|
paint_core_class->paint = gimp_mybrush_core_paint;
|
||||||
|
|
||||||
g_type_class_add_private (klass, sizeof (GimpMybrushCorePrivate));
|
g_type_class_add_private (klass, sizeof (GimpMybrushCorePrivate));
|
||||||
@ -117,6 +123,28 @@ gimp_mybrush_core_init (GimpMybrushCore *mybrush)
|
|||||||
GimpMybrushCorePrivate);
|
GimpMybrushCorePrivate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gimp_mybrush_core_start (GimpPaintCore *paint_core,
|
||||||
|
GimpDrawable *drawable,
|
||||||
|
GimpPaintOptions *paint_options,
|
||||||
|
const GimpCoords *coords,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
GimpMybrushCore *core = GIMP_MYBRUSH_CORE (paint_core);
|
||||||
|
GimpContext *context = GIMP_CONTEXT (paint_options);
|
||||||
|
|
||||||
|
core->private->mybrush = gimp_context_get_mybrush (context);
|
||||||
|
|
||||||
|
if (! core->private->mybrush)
|
||||||
|
{
|
||||||
|
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
|
||||||
|
_("No MyPaint brushes available for use with this tool."));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gimp_mybrush_core_paint (GimpPaintCore *paint_core,
|
gimp_mybrush_core_paint (GimpPaintCore *paint_core,
|
||||||
GimpDrawable *drawable,
|
GimpDrawable *drawable,
|
||||||
@ -162,7 +190,7 @@ gimp_mybrush_core_paint (GimpPaintCore *paint_core,
|
|||||||
|
|
||||||
mybrush->private->brush = mypaint_brush_new ();
|
mybrush->private->brush = mypaint_brush_new ();
|
||||||
mypaint_brush_from_defaults (mybrush->private->brush);
|
mypaint_brush_from_defaults (mybrush->private->brush);
|
||||||
brush_data = gimp_mybrush_options_get_brush_data (options);
|
brush_data = gimp_mybrush_get_brush_json (mybrush->private->mybrush);
|
||||||
if (brush_data)
|
if (brush_data)
|
||||||
mypaint_brush_from_string (mybrush->private->brush, brush_data);
|
mypaint_brush_from_string (mybrush->private->brush, brush_data);
|
||||||
|
|
||||||
|
@ -15,8 +15,6 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_LIBMYPAINT
|
|
||||||
|
|
||||||
#ifndef __GIMP_MYBRUSH_CORE_H__
|
#ifndef __GIMP_MYBRUSH_CORE_H__
|
||||||
#define __GIMP_MYBRUSH_CORE_H__
|
#define __GIMP_MYBRUSH_CORE_H__
|
||||||
|
|
||||||
@ -27,8 +25,8 @@
|
|||||||
#define GIMP_TYPE_MYBRUSH_CORE (gimp_mybrush_core_get_type ())
|
#define GIMP_TYPE_MYBRUSH_CORE (gimp_mybrush_core_get_type ())
|
||||||
#define GIMP_MYBRUSH_CORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_MYBRUSH_CORE, GimpMybrushCore))
|
#define GIMP_MYBRUSH_CORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_MYBRUSH_CORE, GimpMybrushCore))
|
||||||
#define GIMP_MYBRUSH_CORE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_MYBRUSH_CORE, GimpMybrushCoreClass))
|
#define GIMP_MYBRUSH_CORE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_MYBRUSH_CORE, GimpMybrushCoreClass))
|
||||||
#define GIMP_IS_MYBRUSH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_MYBRUSH_CORE))
|
#define GIMP_IS_MYBRUSH_CORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_MYBRUSH_CORE))
|
||||||
#define GIMP_IS_MYBRUSH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_MYBRUSH_CORE))
|
#define GIMP_IS_MYBRUSH_CORE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_MYBRUSH_CORE))
|
||||||
#define GIMP_MYBRUSH_CORE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_MYBRUSH_CORE, GimpMybrushCoreClass))
|
#define GIMP_MYBRUSH_CORE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_MYBRUSH_CORE, GimpMybrushCoreClass))
|
||||||
|
|
||||||
|
|
||||||
@ -55,5 +53,3 @@ GType gimp_mybrush_core_get_type (void) G_GNUC_CONST;
|
|||||||
|
|
||||||
|
|
||||||
#endif /* __GIMP_MYBRUSH_CORE_H__ */
|
#endif /* __GIMP_MYBRUSH_CORE_H__ */
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -17,8 +17,6 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#ifdef HAVE_LIBMYPAINT
|
|
||||||
|
|
||||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||||
#include <gegl.h>
|
#include <gegl.h>
|
||||||
|
|
||||||
@ -28,59 +26,50 @@
|
|||||||
|
|
||||||
#include "core/gimp.h"
|
#include "core/gimp.h"
|
||||||
#include "core/gimpdrawable.h"
|
#include "core/gimpdrawable.h"
|
||||||
|
#include "core/gimpmybrush.h"
|
||||||
#include "core/gimppaintinfo.h"
|
#include "core/gimppaintinfo.h"
|
||||||
|
|
||||||
#include "gimpmybrushoptions.h"
|
#include "gimpmybrushoptions.h"
|
||||||
|
|
||||||
#include "gimp-intl.h"
|
#include "gimp-intl.h"
|
||||||
|
|
||||||
#include <mypaint-brush.h>
|
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
PROP_0,
|
PROP_0,
|
||||||
PROP_RADIUS,
|
PROP_RADIUS,
|
||||||
PROP_OPAQUE,
|
PROP_OPAQUE,
|
||||||
PROP_HARDNESS,
|
PROP_HARDNESS
|
||||||
PROP_MYBRUSH
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
gdouble radius;
|
|
||||||
gdouble opaque;
|
|
||||||
gdouble hardness;
|
|
||||||
gchar *brush_json;
|
|
||||||
} OptionsState;
|
|
||||||
|
|
||||||
static GHashTable *loaded_myb;
|
static void gimp_mybrush_options_set_property (GObject *object,
|
||||||
|
guint property_id,
|
||||||
|
const GValue *value,
|
||||||
|
GParamSpec *pspec);
|
||||||
|
static void gimp_mybrush_options_get_property (GObject *object,
|
||||||
|
guint property_id,
|
||||||
|
GValue *value,
|
||||||
|
GParamSpec *pspec);
|
||||||
|
|
||||||
static void gimp_mybrush_options_set_property (GObject *object,
|
static void gimp_mybrush_options_mybrush_changed (GimpContext *context,
|
||||||
guint property_id,
|
GimpMybrush *brush);
|
||||||
const GValue *value,
|
|
||||||
GParamSpec *pspec);
|
|
||||||
static void gimp_mybrush_options_get_property (GObject *object,
|
|
||||||
guint property_id,
|
|
||||||
GValue *value,
|
|
||||||
GParamSpec *pspec);
|
|
||||||
static void options_state_free (gpointer options)
|
|
||||||
{
|
|
||||||
OptionsState *state = options;
|
|
||||||
g_free (state->brush_json);
|
|
||||||
g_free (state);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
G_DEFINE_TYPE (GimpMybrushOptions, gimp_mybrush_options, GIMP_TYPE_PAINT_OPTIONS)
|
G_DEFINE_TYPE (GimpMybrushOptions, gimp_mybrush_options,
|
||||||
|
GIMP_TYPE_PAINT_OPTIONS)
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gimp_mybrush_options_class_init (GimpMybrushOptionsClass *klass)
|
gimp_mybrush_options_class_init (GimpMybrushOptionsClass *klass)
|
||||||
{
|
{
|
||||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||||
|
GimpContextClass *context_class = GIMP_CONTEXT_CLASS (klass);
|
||||||
|
|
||||||
object_class->set_property = gimp_mybrush_options_set_property;
|
object_class->set_property = gimp_mybrush_options_set_property;
|
||||||
object_class->get_property = gimp_mybrush_options_get_property;
|
object_class->get_property = gimp_mybrush_options_get_property;
|
||||||
|
|
||||||
|
context_class->mybrush_changed = gimp_mybrush_options_mybrush_changed;
|
||||||
|
|
||||||
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_RADIUS,
|
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_RADIUS,
|
||||||
"radius", _("Radius"),
|
"radius", _("Radius"),
|
||||||
@ -94,54 +83,6 @@ gimp_mybrush_options_class_init (GimpMybrushOptionsClass *klass)
|
|||||||
"hardness", NULL,
|
"hardness", NULL,
|
||||||
0.0, 1.0, 1.0,
|
0.0, 1.0, 1.0,
|
||||||
GIMP_PARAM_STATIC_STRINGS);
|
GIMP_PARAM_STATIC_STRINGS);
|
||||||
GIMP_CONFIG_INSTALL_PROP_STRING (object_class, PROP_MYBRUSH,
|
|
||||||
"mybrush", NULL,
|
|
||||||
NULL,
|
|
||||||
GIMP_PARAM_STATIC_STRINGS);
|
|
||||||
|
|
||||||
loaded_myb = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, options_state_free);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gimp_mybrush_options_load_path (GObject *object,
|
|
||||||
gchar *path)
|
|
||||||
{
|
|
||||||
GimpMybrushOptions *options = GIMP_MYBRUSH_OPTIONS (object);
|
|
||||||
|
|
||||||
OptionsState *state = g_hash_table_lookup (loaded_myb, path);
|
|
||||||
if (!state)
|
|
||||||
{
|
|
||||||
gchar *brush_json = NULL;
|
|
||||||
MyPaintBrush *brush = mypaint_brush_new ();
|
|
||||||
|
|
||||||
state = g_new0 (OptionsState, 1);
|
|
||||||
mypaint_brush_from_defaults (brush);
|
|
||||||
|
|
||||||
if (g_file_get_contents (path, &brush_json, NULL, NULL))
|
|
||||||
{
|
|
||||||
if (! mypaint_brush_from_string (brush, brush_json))
|
|
||||||
{
|
|
||||||
g_printerr ("Failed to deserialize MyPaint brush\n");
|
|
||||||
g_free (brush_json);
|
|
||||||
brush_json = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
state->brush_json = brush_json;
|
|
||||||
state->radius = mypaint_brush_get_base_value (brush, MYPAINT_BRUSH_SETTING_RADIUS_LOGARITHMIC);
|
|
||||||
state->opaque = mypaint_brush_get_base_value (brush, MYPAINT_BRUSH_SETTING_OPAQUE);
|
|
||||||
state->hardness = mypaint_brush_get_base_value (brush, MYPAINT_BRUSH_SETTING_HARDNESS);
|
|
||||||
|
|
||||||
g_hash_table_insert (loaded_myb, g_strdup(path), state);
|
|
||||||
}
|
|
||||||
|
|
||||||
options->radius = state->radius;
|
|
||||||
options->opaque = state->opaque;
|
|
||||||
options->hardness = state->hardness;
|
|
||||||
|
|
||||||
g_object_notify (object, "radius");
|
|
||||||
g_object_notify (object, "opaque");
|
|
||||||
g_object_notify (object, "hardness");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -168,12 +109,6 @@ gimp_mybrush_options_set_property (GObject *object,
|
|||||||
case PROP_OPAQUE:
|
case PROP_OPAQUE:
|
||||||
options->opaque = g_value_get_double (value);
|
options->opaque = g_value_get_double (value);
|
||||||
break;
|
break;
|
||||||
case PROP_MYBRUSH:
|
|
||||||
g_free (options->mybrush);
|
|
||||||
options->mybrush = g_value_dup_string (value);
|
|
||||||
if (options->mybrush)
|
|
||||||
gimp_mybrush_options_load_path (object, options->mybrush);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||||
@ -200,9 +135,6 @@ gimp_mybrush_options_get_property (GObject *object,
|
|||||||
case PROP_HARDNESS:
|
case PROP_HARDNESS:
|
||||||
g_value_set_double (value, options->hardness);
|
g_value_set_double (value, options->hardness);
|
||||||
break;
|
break;
|
||||||
case PROP_MYBRUSH:
|
|
||||||
g_value_set_string (value, options->mybrush);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||||
@ -210,13 +142,14 @@ gimp_mybrush_options_get_property (GObject *object,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const gchar *
|
static void
|
||||||
gimp_mybrush_options_get_brush_data (GimpMybrushOptions *options)
|
gimp_mybrush_options_mybrush_changed (GimpContext *context,
|
||||||
|
GimpMybrush *brush)
|
||||||
{
|
{
|
||||||
OptionsState *state = g_hash_table_lookup (loaded_myb, options->mybrush);
|
if (brush)
|
||||||
if (state)
|
g_object_set (context,
|
||||||
return state->brush_json;
|
"radius", gimp_mybrush_get_radius (brush),
|
||||||
return NULL;
|
"opaque", gimp_mybrush_get_opaque (brush),
|
||||||
|
"hardness", gimp_mybrush_get_hardness (brush),
|
||||||
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -15,8 +15,6 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_LIBMYPAINT
|
|
||||||
|
|
||||||
#ifndef __GIMP_MYBRUSH_OPTIONS_H__
|
#ifndef __GIMP_MYBRUSH_OPTIONS_H__
|
||||||
#define __GIMP_MYBRUSH_OPTIONS_H__
|
#define __GIMP_MYBRUSH_OPTIONS_H__
|
||||||
|
|
||||||
@ -41,7 +39,6 @@ struct _GimpMybrushOptions
|
|||||||
gdouble radius;
|
gdouble radius;
|
||||||
gdouble opaque;
|
gdouble opaque;
|
||||||
gdouble hardness;
|
gdouble hardness;
|
||||||
gchar *mybrush;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GimpMybrushOptionsClass
|
struct _GimpMybrushOptionsClass
|
||||||
@ -52,9 +49,5 @@ struct _GimpMybrushOptionsClass
|
|||||||
|
|
||||||
GType gimp_mybrush_options_get_type (void) G_GNUC_CONST;
|
GType gimp_mybrush_options_get_type (void) G_GNUC_CONST;
|
||||||
|
|
||||||
const gchar *
|
|
||||||
gimp_mybrush_options_get_brush_data (GimpMybrushOptions *options);
|
|
||||||
|
|
||||||
#endif /* __GIMP_MYBRUSH_OPTIONS_H__ */
|
#endif /* __GIMP_MYBRUSH_OPTIONS_H__ */
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -17,8 +17,6 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#ifdef HAVE_LIBMYPAINT
|
|
||||||
|
|
||||||
#include <gegl.h>
|
#include <gegl.h>
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
@ -42,124 +40,12 @@
|
|||||||
#include "gimp-intl.h"
|
#include "gimp-intl.h"
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
gimp_mybrush_options_load_brush (GFile *file,
|
|
||||||
GtkTreeModel *model)
|
|
||||||
{
|
|
||||||
GtkListStore *store = GTK_LIST_STORE (model);
|
|
||||||
GtkTreeIter iter = { 0, };
|
|
||||||
GdkPixbuf *pixbuf = NULL;
|
|
||||||
gchar *filename;
|
|
||||||
gchar *basename;
|
|
||||||
gchar *preview_filename;
|
|
||||||
|
|
||||||
filename = g_file_get_path (file);
|
|
||||||
g_object_weak_ref (G_OBJECT (store), (GWeakNotify) g_free, filename);
|
|
||||||
|
|
||||||
basename = g_strndup (filename, strlen (filename) - 4);
|
|
||||||
preview_filename = g_strconcat (basename, "_prev.png", NULL);
|
|
||||||
g_free (basename);
|
|
||||||
|
|
||||||
pixbuf = gdk_pixbuf_new_from_file_at_size (preview_filename,
|
|
||||||
48, 48, NULL);
|
|
||||||
g_free (preview_filename);
|
|
||||||
|
|
||||||
basename = g_file_get_basename (file);
|
|
||||||
|
|
||||||
gtk_list_store_append (store, &iter);
|
|
||||||
gtk_list_store_set (store, &iter,
|
|
||||||
GIMP_INT_STORE_LABEL, gimp_filename_to_utf8 (basename),
|
|
||||||
GIMP_INT_STORE_PIXBUF, pixbuf,
|
|
||||||
GIMP_INT_STORE_USER_DATA, filename,
|
|
||||||
-1);
|
|
||||||
|
|
||||||
g_free (basename);
|
|
||||||
|
|
||||||
if (pixbuf)
|
|
||||||
g_object_unref (pixbuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gimp_mybrush_options_load_recursive (GFile *dir,
|
|
||||||
GtkTreeModel *model)
|
|
||||||
{
|
|
||||||
GFileEnumerator *enumerator;
|
|
||||||
|
|
||||||
enumerator = g_file_enumerate_children (dir,
|
|
||||||
G_FILE_ATTRIBUTE_STANDARD_NAME ","
|
|
||||||
G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN ","
|
|
||||||
G_FILE_ATTRIBUTE_STANDARD_TYPE,
|
|
||||||
G_FILE_QUERY_INFO_NONE,
|
|
||||||
NULL, NULL);
|
|
||||||
|
|
||||||
if (enumerator)
|
|
||||||
{
|
|
||||||
GFileInfo *info;
|
|
||||||
|
|
||||||
while ((info = g_file_enumerator_next_file (enumerator,
|
|
||||||
NULL, NULL)))
|
|
||||||
{
|
|
||||||
if (! g_file_info_get_is_hidden (info))
|
|
||||||
{
|
|
||||||
GFile *file = g_file_enumerator_get_child (enumerator, info);
|
|
||||||
|
|
||||||
switch (g_file_info_get_file_type (info))
|
|
||||||
{
|
|
||||||
case G_FILE_TYPE_DIRECTORY:
|
|
||||||
gimp_mybrush_options_load_recursive (file, model);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case G_FILE_TYPE_REGULAR:
|
|
||||||
if (gimp_file_has_extension (file, ".myb"))
|
|
||||||
gimp_mybrush_options_load_brush (file, model);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_object_unref (file);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_object_unref (info);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_object_unref (enumerator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gimp_mybrush_options_brush_changed (GtkComboBox *combo,
|
|
||||||
GObject *config)
|
|
||||||
{
|
|
||||||
GtkTreeIter iter;
|
|
||||||
|
|
||||||
if (gtk_combo_box_get_active_iter (combo, &iter))
|
|
||||||
{
|
|
||||||
GtkTreeModel *model = gtk_combo_box_get_model (combo);
|
|
||||||
const gchar *brush;
|
|
||||||
|
|
||||||
gtk_tree_model_get (model, &iter,
|
|
||||||
GIMP_INT_STORE_USER_DATA, &brush,
|
|
||||||
-1);
|
|
||||||
|
|
||||||
if (brush)
|
|
||||||
g_object_set (config,
|
|
||||||
"mybrush", brush,
|
|
||||||
NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
GtkWidget *
|
GtkWidget *
|
||||||
gimp_mybrush_options_gui (GimpToolOptions *tool_options)
|
gimp_mybrush_options_gui (GimpToolOptions *tool_options)
|
||||||
{
|
{
|
||||||
GObject *config = G_OBJECT (tool_options);
|
GObject *config = G_OBJECT (tool_options);
|
||||||
GtkWidget *vbox = gimp_paint_options_gui (tool_options);
|
GtkWidget *vbox = gimp_paint_options_gui (tool_options);
|
||||||
GtkWidget *scale;
|
GtkWidget *scale;
|
||||||
GtkWidget *combo;
|
|
||||||
GtkTreeModel *model;
|
|
||||||
GList *path;
|
|
||||||
GList *list;
|
|
||||||
|
|
||||||
/* radius */
|
/* radius */
|
||||||
scale = gimp_prop_spin_scale_new (config, "radius",
|
scale = gimp_prop_spin_scale_new (config, "radius",
|
||||||
@ -182,34 +68,5 @@ gimp_mybrush_options_gui (GimpToolOptions *tool_options)
|
|||||||
gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, FALSE, 0);
|
gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, FALSE, 0);
|
||||||
gtk_widget_show (scale);
|
gtk_widget_show (scale);
|
||||||
|
|
||||||
/* brushes */
|
|
||||||
combo = g_object_new (GIMP_TYPE_INT_COMBO_BOX,
|
|
||||||
"label", _("Brush"),
|
|
||||||
"ellipsize", PANGO_ELLIPSIZE_END,
|
|
||||||
NULL);
|
|
||||||
gtk_box_pack_start (GTK_BOX (vbox), combo, FALSE, FALSE, 0);
|
|
||||||
gtk_widget_show (combo);
|
|
||||||
|
|
||||||
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
|
|
||||||
|
|
||||||
path = gimp_config_path_expand_to_files (GIMP_CONTEXT (config)->gimp->config->mypaint_brush_path, NULL);
|
|
||||||
|
|
||||||
for (list = path; list; list = g_list_next (list))
|
|
||||||
{
|
|
||||||
GFile *dir = list->data;
|
|
||||||
|
|
||||||
gimp_mybrush_options_load_recursive (dir, model);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_list_free_full (path, (GDestroyNotify) g_object_unref);
|
|
||||||
|
|
||||||
g_signal_connect (combo, "changed",
|
|
||||||
G_CALLBACK (gimp_mybrush_options_brush_changed),
|
|
||||||
config);
|
|
||||||
|
|
||||||
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (combo), 0);
|
|
||||||
|
|
||||||
return vbox;
|
return vbox;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -15,8 +15,6 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_LIBMYPAINT
|
|
||||||
|
|
||||||
#ifndef __GIMP_MYBRUSH_OPTIONS_GUI_H__
|
#ifndef __GIMP_MYBRUSH_OPTIONS_GUI_H__
|
||||||
#define __GIMP_MYBRUSH_OPTIONS_GUI_H__
|
#define __GIMP_MYBRUSH_OPTIONS_GUI_H__
|
||||||
|
|
||||||
@ -25,5 +23,3 @@ GtkWidget * gimp_mybrush_options_gui (GimpToolOptions *tool_options);
|
|||||||
|
|
||||||
|
|
||||||
#endif /* __GIMP_MYBRUSH_OPTIONS_GUI_H__ */
|
#endif /* __GIMP_MYBRUSH_OPTIONS_GUI_H__ */
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -17,8 +17,6 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#ifdef HAVE_LIBMYPAINT
|
|
||||||
|
|
||||||
#include <gegl.h>
|
#include <gegl.h>
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
@ -72,7 +70,7 @@ gimp_mybrush_tool_register (GimpToolRegisterCallback callback,
|
|||||||
GIMP_CONTEXT_PROP_MASK_BACKGROUND |
|
GIMP_CONTEXT_PROP_MASK_BACKGROUND |
|
||||||
GIMP_CONTEXT_PROP_MASK_OPACITY |
|
GIMP_CONTEXT_PROP_MASK_OPACITY |
|
||||||
GIMP_CONTEXT_PROP_MASK_PAINT_MODE |
|
GIMP_CONTEXT_PROP_MASK_PAINT_MODE |
|
||||||
GIMP_CONTEXT_PROP_MYBRUSH,
|
GIMP_CONTEXT_PROP_MASK_MYBRUSH,
|
||||||
"gimp-mybrush-tool",
|
"gimp-mybrush-tool",
|
||||||
_("MyPaint Brush"),
|
_("MyPaint Brush"),
|
||||||
_("MyPaint Brush Tool: Use MyPaint brushes in GIMP"),
|
_("MyPaint Brush Tool: Use MyPaint brushes in GIMP"),
|
||||||
@ -133,5 +131,3 @@ gimp_mybrush_tool_get_outline (GimpPaintTool *paint_tool,
|
|||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -15,8 +15,6 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_LIBMYPAINT
|
|
||||||
|
|
||||||
#ifndef __GIMP_MYBRUSH_TOOL_H__
|
#ifndef __GIMP_MYBRUSH_TOOL_H__
|
||||||
#define __GIMP_MYBRUSH_TOOL_H__
|
#define __GIMP_MYBRUSH_TOOL_H__
|
||||||
|
|
||||||
@ -55,5 +53,3 @@ GType gimp_mybrush_tool_get_type (void) G_GNUC_CONST;
|
|||||||
|
|
||||||
|
|
||||||
#endif /* __GIMP_MYBRUSH_TOOL_H__ */
|
#endif /* __GIMP_MYBRUSH_TOOL_H__ */
|
||||||
|
|
||||||
#endif
|
|
||||||
|
Reference in New Issue
Block a user