[gimp/soc-2011-gimpunitentry: 28/30] Initial commit of GimpUnitEntryTable
- From: Martin Nordholts <martinn src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/soc-2011-gimpunitentry: 28/30] Initial commit of GimpUnitEntryTable
- Date: Mon, 6 Jun 2011 14:51:14 +0000 (UTC)
commit 090bf26683515cef05da74d591ea66896dcb4159
Author: Enrico SchroÌ?der <enni schroeder gmail com>
Date: Mon Jun 6 16:18:15 2011 +0200
Initial commit of GimpUnitEntryTable
GimpUnitEntryTable provides an interface for conveniently creating common setups of GimpUnitEntries.
libgimpwidgets/Makefile.am | 2 +
libgimpwidgets/gimpunitentry.c | 87 ++++++++++-----
libgimpwidgets/gimpunitentry.h | 15 ++-
libgimpwidgets/gimpunitentrytable.c | 210 +++++++++++++++++++++++++++++++++++
libgimpwidgets/gimpunitentrytable.h | 90 +++++++++++++++
libgimpwidgets/gimpwidgets.h | 1 +
libgimpwidgets/test-unitentry.c | 62 +++--------
7 files changed, 392 insertions(+), 75 deletions(-)
---
diff --git a/libgimpwidgets/Makefile.am b/libgimpwidgets/Makefile.am
index 05e8314..e7836a6 100644
--- a/libgimpwidgets/Makefile.am
+++ b/libgimpwidgets/Makefile.am
@@ -167,6 +167,8 @@ libgimpwidgets_2_0_la_sources = \
gimpunitadjustment.h \
gimpunitentry.c \
gimpunitentry.h \
+ gimpunitentrytable.c \
+ gimpunitentrytable.h \
gimpunitmenu.c \
gimpunitmenu.h \
gimpunitparser.c \
diff --git a/libgimpwidgets/gimpunitentry.c b/libgimpwidgets/gimpunitentry.c
index fe27536..f6d338b 100644
--- a/libgimpwidgets/gimpunitentry.c
+++ b/libgimpwidgets/gimpunitentry.c
@@ -94,9 +94,7 @@ static void on_menu_item (GtkWidget *menuItem,
static void
gimp_unit_entry_init (GimpUnitEntry *unitEntry)
-{
- GimpUnitEntryClass *class = GIMP_UNIT_ENTRY_GET_CLASS (unitEntry);
-
+{
/* create and set our adjustment subclass */
GObject *adjustment = gimp_unit_adjustment_new ();
@@ -130,9 +128,6 @@ gimp_unit_entry_init (GimpUnitEntry *unitEntry)
"populate-popup",
G_CALLBACK(on_populate_popup),
NULL);
-
- unitEntry->id = class->id;
- class->id++;
}
static void
@@ -146,14 +141,16 @@ gimp_unit_entry_class_init (GimpUnitEntryClass *class)
widgetClass->scroll_event = gimp_unit_entry_scroll;
widgetClass->key_press_event = gimp_unit_entry_key_press;
widgetClass->key_release_event = gimp_unit_entry_key_release;
-
- class->id = 0;
}
GtkWidget*
-gimp_unit_entry_new (void)
+gimp_unit_entry_new (const gchar *id)
{
- return g_object_new (GIMP_TYPE_UNIT_ENTRY, NULL);
+ GtkWidget *entry = g_object_new (GIMP_TYPE_UNIT_ENTRY, NULL);
+
+ GIMP_UNIT_ENTRY (entry)->id = id;
+
+ return entry;
}
GimpUnitAdjustment*
@@ -354,9 +351,9 @@ gimp_unit_entry_focus_out (GtkWidget *widget,
return GTK_WIDGET_CLASS (class)->focus_out_event (widget, event);
}
-static
-gint gimp_unit_entry_button_press (GtkWidget *widget,
- GdkEventButton *event)
+static gint
+gimp_unit_entry_button_press (GtkWidget *widget,
+ GdkEventButton *event)
{
GtkSpinButtonClass *class = GTK_SPIN_BUTTON_CLASS (gimp_unit_entry_parent_class);
GimpUnitEntry *entry = GIMP_UNIT_ENTRY (widget);
@@ -366,9 +363,9 @@ gint gimp_unit_entry_button_press (GtkWidget *widget,
return GTK_WIDGET_CLASS(class)->button_press_event (widget, event);
}
-static
-gint gimp_unit_entry_button_release (GtkWidget *widget,
- GdkEventButton *event)
+static gint
+gimp_unit_entry_button_release (GtkWidget *widget,
+ GdkEventButton *event)
{
GtkSpinButtonClass *class = GTK_SPIN_BUTTON_CLASS (gimp_unit_entry_parent_class);
GimpUnitEntry *entry = GIMP_UNIT_ENTRY (widget);
@@ -379,9 +376,9 @@ gint gimp_unit_entry_button_release (GtkWidget *widget,
return GTK_WIDGET_CLASS(class)->button_release_event (widget, event);
}
-static
-gint gimp_unit_entry_scroll (GtkWidget *widget,
- GdkEventScroll *event)
+static gint
+gimp_unit_entry_scroll (GtkWidget *widget,
+ GdkEventScroll *event)
{
GtkSpinButtonClass *class = GTK_SPIN_BUTTON_CLASS (gimp_unit_entry_parent_class);
GimpUnitEntry *entry = GIMP_UNIT_ENTRY (widget);
@@ -391,9 +388,9 @@ gint gimp_unit_entry_scroll (GtkWidget *widget,
return GTK_WIDGET_CLASS(class)->scroll_event (widget, event);
}
-static
-gint gimp_unit_entry_key_press (GtkWidget *widget,
- GdkEventKey *event)
+static gint
+gimp_unit_entry_key_press (GtkWidget *widget,
+ GdkEventKey *event)
{
GtkSpinButtonClass *class = GTK_SPIN_BUTTON_CLASS (gimp_unit_entry_parent_class);
GimpUnitEntry *entry = GIMP_UNIT_ENTRY (widget);
@@ -412,9 +409,9 @@ gint gimp_unit_entry_key_press (GtkWidget *widget,
return GTK_WIDGET_CLASS(class)->key_press_event (widget, event);
}
-static
-gint gimp_unit_entry_key_release (GtkWidget *widget,
- GdkEventKey *event)
+static gint
+gimp_unit_entry_key_release (GtkWidget *widget,
+ GdkEventKey *event)
{
GtkSpinButtonClass *class = GTK_SPIN_BUTTON_CLASS (gimp_unit_entry_parent_class);
GimpUnitEntry *entry = GIMP_UNIT_ENTRY (widget);
@@ -432,4 +429,42 @@ gint gimp_unit_entry_key_release (GtkWidget *widget,
}
return GTK_WIDGET_CLASS(class)->key_release_event (widget, event);
-}
\ No newline at end of file
+}
+
+/* convenience getters/setters */
+const gchar*
+gimp_unit_entry_get_id (GimpUnitEntry *entry)
+{
+ return entry->id;
+}
+
+void
+gimp_unit_entry_set_unit (GimpUnitEntry *entry, GimpUnit unit)
+{
+ GimpUnitAdjustment *adj = gimp_unit_entry_get_adjustment (entry);
+ gimp_unit_adjustment_set_unit (adj, unit);
+}
+void
+gimp_unit_entry_set_resolution (GimpUnitEntry *entry, gdouble resolution)
+{
+ GimpUnitAdjustment *adj = gimp_unit_entry_get_adjustment (entry);
+ gimp_unit_adjustment_set_resolution (adj, resolution);
+}
+void
+gimp_unit_entry_set_value (GimpUnitEntry *entry, gdouble value)
+{
+ GimpUnitAdjustment *adj = gimp_unit_entry_get_adjustment (entry);
+ gimp_unit_adjustment_set_value (adj, value);
+}
+gdouble
+gimp_unit_entry_get_value (GimpUnitEntry *entry)
+{
+ GimpUnitAdjustment *adj = gimp_unit_entry_get_adjustment (entry);
+ return gimp_unit_adjustment_get_value (adj);
+}
+gdouble
+gimp_unit_entry_get_value_in_unit (GimpUnitEntry *entry, GimpUnit unit)
+{
+ GimpUnitAdjustment *adj = gimp_unit_entry_get_adjustment (entry);
+ return gimp_unit_adjustment_get_value_in_unit (adj, unit);
+}
diff --git a/libgimpwidgets/gimpunitentry.h b/libgimpwidgets/gimpunitentry.h
index 80a7713..00ab53e 100644
--- a/libgimpwidgets/gimpunitentry.h
+++ b/libgimpwidgets/gimpunitentry.h
@@ -22,6 +22,8 @@
#ifndef __GIMP_UNIT_ENTRY_H__
#define __GIMP_UNIT_ENTRY_H__
+#include <gtk/gtkspinbutton.h>
+
#include "gimpunitadjustment.h"
G_BEGIN_DECLS
@@ -51,24 +53,29 @@ struct _GimpUnitEntry
gboolean buttonPressed;
gboolean scrolling;
- gint id; /* for debugging */
+ const gchar *id; /* identifier string of unit entry (used by GimpUnitEntryTable) */
};
struct _GimpUnitEntryClass
{
GtkSpinButtonClass parent_class;
-
- gint id; /* for debugging */
};
/**
* prototypes
**/
GType gimp_unit_entry_get_type (void);
-GtkWidget *gimp_unit_entry_new (void);
+GtkWidget *gimp_unit_entry_new (const gchar *id);
GimpUnitAdjustment *gimp_unit_entry_get_adjustment (GimpUnitEntry *entry);
/* connect to another entry */
void gimp_unit_entry_connect (GimpUnitEntry *entry, GimpUnitEntry *target);
+/* convenience getters/setters */
+const gchar* gimp_unit_entry_get_id (GimpUnitEntry *entry);
+void gimp_unit_entry_set_unit (GimpUnitEntry *entry, GimpUnit unit);
+void gimp_unit_entry_set_resolution (GimpUnitEntry *entry, gdouble resolution);
+void gimp_unit_entry_set_value (GimpUnitEntry *entry, gdouble resolution);
+gdouble gimp_unit_entry_get_value (GimpUnitEntry *entry);
+gdouble gimp_unit_entry_get_value_in_unit (GimpUnitEntry *entry, GimpUnit unit);
G_END_DECLS
diff --git a/libgimpwidgets/gimpunitentrytable.c b/libgimpwidgets/gimpunitentrytable.c
new file mode 100644
index 0000000..7ff5a8c
--- /dev/null
+++ b/libgimpwidgets/gimpunitentrytable.c
@@ -0,0 +1,210 @@
+/* LIBGIMP - The GIMP Library
+ * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
+ *
+ * gimpunitentrytable.c
+ * Copyright (C) 2011 Enrico Schröder <enni schroeder gmail com>
+ *
+ * This library is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "gimpunitentrytable.h"
+
+#include <gtk/gtklabel.h>
+#include <glib/gprintf.h>
+
+/* debug macro */
+//#define UNITENTRY_DEBUG
+#ifdef UNITENTRY_DEBUG
+#define DEBUG(x) g_debug x
+#else
+#define DEBUG(x) /* nothing */
+#endif
+
+#define DEFAULT_TABLE_SIZE_X 3
+#define DEFAULT_TABLE_SIZE_Y 3
+
+G_DEFINE_TYPE (GimpUnitEntryTable, gimp_unit_entry_table, G_TYPE_OBJECT);
+
+/**
+ * signal handler
+ **/
+static void label_updater (GtkAdjustment *adj, gpointer userData);
+
+static void
+gimp_unit_entry_table_init (GimpUnitEntryTable *table)
+{
+ /* initialize our fields */
+ table->table = gtk_table_new (DEFAULT_TABLE_SIZE_X, DEFAULT_TABLE_SIZE_Y, FALSE);
+ table->entries = NULL;
+ table->previewLabel = NULL;
+}
+
+static void
+gimp_unit_entry_table_class_init (GimpUnitEntryTableClass *class)
+{
+}
+
+GObject*
+gimp_unit_entry_table_new (void)
+{
+ GObject *table;
+
+ table = g_object_new (GIMP_TYPE_UNIT_ENTRY_TABLE, NULL);
+
+ return table;
+}
+
+/* add an UnitEntry */
+/* TODO: have options for default and custom layout */
+GtkWidget*
+gimp_unit_entry_table_add_entry (GimpUnitEntryTable *table,
+ const gchar *id,
+ const gchar *labelStr)
+{
+ GimpUnitEntry *entry = GIMP_UNIT_ENTRY (gimp_unit_entry_new (id)) , *entry2;
+ gint count = g_list_length (table->entries);
+ GtkWidget *label;
+ int i;
+
+ /* add entry to table at position (1, count) */
+ gtk_table_attach_defaults (GTK_TABLE (table->table),
+ GTK_WIDGET (entry),
+ 1, 2, count, count + 1);
+
+ /* if label is given, create label and attach to the left of entry */
+ if (labelStr != NULL)
+ {
+ label = gtk_label_new (labelStr);
+ gtk_table_attach (GTK_TABLE (table->table),
+ label,
+ 0, 1, count, count + 1,
+ GTK_SHRINK, GTK_EXPAND | GTK_FILL,
+ 10, 0);
+ }
+
+ /* connect entry to others */
+ for (i = 0; i < count; i++)
+ {
+ entry2 = gimp_unit_entry_table_get_nth_entry (table, i);
+ gimp_unit_entry_connect (GIMP_UNIT_ENTRY (entry), GIMP_UNIT_ENTRY (entry2));
+ gimp_unit_entry_connect (GIMP_UNIT_ENTRY (entry2), GIMP_UNIT_ENTRY (entry));
+ }
+
+ gtk_widget_show_all (table->table);
+
+ table->entries = g_list_append (table->entries, (gpointer) entry);
+
+ return GTK_WIDGET (entry);
+}
+
+/* add preview label showing the current value in given unit */
+/** TODO: The whole label thing is subject to change.
+ * Just a quick'n dirty solution for now
+ **/
+void
+gimp_unit_entry_table_add_label (GimpUnitEntryTable *table, GimpUnit unit)
+{
+ GtkWidget *label = gtk_label_new("preview");
+ gint count = g_list_length (table->entries);
+ gint i;
+ GimpUnitEntry *entry;
+
+ /* save unit */
+ table->previewUnit = unit;
+
+ /* add label below unit entries */
+ gtk_table_attach (GTK_TABLE (table->table),
+ label,
+ 1, 2,
+ count, count+1,
+ GTK_SHRINK, GTK_EXPAND | GTK_FILL,
+ 10, 0);
+
+ table->previewLabel = GTK_LABEL (label);
+ gtk_widget_show (GTK_WIDGET (table->previewLabel));
+
+ /* connect label updater to changed signal */
+ for (i = 0; i < count; i++)
+ {
+ entry = gimp_unit_entry_table_get_nth_entry (table, i);
+ g_signal_connect (G_OBJECT (gimp_unit_entry_get_adjustment (entry)), "value-changed",
+ G_CALLBACK (label_updater), (gpointer) table);
+ }
+
+ label_updater (NULL, (gpointer) table);
+}
+
+/* get UnitEntry by label */
+GimpUnitEntry*
+gimp_unit_entry_table_get_entry (GimpUnitEntryTable *table,
+ const gchar *id)
+{
+ GimpUnitEntry *entry;
+ gint i, count = g_list_length (table->entries);
+
+ /* iterate over list to find our entry */
+ for (i = 0; i < count; i++)
+ {
+ entry = gimp_unit_entry_table_get_nth_entry (table, i);
+ if (g_strcmp0 (gimp_unit_entry_get_id (entry), id) == 0)
+ return entry;
+ }
+ g_warning ("gimp_unit_entry_table_get_entry: entry with id '%s' does not exist", id);
+ return NULL;
+}
+
+/* get UnitEntry by index */
+GimpUnitEntry*
+gimp_unit_entry_table_get_nth_entry (GimpUnitEntryTable *table,
+ gint index)
+{
+ if (g_list_length (table->entries) <= index)
+ {
+ return NULL;
+ }
+
+ return GIMP_UNIT_ENTRY (g_list_nth (table->entries, index)->data);
+}
+
+/* updates the text of the preview label */
+/** TODO: The whole label thing is subject to change.
+ * Just a quick'n dirty solution for now
+ **/
+static
+void label_updater (GtkAdjustment *adj, gpointer userData)
+{
+ gchar str[40];
+ GimpUnitEntryTable *table = GIMP_UNIT_ENTRY_TABLE (userData);
+ GimpUnitAdjustment *adjustment;
+ gint count = g_list_length (table->entries);
+ gint i = 0;
+ GimpUnit *unit;
+
+ if (table->previewLabel == NULL || count <= 0)
+ return;
+
+ adjustment = gimp_unit_entry_get_adjustment (gimp_unit_entry_table_get_nth_entry (table, 0));
+ g_sprintf (str, "%s", gimp_unit_adjustment_to_string_in_unit (adjustment, table->previewUnit));
+
+ for (i = 1; i < count; i++)
+ {
+ adjustment = gimp_unit_entry_get_adjustment (gimp_unit_entry_table_get_nth_entry (table, i));
+ g_sprintf (str, "%s x %s ", str, gimp_unit_adjustment_to_string_in_unit (adjustment, table->previewUnit));
+ }
+
+ gtk_label_set_text (table->previewLabel, str);
+}
diff --git a/libgimpwidgets/gimpunitentrytable.h b/libgimpwidgets/gimpunitentrytable.h
new file mode 100644
index 0000000..f4f2abc
--- /dev/null
+++ b/libgimpwidgets/gimpunitentrytable.h
@@ -0,0 +1,90 @@
+/* LIBGIMP - The GIMP Library
+ * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
+ *
+ * gimpunitentrytable.h
+ * Copyright (C) 2011 Enrico Schröder <enni schroeder gmail com>
+ *
+ * This library is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_UNIT_ENTRY_TABLE_H__
+#define __GIMP_UNIT_ENTRY_TABLE_H__
+
+#include <stdarg.h>
+
+#include <gtk/gtktable.h>
+#include <gtk/gtklabel.h>
+#include <glib.h>
+
+#include "gimpunitentry.h"
+
+G_BEGIN_DECLS
+
+/**
+ * boiler-plate
+ **/
+#define GIMP_TYPE_UNIT_ENTRY_TABLE (gimp_unit_entry_table_get_type ())
+#define GIMP_UNIT_ENTRY_TABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_UNIT_ENTRY_TABLE, GimpUnitEntryTable))
+#define GIMP_UNIT_ENTRY_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_UNIT_ENTRY_TABLE, GimpUnitEntryTableClass))
+#define GIMP_IS_UNIT_ENTRY_TABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, GIMP_TYPE_UNIT_ENTRY_TABLE))
+#define GIMP_IS_UNIT_ENTRY_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_UNIT_ENTRY_TABLE))
+#define GIMP_UNIT_ENTRY_TABLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_UNIT_ENTRY_TABLE, GimpUnitEntryTableClass))
+
+typedef struct _GimpUnitEntryTable GimpUnitEntryTable;
+typedef struct _GimpUnitEntryTableClass GimpUnitEntryTableClass;
+
+/* enum for standard 'set-ups' */
+typedef enum
+{
+ GIMP_UNIT_ENTRY_TABLE_EMPTY, /* empty table */
+ GIMP_UNIT_ENTRY_TABLE_DEFAULT, /* just two entries */
+ GIMP_UNIT_ENTRY_TABLE_DEFAULT_WITH_PREVIEW /* ... with label showing value */
+} GimpUnitEntryTableSetup;
+
+struct _GimpUnitEntryTable
+{
+ GObject parent_instance;
+
+ /* private */
+ GtkWidget *table;
+ GList *entries; /* list of entries */
+ GtkLabel *previewLabel; /* (optional) preview label automatically showing value */
+ GimpUnit previewUnit; /* unit in which the preview is shown */
+};
+
+struct _GimpUnitEntryTableClass
+{
+ GObjectClass parent_class;
+};
+
+/**
+ * prototypes
+ **/
+GType gimp_unit_entry_table_get_type (void);
+GObject *gimp_unit_entry_table_new (void);
+
+/* add UnitEntry */
+GtkWidget* gimp_unit_entry_table_add_entry (GimpUnitEntryTable *table, const gchar* id, const gchar *label);
+//void gimp_unit_entry_table_add_entries ()
+/* add preview label showing the current value in given unit */
+void gimp_unit_entry_table_add_label (GimpUnitEntryTable *table, GimpUnit unit);
+/* get UnitEntry by id */
+GimpUnitEntry* gimp_unit_entry_table_get_entry (GimpUnitEntryTable *table, const gchar* id);
+/* get UnitEntry by index */
+GimpUnitEntry* gimp_unit_entry_table_get_nth_entry (GimpUnitEntryTable *table, gint index);
+
+G_END_DECLS
+
+#endif /*__GIMP_UNIT_ENTRY_TABLE_H__*/
\ No newline at end of file
diff --git a/libgimpwidgets/gimpwidgets.h b/libgimpwidgets/gimpwidgets.h
index 51d5eb8..9a47b09 100644
--- a/libgimpwidgets/gimpwidgets.h
+++ b/libgimpwidgets/gimpwidgets.h
@@ -74,6 +74,7 @@
#include <libgimpwidgets/gimpstock.h>
#include <libgimpwidgets/gimpstringcombobox.h>
#include <libgimpwidgets/gimpunitcombobox.h>
+#include <libgimpwidgets/gimpunitentrytable.h>
#include <libgimpwidgets/gimpunitmenu.h>
#include <libgimpwidgets/gimpunitstore.h>
#include <libgimpwidgets/gimpwidgets-error.h>
diff --git a/libgimpwidgets/test-unitentry.c b/libgimpwidgets/test-unitentry.c
index 2f62317..030648a 100644
--- a/libgimpwidgets/test-unitentry.c
+++ b/libgimpwidgets/test-unitentry.c
@@ -6,42 +6,25 @@
#include <glib-object.h>
#include <glib/gprintf.h>
#include <gtk/gtk.h>
+#include "libgimpbase/gimpbase.h"
#include "devel-docs/tools/units.h"
-#include "gimpunitentry.h"
+#include "gimpunitentrytable.h"
/* global objects */
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *valign;
-GtkWidget *inLabel;
-GtkWidget *pxLabel;
-GtkWidget *entry1;
-GtkWidget *entry2;
-
-void on_value_changed (GtkAdjustment *adj, gpointer userData)
-{
- gchar text[40];
- gchar *val1 = gimp_unit_adjustment_to_string_in_unit (GIMP_UNIT_ENTRY (entry1)->unitAdjustment, GIMP_UNIT_INCH);
- gchar *val2 = gimp_unit_adjustment_to_string_in_unit (GIMP_UNIT_ENTRY (entry2)->unitAdjustment, GIMP_UNIT_INCH);
- g_sprintf (text, "%s x %s", val1, val2);
- gtk_label_set_text (GTK_LABEL(inLabel), text);
-
- val1 = gimp_unit_adjustment_to_string_in_unit (GIMP_UNIT_ENTRY (entry1)->unitAdjustment, GIMP_UNIT_PIXEL);
- val2 = gimp_unit_adjustment_to_string_in_unit (GIMP_UNIT_ENTRY (entry2)->unitAdjustment, GIMP_UNIT_PIXEL);
- g_sprintf (text, "%s x %s", val1, val2);
- gtk_label_set_text (GTK_LABEL(pxLabel), text);
-
- g_free (val1);
- g_free (val2);
-}
+GimpUnitEntryTable *entryTable;
/* set up interface */
void
create_interface(void)
{
+ GimpUnitEntry *a, *b;
+
/* main window */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
@@ -56,35 +39,24 @@ create_interface(void)
gtk_container_add (GTK_CONTAINER (valign), vbox);
gtk_container_add (GTK_CONTAINER (window), valign);
- /* the entries */
- entry1 = gimp_unit_entry_new ();
- entry2 = gimp_unit_entry_new ();
+ /* entry table */
+ entryTable = GIMP_UNIT_ENTRY_TABLE (gimp_unit_entry_table_new ());
+ gimp_unit_entry_table_add_entry (entryTable, "width", "Width");
+ gimp_unit_entry_table_add_entry (entryTable, "height", "Height");
+ gimp_unit_entry_table_add_label (entryTable, GIMP_UNIT_PIXEL);
- gtk_box_pack_start (GTK_BOX (vbox), entry1, TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (vbox), entry2, TRUE, TRUE, 0);
+ /* set some default values */
+ a = gimp_unit_entry_table_get_entry (entryTable, 0);
+ b = gimp_unit_entry_table_get_entry (entryTable, 1);
+ gimp_unit_adjustment_set_value (gimp_unit_entry_get_adjustment (a), 20);
+ gimp_unit_adjustment_set_value (gimp_unit_entry_get_adjustment (b), 20);
- gimp_unit_entry_connect (GIMP_UNIT_ENTRY (entry1), GIMP_UNIT_ENTRY (entry2));
- gimp_unit_entry_connect (GIMP_UNIT_ENTRY (entry2), GIMP_UNIT_ENTRY (entry1));
-
- gimp_unit_adjustment_set_value (gimp_unit_entry_get_adjustment (GIMP_UNIT_ENTRY (entry1)), 20);
- gimp_unit_adjustment_set_value (gimp_unit_entry_get_adjustment (GIMP_UNIT_ENTRY (entry2)), 20);
-
- /* status label */
- inLabel = gtk_label_new ("inches");
- pxLabel = gtk_label_new ("pixels");
- gtk_box_pack_end (GTK_BOX (vbox), pxLabel, TRUE, TRUE, 0);
- gtk_box_pack_end (GTK_BOX (vbox), inLabel, TRUE, TRUE, 0);
-
- on_value_changed (NULL, NULL);
+ gtk_box_pack_start (GTK_BOX (vbox), entryTable->table, TRUE, TRUE, 0);
/* signals */
g_signal_connect_swapped (G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);
- g_signal_connect (G_OBJECT (GIMP_UNIT_ENTRY (entry1)->unitAdjustment), "value-changed",
- G_CALLBACK (on_value_changed), NULL);
- g_signal_connect (G_OBJECT (GIMP_UNIT_ENTRY (entry2)->unitAdjustment), "value-changed",
- G_CALLBACK (on_value_changed), NULL);
-
+
gtk_widget_show_all (window);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]