tools/Makefile.am added a very basic GimpUnit implementation.

2005-04-28  Sven Neumann  <sven@gimp.org>

	* tools/Makefile.am
	* tools/units.[ch]: added a very basic GimpUnit implementation.

	* tools/shooter.c
	* tools/widgets.c: initialize the units and enable GimpUnitMenu.
This commit is contained in:
Sven Neumann 2005-04-28 14:22:25 +00:00 committed by Sven Neumann
parent 998ea546cd
commit dde381c190
6 changed files with 126 additions and 9 deletions

View File

@ -1,3 +1,11 @@
2005-04-28 Sven Neumann <sven@gimp.org>
* 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 <sven@gimp.org>
* tools/shooter.c: read the GIMP gtkrc file.

View File

@ -27,6 +27,8 @@ doc_shooter_SOURCES = \
shadow.c \
shadow.h \
shooter.c \
units.c \
units.h \
widgets.c \
widgets.h

View File

@ -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))

102
devel-docs/tools/units.c Normal file
View File

@ -0,0 +1,102 @@
#include "config.h"
#include <glib-object.h>
#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);
}

8
devel-docs/tools/units.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef __UNITS_H__
#define __UNITS_H__
void units_init (void);
#endif /* __UNITS_H__ */

View File

@ -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;
}