Commit 7fe80e8d authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

the virtual serialize_property() returning FALSE doesn't mean the

2003-02-08  Michael Natterer  <mitch@gimp.org>

	* app/config/gimpconfig-serialize.c (gimp_config_serialize_property):
	the virtual serialize_property() returning FALSE doesn't mean the
	serialization failed but that the function didn't handle the
	property, so don't error but continue with the default
	implementation. Print newlines after properties only if
	indent_level == 0.

	* app/gui/tool-options-dialog.c: added tool options saving/loading
	as quickly hacked proof-of-concept.

	* app/paint/paint-enums.[ch]: added enum GimpInkBlobType.

	* app/tools/gimpinkoptions.[ch]: ported to object properties,
	cleanup.

	* app/tools/gimpinktool.c: changed accordingly.
parent 4093cd2e
2003-02-08 Michael Natterer <mitch@gimp.org>
* app/config/gimpconfig-serialize.c (gimp_config_serialize_property):
the virtual serialize_property() returning FALSE doesn't mean the
serialization failed but that the function didn't handle the
property, so don't error but continue with the default
implementation. Print newlines after properties only if
indent_level == 0.
* app/gui/tool-options-dialog.c: added tool options saving/loading
as quickly hacked proof-of-concept.
* app/paint/paint-enums.[ch]: added enum GimpInkBlobType.
* app/tools/gimpinkoptions.[ch]: ported to object properties,
cleanup.
* app/tools/gimpinktool.c: changed accordingly.
2003-02-08 Sven Neumann <sven@gimp.org>
* HACKING: added a note about generating the developers
......
......@@ -92,7 +92,10 @@ gimp_config_serialize_properties (GObject *object,
return FALSE;
}
g_string_assign (str, "\n");
if (indent_level == 0)
g_string_assign (str, "\n");
else
g_string_assign (str, "");
}
g_free (property_specs);
......@@ -196,8 +199,9 @@ gimp_config_serialize_property (GObject *object,
{
GTypeClass *owner_class;
GimpConfigInterface *config_iface;
GimpConfigInterface *parent_iface;
GimpConfigInterface *parent_iface = NULL;
GValue value = { 0, };
gboolean success = FALSE;
if (! (param_spec->flags & GIMP_PARAM_SERIALIZE))
return FALSE;
......@@ -234,39 +238,41 @@ gimp_config_serialize_property (GObject *object,
if (config_iface &&
config_iface != parent_iface && /* see comment above */
config_iface->serialize_property)
config_iface->serialize_property &&
config_iface->serialize_property (object,
param_spec->param_id,
(const GValue *) &value,
param_spec,
str))
{
if (! config_iface->serialize_property (object,
param_spec->param_id,
(const GValue *) &value,
param_spec,
str))
{
g_value_unset (&value);
return FALSE;
}
success = TRUE;
}
else
/* If there is no serialize_property() method *or* if it returned
* FALSE, continue with the default implementation
*/
if (! success && gimp_config_serialize_value (&value, str, escaped))
{
if (! gimp_config_serialize_value (&value, str, escaped))
{
/* don't warn for empty string properties */
if (! G_VALUE_HOLDS_STRING (&value))
g_warning ("couldn't serialize property %s::%s of type %s",
g_type_name (G_TYPE_FROM_INSTANCE (object)),
param_spec->name,
g_type_name (param_spec->value_type));
success = TRUE;
}
g_value_unset (&value);
return FALSE;
}
if (! success)
{
/* don't warn for empty string properties */
if (! G_VALUE_HOLDS_STRING (&value))
g_warning ("couldn't serialize property %s::%s of type %s",
g_type_name (G_TYPE_FROM_INSTANCE (object)),
param_spec->name,
g_type_name (param_spec->value_type));
}
g_value_unset (&value);
g_string_append (str, ")\n");
if (success)
g_string_append (str, ")\n");
return TRUE;
return success;
}
/**
......
......@@ -20,10 +20,13 @@
#include <gtk/gtk.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "gui-types.h"
#include "config/gimpconfig.h"
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimplist.h"
......@@ -244,14 +247,62 @@ static void
tool_options_dialog_save_callback (GtkWidget *widget,
GimpContext *context)
{
g_print ("Save clicked\n");
GimpToolInfo *tool_info;
gchar *filename;
GError *error = NULL;
tool_info = gimp_context_get_tool (context);
if (! tool_info)
return;
filename = g_build_filename (gimp_directory (),
"tool-options",
gimp_object_get_name (GIMP_OBJECT (tool_info)),
NULL);
if (! gimp_config_serialize (G_OBJECT (tool_info->tool_options),
filename,
"# foo\n",
"# bar",
NULL,
&error))
{
g_message ("EEK: %s\n", error->message);
g_clear_error (&error);
}
g_free (filename);
}
static void
tool_options_dialog_restore_callback (GtkWidget *widget,
GimpContext *context)
{
g_print ("Restore clicked\n");
GimpToolInfo *tool_info;
gchar *filename;
GError *error = NULL;
tool_info = gimp_context_get_tool (context);
if (! tool_info)
return;
filename = g_build_filename (gimp_directory (),
"tool-options",
gimp_object_get_name (GIMP_OBJECT (tool_info)),
NULL);
if (! gimp_config_deserialize (G_OBJECT (tool_info->tool_options),
filename,
NULL,
&error))
{
g_message ("EEK: %s\n", error->message);
g_clear_error (&error);
}
g_free (filename);
}
static void
......
......@@ -477,13 +477,14 @@ ink_pen_ellipse (GimpInkOptions *options,
gdouble ytilt,
gdouble velocity)
{
gdouble size;
gdouble tsin, tcos;
gdouble aspect, radmin;
gdouble x,y;
gdouble tscale;
gdouble tscale_c;
gdouble tscale_s;
BlobFunc function = blob_ellipse;
gdouble size;
gdouble tsin, tcos;
gdouble aspect, radmin;
gdouble x,y;
gdouble tscale;
gdouble tscale_c;
gdouble tscale_s;
/* Adjust the size depending on pressure. */
......@@ -526,42 +527,54 @@ ink_pen_ellipse (GimpInkOptions *options,
tscale_c = tscale * cos (gimp_deg_to_rad (options->tilt_angle));
tscale_s = tscale * sin (gimp_deg_to_rad (options->tilt_angle));
x = (options->aspect * cos (options->angle) +
x = (options->blob_aspect * cos (options->blob_angle) +
xtilt * tscale_c - ytilt * tscale_s);
y = (options->aspect * sin (options->angle) +
y = (options->blob_aspect * sin (options->blob_angle) +
ytilt * tscale_c + xtilt * tscale_s);
#ifdef VERBOSE
g_print ("angle %g aspect %g; %g %g; %g %g\n",
options->angle, options->aspect, tscale_c, tscale_s, x, y);
options->blob_angle, options->blob_aspect, tscale_c, tscale_s, x, y);
#endif
aspect = sqrt(x*x+y*y);
aspect = sqrt (x*x + y*y);
if (aspect != 0)
{
tcos = x/aspect;
tsin = y/aspect;
tcos = x / aspect;
tsin = y / aspect;
}
else
{
tsin = sin (options->angle);
tcos = cos (options->angle);
tsin = sin (options->blob_angle);
tcos = cos (options->blob_angle);
}
if (aspect < 1.0)
aspect = 1.0;
else if (aspect > 10.0)
aspect = 10.0;
aspect = CLAMP (aspect, 1.0, 10.0);
radmin = SUBSAMPLE * size/aspect;
if (radmin < 1.0) radmin = 1.0;
return options->function (x_center * SUBSAMPLE,
y_center * SUBSAMPLE,
radmin * aspect * tcos,
radmin * aspect * tsin,
-radmin * tsin,
radmin * tcos);
radmin = MAX (1.0, SUBSAMPLE * size / aspect);
switch (options->blob_type)
{
case GIMP_INK_BLOB_TYPE_ELLIPSE:
function = blob_ellipse;
break;
case GIMP_INK_BLOB_TYPE_SQUARE:
function = blob_square;
break;
case GIMP_INK_BLOB_TYPE_DIAMOND:
function = blob_diamond;
break;
}
return (* function) (x_center * SUBSAMPLE,
y_center * SUBSAMPLE,
radmin * aspect * tcos,
radmin * aspect * tsin,
-radmin * tsin,
radmin * tcos);
}
static void
......@@ -572,7 +585,7 @@ dist_smoother_init (GimpInkTool *ink_tool,
ink_tool->dt_index = 0;
for (i=0; i<DIST_SMOOTHER_BUFFER; i++)
for (i = 0; i < DIST_SMOOTHER_BUFFER; i++)
{
ink_tool->dt_buffer[i] = initval;
}
......
This diff is collapsed.
......@@ -21,7 +21,6 @@
#include "paint/gimppaintoptions.h"
#include "gimpinktool-blob.h" /* only used by ink */
#define GIMP_TYPE_INK_OPTIONS (gimp_ink_options_get_type ())
......@@ -34,51 +33,20 @@
typedef struct _GimpInkOptions GimpInkOptions;
typedef struct _GimpPaintOptionsClass GimpInkOptionsClass;
typedef struct _BrushWidget BrushWidget;
struct _BrushWidget
{
GtkWidget *widget;
gboolean state;
/* EEK */
GimpInkOptions *ink_options;
};
struct _GimpInkOptions
{
GimpPaintOptions paint_options;
gdouble size;
gdouble size_d;
GtkObject *size_w;
gdouble sensitivity;
gdouble sensitivity_d;
GtkObject *sensitivity_w;
gdouble vel_sensitivity;
gdouble vel_sensitivity_d;
GtkObject *vel_sensitivity_w;
gdouble tilt_sensitivity;
gdouble tilt_sensitivity_d;
GtkObject *tilt_sensitivity_w;
gdouble tilt_angle;
gdouble tilt_angle_d;
GtkObject *tilt_angle_w;
BlobFunc function;
BlobFunc function_d;
GtkWidget *function_w[3]; /* 3 radio buttons */
gdouble aspect;
gdouble aspect_d;
gdouble angle;
gdouble angle_d;
BrushWidget *brush_w;
GimpInkBlobType blob_type;
gdouble blob_aspect;
gdouble blob_angle;
};
......
......@@ -106,5 +106,25 @@ gimp_convolve_type_get_type (void)
}
static const GEnumValue gimp_ink_blob_type_enum_values[] =
{
{ GIMP_INK_BLOB_TYPE_ELLIPSE, "GIMP_INK_BLOB_TYPE_ELLIPSE", "ellipse" },
{ GIMP_INK_BLOB_TYPE_SQUARE, "GIMP_INK_BLOB_TYPE_SQUARE", "square" },
{ GIMP_INK_BLOB_TYPE_DIAMOND, "GIMP_INK_BLOB_TYPE_DIAMOND", "diamond" },
{ 0, NULL, NULL }
};
GType
gimp_ink_blob_type_get_type (void)
{
static GType enum_type = 0;
if (!enum_type)
enum_type = g_enum_register_static ("GimpInkBlobType", gimp_ink_blob_type_enum_values);
return enum_type;
}
/* Generated data ends here */
......@@ -95,6 +95,18 @@ typedef enum
} GimpConvolveType;
#define GIMP_TYPE_INK_BLOB_TYPE (gimp_ink_blob_type_get_type ())
GType gimp_ink_blob_type_get_type (void) G_GNUC_CONST;
typedef enum /*< pdb-skip >*/
{
GIMP_INK_BLOB_TYPE_ELLIPSE,
GIMP_INK_BLOB_TYPE_SQUARE,
GIMP_INK_BLOB_TYPE_DIAMOND
} GimpInkBlobType;
/*
* non-registered enums; register them if needed
*/
......
This diff is collapsed.
......@@ -21,7 +21,6 @@
#include "paint/gimppaintoptions.h"
#include "gimpinktool-blob.h" /* only used by ink */
#define GIMP_TYPE_INK_OPTIONS (gimp_ink_options_get_type ())
......@@ -34,51 +33,20 @@
typedef struct _GimpInkOptions GimpInkOptions;
typedef struct _GimpPaintOptionsClass GimpInkOptionsClass;
typedef struct _BrushWidget BrushWidget;
struct _BrushWidget
{
GtkWidget *widget;
gboolean state;
/* EEK */
GimpInkOptions *ink_options;
};
struct _GimpInkOptions
{
GimpPaintOptions paint_options;
gdouble size;
gdouble size_d;
GtkObject *size_w;
gdouble sensitivity;
gdouble sensitivity_d;
GtkObject *sensitivity_w;
gdouble vel_sensitivity;
gdouble vel_sensitivity_d;
GtkObject *vel_sensitivity_w;
gdouble tilt_sensitivity;
gdouble tilt_sensitivity_d;
GtkObject *tilt_sensitivity_w;
gdouble tilt_angle;
gdouble tilt_angle_d;
GtkObject *tilt_angle_w;
BlobFunc function;
BlobFunc function_d;
GtkWidget *function_w[3]; /* 3 radio buttons */
gdouble aspect;
gdouble aspect_d;
gdouble angle;
gdouble angle_d;
BrushWidget *brush_w;
GimpInkBlobType blob_type;
gdouble blob_aspect;
gdouble blob_angle;
};
......
This diff is collapsed.
......@@ -21,7 +21,6 @@
#include "paint/gimppaintoptions.h"
#include "gimpinktool-blob.h" /* only used by ink */
#define GIMP_TYPE_INK_OPTIONS (gimp_ink_options_get_type ())
......@@ -34,51 +33,20 @@
typedef struct _GimpInkOptions GimpInkOptions;
typedef struct _GimpPaintOptionsClass GimpInkOptionsClass;
typedef struct _BrushWidget BrushWidget;
struct _BrushWidget
{
GtkWidget *widget;
gboolean state;
/* EEK */
GimpInkOptions *ink_options;
};
struct _GimpInkOptions
{
GimpPaintOptions paint_options;
gdouble size;
gdouble size_d;
GtkObject *size_w;
gdouble sensitivity;
gdouble sensitivity_d;
GtkObject *sensitivity_w;
gdouble vel_sensitivity;
gdouble vel_sensitivity_d;
GtkObject *vel_sensitivity_w;
gdouble tilt_sensitivity;
gdouble tilt_sensitivity_d;
GtkObject *tilt_sensitivity_w;
gdouble tilt_angle;
gdouble tilt_angle_d;
GtkObject *tilt_angle_w;
BlobFunc function;
BlobFunc function_d;
GtkWidget *function_w[3]; /* 3 radio buttons */
gdouble aspect;
gdouble aspect_d;
gdouble angle;
gdouble angle_d;
BrushWidget *brush_w;
GimpInkBlobType blob_type;
gdouble blob_aspect;
gdouble blob_angle;
};
......
......@@ -477,13 +477,14 @@ ink_pen_ellipse (GimpInkOptions *options,
gdouble ytilt,
gdouble velocity)
{
gdouble size;
gdouble tsin, tcos;
gdouble aspect, radmin;
gdouble x,y;
gdouble tscale;
gdouble tscale_c;
gdouble tscale_s;
BlobFunc function = blob_ellipse;
gdouble size;
gdouble tsin, tcos;
gdouble aspect, radmin;
gdouble x,y;
gdouble tscale;
gdouble tscale_c;
gdouble tscale_s;
/* Adjust the size depending on pressure. */
......@@ -526,42 +527,54 @@ ink_pen_ellipse (GimpInkOptions *options,
tscale_c = tscale * cos (gimp_deg_to_rad (options->tilt_angle));
tscale_s = tscale * sin (gimp_deg_to_rad (options->tilt_angle));
x = (options->aspect * cos (options->angle) +
x = (options->blob_aspect * cos (options->blob_angle) +
xtilt * tscale_c - ytilt * tscale_s);
y = (options->aspect * sin (options->angle) +
y = (options->blob_aspect * sin (options->blob_angle) +
ytilt * tscale_c + xtilt * tscale_s);
#ifdef VERBOSE
g_print ("angle %g aspect %g; %g %g; %g %g\n",
options->angle, options->aspect, tscale_c, tscale_s, x, y);
options->blob_angle, options->blob_aspect, tscale_c, tscale_s, x, y);
#endif
aspect = sqrt(x*x+y*y);
aspect = sqrt (x*x + y*y);
if (aspect != 0)
{
tcos = x/aspect;
tsin = y/aspect;
tcos = x / aspect;
tsin = y / aspect;
}
else
{
tsin = sin (options->angle);
tcos = cos (options->angle);
tsin = sin (options->blob_angle);
tcos = cos (options->blob_angle);
}
if (aspect < 1.0)
aspect = 1.0;
else if (aspect > 10.0)
aspect = 10.0;
aspect = CLAMP (aspect, 1.0, 10.0);
radmin = SUBSAMPLE * size/aspect;
if (radmin < 1.0) radmin = 1.0;
return options->function (x_center * SUBSAMPLE,
y_center * SUBSAMPLE,
radmin * aspect * tcos,
radmin * aspect * tsin,
-radmin * tsin,
radmin * tcos);
radmin = MAX (1.0, SUBSAMPLE * size / aspect);
switch (options->blob_type)
{
case GIMP_INK_BLOB_TYPE_ELLIPSE:
function = blob_ellipse;
break;
case GIMP_INK_BLOB_TYPE_SQUARE:
function = blob_square;
break;
case GIMP_INK_BLOB_TYPE_DIAMOND:
function = blob_diamond;
break;
}
return (* function) (x_center * SUBSAMPLE,
y_center * SUBSAMPLE,
radmin * aspect * tcos,
radmin * aspect * tsin,
-radmin * tsin,
radmin * tcos);
}
static void
......@@ -572,7 +585,7 @@ dist_smoother_init (GimpInkTool *ink_tool,
ink_tool->dt_index = 0;
for (i=0; i<DIST_SMOOTHER_BUFFER; i++)
for (i = 0; i < DIST_SMOOTHER_BUFFER; i++)
{
ink_tool->dt_buffer[i] = initval;
}
......
......@@ -20,10 +20,13 @@
#include <gtk/gtk.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "gui-types.h"