File Coverage

blib/lib/Tk/Splash.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             # -*- perl -*-
2              
3             #
4             # Author: Slaven Rezic
5             #
6             # Copyright (C) 1999,2003,2005,2014 Slaven Rezic. All rights reserved.
7             # This package is free software; you can redistribute it and/or
8             # modify it under the same terms as Perl itself.
9             #
10             # Mail: srezic@cpan.org
11             # WWW: http://www.rezic.de/eserte/
12             #
13              
14             package Tk::Splash;
15 1     1   22386 use Tk;
  0            
  0            
16             use strict;
17             use vars qw($VERSION @ISA);
18              
19             $VERSION = 0.08;
20              
21             @ISA = qw(Tk::Widget);
22              
23             sub Show {
24             my($pkg,
25             $image_file, $image_width, $image_height, $title, $override) = @_;
26             $title = $0 if !defined $title;
27             my $splash_screen = {};
28             $splash_screen = new MainWindow;
29             $splash_screen->title($title);
30             if ($override) {
31             $splash_screen->overrideredirect(1);
32             }
33             my $splashphoto = $splash_screen->{Photo} = $splash_screen->Photo(-file => $image_file);
34             my $sw = $splash_screen->screenwidth;
35             my $sh = $splash_screen->screenheight;
36             $image_width = $splashphoto->width unless defined $image_width;
37             $splash_screen->{ImageWidth} = $image_width;
38             $image_height = $splashphoto->height unless defined $image_height;
39             $splash_screen->geometry("+" . int($sw/2 - $image_width/2) .
40             "+" . int($sh/2 - $image_height/2));
41             my $l = $splash_screen->Label(-image => $splashphoto, -bd => 0)->pack
42             (-fill => 'both', -expand => 1);
43             $splash_screen->update;
44             $splash_screen->{"Exists"} = 1;
45             bless $splash_screen, $pkg;
46             }
47              
48             sub Raise {
49             my $w = shift;
50             if ($w->{"Exists"}) {
51             Tk::catch(sub { Tk::raise($w) });
52             }
53             }
54              
55             sub Destroy {
56             my $w = shift;
57             if ($w->{Photo}) {
58             $w->{Photo}->delete;
59             undef $w->{Photo};
60             }
61             if ($w->{"Exists"}) {
62             Tk::catch(sub { Tk::destroy($w) });
63             }
64             }
65              
66             1;
67              
68             =head1 NAME
69              
70             Tk::Splash - create a splash screen
71              
72             =head1 SYNOPSIS
73              
74             BEGIN {
75             require Tk::Splash;
76             $splash = Tk::Splash->Show($image, $width, $height, $title,
77             $overrideredirect);
78             }
79             ...
80             use Tk;
81             ...
82             $splash->Destroy;
83             MainLoop;
84              
85             =head1 DESCRIPTION
86              
87             This module is another way to create a splash screen. It is slower
88             than L, but tries to be compatible by using standard
89             Tk methods for creation.
90              
91             The splash screen is created with the B function. Supplied
92             arguments are: filename of the displayed image, width and height of
93             the image and the string for the title bar. I<$width> and I<$height>
94             may be left undefined. If I<$overrideredirect> is set to a true value,
95             then the splash screen will come without window manager decoration. If
96             something goes wrong, then B will silently ignore all errors and
97             continue without a splash screen. The splash screen can be destroyed
98             with the B method, best short before calling B.
99              
100             I<$image> should be one of the core Perl/Tk image types (gif, ppm,
101             bmp). For jpegs and pngs, a C or C prior to
102             the call of the C method would be necessary.
103              
104             =head1 NOTES
105              
106             Since displaying the splash screen is done during compile time (if put
107             in a C block, like the SYNOPSIS example shows), the splash
108             screen will also occur if the script is started using perl's C<-c>
109             (check) switch.
110              
111             =head1 AUTHOR
112              
113             Slaven Rezic
114              
115             =head1 SEE ALSO
116              
117             L, L.
118              
119             =cut
120              
121             __END__