Commit 390ef444 authored by Michael Natterer's avatar Michael Natterer

pdb, libgimp: allow to use external GType-registered enums in the PDB

The enums have to be menually registered in pdb/enums-external.pl.
Currently supports enums from GEGL only.

Add enum GeglDistanceMetric as first external enum.
parent c3ef34b4
......@@ -445,7 +445,7 @@ CLEANFILES = $(gen_sources)
gimpenums.c: $(srcdir)/gimpenums.h $(srcdir)/gimpenums.c.tail $(GIMP_MKENUMS) Makefile.am
$(AM_V_GEN) $(GIMP_MKENUMS) \
--fhead "#include \"config.h\"\n#include <gio/gio.h>\n#undef GIMP_DISABLE_DEPRECATED\n#include \"libgimpbase/gimpbase.h\"\n#include \"libgimpbase/gimpbase-private.h\"\n#include \"libgimpconfig/gimpconfigenums.h\"\n#include \"gimpenums.h\"" \
--fhead "#include \"config.h\"\n#include <gio/gio.h>\n#include <gegl.h>\n#undef GIMP_DISABLE_DEPRECATED\n#include \"libgimpbase/gimpbase.h\"\n#include \"libgimpbase/gimpbase-private.h\"\n#include \"libgimpconfig/gimpconfigenums.h\"\n#include \"gimpenums.h\"" \
--fprod "\n/* enumerations from \"@filename@\" */" \
--vhead "GType\n@enum_name@_get_type (void)\n{\n static const G@Type@Value values[] =\n {" \
--vprod " { @VALUENAME@, \"@VALUENAME@\", \"@valuenick@\" }," \
......
......@@ -3,6 +3,7 @@ typedef GType (* GimpGetTypeFunc) (void);
static const GimpGetTypeFunc get_type_funcs[] =
{
gegl_distance_metric_get_type,
gimp_add_mask_type_get_type,
gimp_blend_mode_get_type,
gimp_brush_application_mode_get_type,
......@@ -69,6 +70,7 @@ static const GimpGetTypeFunc get_type_funcs[] =
static const gchar * const type_names[] =
{
"GeglDistanceMetric",
"GimpAddMaskType",
"GimpBlendMode",
"GimpBrushApplicationMode",
......
......@@ -66,6 +66,7 @@ EXTRA_DIST = \
enumcode.pl \
enumgen.pl \
enums.pl \
enums-external.pl \
groups.pl \
lib.pl \
pdb.pl \
......@@ -112,7 +113,7 @@ DISTCLEANFILES = $(stamp_files)
$(srcdir)/enums.pl: stamp-enums
@:
stamp-enums: $(srcdir)/enumgen.pl $(enum_headers) Makefile.am
stamp-enums: $(srcdir)/enumgen.pl $(enum_headers) enums-external.pl Makefile.am
rootme=`pwd`; \
destdir=`cd $(top_srcdir) && pwd`; export destdir; \
builddir=`cd $(top_builddir) && pwd`; export builddir; \
......
......@@ -68,7 +68,8 @@ G_BEGIN_DECLS
HEADER
foreach (sort keys %enums) {
if (! ($enums{$_}->{header} =~ /libgimp/)) {
if (! ($enums{$_}->{header} =~ /libgimp/) &&
! $enums{$_}->{external}) {
my $gtype = $func = $_;
for ($gtype) { s/Gimp//; s/([A-Z][^A-Z]+)/\U$1\E_/g; s/_$// }
......@@ -125,11 +126,18 @@ foreach (sort keys %enums) {
if (! ($_ =~ /GimpUnit/)) {
my $enum = $enums{$_};
my $func = $_;
my $gegl_enum = ($func =~ /Gegl/);
for ($func) { s/Gimp//; s/PDB/Pdb/; s/([A-Z][^A-Z]+)/\L$1\E_/g; s/_$// }
for ($func) { s/Gimp//; s/Gegl//; s/PDB/Pdb/;
s/([A-Z][^A-Z]+)/\L$1\E_/g; s/_$// }
print ENUMFILE ",\n" unless $first;
print ENUMFILE " gimp_$func\_get_type";
if ($gegl_enum) {
print ENUMFILE " gegl_$func\_get_type";
} else {
print ENUMFILE " gimp_$func\_get_type";
}
$first = 0;
}
......
......@@ -57,6 +57,14 @@ my $header = <<'HEADER';
:%enums = (
HEADER
my $external;
open my $EXTERNAL, "enums-external.pl";
{
local $/;
$external = <$EXTERNAL>;
}
close $EXTERNAL;
my $footer = <<'FOOTER';
:);
:
......@@ -255,6 +263,6 @@ foreach ($header, $code, $footer) { s/^://mg }
$outfile = "$builddir/pdb/enums.pl$FILE_EXT";
open OUTFILE, "> $outfile";
print OUTFILE $header, $code, $footer;
print OUTFILE $header, $external, $code, $footer;
close OUTFILE;
&write_file($outfile, "$destdir/pdb");
GeglDistanceMetric =>
{ contig => 1,
external => 1,
symbols => [ qw(GEGL_DISTANCE_METRIC_EUCLIDEAN
GEGL_DISTANCE_METRIC_MANHATTAN
GEGL_DISTANCE_METRIC_CHEBYSHEV) ],
mapping => { GEGL_DISTANCE_METRIC_EUCLIDEAN => '0',
GEGL_DISTANCE_METRIC_MANHATTAN => '1',
GEGL_DISTANCE_METRIC_CHEBYSHEV => '2' }
},
......@@ -19,6 +19,16 @@
package Gimp::CodeGen::enums;
%enums = (
GeglDistanceMetric =>
{ contig => 1,
external => 1,
symbols => [ qw(GEGL_DISTANCE_METRIC_EUCLIDEAN
GEGL_DISTANCE_METRIC_MANHATTAN
GEGL_DISTANCE_METRIC_CHEBYSHEV) ],
mapping => { GEGL_DISTANCE_METRIC_EUCLIDEAN => '0',
GEGL_DISTANCE_METRIC_MANHATTAN => '1',
GEGL_DISTANCE_METRIC_CHEBYSHEV => '2' }
},
GimpAddMaskType =>
{ contig => 1,
header => 'libgimpbase/gimpbaseenums.h',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment