lib/TUI/ColorSel/ColorSelector.pm

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