aboutsummaryrefslogtreecommitdiff
path: root/Perl/t/Images.t
blob: 99111c52eec11a336c26ee861ad595b878bf09c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/usr/bin/perl -w

#
# $Id: Images.t,v 1.5 2004-05-12 12:33:33 mertz Exp $
# Author: Christophe Mertz
#

# testing all the -tile, -image, -mask, -fillpattern, -linepattern widget and items options 

# this script can be used with an optionnal argument, an integer giving
# the delay in seconds during which the graphic updates will be displayed
# this is usefull for visual inspection!

BEGIN {
    if (!eval q{
#        use Test::More qw(no_plan);
        use Test::More tests => 36;
        1;
    }) {
        print "# tests only work properly with installed Test::More module\n";
        print "1..1\n";
        print "ok 1\n";
        exit;
    }
    if (!eval q{
	use Tk::Zinc;
 	1;
    }) {
        print "unable to load Tk::Zinc";
        print "1..1\n";
        print "ok 1\n";
        exit;
    }
    if (!eval q{
 	$mw = MainWindow->new();
 	1;
    }) {
        print "# tests only work properly when it is possible to create a mainwindow in your env\n";
        print "1..1\n";
        print "ok 1\n";
        exit;
    }
}


$zinc = $mw->Zinc(-render => 0,
		  -width => 400, -height => 400)->pack;

like  ($zinc, qr/^Tk::Zinc=HASH/ , "zinc has been created");

#### creating different images, bitmaps and pixmaps...
my $photoMickey = $zinc->Photo('mickey.gif', -file => Tk->findINC("demos/images/mickey.gif"));
like ($photoMickey, qr/^Tk::Photo=HASH/ , "creating a Tk::Photo with a .gif");

my $bitmap = $zinc->Bitmap('file.xbm', -file => Tk->findINC("file.xbm"));
like ($bitmap, qr/^Tk::Bitmap=HASH/ , "creating a Tk::Bitmap with a .xbm");

my $xpm = $zinc->Photo('QuitPB.xpm', -file => Tk->findINC("demos/images/QuitPB.xpm"));
like ($xpm, qr/^Tk::Photo=HASH/ , "creating a Tk::Photo with a .xpm");

#### tiling Tk::Zinc
$zinc->configure(-tile => $xpm);
if ($Tk::VERSION < 804) {
  is ($zinc->cget(-tile), "QuitPB.xpm", "verifying Tk::Zinc -tile option value");
} else {
    is ($zinc->cget(-tile), $xpm, "verifying Tk::Zinc -tile option value");
}

&wait ("-tile of Tk::Zinc with QuitPB.xpm");

$zinc->configure(-tile => $photoMickey);
if ($Tk::VERSION < 804) {
  is ($zinc->cget(-tile), "mickey.gif", "verifying Tk::Zinc -tile option value");
} else {
  is ($zinc->cget(-tile), $photoMickey, "verifying Tk::Zinc -tile option value");
}
&wait ("-tile of Tk::Zinc with mickey.gif");

# modifying the Tk::Photo to see if the Tk::Zinc -tile changes
$photoMickey->read( Tk->findINC("demos/images/earth.gif") );
&wait ("-tile of Tk::Zinc should display the earth VISUAL INSPECTION!"); sleep 1;
# going back to the "real" mickey
$photoMickey->read( Tk->findINC("demos/images/mickey.gif") );
&wait ("-tile of Tk::Zinc should display mickey again VISUAL INSPECTION!"); sleep 1;

$zinc->configure(-tile => "");
if ($Tk::VERSION < 804) {
  is ($zinc->cget(-tile), "", "removing Tk::Zinc -tile");
} else {
  is ($zinc->cget(-tile), undef, "removing Tk::Zinc -tile");
}
&wait ("-tile of Tk::Zinc with nothing");



#### rectangle item
my $rect1 = $zinc->add('rectangle', 1, [10,10,190,190], -filled => 1);


$zinc->itemconfigure($rect1, -tile => $xpm);
is ($zinc->itemcget($rect1, -tile), "QuitPB.xpm", "verifying rectangle -tile option value");
&wait ("-tile of rectangle with QuitPB.xpm");

$zinc->itemconfigure($rect1, -tile => $photoMickey);
is ($zinc->itemcget($rect1, -tile), "mickey.gif", "verifying rectangle -tile option value");
&wait ("-tile of rectangle with mickey");

# modifying the Tk::Photo to see if the rectangle -tile changes
$photoMickey->read( Tk->findINC("demos/images/earth.gif") );
&wait ("-tile of rectangle should display the earth VISUAL INSPECTION!"); sleep 1;
# going back to the "real" mickey
$photoMickey->read( Tk->findINC("demos/images/mickey.gif") );
&wait ("-tile of rectangle should display mickey again VISUAL INSPECTION!"); sleep 1;


$zinc->itemconfigure($rect1, -tile => "");
is ($zinc->itemcget($rect1, -tile), "", "removing rectangle -tile");
&wait ("-tile of rectangle with nothing");

TODO: {
    local $TODO = "because it makes Tk::Zinc dying" if 1;

    # the next line makes Tk::Zinc (v3.29x) dying... so I comment it out the 3 next lines 
    # $zinc->itemconfigure($rect1, -fillpattern => $bitmap);
    # is ($zinc->itemcget($rect1, -fillpattern), $bitmap, "verifying rectangle -fillpattern option value as a Tk::Bitmap");
    # &wait ("displaying a rectangle with -fillpattern as a Tk::Bitmap");
}

$zinc->itemconfigure($rect1, -fillpattern => 'AlphaStipple3');
is ($zinc->itemcget($rect1, -fillpattern), 'AlphaStipple3', "verifying rectangle -fillpattern option value");
&wait ("-fillpattern of rectangle with 'AlphaStipple3'");

$zinc->itemconfigure($rect1, -fillpattern => "");
is ($zinc->itemcget($rect1, -fillpattern), "", "removing rectangle -fillpattern");
&wait ("-fillpattern of rectangle with nothing");


$zinc->itemconfigure($rect1, -filled => 0,-linepattern => 'AlphaStipple3', -linecolor => "red");
is ($zinc->itemcget($rect1, -linepattern), 'AlphaStipple3', "verifying rectangle -linepattern option value");
&wait ("-linepattern of rectangle with 'AlphaStipple3'");

$zinc->itemconfigure($rect1, -linepattern => "");
is ($zinc->itemcget($rect1, -linepattern), "", "removing rectangle -linepattern");
&wait ("-linepattern of rectangle with nothing");

$zinc->remove($rect1);

#####  icon item
my $icon1 = $zinc->add('icon', 1, -position => [20,100], -image => $photoMickey);
&wait ("displaying an icon");

$zinc->remove($icon1);

my $icon2 = $zinc->add('icon', 1, -position => [40,100]);

SKIP: {
    skip "with Tk::Zinc < 3.295", 4 if ($Tk::Zinc::VERSION < 3.295);

    $zinc->itemconfigure($icon2, -image => $bitmap);

    &wait ("displaying an icon with -image as a Tk::Bitmap");
    is ($zinc->itemcget($icon2, -image), 'file.xbm', "verifying icon -image option value as file.xbm");
    $zinc->itemconfigure($icon2, -image => "");

    $zinc->itemconfigure($icon2, -image => '@'.Tk->findINC("openfile.xbm"));
    is ($zinc->itemcget($icon2, -image), '@'.Tk->findINC("openfile.xbm"),"verifying icon -image option value as @/path/openfile.xbm");
    &wait ("displaying an icon with -image as a \@filename.xbm");
}
$zinc->remove($icon2);

my $icon3 = $zinc->add('icon', 1, -position => [60,100], -mask => '@'.Tk->findINC("openfolder.xbm"),
		       -color => "red");
is ($zinc->itemcget($icon3, -mask), '@'.Tk->findINC("openfolder.xbm"),"verifying icon -mask option value as \@/path/openfolder.xbm");
&wait ("displaying an icon with -mask as a \@filename.xbm");

$zinc->itemconfigure($icon3, -image => "");
is ($zinc->itemcget($icon3, -image), "", "removing icon -image");

TODO: {
    local $TODO = "because it makes Tk::Zinc dying" if 1;

    # the next line makes Tk::Zinc (v3.29x) dying... so I comment it out the 3 next lines 
    # $zinc->itemconfigure($icon3, -mask => $bitmap);
    # is ($zinc->itemcget($icon3, -mask), $bitmap, "verifying icon -mask option value as a Tk::Bitmap");
    # &wait ("displaying an icon with -mask as a Tk::Bitmap");
}

$zinc->remove($icon3);

# We should also test that changing the content of a Tk::Photo should change the display of an icon



sub wait {
    $zinc->update;
    ok (1, $_[0]);

    my $delay = $ARGV[0];
    if (defined $delay) {
	$zinc->update;
	if ($delay =~ /^\d+$/) {
	    sleep $delay;
	} else {
	    sleep 1;
	}
    }
    
}



diag("############## Images test");