[gimp/soc-2009-dynamics] Add dynamics context and factory data and functions (need debugging).
- From: zhenfeng zhao <zhenfengz src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gimp/soc-2009-dynamics] Add dynamics context and factory data and functions (need debugging).
- Date: Tue, 18 Aug 2009 02:50:03 +0000 (UTC)
commit f48a7e4a8beb8dc21b83d1781586b26521404b03
Author: zhenfeng zhao <zhzzf_0808 hotmail com>
Date: Mon Aug 17 23:47:26 2009 -0300
Add dynamics context and factory data and functions (need debugging).
app/core/gimp.c | 32 +++++++
app/core/gimp.h | 1 +
app/core/gimpcontext.c | 182 ++++++++++++++++++++++++++++++++++++++
app/core/gimpcontext.h | 19 ++++
app/paint/gimpdynamicsoptions.c | 20 ++++
app/paint/gimpdynamicsoptions.h | 2 +-
app/widgets/gimpdynamicseditor.c | 19 +---
7 files changed, 259 insertions(+), 16 deletions(-)
---
diff --git a/app/core/gimp.c b/app/core/gimp.c
index 50d60e5..590301a 100644
--- a/app/core/gimp.c
+++ b/app/core/gimp.c
@@ -75,6 +75,8 @@
#include "gimptemplate.h"
#include "gimptoolinfo.h"
+#include "paint/gimpdynamicsoptions.h"
+
#include "gimp-intl.h"
@@ -238,6 +240,7 @@ gimp_init (Gimp *gimp)
gimp->fonts = NULL;
gimp->brush_factory = NULL;
+ gimp->dynamics_factory = NULL;
gimp->pattern_factory = NULL;
gimp->gradient_factory = NULL;
gimp->palette_factory = NULL;
@@ -276,6 +279,9 @@ gimp_dispose (GObject *object)
if (gimp->brush_factory)
gimp_data_factory_data_free (gimp->brush_factory);
+
+ if (gimp->dynamics_factory)
+ gimp_data_factory_data_free (gimp->dynamics_factory);
if (gimp->pattern_factory)
gimp_data_factory_data_free (gimp->pattern_factory);
@@ -339,6 +345,12 @@ gimp_finalize (GObject *object)
gimp->brush_factory = NULL;
}
+ if (gimp->dynamics_factory)
+ {
+ g_object_unref (gimp->dynamics_factory);
+ gimp->dynamics_factory = NULL;
+ }
+
if (gimp->pattern_factory)
{
g_object_unref (gimp->pattern_factory);
@@ -478,6 +490,8 @@ gimp_get_memsize (GimpObject *object,
gui_size);
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->brush_factory),
gui_size);
+ memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->dynamics_factory),
+ gui_size);
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->pattern_factory),
gui_size);
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->gradient_factory),
@@ -526,6 +540,12 @@ gimp_real_initialize (Gimp *gimp,
{ gimp_brush_pipe_load, GIMP_BRUSH_PIPE_FILE_EXTENSION, FALSE }
};
+ static const GimpDataFactoryLoaderEntry dynamics_loader_entries[] =
+ {
+ { gimp_pattern_load, GIMP_PATTERN_FILE_EXTENSION, FALSE },
+ { gimp_pattern_load_pixbuf, NULL, FALSE }
+ };
+
static const GimpDataFactoryLoaderEntry pattern_loader_entries[] =
{
{ gimp_pattern_load, GIMP_PATTERN_FILE_EXTENSION, FALSE },
@@ -566,6 +586,18 @@ gimp_real_initialize (Gimp *gimp,
gimp_object_set_static_name (GIMP_OBJECT (gimp->brush_factory),
"brush factory");
+
+ gimp->dynamics_factory =
+ gimp_data_factory_new (gimp,
+ GIMP_TYPE_DYNAMICS_OPTIONS,
+ "dynamics-path", "dynamics-path-writable",
+ dynamics_loader_entries,
+ G_N_ELEMENTS (dynamics_loader_entries),
+ gimp_dynamics_options_new,
+ gimp_dynamics_get_standard);
+ gimp_object_set_static_name (GIMP_OBJECT (gimp->dynamics_factory),
+ "dynamics factory");
+
gimp->pattern_factory =
gimp_data_factory_new (gimp,
GIMP_TYPE_PATTERN,
diff --git a/app/core/gimp.h b/app/core/gimp.h
index 1a78f22..448424d 100644
--- a/app/core/gimp.h
+++ b/app/core/gimp.h
@@ -90,6 +90,7 @@ struct _Gimp
GimpContainer *fonts;
GimpDataFactory *brush_factory;
+ GimpDataFactory *dynamics_factory;
GimpDataFactory *pattern_factory;
GimpDataFactory *gradient_factory;
GimpDataFactory *palette_factory;
diff --git a/app/core/gimpcontext.c b/app/core/gimpcontext.c
index a749ad5..8cb7c00 100644
--- a/app/core/gimpcontext.c
+++ b/app/core/gimpcontext.c
@@ -47,6 +47,7 @@
#include "gimptemplate.h"
#include "gimptoolinfo.h"
+#include "paint/gimpdynamicsoptions.h"
#include "text/gimpfont.h"
#include "gimp-intl.h"
@@ -156,9 +157,22 @@ static void gimp_context_brush_removed (GimpContainer *brush_list,
GimpContext *context);
static void gimp_context_brush_list_thaw (GimpContainer *container,
GimpContext *context);
+
static void gimp_context_real_set_brush (GimpContext *context,
GimpBrush *brush);
+/* dynamics */
+
+static void gimp_context_dynamics_dirty (GimpDynamicsOptions *dynamics,
+ GimpContext *context);
+static void gimp_context_dynamics_removed (GimpContainer *dynamics_list,
+ GimpDynamicsOptions *dynamics,
+ GimpContext *context);
+static void gimp_context_dynamics_list_thaw (GimpContainer *container,
+ GimpContext *context);
+static void gimp_context_real_set_dynamics (GimpContext *context,
+ GimpDynamicsOptions *dynamics);
+
/* pattern */
static void gimp_context_pattern_dirty (GimpPattern *pattern,
GimpContext *context);
@@ -267,6 +281,7 @@ enum
OPACITY_CHANGED,
PAINT_MODE_CHANGED,
BRUSH_CHANGED,
+ DYNAMICS_CHANGED,
PATTERN_CHANGED,
GRADIENT_CHANGED,
PALETTE_CHANGED,
@@ -440,6 +455,16 @@ gimp_context_class_init (GimpContextClass *klass)
G_TYPE_NONE, 1,
GIMP_TYPE_BRUSH);
+ gimp_context_signals[DYNAMICS_CHANGED] =
+ g_signal_new ("dynamics-changed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GimpContextClass, dynamics_changed),
+ NULL, NULL,
+ gimp_marshal_VOID__OBJECT,
+ G_TYPE_NONE, 1,
+ GIMP_TYPE_DYNAMICS_OPTIONS);
+
gimp_context_signals[PATTERN_CHANGED] =
g_signal_new ("pattern-changed",
G_TYPE_FROM_CLASS (klass),
@@ -527,6 +552,7 @@ gimp_context_class_init (GimpContextClass *klass)
klass->opacity_changed = NULL;
klass->paint_mode_changed = NULL;
klass->brush_changed = NULL;
+ klass->dynamics_changed = NULL;
klass->pattern_changed = NULL;
klass->gradient_changed = NULL;
klass->palette_changed = NULL;
@@ -539,6 +565,7 @@ gimp_context_class_init (GimpContextClass *klass)
gimp_context_prop_types[GIMP_CONTEXT_PROP_TOOL] = GIMP_TYPE_TOOL_INFO;
gimp_context_prop_types[GIMP_CONTEXT_PROP_PAINT_INFO] = GIMP_TYPE_PAINT_INFO;
gimp_context_prop_types[GIMP_CONTEXT_PROP_BRUSH] = GIMP_TYPE_BRUSH;
+ gimp_context_prop_types[GIMP_CONTEXT_PROP_DYNAMICS] = GIMP_TYPE_DYNAMICS_OPTIONS;
gimp_context_prop_types[GIMP_CONTEXT_PROP_PATTERN] = GIMP_TYPE_PATTERN;
gimp_context_prop_types[GIMP_CONTEXT_PROP_GRADIENT] = GIMP_TYPE_GRADIENT;
gimp_context_prop_types[GIMP_CONTEXT_PROP_PALETTE] = GIMP_TYPE_PALETTE;
@@ -608,6 +635,12 @@ gimp_context_class_init (GimpContextClass *klass)
NULL,
GIMP_TYPE_BRUSH,
GIMP_PARAM_STATIC_STRINGS);
+
+ GIMP_CONFIG_INSTALL_PROP_OBJECT (object_class, GIMP_CONTEXT_PROP_DYNAMICS,
+ gimp_context_prop_names[GIMP_CONTEXT_PROP_DYNAMICS],
+ NULL,
+ GIMP_TYPE_DYNAMICS_OPTIONS,
+ GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_INSTALL_PROP_OBJECT (object_class, GIMP_CONTEXT_PROP_PATTERN,
gimp_context_prop_names[GIMP_CONTEXT_PROP_PATTERN],
@@ -748,6 +781,13 @@ gimp_context_constructor (GType type,
G_CALLBACK (gimp_context_brush_list_thaw),
object, 0);
+ g_signal_connect_object (gimp_data_factory_get_container (gimp->dynamics_factory), "remove",
+ G_CALLBACK (gimp_context_dynamics_removed),
+ object, 0);
+ g_signal_connect_object (gimp_data_factory_get_container (gimp->dynamics_factory), "thaw",
+ G_CALLBACK (gimp_context_dynamics_list_thaw),
+ object, 0);
+
g_signal_connect_object (gimp_data_factory_get_container (gimp->pattern_factory), "remove",
G_CALLBACK (gimp_context_pattern_removed),
object, 0);
@@ -977,6 +1017,9 @@ gimp_context_set_property (GObject *object,
case GIMP_CONTEXT_PROP_BRUSH:
gimp_context_set_brush (context, g_value_get_object (value));
break;
+ case GIMP_CONTEXT_PROP_DYNAMICS:
+ gimp_context_set_dynamics (context, g_value_get_object (value));
+ break;
case GIMP_CONTEXT_PROP_PATTERN:
gimp_context_set_pattern (context, g_value_get_object (value));
break;
@@ -1054,6 +1097,9 @@ gimp_context_get_property (GObject *object,
case GIMP_CONTEXT_PROP_BRUSH:
g_value_set_object (value, gimp_context_get_brush (context));
break;
+ case GIMP_CONTEXT_PROP_DYNAMICS:
+ g_value_set_object (value, gimp_context_get_dynamics (context));
+ break;
case GIMP_CONTEXT_PROP_PATTERN:
g_value_set_object (value, gimp_context_get_pattern (context));
break;
@@ -1129,6 +1175,7 @@ gimp_context_serialize_property (GimpConfig *config,
case GIMP_CONTEXT_PROP_TOOL:
case GIMP_CONTEXT_PROP_PAINT_INFO:
case GIMP_CONTEXT_PROP_BRUSH:
+ case GIMP_CONTEXT_PROP_DYNAMICS:
case GIMP_CONTEXT_PROP_PATTERN:
case GIMP_CONTEXT_PROP_GRADIENT:
case GIMP_CONTEXT_PROP_PALETTE:
@@ -1189,6 +1236,12 @@ gimp_context_deserialize_property (GimpConfig *object,
name_loc = &context->brush_name;
break;
+ case GIMP_CONTEXT_PROP_DYNAMICS:
+ container = gimp_data_factory_get_container (context->gimp->dynamics_factory);
+ current = (GimpObject *) context->dynamics;
+ name_loc = &context->dynamics_name;
+ break;
+
case GIMP_CONTEXT_PROP_PATTERN:
container = gimp_data_factory_get_container (context->gimp->pattern_factory);
current = (GimpObject *) context->pattern;
@@ -1492,6 +1545,14 @@ gimp_context_copy_property (GimpContext *src,
dest_name_loc = &dest->brush_name;
break;
+ case GIMP_CONTEXT_PROP_DYNAMICS:
+ gimp_context_real_set_dynamics (dest, src->dynamics);
+ object = src->dynamics;
+ standard_object = standard_dynamics;
+ src_name = src->dynamics_name;
+ dest_name_loc = &dest->dynamics_name;
+ break;
+
case GIMP_CONTEXT_PROP_PATTERN:
gimp_context_real_set_pattern (dest, src->pattern);
object = src->pattern;
@@ -2405,6 +2466,127 @@ gimp_context_real_set_brush (GimpContext *context,
/*****************************************************************************/
+/* dynamics *****************************************************************/
+
+
+GimpBrush *
+gimp_context_get_dynamics (GimpContext *context)
+{
+ g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
+
+ return context->dynamics;
+}
+
+void
+gimp_context_set_dynamics (GimpContext *context,
+ GimpDynamicsOptions *dynamics)
+{
+ g_return_if_fail (GIMP_IS_CONTEXT (context));
+ g_return_if_fail (! dynamics || GIMP_IS_DYNAMICS (dynamics));
+ context_find_defined (context, GIMP_CONTEXT_PROP_DYNAMICS);
+
+ gimp_context_real_set_dynamics (context, dynamics);
+}
+
+void
+gimp_context_dynamics_changed (GimpContext *context)
+{
+ g_return_if_fail (GIMP_IS_CONTEXT (context));
+
+ g_signal_emit (context,
+ gimp_context_signals[DYNAMICS_CHANGED], 0,
+ context->dynamics);
+}
+
+static void
+gimp_context_dynamics_dirty (GimpDynamicsOptions *dynamics,
+ GimpContext *context)
+{
+ g_free (context->dynamics_name);
+ context->dynamics_name = g_strdup (GIMP_OBJECT (dynamics)->name);
+}
+
+static void gimp_context_dynamics_removed (GimpContainer *dynamics_list,
+ GimpDynamicsOptions *dynamics,
+ GimpContext *context);
+{
+ if (dynamics == context->dynamics)
+ {
+ context->dynamics = NULL;
+
+ g_signal_handlers_disconnect_by_func (dynamics,
+ gimp_context_dynamics_dirty,
+ context);
+ g_object_unref (dynamics);
+
+ if (! gimp_container_frozen (container))
+ gimp_context_dynamics_list_thaw (container, context);
+ }
+}
+
+
+static void gimp_context_dynamics_list_thaw (GimpContainer *container,
+ GimpContext *context);
+{
+ GimpDynamicsOptions *dynamics;
+/*
+ if (! context->dynamics_name)
+ context->dynamics_name = g_strdup (context->gimp->config->default_dynamics);
+*/
+ dynamics = gimp_context_find_object (context, container,
+ context->dynamics_name,
+ gimp_dynamics_get_standard ());
+
+ gimp_context_real_set_dynamics (context, dynamics);
+}
+
+
+static void
+gimp_context_real_set_dynamics (GimpContext *context,
+ GimpDynamicsOptions *dynamics)
+{
+/* if (! standard_dynamics)
+ standard_dynamics = GIMP_BRUSH (gimp_dynamics_get_standard ());
+*/
+ if (context->dynamics == dynamics)
+ return;
+
+ if (context->dynamics_name && dynamics != standard_dynamics)
+ {
+ g_free (context->dynamics_name);
+ context->dynamics_name = NULL;
+ }
+
+ /* disconnect from the old brush's signals */
+ if (context->dynamics)
+ {
+ g_signal_handlers_disconnect_by_func (context->dynamics,
+ gimp_context_dynamics_dirty,
+ context);
+ g_object_unref (context->dynamics);
+ }
+
+ context->dynamics = dynamics;
+
+ if (dynamics)
+ {
+ g_object_ref (dynamics);
+
+ g_signal_connect_object (dynamics, "name-changed",
+ G_CALLBACK (gimp_context_dynamics_dirty),
+ context,
+ 0);
+
+ if (dynamics != standard_dynamics)
+ context->dynamics_name = g_strdup (GIMP_OBJECT (dynamics)->name);
+ }
+
+ g_object_notify (G_OBJECT (context), "dynamics");
+ gimp_context_dynamics_changed (context);
+}
+
+
+/*****************************************************************************/
/* pattern *****************************************************************/
GimpPattern *
diff --git a/app/core/gimpcontext.h b/app/core/gimpcontext.h
index 83dfe11..613ec98 100644
--- a/app/core/gimpcontext.h
+++ b/app/core/gimpcontext.h
@@ -64,6 +64,9 @@ struct _GimpContext
GimpBrush *brush;
gchar *brush_name;
+ GimpDynamicsOptions *dynamics;
+ gchar *dynamics_name;
+
GimpPattern *pattern;
gchar *pattern_name;
@@ -110,6 +113,8 @@ struct _GimpContextClass
GimpLayerModeEffects paint_mode);
void (* brush_changed) (GimpContext *context,
GimpBrush *brush);
+ void (* dynamics_changed) (GimpContext *context,
+ GimpDynamicsOptions *dynamics);
void (* pattern_changed) (GimpContext *context,
GimpPattern *pattern);
void (* gradient_changed) (GimpContext *context,
@@ -257,6 +262,20 @@ void gimp_context_set_brush (GimpContext *context,
GimpBrush *brush);
void gimp_context_brush_changed (GimpContext *context);
+/* brush */
+GimpBrush * gimp_context_get_brush (GimpContext *context);
+void gimp_context_set_brush (GimpContext *context,
+ GimpBrush *brush);
+void gimp_context_brush_changed (GimpContext *context);
+
+
+/* dynamics */
+GimpDynamicsOptions * gimp_context_get_dynamics (GimpContext *context);
+void gimp_context_set_dynamics (GimpContext *context,
+ GimpDynamicsOptions *dynamics);
+void gimp_context_dynamics_changed (GimpContext *context);
+
+
/* pattern */
GimpPattern * gimp_context_get_pattern (GimpContext *context);
diff --git a/app/paint/gimpdynamicsoptions.c b/app/paint/gimpdynamicsoptions.c
index a5fe59a..c6b523a 100644
--- a/app/paint/gimpdynamicsoptions.c
+++ b/app/paint/gimpdynamicsoptions.c
@@ -1023,6 +1023,26 @@ gimp_dynamics_options_new (GimpPaintInfo *dynamics_info)
}
+GimpData *
+gimp_dynamics_get_standard (void)
+{
+ static GimpData *standard_dynamics = NULL;
+
+ if (! standard_dynamics)
+ {
+ standard_dynamics = gimp_dynamics_options_new ("Standard");
+
+ standard_dynamics->dirty = FALSE;
+ gimp_data_make_internal (standard_dynamics,
+ "gimp-dynamics-standard");
+
+ g_object_ref (standard_dynamics);
+ }
+
+ return standard_dynamics;
+}
+
+
/* Calculates dynamics mix to be used for same parameter
* (velocity/pressure/direction/tilt/random) mix Needed in may places and tools.
*
diff --git a/app/paint/gimpdynamicsoptions.h b/app/paint/gimpdynamicsoptions.h
index 6966fd9..2a9810f 100644
--- a/app/paint/gimpdynamicsoptions.h
+++ b/app/paint/gimpdynamicsoptions.h
@@ -98,6 +98,6 @@ GType gimp_dynamics_options_get_type (void) G_GNUC_CONST;
GimpData * gimp_dynamics_options_new (GimpPaintInfo *dynamics_info);
-
+GimpData * gimp_dynamics_get_standard (void);
#endif /* __GIMP_DYNAMICS_OPTIONS_H__ */
diff --git a/app/widgets/gimpdynamicseditor.c b/app/widgets/gimpdynamicseditor.c
index 449b458..1296505 100644
--- a/app/widgets/gimpdynamicseditor.c
+++ b/app/widgets/gimpdynamicseditor.c
@@ -201,8 +201,8 @@ gimp_dynamics_editor_init (GimpDynamicsEditor *editor)
gtk_container_add (GTK_CONTAINER (frame), data_editor->view);
gtk_widget_show (data_editor->view);
+/*
//editor->shape_group = NULL;
- /* table for sliders/labels */
editor->options_vbox = gtk_table_new (4, 3, FALSE);
gtk_table_set_row_spacings (GTK_TABLE (editor->options_vbox), 2);
gtk_table_set_col_spacings (GTK_TABLE (editor->options_vbox), 2);
@@ -214,7 +214,7 @@ gimp_dynamics_editor_init (GimpDynamicsEditor *editor)
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_box_pack_start (GTK_BOX (editor->options_vbox), table, FALSE, FALSE, 0);
gtk_widget_show (table);
-
+*/
/*
g_object_set_data (G_OBJECT (vbox), "set_options", table);
@@ -279,9 +279,9 @@ gimp_dynamics_editor_new (GimpContext *context,
"menu-factory", menu_factory,
"menu-identifier", "<DynamicsEditor>",
"ui-path", "/dynamics-editor-popup",
- "data-factory", context->gimp->brush_factory,
+ "data-factory", context->gimp->dynamics_factory,
"context", context,
- "data", gimp_context_get_brush (context),
+ "data", gimp_context_get_dynamics (context),*/
NULL);
GtkWidget *vbox;
@@ -297,17 +297,6 @@ gimp_dynamics_editor_new (GimpContext *context,
//tool_type = tool_options->tool_info->tool_type;
- /* the main table */
-/*
- return g_object_new (GIMP_TYPE_DYNAMICS_EDITOR,
- "menu-factory", menu_factory,
- "menu-identifier", "<DynamicsEditor>",
- "ui-path", "/dynamics-editor-popup",
- "data-factory", context->gimp->brush_factory,
- "context", context,
- "data", gimp_context_get_brush (context),
- NULL);
-*/
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]