diff --git a/devel-docs/ChangeLog b/devel-docs/ChangeLog index 6890af5674..f9c31b757a 100644 --- a/devel-docs/ChangeLog +++ b/devel-docs/ChangeLog @@ -1,3 +1,11 @@ +2005-04-28 Sven Neumann + + * tools/Makefile.am + * tools/units.[ch]: added a very basic GimpUnit implementation. + + * tools/shooter.c + * tools/widgets.c: initialize the units and enable GimpUnitMenu. + 2005-04-23 Sven Neumann * tools/shooter.c: read the GIMP gtkrc file. diff --git a/devel-docs/tools/Makefile.am b/devel-docs/tools/Makefile.am index e39d835636..6679571e9d 100644 --- a/devel-docs/tools/Makefile.am +++ b/devel-docs/tools/Makefile.am @@ -27,6 +27,8 @@ doc_shooter_SOURCES = \ shadow.c \ shadow.h \ shooter.c \ + units.c \ + units.h \ widgets.c \ widgets.h diff --git a/devel-docs/tools/shooter.c b/devel-docs/tools/shooter.c index 58abc7505c..0f7182de5a 100644 --- a/devel-docs/tools/shooter.c +++ b/devel-docs/tools/shooter.c @@ -18,8 +18,9 @@ #include "libgimpwidgets/gimpwidgets.h" #include "libgimpwidgets/gimpwidgets-private.h" -#include "widgets.h" #include "shadow.h" +#include "units.h" +#include "widgets.h" static Window @@ -245,12 +246,13 @@ main (int argc, char **argv) gtk_rc_add_default_file (gimp_gtkrc ()); + units_init (); + gimp_widgets_init (shooter_standard_help, shooter_get_foreground, shooter_get_background, shooter_ensure_modules); - toplevels = get_all_widgets (); for (node = toplevels; node; node = g_list_next (node)) diff --git a/devel-docs/tools/units.c b/devel-docs/tools/units.c new file mode 100644 index 0000000000..42c0af7ab5 --- /dev/null +++ b/devel-docs/tools/units.c @@ -0,0 +1,102 @@ + +#include "config.h" + +#include + +#include "libgimpbase/gimpbase.h" +#include "libgimpbase/gimpbase-private.h" + +#include "units.h" + + +typedef struct +{ + gdouble factor; + gint digits; + const gchar *identifier; + const gchar *symbol; + const gchar *abbreviation; + const gchar *singular; + const gchar *plural; +} GimpUnitDef; + +static const GimpUnitDef unit_defs[] = +{ + { 0.0, 0, "pixels", "px", "px", "pixel", "pixels" }, + { 1.0, 2, "inches", "''", "in", "inch", "inches" }, + { 25.4, 1, "millimeters", "mm", "mm", "millimeter", "millimeters" } +}; + + +static gint +units_get_number_of_units (void) +{ + return G_N_ELEMENTS (unit_defs); +} + +static gint +units_get_number_of_built_in_units (void) +{ + return G_N_ELEMENTS (unit_defs); +} + +static gdouble +units_unit_get_factor (GimpUnit unit) +{ + return unit_defs[unit].factor; +} + +static gint +units_unit_get_digits (GimpUnit unit) +{ + return unit_defs[unit].digits; +} + +static const gchar * +units_unit_get_identifier (GimpUnit unit) +{ + return unit_defs[unit].identifier; +} + +static const gchar * +units_unit_get_symbol (GimpUnit unit) +{ + return unit_defs[unit].symbol; +} + +static const gchar * +units_unit_get_abbreviation (GimpUnit unit) +{ + return unit_defs[unit].abbreviation; +} + +static const gchar * +units_unit_get_singular (GimpUnit unit) +{ + return unit_defs[unit].singular; +} + +static const gchar * +units_unit_get_plural (GimpUnit unit) +{ + return unit_defs[unit].plural; +} + +void +units_init (void) +{ + GimpUnitVTable vtable; + + vtable.unit_get_number_of_units = units_get_number_of_units; + vtable.unit_get_number_of_built_in_units = units_get_number_of_built_in_units; + vtable.unit_new = NULL; + vtable.unit_get_factor = units_unit_get_factor; + vtable.unit_get_digits = units_unit_get_digits; + vtable.unit_get_identifier = units_unit_get_identifier; + vtable.unit_get_symbol = units_unit_get_symbol; + vtable.unit_get_abbreviation = units_unit_get_abbreviation; + vtable.unit_get_singular = units_unit_get_singular; + vtable.unit_get_plural = units_unit_get_plural; + + gimp_base_init (&vtable); +} diff --git a/devel-docs/tools/units.h b/devel-docs/tools/units.h new file mode 100644 index 0000000000..8875e8acd2 --- /dev/null +++ b/devel-docs/tools/units.h @@ -0,0 +1,8 @@ +#ifndef __UNITS_H__ +#define __UNITS_H__ + + +void units_init (void); + + +#endif /* __UNITS_H__ */ diff --git a/devel-docs/tools/widgets.c b/devel-docs/tools/widgets.c index de1bff4193..630f53fde5 100644 --- a/devel-docs/tools/widgets.c +++ b/devel-docs/tools/widgets.c @@ -567,8 +567,7 @@ create_unit_menu (void) vbox = gtk_vbox_new (FALSE, 6); align = gtk_alignment_new (0.5, 0.5, 0.5, 0.0); - menu = gimp_unit_menu_new ("%a - %y (%f\"", GIMP_UNIT_POINT, - TRUE, TRUE, TRUE); + menu = gimp_unit_menu_new ("%p", GIMP_UNIT_MM, TRUE, FALSE, FALSE); gtk_container_add (GTK_CONTAINER (align), menu); gtk_box_pack_start (GTK_BOX (vbox), align, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), @@ -600,11 +599,7 @@ get_all_widgets (void) retval = g_list_append (retval, create_path_editor ()); retval = g_list_append (retval, create_pick_button ()); retval = g_list_append (retval, create_preview_area ()); - - /* - * The following doesn't work, we should init the unit system before. - * retval = g_list_append (retval, create_unit_menu ()); - */ + retval = g_list_append (retval, create_unit_menu ()); return retval; }