libgimpbase/Makefile.am libgimpbase/gimpbase.h libgimpbase/gimpbase.def
2004-07-27 Sven Neumann <sven@gimp.org> * libgimpbase/Makefile.am * libgimpbase/gimpbase.h * libgimpbase/gimpbase.def * libgimpbase/gimpmemsize.[ch]: added new files with memsize related functions (moved here from gimputil.c) and GIMP_TYPE_MEMSIZE (moved here from app/config/gimpconfig-types.[ch]). * libgimpbase/gimputils.[ch]: removed gimp_memsize_to_string() here. * libgimpbase/gimpunit.[ch]: added GIMP_TYPE_UNIT (moved here from app/config/gimpconfig-types.[ch]). * libgimpbase/gimpbase-private.c * libgimp/gimptile.c * libgimp/gimpunitcache.c * plug-ins/help/domain.c * app/xcf/xcf-read.c: need to include glib-object.h. * plug-ins/common/uniteditor.c: use GIMP_TYPE_UNIT. * app/config/gimpconfig-types.[ch]: removed code that lives in libgimpbase now. * app/config/gimpconfig-deserialize.c: changed accordingly. * app/config/gimpbaseconfig.c * app/config/gimpdisplayconfig.c * app/core/gimpcontext.c * app/gui/grid-dialog.c * app/tools/gimpcolortool.c * app/widgets/gimpaction.c * app/widgets/gimpunitstore.c: no need to include gimpconfig-types.h any longer.
This commit is contained in:

committed by
Sven Neumann

parent
ed3f8fd1bc
commit
bd427b2e4d
@ -22,7 +22,9 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "gimpbasetypes.h"
|
||||
|
||||
@ -30,6 +32,76 @@
|
||||
#include "gimpunit.h"
|
||||
|
||||
|
||||
static void unit_to_string (const GValue *src_value,
|
||||
GValue *dest_value);
|
||||
static void string_to_unit (const GValue *src_value,
|
||||
GValue *dest_value);
|
||||
|
||||
GType
|
||||
gimp_unit_get_type (void)
|
||||
{
|
||||
static GType unit_type = 0;
|
||||
|
||||
if (!unit_type)
|
||||
{
|
||||
static const GTypeInfo type_info = { 0, };
|
||||
|
||||
unit_type = g_type_register_static (G_TYPE_INT, "GimpUnit",
|
||||
&type_info, 0);
|
||||
|
||||
g_value_register_transform_func (unit_type, G_TYPE_STRING,
|
||||
unit_to_string);
|
||||
g_value_register_transform_func (G_TYPE_STRING, unit_type,
|
||||
string_to_unit);
|
||||
}
|
||||
|
||||
return unit_type;
|
||||
}
|
||||
|
||||
static void
|
||||
unit_to_string (const GValue *src_value,
|
||||
GValue *dest_value)
|
||||
{
|
||||
GimpUnit unit = (GimpUnit) g_value_get_int (src_value);
|
||||
|
||||
g_value_set_string (dest_value, gimp_unit_get_identifier (unit));
|
||||
}
|
||||
|
||||
static void
|
||||
string_to_unit (const GValue *src_value,
|
||||
GValue *dest_value)
|
||||
{
|
||||
const gchar *str;
|
||||
gint num_units;
|
||||
gint i;
|
||||
|
||||
str = g_value_get_string (src_value);
|
||||
|
||||
if (!str || !*str)
|
||||
goto error;
|
||||
|
||||
num_units = gimp_unit_get_number_of_units ();
|
||||
|
||||
for (i = GIMP_UNIT_PIXEL; i < num_units; i++)
|
||||
if (strcmp (str, gimp_unit_get_identifier (i)) == 0)
|
||||
break;
|
||||
|
||||
if (i == num_units)
|
||||
{
|
||||
if (strcmp (str, gimp_unit_get_identifier (GIMP_UNIT_PERCENT)) == 0)
|
||||
i = GIMP_UNIT_PERCENT;
|
||||
else
|
||||
goto error;
|
||||
}
|
||||
|
||||
g_value_set_int (dest_value, i);
|
||||
return;
|
||||
|
||||
error:
|
||||
g_warning ("Can't convert string to GimpUnit.");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* gimp_unit_get_number_of_units:
|
||||
*
|
||||
|
Reference in New Issue
Block a user