ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra/Deliantra/Gtk2.pm
Revision: 1.2
Committed: Sun Feb 5 21:18:07 2006 UTC (18 years, 3 months ago) by root
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -0 lines
State: FILE REMOVED
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 =head1 NAME
2    
3     Crossfire::Gtk2 - Gtk2-specific utilities
4    
5     =cut
6    
7     package Crossfire::Gtk2;
8    
9     our $VERSION = '0.1';
10    
11     use strict;
12    
13     use Gtk2;
14    
15     use Crossfire;
16    
17     our $TILECACHE;
18     our %TILECACHE;
19    
20     sub init_tilecache($) {
21     my ($cacheprefix) = @_;
22    
23     eval {
24     -M "$cacheprefix.pst" < -M "$Crossfire::LIB/crossfire.0"
25     && ($TILECACHE = new_from_file Gtk2::Gdk::Pixbuf "$cacheprefix.png")
26     && (*TILECACHE = Storable::retrieve "$cacheprefix.pst")
27     } or do {
28     my $tile = read_pak "$Crossfire::LIB/crossfire.0";
29    
30     my %cache;
31    
32     my $idx = 0;
33    
34     for my $name (sort keys %$tile) {
35     my $file = "/tmp/map2png.$$~";
36    
37     open my $fh, ">:raw", $file
38     or die "$file: $!";
39     print $fh $tile->{$name};
40     close $fh;
41    
42     my $tile = $cache{$name} = {};
43    
44     my $pb = $tile->{$name} = new_from_file Gtk2::Gdk::Pixbuf $file;
45    
46     unlink $file;
47    
48     $tile->{pb} = $pb;
49     $tile->{idx} = $idx;
50     $tile->{w} = int $pb->get_width / TILESIZE;
51     $tile->{h} = int $pb->get_height / TILESIZE;
52    
53     $idx += $tile->{w} * $tile->{h};
54     }
55    
56     my $pb = new Gtk2::Gdk::Pixbuf "rgb", 1, 8, 64 * TILESIZE, TILESIZE * int +($idx + 63) / 64;
57    
58     while (my ($name, $tile) = each %cache) {
59     my $tpb = delete $tile->{pb};
60     my $ofs = $tile->{idx};
61    
62     for my $y (0 .. $tile->{h} - 1) {
63     for my $x (0 .. $tile->{w} - 1) {
64     my $idx = $ofs + $y * $tile->{w} + $x;
65     $tpb->copy_area ($x * TILESIZE, $y * TILESIZE, TILESIZE, TILESIZE,
66     $pb, ($idx % 64) * TILESIZE, TILESIZE * int $idx / 64);
67     }
68     }
69     }
70    
71     $pb->save ("$cacheprefix.png", "png");
72     Storable::nstore \%cache, "$cacheprefix.pst";
73    
74     $TILECACHE = $pb;
75     *TILESIZE = \%cache;
76     }
77     }
78    
79     =head1 AUTHOR
80    
81     Marc Lehmann <schmorp@schmorp.de>
82     http://home.schmorp.de/
83    
84     Robin Redeker <elmex@ta-sa.org>
85     http://www.ta-sa.org/
86    
87     =cut
88    
89     1