From f12cdd7284a3d144b17c25e271d1edf701692ece Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 27 Dec 2006 15:10:59 +0000 Subject: [PATCH] Support for run-time icons in the GTK puzzles. This involved another mkfiles.pl change (I don't seem to be planning ahead very well this week), this time to provide a list of fallback options for an object file. That way, I have a no-icon.c which quietly replaces icons/foo-icon.c if the latter doesn't exist, and so again people checking straight out from Subversion shouldn't have trouble. git-svn-id: svn://svn.tartarus.org/sgt/puzzles@7021 cda61777-01e9-0310-a592-d414129be87e --- blackbox.R | 2 +- bridges.R | 2 +- cube.R | 2 +- dominosa.R | 2 +- fifteen.R | 2 +- flip.R | 2 +- gtk.c | 21 +++++++++++++++++++++ guess.R | 2 +- icons/Makefile | 8 +++++++- icons/cicon.pl | 27 +++++++++++++++++++++++++++ inertia.R | 2 +- lightup.R | 2 +- loopy.R | 2 +- map.R | 2 +- mines.R | 2 +- mkfiles.pl | 15 +++++++++++++-- net.R | 2 +- netslide.R | 2 +- no-icon.c | 9 +++++++++ nullgame.R | 2 +- pattern.R | 2 +- pegs.R | 2 +- rect.R | 2 +- samegame.R | 2 +- sixteen.R | 2 +- slant.R | 2 +- solo.R | 2 +- tents.R | 2 +- twiddle.R | 2 +- untangle.R | 2 +- 30 files changed, 102 insertions(+), 28 deletions(-) create mode 100755 icons/cicon.pl create mode 100644 no-icon.c diff --git a/blackbox.R b/blackbox.R index 884fe44..4235840 100644 --- a/blackbox.R +++ b/blackbox.R @@ -1,6 +1,6 @@ # -*- makefile -*- -blackbox : [X] GTK COMMON blackbox +blackbox : [X] GTK COMMON blackbox blackbox-icon|no-icon blackbox : [G] WINDOWS COMMON blackbox blackbox.res? diff --git a/bridges.R b/bridges.R index f11fd41..75b9731 100644 --- a/bridges.R +++ b/bridges.R @@ -2,7 +2,7 @@ BRIDGES = bridges dsf -bridges : [X] GTK COMMON BRIDGES +bridges : [X] GTK COMMON BRIDGES bridges-icon|no-icon bridges : [G] WINDOWS COMMON BRIDGES bridges.res? diff --git a/cube.R b/cube.R index cc10fde..f08e000 100644 --- a/cube.R +++ b/cube.R @@ -1,6 +1,6 @@ # -*- makefile -*- -cube : [X] GTK COMMON cube +cube : [X] GTK COMMON cube cube-icon|no-icon cube : [G] WINDOWS COMMON cube cube.res? diff --git a/dominosa.R b/dominosa.R index 3bc8e34..e243c43 100644 --- a/dominosa.R +++ b/dominosa.R @@ -1,6 +1,6 @@ # -*- makefile -*- -dominosa : [X] GTK COMMON dominosa +dominosa : [X] GTK COMMON dominosa dominosa-icon|no-icon dominosa : [G] WINDOWS COMMON dominosa dominosa.res? diff --git a/fifteen.R b/fifteen.R index fd371d7..a9e2108 100644 --- a/fifteen.R +++ b/fifteen.R @@ -1,6 +1,6 @@ # -*- makefile -*- -fifteen : [X] GTK COMMON fifteen +fifteen : [X] GTK COMMON fifteen fifteen-icon|no-icon fifteen : [G] WINDOWS COMMON fifteen fifteen.res? diff --git a/flip.R b/flip.R index 91764de..40ca546 100644 --- a/flip.R +++ b/flip.R @@ -2,7 +2,7 @@ FLIP = flip tree234 -flip : [X] GTK COMMON FLIP +flip : [X] GTK COMMON FLIP flip-icon|no-icon flip : [G] WINDOWS COMMON FLIP flip.res? diff --git a/gtk.c b/gtk.c index d9b9a27..35e7466 100644 --- a/gtk.c +++ b/gtk.c @@ -15,6 +15,8 @@ #include #include +#include + #include #include #include @@ -1458,8 +1460,12 @@ static frontend *new_window(char *arg, int argtype, char **error) frontend *fe; GtkBox *vbox; GtkWidget *menubar, *menu, *menuitem; + GdkPixmap *iconpm; + GList *iconlist; int x, y, n; char errbuf[1024]; + extern char *const *const xpm_icons[]; + extern const int n_xpm_icons; fe = snew(frontend); @@ -1745,6 +1751,21 @@ static frontend *new_window(char *arg, int argtype, char **error) GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_MOTION_MASK); + if (n_xpm_icons) { + gtk_widget_realize(fe->window); + iconpm = gdk_pixmap_create_from_xpm_d(fe->window->window, NULL, + NULL, (gchar **)xpm_icons[0]); + gdk_window_set_icon(fe->window->window, NULL, iconpm, NULL); + iconlist = NULL; + for (n = 0; n < n_xpm_icons; n++) { + iconlist = + g_list_append(iconlist, + gdk_pixbuf_new_from_xpm_data((const gchar **) + xpm_icons[n])); + } + gdk_window_set_icon_list(fe->window->window, iconlist); + } + gtk_widget_show(fe->area); gtk_widget_show(fe->window); diff --git a/guess.R b/guess.R index fa98337..0956e65 100644 --- a/guess.R +++ b/guess.R @@ -1,6 +1,6 @@ # -*- makefile -*- -guess : [X] GTK COMMON guess +guess : [X] GTK COMMON guess guess-icon|no-icon guess : [G] WINDOWS COMMON guess guess.res? diff --git a/icons/Makefile b/icons/Makefile index 233f767..bec2a4a 100644 --- a/icons/Makefile +++ b/icons/Makefile @@ -19,6 +19,7 @@ P16D24 = $(patsubst %,%-16d24.png,$(PUZZLES)) P16D8 = $(patsubst %,%-16d8.png,$(PUZZLES)) P16D4 = $(patsubst %,%-16d4.png,$(PUZZLES)) ICONS = $(patsubst %,%.ico,$(PUZZLES)) +CICONS = $(patsubst %,%-icon.c,$(PUZZLES)) RC = $(patsubst %,%.rc,$(PUZZLES)) BIN = ../ @@ -28,6 +29,7 @@ base: $(BASE) web: $(WEB) pngicons: $(P48D24) $(P32D24) $(P16D24) winicons: $(ICONS) $(RC) +gtkicons: $(CICONS) # Build the base puzzle screenshots from which all the other images # are derived. Some of them involve showing a move animation @@ -120,5 +122,9 @@ $(ICONS): %.ico: %-48d24.png %-48d8.png %-48d4.png \ $(RC): %.rc: echo '200 ICON "$*.ico"' > $@ +# Build the GTK icon source files. +$(CICONS): %-icon.c: %-16d24.png %-32d24.png %-48d24.png + $(PIC)cicon.pl $^ > $@ + clean: - rm -f *.png *.ico *.rc + rm -f *.png *.ico *.rc *-icon.c diff --git a/icons/cicon.pl b/icons/cicon.pl new file mode 100755 index 0000000..3578bd3 --- /dev/null +++ b/icons/cicon.pl @@ -0,0 +1,27 @@ +#!/usr/bin/perl + +# Given a list of input PNGs, create a C source file file +# containing a const array of XPMs, under the name `xpm_icon'. + +$k = 0; +@xpms = (); +foreach $f (@ARGV) { + # XPM format is generated directly by ImageMagick, so that's easy + # enough. We just have to adjust the declaration line so that it + # has the right name, linkage and storage class. + @lines = (); + open XPM, "convert $f xpm:- |"; + push @lines, $_ while ; + close XPM; + die "XPM from $f in unexpected format\n" unless $lines[1] =~ /^static.*\{$/; + $lines[1] = "static const char *const xpm_icon_$k"."[] = {\n"; + $k++; + push @xpms, @lines, "\n"; +} + +# Now output. +foreach $line (@xpms) { print $line; } +print "const char *const *const xpm_icons[] = {\n"; +for ($i = 0; $i < $k; $i++) { print " xpm_icon_$i,\n"; } +print "};\n"; +print "const int n_xpm_icons = $k;\n"; diff --git a/inertia.R b/inertia.R index 33e1841..867484e 100644 --- a/inertia.R +++ b/inertia.R @@ -1,6 +1,6 @@ # -*- makefile -*- -inertia : [X] GTK COMMON inertia +inertia : [X] GTK COMMON inertia inertia-icon|no-icon inertia : [G] WINDOWS COMMON inertia inertia.res? diff --git a/lightup.R b/lightup.R index 17a2c6c..b4c4a3d 100644 --- a/lightup.R +++ b/lightup.R @@ -2,7 +2,7 @@ LIGHTUP = lightup combi -lightup : [X] GTK COMMON LIGHTUP +lightup : [X] GTK COMMON LIGHTUP lightup-icon|no-icon lightup : [G] WINDOWS COMMON LIGHTUP lightup.res? diff --git a/loopy.R b/loopy.R index 37e64b6..1856d53 100644 --- a/loopy.R +++ b/loopy.R @@ -2,7 +2,7 @@ LOOPY = loopy tree234 dsf -loopy : [X] GTK COMMON LOOPY +loopy : [X] GTK COMMON LOOPY loopy-icon|no-icon loopy : [G] WINDOWS COMMON LOOPY loopy.res? diff --git a/map.R b/map.R index 7752ec2..20e6706 100644 --- a/map.R +++ b/map.R @@ -2,7 +2,7 @@ MAP = map dsf -map : [X] GTK COMMON MAP +map : [X] GTK COMMON MAP map-icon|no-icon map : [G] WINDOWS COMMON MAP map.res? diff --git a/mines.R b/mines.R index 46913de..bc7e3a9 100644 --- a/mines.R +++ b/mines.R @@ -2,7 +2,7 @@ MINES = mines tree234 -mines : [X] GTK COMMON MINES +mines : [X] GTK COMMON MINES mines-icon|no-icon mines : [G] WINDOWS COMMON MINES mines.res? diff --git a/mkfiles.pl b/mkfiles.pl index c81d64d..165f796 100755 --- a/mkfiles.pl +++ b/mkfiles.pl @@ -131,11 +131,22 @@ readinput: while (1) { $type = substr($i,1,(length $i)-2); } else { if ($i =~ /\?$/) { - # Source files with a trailing question mark are optional: + # Object files with a trailing question mark are optional: # the build can proceed fine without them, so we only use - # them if they're present. + # them if their primary source files are present. $i =~ s/\?$//; $i = undef unless defined &finddep($i); + } elsif ($i =~ /\|/) { + # Object file descriptions containing a vertical bar are + # lists of choices: we use the _first_ one whose primary + # source file is present. + @options = split /\|/, $i; + $j = undef; + foreach $k (@options) { + $j=$k, last if defined &finddep($k); + } + die "no alternative found for $i\n" unless defined $j; + $i = $j; } if (defined $i) { push @$listref, $i; diff --git a/net.R b/net.R index ec7c8a3..5edddb5 100644 --- a/net.R +++ b/net.R @@ -2,7 +2,7 @@ NET = net tree234 dsf -net : [X] GTK COMMON NET +net : [X] GTK COMMON NET net-icon|no-icon # The Windows Net shouldn't be called `net.exe' since Windows # already has a reasonably important utility program by that name! diff --git a/netslide.R b/netslide.R index 69e643d..b558de9 100644 --- a/netslide.R +++ b/netslide.R @@ -2,7 +2,7 @@ NETSLIDE = netslide tree234 -netslide : [X] GTK COMMON NETSLIDE +netslide : [X] GTK COMMON NETSLIDE netslide-icon|no-icon netslide : [G] WINDOWS COMMON NETSLIDE netslide.res? diff --git a/no-icon.c b/no-icon.c new file mode 100644 index 0000000..8a1de91 --- /dev/null +++ b/no-icon.c @@ -0,0 +1,9 @@ +#include + +/* + * Dummy source file which replaces the files generated in the + * `icons' subdirectory, when they're absent. + */ + +const char *const *const xpm_icons[] = { 0 }; +const int n_xpm_icons = 0; diff --git a/nullgame.R b/nullgame.R index 993f1ef..941623c 100644 --- a/nullgame.R +++ b/nullgame.R @@ -8,5 +8,5 @@ # it in the Makefile because it will be worse than useless if it # ever fails to compile, so it's important that it should actually # be built on a regular basis. -nullgame : [X] GTK COMMON nullgame +nullgame : [X] GTK COMMON nullgame nullgame-icon|no-icon nullgame : [G] WINDOWS COMMON nullgame diff --git a/pattern.R b/pattern.R index 13dbfe2..0b96d46 100644 --- a/pattern.R +++ b/pattern.R @@ -1,6 +1,6 @@ # -*- makefile -*- -pattern : [X] GTK COMMON pattern +pattern : [X] GTK COMMON pattern pattern-icon|no-icon pattern : [G] WINDOWS COMMON pattern pattern.res? diff --git a/pegs.R b/pegs.R index a1ab945..97a1750 100644 --- a/pegs.R +++ b/pegs.R @@ -2,7 +2,7 @@ PEGS = pegs tree234 -pegs : [X] GTK COMMON PEGS +pegs : [X] GTK COMMON PEGS pegs-icon|no-icon pegs : [G] WINDOWS COMMON PEGS pegs.res? diff --git a/rect.R b/rect.R index 20d3b49..e050b40 100644 --- a/rect.R +++ b/rect.R @@ -1,6 +1,6 @@ # -*- makefile -*- -rect : [X] GTK COMMON rect +rect : [X] GTK COMMON rect rect-icon|no-icon rect : [G] WINDOWS COMMON rect rect.res? diff --git a/samegame.R b/samegame.R index c3905bd..fa1f2ca 100644 --- a/samegame.R +++ b/samegame.R @@ -1,6 +1,6 @@ # -*- makefile -*- -samegame : [X] GTK COMMON samegame +samegame : [X] GTK COMMON samegame samegame-icon|no-icon samegame : [G] WINDOWS COMMON samegame samegame.res? diff --git a/sixteen.R b/sixteen.R index 46147af..4a69961 100644 --- a/sixteen.R +++ b/sixteen.R @@ -1,6 +1,6 @@ # -*- makefile -*- -sixteen : [X] GTK COMMON sixteen +sixteen : [X] GTK COMMON sixteen sixteen-icon|no-icon sixteen : [G] WINDOWS COMMON sixteen sixteen.res? diff --git a/slant.R b/slant.R index b735ec4..b615a9f 100644 --- a/slant.R +++ b/slant.R @@ -2,7 +2,7 @@ SLANT = slant dsf -slant : [X] GTK COMMON SLANT +slant : [X] GTK COMMON SLANT slant-icon|no-icon slant : [G] WINDOWS COMMON SLANT slant.res? diff --git a/solo.R b/solo.R index 6fe4ea0..126e338 100644 --- a/solo.R +++ b/solo.R @@ -1,6 +1,6 @@ # -*- makefile -*- -solo : [X] GTK COMMON solo +solo : [X] GTK COMMON solo solo-icon|no-icon solo : [G] WINDOWS COMMON solo solo.res? diff --git a/tents.R b/tents.R index ab6066f..c875289 100644 --- a/tents.R +++ b/tents.R @@ -2,7 +2,7 @@ TENTS = tents maxflow -tents : [X] GTK COMMON TENTS +tents : [X] GTK COMMON TENTS tents-icon|no-icon tents : [G] WINDOWS COMMON TENTS tents.res? diff --git a/twiddle.R b/twiddle.R index c525953..6b23df1 100644 --- a/twiddle.R +++ b/twiddle.R @@ -1,6 +1,6 @@ # -*- makefile -*- -twiddle : [X] GTK COMMON twiddle +twiddle : [X] GTK COMMON twiddle twiddle-icon|no-icon twiddle : [G] WINDOWS COMMON twiddle twiddle.res? diff --git a/untangle.R b/untangle.R index 8c467d6..fd74f31 100644 --- a/untangle.R +++ b/untangle.R @@ -2,7 +2,7 @@ UNTANGLE = untangle tree234 -untangle : [X] GTK COMMON UNTANGLE +untangle : [X] GTK COMMON UNTANGLE untangle-icon|no-icon untangle : [G] WINDOWS COMMON UNTANGLE untangle.res? -- 2.11.0