lib/TUI/Views/Frame.pm

filter: Statementstmt 35.4% 57 / 161 Branchbran 0.0% 0 / 52 Conditioncond 0.0% 0 / 36 MC/DCmcdc 0.0% 0 / 17 Subroutinesub 68.1% 15 / 22 Podpod 100% 7 / 7 totaltotal 26.7% 79 / 295 CC 39 SCAR 54.6
CC
39
Cov
23%
handleEvent
462.0
draw
272.0
BUILD
12.0
CRAP 235.4
« lib/TUI/Dialogs/Button.pm ↑ Summary lib/TUI/Dialogs/StaticText.pm »
1 package TUI::Views::Frame;
2 # ABSTRACT: Frame class used by windows
3
4 34 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 34 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 34 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 34 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8
9 34 our $VERSION = '2.000002';
10 34 $VERSION =~ tr/_//d;
11 34 our $AUTHORITY = 'cpan:BRICKPOOL';
12
13 34 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 34 our @EXPORT = qw(
15 TFrame
16 new_TFrame
17 );
18
19 34 ▶use Encode qw( encode );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 34 ▶use List::Util qw( min max );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 34 ▶use TUI::toolkit;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 34 ▶use TUI::toolkit::Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
23 :is
24 :types
25 34 );
26
27 34 ▶use TUI::Drivers::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
28 :evXXXX
29 meDoubleClick
30 34 );
31 34 ▶use TUI::Objects::Point;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 34 ▶use TUI::Views::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
33 :cmXXXX
34 cpFrame
35 :dmXXXX
36 :gfXXXX
37 :sfXXXX
38 :wfXXXX
39 wnNoNumber
40 34 );
41 34 ▶use TUI::Views::DrawBuffer;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 34 ▶use TUI::Views::Palette;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 34 ▶use TUI::Views::View;
Subroutine BEGIN: called CC=1 SCAR=0.0
44
45 sub TFrame() { __PACKAGE__ }
46 sub name() { 'TFrame' }
47 0 ▶sub new_TFrame { __PACKAGE__->from(@_) }
Subroutine new_TFrame: not called CC=1 SCAR=6.9
Pod documented
48
49 34 extends TView;
50
51 # declare global variables
52 34 our $initFrame =
53 "\x06\x0A\x0C\x05\x00\x05\x03\x0A\x09\x16\x1A\x1C\x15\x00\x15\x13\x1A\x19";
54
55 # for UnitedStates code page
56 34 our $frameChars = encode( cp437 => " └ │┌├ ┘─┴┐┤┬┼ ╚ ║╔╟ ╝═╧╗╢╤ ");
57
58 34 our $closeIcon = "[~\xFE~]"; # "[~■~]"
59 34 our $zoomIcon = "[~\x18~]"; # "[~↑~]"
60 34 our $unZoomIcon = "[~\x12~]"; # "[~↕~]"
61 # our $closeIcon = encode( cp437 => "[~■~]" );
62 # our $zoomIcon = encode( cp437 => "[~↑~]" );
63 # our $unZoomIcon = encode( cp437 => "[~↕~]" );
64 34 our $dragIcon = encode( cp437 => "~─┘~" );
65
66 # import frameLine
67 34 require TUI::Views::Frame::Line;
68
69 0 ▶sub BUILD { # void (\%args)
Subroutine BUILD: not called CC=3 SCAR=24.8
Pod documented
70 0 my ( $self, $args ) = @_;
71 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
72 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
73 0 $self->{growMode} = gfGrowHiX | gfGrowHiY;
74 0 $self->{eventMask} |= evBroadcast | evMouseUp;
75 0 return;
76 }
77
78 0 ▶sub draw { # void ()
Subroutine draw: not called CC=16 SCAR=56.1
Pod documented
79 0 state $sig = signature(
80 method => Object,
81 pos => [],
82 );
83 0 my ( $self ) = $sig->( @_ );
84 0 my ( $cFrame, $cTitle );
85 0 my ( $f, $i, $l, $width );
86 0 my $b = TDrawBuffer->new();
87
88 0 ▶ if ( ( $self->{state} & sfDragging ) != 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (($self->{'state'} & 128) != 0) { } 0 0 0
elsif (($self->{'state'} & 16) == 0) { } 0 0 0
89 0 $cFrame = 0x0505;
90 0 $cTitle = 0x0005;
91 0 $f = 0;
92 }
93 elsif ( ( $self->{state} & sfActive ) == 0 ) {
94 0 $cFrame = 0x0101;
95 0 $cTitle = 0x0002;
96 0 $f = 0;
97 }
98 else {
99 0 $cFrame = 0x0503;
100 0 $cTitle = 0x0004;
101 0 $f = 9;
102 }
103
104 0 $cFrame = $self->getColor( $cFrame );
105 0 $cTitle = $self->getColor( $cTitle );
106
107 0 $width = $self->{size}{x};
108 0 $l = $width - 10;
109
110 $l -= 6
111 0 ▶ if $self->{owner}{flags} & ( wfClose | wfZoom );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"owner"}{"flags"} & 12 0 0 0
112 0 $self->frameLine( $b, 0, $f, $cFrame );
113 0 ▶ if ( $self->{owner}{number} != wnNoNumber
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"owner"}{"number"} != 0 and $self->{"owner"}{"number"} < 10) 0 0 0
Condition0%0/3
$self->{"owner"}{"number"} != 0 and $self->{"owner"}{"number"} < 10
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"owner"}{"number"} != 0 and $self->{"owner"}{"number"} < 10
$self->{"owner"}{"number"} != 0 $self->{"owner"}{"number"} < 10
Truth table0%0/3
A and B
A= $self->{"owner"}{"number"} != 0B= $self->{"owner"}{"number"} < 10
ABresult
0X0
100
111
114 && $self->{owner}{number} < 10
115 ) {
116 0 $l -= 4;
117 0 ▶ $i = ( $self->{owner}{flags} & wfZoom )
Branch: 1 branch
BranchTrueFalseTotal
$self->{'owner'}{'flags'} & 8 ? : 0 0 0
118 ? 7
119 : 3;
120 0 $b->putChar( $width - $i, chr( $self->{owner}{number} + ord( '0' ) ) );
121 }
122
123 0 ▶ if ( $self->{owner} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"owner"}) 0 0 0
124 0 my $title = $self->{owner}->getTitle( $l );
125 0 ▶ if ( $title ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($title) 0 0 0
126 0 $l = min( length( $title ), $width - 10 );
127 0 $l = max( $l, 0 );
128 0 $i = ( $width - $l ) >> 1;
129 0 $b->putChar( $i - 1, ' ' );
130 0 $b->moveBuf( $i, [ unpack 'W*' => $title ], $cTitle, $l );
131 0 $b->putChar( $i + $l, ' ' );
132 }
133 } #/ if ( $self->{owner} )
134
135 0 ▶ if ( $self->{state} & sfActive ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"state"} & 16) 0 0 0
136 0 ▶ if ( $self->{owner}{flags} & wfClose ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"owner"}{"flags"} & 4) 0 0 0
137 0 $b->moveCStr( 2, $closeIcon, $cFrame );
138 }
139 0 ▶ if ( $self->{owner}{flags} & wfZoom ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"owner"}{"flags"} & 8) 0 0 0
140 0 my ( $minSize, $maxSize ) = ( TPoint->new(), TPoint->new() );
141 0 $self->{owner}->sizeLimits( $minSize, $maxSize );
142 0 ▶ if ( $self->{owner}{size} == $maxSize ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'owner'}{'size'} == $maxSize) { } 0 0 0
143 0 $b->moveCStr( $width - 5, $unZoomIcon, $cFrame );
144 }
145 else {
146 0 $b->moveCStr( $width - 5, $zoomIcon, $cFrame );
147 }
148 } #/ if ( ( $self->{owner}...))
149 } #/ if ( ( $self->{state} ...))
150
151 0 $self->writeLine( 0, 0, $self->{size}{x}, 1, $b );
152 0 ▶ for ( $i = 1 ; $i <= $self->{size}{y} - 2 ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $self->{"size"}{"y"} - 2) 0 0 0
153 0 $self->frameLine( $b, $i, $f + 3, $cFrame );
154 0 $self->writeLine( 0, $i, $self->{size}{x}, 1, $b );
155 }
156 0 $self->frameLine( $b, $self->{size}{y} - 1, $f + 6, $cFrame );
157 0 ▶ if ( $self->{state} & sfActive ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"state"} & 16) 0 0 0
158 0 ▶ if ( $self->{owner}{flags} & wfGrow ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"owner"}{"flags"} & 2) 0 0 0
159 0 $b->moveCStr( $width - 2, $dragIcon, $cFrame );
160 }
161 }
162 0 $self->writeLine( 0, $self->{size}{y} - 1, $self->{size}{x}, 1, $b );
163 0 return;
164 } #/ sub draw
165
166 0 ▶sub getPalette { # $palette ()
Subroutine getPalette: not called CC=1 SCAR=6.9
Pod documented
167 0 state $sig = signature(
168 method => Object,
169 pos => [],
170 );
171 0 my ( $self ) = $sig->( @_ );
172 0 state $palette = TPalette->new( data => cpFrame, size => length( cpFrame ) );
173 0 return $palette->clone();
174 }
175
176 0 ▶sub handleEvent { # void ($event)
Subroutine handleEvent: not called CC=21 SCAR=61.4
Pod documented
177 0 state $sig = signature(
178 method => Object,
179 pos => [Object],
180 );
181 0 my ( $self, $event ) = $sig->( @_ );
182 0 $self->SUPER::handleEvent( $event );
183 0 ▶ if ( $event->{what} == evMouseDown ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($event->{"what"} == 1) 0 0 0
184 0 my $mouse = $self->makeLocal( $event->{mouse}{where} );
185 0 ▶ if ( $mouse->{y} == 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($mouse->{'y'} == 0) { } 0 0 0
elsif ($mouse->{'x'} >= $self->{'size'}{'x'} - 2 and $mouse->{'y'} >= $self->{'size'}{'y'} - 1 and $self->{'state'} & 16) { } 0 0 0
186 0 ▶ if ( ( $self->{owner}{flags} & wfClose ) != 0
Branch: 3 branches
BranchTrueFalseTotal
if (($self->{'owner'}{'flags'} & 4) != 0 and $self->{'state'} & 16 and $mouse->{'x'} >= 2 and $mouse->{'x'} <= 4) { } 0 0 0
elsif (($self->{'owner'}{'flags'} & 8) != 0 and $self->{'state'} & 16 and $mouse->{'x'} >= $self->{'size'}{'x'} - 5 && $mouse->{'x'} <= $self->{'size'}{'x'} - 3 || $event->{'mouse'}{'eventFlags'} & 2) { } 0 0 0
elsif ($self->{'owner'}{'flags'} & 1) { } 0 0 0
Condition0%0/9
($self->{"owner"}{"flags"} & 4) != 0 and $self->{"state"} & 16 and $mouse->{"x"} >= 2 and $mouse->{"x"} <= 4
!ll&&!rl&&r
000
($self->{"owner"}{"flags"} & 4) != 0 and $self->{"state"} & 16 and $mouse->{"x"} >= 2
!ll&&!rl&&r
000
($self->{"owner"}{"flags"} & 4) != 0 and $self->{"state"} & 16
!ll&&!rl&&r
000
MC/DC0%0/4
($self->{"owner"}{"flags"} & 4) != 0 and $self->{"state"} & 16 and $mouse->{"x"} >= 2 and $mouse->{"x"} <= 4
($self->{"owner"}{"flags"} & 4) != 0 $self->{"state"} & 16 $mouse->{"x"} >= 2 $mouse->{"x"} <= 4
Truth table0%0/5
A and B and C and D
A= ($self->{"owner"}{"flags"} & 4) != 0B= $self->{"state"} & 16C= $mouse->{"x"} >= 2D= $mouse->{"x"} <= 4
ABCDresult
0XXX0
10XX0
110X0
11100
11111
187 && ( $self->{state} & sfActive )
188 && $mouse->{x} >= 2
189 && $mouse->{x} <= 4
190 ) {
191 0 ▶ while ( $self->mouseEvent( $event, evMouse ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->mouseEvent($event, 15)) 0 0 0
192 }
193 0 $mouse = $self->makeLocal( $event->{mouse}{where} );
194 0 ▶ if ( $mouse->{y} == 0 && $mouse->{x} >= 2 && $mouse->{x} <= 4 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mouse->{"y"} == 0 and $mouse->{"x"} >= 2 and $mouse->{"x"} <= 4) 0 0 0
Condition0%0/6
$mouse->{"y"} == 0 and $mouse->{"x"} >= 2 and $mouse->{"x"} <= 4
!ll&&!rl&&r
000
$mouse->{"y"} == 0 and $mouse->{"x"} >= 2
!ll&&!rl&&r
000
MC/DC0%0/3
$mouse->{"y"} == 0 and $mouse->{"x"} >= 2 and $mouse->{"x"} <= 4
$mouse->{"y"} == 0 $mouse->{"x"} >= 2 $mouse->{"x"} <= 4
Truth table0%0/4
A and B and C
A= $mouse->{"y"} == 0B= $mouse->{"x"} >= 2C= $mouse->{"x"} <= 4
ABCresult
0XX0
10X0
1100
1111
195 0 $event->{what} = evCommand;
196 0 $event->{message}{command} = cmClose;
197 0 $event->{message}{infoPtr} = $self->{owner};
198 0 $self->putEvent( $event );
199 0 $self->clearEvent( $event );
200 }
201 } #/ if ( ( $self->{owner}...))
202 ▶ elsif (
Condition0%0/12
($self->{"owner"}{"flags"} & 8) != 0 and $self->{"state"} & 16 and $mouse->{"x"} >= $self->{"size"}{"x"} - 5 && $mouse->{"x"} <= $self->{"size"}{"x"} - 3 || $event->{"mouse"}{"eventFlags"} & 2
!ll&&!rl&&r
000
($self->{"owner"}{"flags"} & 8) != 0 and $self->{"state"} & 16
!ll&&!rl&&r
000
$mouse->{"x"} >= $self->{"size"}{"x"} - 5 and $mouse->{"x"} <= $self->{"size"}{"x"} - 3 or $event->{"mouse"}{"eventFlags"} & 2
l!l&&r!l&&!r
000
$mouse->{"x"} >= $self->{"size"}{"x"} - 5 and $mouse->{"x"} <= $self->{"size"}{"x"} - 3
!ll&&!rl&&r
000
MC/DC0%0/5
($self->{"owner"}{"flags"} & 8) != 0 and $self->{"state"} & 16 and $mouse->{"x"} >= $self->{"size"}{"x"} - 5 && $mouse->{"x"} <= $self->{"size"}{"x"} - 3 || $event->{"mouse"}{"eventFlags"} & 2
($self->{"owner"}{"flags"} & 8) != 0 $self->{"state"} & 16 $mouse->{"x"} >= $self->{"size"}{"x"} - 5 $mouse->{"x"} <= $self->{"size"}{"x"} - 3 $event->{"mouse"}{"eventFlags"} & 2
Truth table0%0/7
A and B and C and D or E
A= ($self->{"owner"}{"flags"} & 8) != 0B= $self->{"state"} & 16C= $mouse->{"x"} >= $self->{"size"}{"x"} - 5D= $mouse->{"x"} <= $self->{"size"}{"x"} - 3E= $event->{"mouse"}{"eventFlags"} & 2
ABCDEresult
0XXXX0
10XXX0
110X00
111000
1111X1
110X11
111011
203 ( $self->{owner}{flags} & wfZoom ) != 0
204 && ( $self->{state} & sfActive )
205 && (
206 (
207 $mouse->{x} >= $self->{size}{x} - 5
208 && $mouse->{x} <= $self->{size}{x} - 3
209 )
210 || ( $event->{mouse}{eventFlags} & meDoubleClick )
211 )
212 ) {
213 0 $event->{what} = evCommand;
214 0 $event->{message}{command} = cmZoom;
215 0 $event->{message}{infoPtr} = $self->{owner};
216 0 $self->putEvent( $event );
217 0 $self->clearEvent( $event );
218 } #/ elsif ( ( $self->{owner}...))
219 elsif ( $self->{owner}{flags} & wfMove ) {
220 0 $self->dragWindow( $event, dmDragMove );
221 }
222 } #/ if ( $mouse->{y} == 0 )
223 ▶ elsif ( ( $mouse->{x} >= $self->{size}{x} - 2 &&
Condition0%0/6
$mouse->{"x"} >= $self->{"size"}{"x"} - 2 and $mouse->{"y"} >= $self->{"size"}{"y"} - 1 and $self->{"state"} & 16
!ll&&!rl&&r
000
$mouse->{"x"} >= $self->{"size"}{"x"} - 2 and $mouse->{"y"} >= $self->{"size"}{"y"} - 1
!ll&&!rl&&r
000
MC/DC0%0/3
$mouse->{"x"} >= $self->{"size"}{"x"} - 2 and $mouse->{"y"} >= $self->{"size"}{"y"} - 1 and $self->{"state"} & 16
$mouse->{"x"} >= $self->{"size"}{"x"} - 2 $mouse->{"y"} >= $self->{"size"}{"y"} - 1 $self->{"state"} & 16
Truth table0%0/4
A and B and C
A= $mouse->{"x"} >= $self->{"size"}{"x"} - 2B= $mouse->{"y"} >= $self->{"size"}{"y"} - 1C= $self->{"state"} & 16
ABCresult
0XX0
10X0
1100
1111
224 $mouse->{y} >= $self->{size}{y} - 1 )
225 && ( $self->{state} & sfActive )
226 ) {
227 0 ▶ if ( $self->{owner}{flags} & wfGrow ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"owner"}{"flags"} & 2) 0 0 0
228 0 $self->dragWindow( $event, dmDragGrow );
229 }
230 }
231 } #/ if ( $event->{what} ==...)
232 0 return;
233 } #/ sub handleEvent
234
235 0 ▶sub setState { # void ($aState, $enable)
Subroutine setState: not called CC=2 SCAR=17.9
Pod documented
236 0 state $sig = signature(
237 method => Object,
238 pos => [PositiveOrZeroInt, Bool],
239 );
240 0 my ( $self, $aState, $enable ) = $sig->( @_ );
241 0 $self->SUPER::setState( $aState, $enable );
242 0 ▶ if ( $aState & ( sfActive | sfDragging ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($aState & 144) 0 0 0
243 0 $self->drawView();
244 }
245 0 return;
246 }
247
248 0 ▶sub dragWindow { # void ($event, $mode)
Subroutine dragWindow: not called CC=1 SCAR=6.9
Pod documented
249 0 state $sig = signature(
250 method => Object,
251 pos => [Object, PositiveOrZeroInt],
252 );
253 0 my ( $self, $event, $mode ) = $sig->( @_ );
254 0 my $limits = $self->{owner}{owner}->getExtent();
255 0 my ( $min, $max ) = ( TPoint->new(), TPoint->new() );
256 0 $self->{owner}->sizeLimits( $min, $max );
257 $self->{owner}->dragView(
258 0 $event, $self->{owner}{dragMode} | $mode, $limits, $min, $max
259 );
260 0 $self->clearEvent( $event );
261 0 return;
262 }
263
264 34 1
265
266 __END__
« lib/TUI/Dialogs/Button.pm ↑ Summary lib/TUI/Dialogs/StaticText.pm »