blib/lib/Tkx/SplashScreen.pm untested

filter: Statementstmt 0.0% 0 / 95 Branchbran 0.0% 0 / 50 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 179 CC 26 SCAR 51.4
CC
26
Cov
0%
_obj_init
272.0
_Populate
132.0
show
2.0
CRAP 171.1
1 package Tkx::SplashScreen;
2
3 use strict;
4 use warnings;
5
6 our $VERSION = '0.16';
7
8 use Tkx;
9 use base qw(Tkx::widget Tkx::MegaConfig);
10
11 __PACKAGE__->_Mega('tkx_SplashScreen');
12 __PACKAGE__->_Config();
13
14
15 #----------------------------------------------------------------------------
16 # Method : _Populate
17 # Purpose : Create a new splash screen
18 # Notes :
19 #----------------------------------------------------------------------------
20 sub _Populate {
21 my ($class, $widget, $path, %opt) = @_;
22
23 my $self = $class->new($path)->_parent->new_toplevel(
24 -name => $path,
25 -class => 'tkx_SplashScreen'
26 );
27
28 $self->_class($class);
29
30 # Withdraw window
31 $self->g_wm_withdraw();
32
33 # Data
34 my $data = $self->_data();
35 $data->{-title} = delete $opt{-title};
36 $data->{-image} = delete $opt{-image};
37
38 $data->{-override} = defined $opt{-override} ? $opt{-override} : 1;
39 $data->{-width} = defined $opt{-width } ? $opt{-width} : 400;
40 $data->{-height} = defined $opt{-height} ? $opt{-height} : 300;
41 $data->{-alpha} = defined $opt{-alpha} ? $opt{-alpha} : 1.0;
42 $data->{-show} = defined $opt{-show} ? $opt{-show} : 1;
43 $data->{-posx} = defined $opt{-posx} ? $opt{-posx} : -1;
44 $data->{-posy} = defined $opt{-posy} ? $opt{-posy} : -1;
45 $data->{-hideonclick} = defined $opt{-hideonclick} ? $opt{-hideonclick} : 0;
46 $data->{-topmost} = defined $opt{-topmost} ? $opt{-topmost} : 0;
47 $data->{-delay} = defined $opt{-delay} ? $opt{-delay} : 0;
48
49 # Initialize
50 $self->_obj_init();
51
52 # Widget
53 return $self;
54 }
55
56
57 #----------------------------------------------------------------------------
58 # Method : _obj_init
59 # Purpose : Initializes splashscreen
60 # Notes :
61 #----------------------------------------------------------------------------
62 sub _obj_init {
63 my ($self) = @_;
64
65 my $data = $self->_data();
66
67 # Title
68 if (defined $data->{-title}) {
69 $self->g_wm_title($data->{-title});
70 }
71
72 # Override redirect
73 if ($data->{-override}) {
74 $self->g_wm_overrideredirect(1);
75 }
76
77 # Alpha channel
78 if ($data->{-alpha}) {
79 if (Tkx::tk_windowingsystem() eq 'win32') {
80 $self->g_wm_attributes(-alpha => $data->{-alpha});
81 }
82 }
83
84 # Topmost
85 if ($data->{-topmost}) {
86 $self->g_wm_attributes(-topmost => $data->{-topmost});
87 }
88
89 # Fullscreen
90 if ($data->{-fullscreen}) {
91 $self->g_wm_attributes(-fullscreen => $data->{-fullscreen});
92 }
93
94 # Set width/height
95 my ($image_width, $image_height);
96 my ($width, $height);
97
98 if ($data->{-image}) {
99 $image_width = Tkx::image_width($data->{-image});
100 $image_height = Tkx::image_height($data->{-image});
101 }
102 else {
103 $image_width = 400;
104 $image_height = 300;
105 }
106
107 if (($data->{-width} eq 'auto') or ($data->{-width} < 0)) {
108 $width = $image_width;
109 }
110 else {
111 $width = $data->{-width};
112 }
113
114 if (($data->{-height} eq 'auto') or ($data->{-height} < 0)) {
115 $height = $image_height;
116 }
117 else {
118 $height = $data->{-height};
119 }
120
121 # Set position
122 my ($posx, $posy);
123
124 if (($data->{-posx} eq 'auto') or ($data->{-posx} < 0)) {
125 $posx = int(($self->g_winfo_screenwidth() - $width) / 2);
126 }
127 else {
128 $posx = $data->{-posx};
129 }
130
131 if (($data->{-posy} eq 'auto') or ($data->{-posy} < 0)) {
132 $posy = int(($self->g_winfo_screenheight() - $height) / 2);
133 }
134 else {
135 $posy = $data->{-posy};
136 }
137
138 # Set image
139 my $canvas = $data->{canvas} = $self->new_canvas(
140 -width => $width,
141 -height => $height,
142 -highlightthickness => 0,
143 );
144
145 $canvas->g_pack();
146
147 if ($data->{-image}) {
148 $canvas->create_image(qw(0 0), -anchor => 'nw', -image => $data->{-image});
149 }
150
151 # Hide on click
152 if ($data->{-hideonclick}) {
153 Tkx::bind($canvas, '<ButtonPress-1>', sub {
154 $self->hide();
155 });
156 }
157
158 # Hide on delay
159 if ($data->{-delay}) {
160 Tkx::after($data->{-delay}, sub {
161 $self->hide();
162 })
163 }
164
165 # Set geometry
166 $self->g_wm_geometry("${width}x${height}+${posx}+${posy}");
167
168 # Show window
169 if ($data->{-show}) {
170 $self->show();
171 }
172 }
173
174
175 #----------------------------------------------------------------------------
176 # Method : show
177 # Purpose : Show splashscreen toplevel
178 # Notes :
179 #----------------------------------------------------------------------------
180 sub show {
181 my ($self) = @_;
182 $self->g_wm_deiconify();
183 $self->g_raise();
184 $self->g_focus();
185 }
186
187
188 #----------------------------------------------------------------------------
189 # Method : hide
190 # Purpose : Hide splashscreen
191 # Notes :
192 #----------------------------------------------------------------------------
193 sub hide {
194 my ($self) = @_;
195 $self->g_wm_withdraw();
196 }
197
198
199 #----------------------------------------------------------------------------
200 # Method : canvas
201 # Purpose : Return canvas
202 # Notes :
203 #----------------------------------------------------------------------------
204 sub canvas {
205 my ($self) = @_;
206 return $self->_data->{canvas};
207 }
208
209 1;
210 __END__