lib/TUI/ColorSel/ColorSelector.pm

filter: Statementstmt 36.8% 67 / 182 Branchbran 0.0% 0 / 66 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 65.5% 19 / 29 Podpod 55.5% 5 / 9 totaltotal 31.8% 91 / 286 CC 36 SCAR 49.4
CC
36
Cov
27%
handleEvent
385.9
draw
72.0
__ANON__
20.0
CRAP 139.1
« lib/TUI/Dialogs/StaticText.pm ↑ Summary lib/TUI/Gadgets/Table.pm »
1 package TUI::ColorSel::ColorSelector;
2 # ABSTRACT: interactive color selection view
3
4 6 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8
9 6 our $VERSION = '2.000003';
10 6 $VERSION =~ tr/_//d;
11 6 our $AUTHORITY = 'cpan:BRICKPOOL';
12
13 6 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 6 our @EXPORT = qw(
15 TColorSelector
16 new_TColorSelector
17 );
18
19 6 ▶use Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 6 ▶use TUI::toolkit;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 6 ▶use TUI::toolkit::Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
22 is_Object
23 :types
24 6 );
25
26 6 ▶use TUI::Drivers::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
27 :evXXXX
28 kbLeft
29 kbRight
30 kbUp
31 kbDown
32 6 );
33 6 ▶use TUI::Drivers::HardwareInfo;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 6 ▶use TUI::Drivers::Util qw( ctrlToArrow );
Subroutine BEGIN: called CC=1 SCAR=0.0
35 6 ▶use TUI::Objects::Rect;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 6 ▶use TUI::ColorSel::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
37 :cmXXXX
38 :csXXXX
39 6 );
40 6 ▶use TUI::Views::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
41 ofSelectable
42 ofFirstClick
43 ofFramed
44 6 );
45 6 ▶use TUI::Views::DrawBuffer;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 6 ▶use TUI::Views::View;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 6 ▶use TUI::Views::Util qw( message );
Subroutine BEGIN: called CC=1 SCAR=0.0
48
49 sub TColorSelector() { __PACKAGE__ }
50 sub name() { 'TColorSelector' }
51 0 ▶sub new_TColorSelector { __PACKAGE__->from(@_) }
Subroutine new_TColorSelector: not called CC=1 SCAR=6.9
Pod documented
52
53 6 extends TView;
54
55 # declare global variables
56 6 our $icon = "\xDB"; # cp437: "█"
57 # our $icon = encode( cp437 => "█" );
58
59 # protected attributes
60 6 has color => ( is => 'ro', default => 0 );
61 6 has selType => ( is => 'ro', default => csBackground );
62
63 # predeclare private methods
64 my (
65 6 $colorChanged,
66 );
67
68 0 ▶sub BUILDARGS { # \%args (%args)
Subroutine BUILDARGS: not called CC=1 SCAR=6.9
Pod documented
69 0 state $sig = signature(
70 method => 1,
71 named => [
72 bounds => Object,
73 selType => PositiveOrZeroInt, { alias => 'aSelType' },
74 ],
75 caller_level => +1,
76 );
77 0 my ( $class, $args ) = $sig->( @_ );
78 0 return { %$args };
79 }
80
81 0 ▶sub BUILD { # void (\%args)
Subroutine BUILD: not called CC=3 SCAR=24.8
Pod documented
82 0 my ( $self, $args ) = @_;
83 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
84 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
85 0 $self->{options} |= ofSelectable | ofFirstClick | ofFramed;
86 0 $self->{eventMask} |= evBroadcast;
87 0 return;
88 }
89
90 0 ▶sub from { # $obj ($bounds, $aSelType)
Subroutine from: not called CC=1 SCAR=6.9
Pod undocumented
91 0 state $sig = signature(
92 method => 1,
93 pos => [Object, Str],
94 );
95 0 my ( $class, @args ) = $sig->( @_ );
96 0 return $class->new( bounds => $args[0], selType => $args[1] );
97 }
98
99 0 ▶sub draw { # void ()
Subroutine draw: not called CC=8 SCAR=42.8
Pod documented
100 0 state $sig = signature(
101 method => Object,
102 pos => [],
103 );
104 0 my ( $self ) = $sig->( @_ );
105 0 my $b = TDrawBuffer->new();
106 0 $b->moveChar( 0, ' ', 0x70, $self->{size}{x} );
107 0 ▶ for ( my $i = 0 ; $i <= $self->{size}{y} ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $self->{"size"}{"y"}) 0 0 0
108 0 ▶ if ( $i < 4 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 4) 0 0 0
109 0 ▶ for ( my $j = 0 ; $j < 4 ; $j++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < 4) 0 0 0
110 0 my $c = $i * 4 + $j;
111 0 $b->moveChar( $j * 3, $icon, $c, 3 );
112 0 ▶ if ( $c == $self->{color} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c == $self->{"color"}) 0 0 0
113 # We do not use the INVERSE BULLET "\x8" (U+25D8) character, because
114 # some Unicode fonts display the character differently than IBM437.
115 0 ▶ if ( THardwareInfo->getColorCount() > 8 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&THardwareInfo()->getColorCount > 8) { } 0 0 0
116 # Use the BULLET ("\x7", U+2022) character and invert the color.
117 0 $b->putChar( $j * 3 + 1, "\x7" );
118 0 ▶ $b->putAttribute( $j * 3 + 1, $c == 0 ? 0x07 : ( $c << 4 ) );
Branch: 1 branch
BranchTrueFalseTotal
$c == 0 ? : 0 0 0
119 }
120 else {
121 # Use the UPPER HALF BLOCK ("\xDF", U+2580) character
122 # if only 8 colors are available.
123 0 $b->putChar( $j * 3 + 1, "\xdf" );
124 0 ▶ $b->putAttribute( $j * 3 + 1, $c == 0 ? 0x70 : $c );
Branch: 1 branch
BranchTrueFalseTotal
$c == 0 ? : 0 0 0
125 }
126 }
127 }
128 }
129 0 $self->writeLine( 0, $i, $self->{size}{x}, 1, $b );
130 }
131 0 return;
132 }
133
134 0 ▶sub handleEvent { # void ($event)
Subroutine handleEvent: not called CC=21 SCAR=59.6
Pod documented
135 6 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
136 0 state $sig = signature(
137 method => Object,
138 pos => [Object],
139 );
140 0 my ( $self, $event ) = $sig->( @_ );
141
142 6 ▶ use constant width => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
143
144 0 $self->SUPER::handleEvent( $event );
145
146 0 my $oldColor = $self->{color};
147 0 ▶ my $maxCol = $self->{selType} == csBackground ? 7 : 15;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'selType'} == 0 ? : 0 0 0
148 0 SWITCH: for ( $event->{what} ) {
149 0 ▶ evMouseDown == $_ and do {
Branch: 1 branch
BranchTrueFalseTotal
1 == $_ and do { do { if ($self->mouseInView($event->{"mouse"}{"where"})) { my $mouse = $self->makeLocal($event->{"mouse"}{"where"}); $self->{"color"} = $mouse->{"y"} * 4 + int($mouse->{"x"} / 3); } else { $self->{"color"} = $oldColor; } ; $self->$colorChanged; $self->drawView } while $self->mouseEvent($event, 4); last } 0 0 0
150 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$self->mouseEvent($event, 4) and do { do { if ($self->mouseInView($event->{"mouse"}{"where"})) { my $mouse = $self->makeLocal($event->{"mouse"}{"where"}); $self->{"color"} = $mouse->{"y"} * 4 + int($mouse->{"x"} / 3); } else { $self->{"color"} = $oldColor; } ; $self->$colorChanged; $self->drawView } } 0 0 0
151 0 ▶ if ( $self->mouseInView( $event->{mouse}{where} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->mouseInView($event->{'mouse'}{'where'})) { } 0 0 0
152 0 my $mouse = $self->makeLocal( $event->{mouse}{where} );
153 0 $self->{color} = $mouse->{y} * 4 + int( $mouse->{x} / 3 );
154 }
155 else {
156 0 $self->{color} = $oldColor;
157 }
158 0 $self->$colorChanged();
159 0 $self->drawView();
160 } while ( $self->mouseEvent( $event, evMouseMove ) );
161 0 last;
162 };
163 0 ▶ evKeyDown == $_ and do {
Branch: 1 branch
BranchTrueFalseTotal
16 == $_ and do { SWITCH: foreach $_ (&ctrlToArrow($event->{"keyDown"}{"keyCode"})) { 19200 == $_ and do { if ($self->{"color"} > 0) { --$self->{"color"}; } else { $self->{"color"} = $maxCol; } ; last }; 19712 == $_ and do { if ($self->{"color"} < $maxCol) { ++$self->{"color"}; } else { $self->{"color"} = 0; } ; last }; 18432 == $_ and do { if ($self->{"color"} > 3) { $self->{"color"} -= 4; } elsif ($self->{"color"} == 0) { $self->{"color"} = $maxCol; } else { $self->{"color"} += $maxCol - 4; } ; last }; 20480 == $_ and do { if ($self->{"color"} < $maxCol - 3) { $self->{"color"} += 4; } elsif ($self->{"color"} == $maxCol) { $self->{"color"} = 0; } else { $self->{"color"} -= $maxCol - 4; } ; last }; DEFAULT: { return; } ; } ; last } 0 0 0
164 0 SWITCH: for ( ctrlToArrow( $event->{keyDown}{keyCode} ) ) {
165 0 ▶ kbLeft == $_ and do {
Branch: 1 branch
BranchTrueFalseTotal
19200 == $_ and do { if ($self->{"color"} > 0) { --$self->{"color"}; } else { $self->{"color"} = $maxCol; } ; last } 0 0 0
166 0 ▶ if ( $self->{color} > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'color'} > 0) { } 0 0 0
167 0 $self->{color}--;
168 }
169 else {
170 0 $self->{color} = $maxCol;
171 }
172 0 last;
173 };
174 0 ▶ kbRight == $_ and do {
Branch: 1 branch
BranchTrueFalseTotal
19712 == $_ and do { if ($self->{"color"} < $maxCol) { ++$self->{"color"}; } else { $self->{"color"} = 0; } ; last } 0 0 0
175 0 ▶ if ( $self->{color} < $maxCol ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'color'} < $maxCol) { } 0 0 0
176 0 $self->{color}++;
177 }
178 else {
179 0 $self->{color} = 0;
180 }
181 0 last;
182 };
183 0 ▶ kbUp == $_ and do {
Branch: 1 branch
BranchTrueFalseTotal
18432 == $_ and do { if ($self->{"color"} > 3) { $self->{"color"} -= 4; } elsif ($self->{"color"} == 0) { $self->{"color"} = $maxCol; } else { $self->{"color"} += $maxCol - 4; } ; last } 0 0 0
184 0 ▶ if ( $self->{color} > width- 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'color'} > 3) { } 0 0 0
elsif ($self->{'color'} == 0) { } 0 0 0
185 0 $self->{color} -= width;
186 }
187 elsif ( $self->{color} == 0 ) {
188 0 $self->{color} = $maxCol;
189 }
190 else {
191 0 $self->{color} += $maxCol - width;
192 }
193 0 last;
194 };
195 0 ▶ kbDown == $_ and do {
Branch: 1 branch
BranchTrueFalseTotal
20480 == $_ and do { if ($self->{"color"} < $maxCol - 3) { $self->{"color"} += 4; } elsif ($self->{"color"} == $maxCol) { $self->{"color"} = 0; } else { $self->{"color"} -= $maxCol - 4; } ; last } 0 0 0
196 0 ▶ if ( $self->{color} < $maxCol - ( width- 1 ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'color'} < $maxCol - 3) { } 0 0 0
elsif ($self->{'color'} == $maxCol) { } 0 0 0
197 0 $self->{color} += width;
198 }
199 elsif ( $self->{color} == $maxCol ) {
200 0 $self->{color} = 0;
201 }
202 else {
203 0 $self->{color} -= $maxCol - width;
204 }
205 0 last;
206 };
207 DEFAULT: {
208 0 return;
209 }
210 } #/ SWITCH: for ( ctrlToArrow( $event...))
211 0 last;
212 };
213 0 ▶ evBroadcast == $_ and do {
Branch: 1 branch
BranchTrueFalseTotal
512 == $_ and do { if ($event->{"message"}{"command"} == 73) { if ($self->{"selType"} == 0) { $self->{"color"} = $event->{"message"}{"infoByte"} >> 4; } else { $self->{"color"} = $event->{"message"}{"infoByte"} & 15; } ; $self->drawView; return; } else { return; } } 0 0 0
214 0 ▶ if ( $event->{message}{command} == cmColorSet ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($event->{'message'}{'command'} == 73) { } 0 0 0
215 0 ▶ if ( $self->{selType} == csBackground ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'selType'} == 0) { } 0 0 0
216 0 $self->{color} = $event->{message}{infoByte} >> 4;
217 }
218 else {
219 0 $self->{color} = $event->{message}{infoByte} & 0x0f;
220 }
221 0 $self->drawView();
222 0 return;
223 }
224 else {
225 0 return;
226 }
227 };
228 DEFAULT: {
229 0 return;
230 }
231 }
232 0 $self->drawView();
233 0 $self->$colorChanged();
234 0 $self->clearEvent( $event );
235 0 return;
236 }
237
238 0 ▶$colorChanged = sub { # void ()
Subroutine __ANON__: not called CC=4 SCAR=30.0
239 0 my ( $self ) = @_;
240 0 ▶ assert ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 0 0
241 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
242 0 ▶ my $msg = $self->{selType} == csForeground
Branch: 1 branch
BranchTrueFalseTotal
$self->{'selType'} == 1 ? : 0 0 0
243 ? cmColorForegroundChanged
244 : cmColorBackgroundChanged;
245 0 message( $self->{owner}, evBroadcast, $msg, 0+ $self->{color} );
246 0 return;
247 6 };
248
249 0 ▶sub write :method { # void ($os)
Subroutine write: not called CC=1 SCAR=6.9
Pod undocumented
250 0 state $sig = signature(
251 method => Object,
252 pos => [Object],
253 );
254 0 my ( $self, $os ) = $sig->( @_ );
255 0 $self->SUPER::write( $os );
256 $os->put(
257 $self->{color},
258 $self->{selType}
259 0 );
260 0 return;
261 }
262
263 0 ▶sub read :method { # $self ($is)
Subroutine read: not called CC=1 SCAR=6.9
Pod undocumented
264 0 state $sig = signature(
265 method => Object,
266 pos => [Object],
267 );
268 0 my ( $self, $is ) = $sig->( @_ );
269 0 $self->SUPER::read( $is );
270 0 $self->{color} = $is->get();
271 0 $self->{selType} = $is->get();
272 0 return $self;
273 }
274
275 0 ▶sub build { # $obj ()
Subroutine build: not called CC=4 SCAR=30.0
Pod undocumented
276 0 my ( $class ) = @_;
277 0 ▶ assert ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 0 0
278 0 ▶ assert ( is_Str $class );
Branch: 1 branch
BranchTrueFalseTotal
unless $class->is_Str 0 0 0
279 0 ▶ assert ( Storable::is_retrieving );
Branch: 1 branch
BranchTrueFalseTotal
unless &Storable::is_retrieving() 0 0 0
280 0 return $class->new(
281 bounds => TRect->new(),
282 selType => csBackground,
283 );
284 }
285
286 6 1
287
288 __END__
« lib/TUI/Dialogs/StaticText.pm ↑ Summary lib/TUI/Gadgets/Table.pm »