lib/TUI/ColorSel/ColorDialog.pm

filter: Statementstmt 50.9% 109 / 214 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 69.2% 27 / 39 Podpod 70.0% 7 / 10 totaltotal 47.0% 143 / 304 CC 17 SCAR 23.9
CC
17
Cov
44%
BUILD
42.0
handleEvent
30.0
setIndexes
22.0
CRAP 10.9
« lib/TUI/Dialogs/Util.pm ↑ Summary lib/TUI/toolkit/UO/Antlers.pm »
1 package TUI::ColorSel::ColorDialog;
2 # ABSTRACT: Common dialog box for selecting a color
3
4 4 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 4 our $VERSION = '2.000002';
9 4 $VERSION =~ tr/_//d;
10 4 our $AUTHORITY = 'cpan:BRICKPOOL';
11
12 4 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 our @EXPORT = qw(
14 TColorDialog
15 new_TColorDialog
16 );
17
18 4 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19 4 ▶use TUI::toolkit;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 4 ▶use TUI::toolkit::Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
21 Maybe
22 :is
23 :types
24 4 );
25
26 4 ▶use TUI::Drivers::Const qw( evBroadcast );
Subroutine BEGIN: called CC=1 SCAR=0.0
27 4 ▶use TUI::Drivers::ColorAttr;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 4 ▶use TUI::Dialogs::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
29 bfDefault
30 bfNormal
31 4 );
32 4 ▶use TUI::Dialogs::Button;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 4 ▶use TUI::Dialogs::Dialog;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 4 ▶use TUI::Dialogs::Label;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 4 ▶use TUI::ColorSel::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
36 cmNewColorItem
37 cmNewColorIndex
38 :csXXXX
39 4 );
40 4 ▶use TUI::ColorSel::ColorDisplay;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 4 ▶use TUI::ColorSel::ColorGroupList;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 4 ▶use TUI::ColorSel::ColorItemList;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 4 ▶use TUI::ColorSel::ColorSelector;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 4 ▶use TUI::ColorSel::MonoSelector;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 4 ▶use TUI::Objects::Rect;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 4 ▶use TUI::Views::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
47 cmOK
48 cmCancel
49 ofCentered
50 4 );
51 4 ▶use TUI::Views::ScrollBar;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 4 ▶use TUI::Views::View;
Subroutine BEGIN: called CC=1 SCAR=0.0
53
54 sub TColorDialog() { __PACKAGE__ }
55 sub name() { 'TColorDialog' }
56 0 ▶sub new_TColorDialog { __PACKAGE__->from(@_) }
Subroutine new_TColorDialog: not called CC=1 SCAR=6.9
Pod documented
57
58 4 extends TDialog;
59
60 # declare global variables
61 4 our $colors = "Colors";
62 4 our $groupText = "~G~roup";
63 4 our $itemText = "~I~tem";
64 4 our $forText = "~F~oreground";
65 4 our $bakText = "~B~ackground";
66 4 our $textText = "Text ";
67 4 our $colorText = "Color";
68 4 our $okText = "O~K~";
69 4 our $cancelText = "Cancel";
70
71 # import global variables
72 4 ▶use vars qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
73 $showMarkers
74 4 );
75 {
76 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
77 4 *showMarkers = \${ TView . '::showMarkers' };
78 }
79
80 # public attributes
81 0 ▶has pal => ( is => 'rw', default => sub { die 'required' } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
82
83 # protected attributes
84 4 has display => ( is => 'ro' );
85 0 ▶has groups => ( is => 'ro', default => sub { die 'required' } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
86 4 has forLabel => ( is => 'ro' );
87 4 has forSel => ( is => 'ro' );
88 4 has bakLabel => ( is => 'ro' );
89 4 has bakSel => ( is => 'ro' );
90 4 has monoLabel => ( is => 'ro' );
91 4 has monoSel => ( is => 'ro' );
92 4 has groupIndex => ( is => 'ro', default => 0 );
93
94 # local color indexes for the get/setIndexes methods
95 4 my $colorIndexes = TColorIndex->new();
96
97 4 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
98 4 groupIndex => 0,
99 colorSize => 1,
100 colorIndex => 2,
101 4 };
102
103 0 ▶sub BUILDARGS { # \%args (%args)
Subroutine BUILDARGS: not called CC=1 SCAR=6.9
Pod documented
104 0 state $sig = signature(
105 method => 1,
106 named => [
107 pal => Maybe[Object], { alias => 'aPalette' },
108 groups => Maybe[Object], { alias => 'aGroups' },
109 ],
110 caller_level => +1,
111 );
112 0 my ( $class, $args1 ) = $sig->( @_ );
113 0 local $Carp::CarpLevel = $Carp::CarpLevel + 1;
114 0 my $args2 = $class->SUPER::BUILDARGS(
115 bounds => TRect->new( ax => 0, ay => 0, bx => 79, by => 18 ),
116 title => $colors,
117 );
118 0 return { %$args1, %$args2 };
119 }
120
121 0 ▶sub BUILD { # void (\%args)
Subroutine BUILD: not called CC=6 SCAR=37.4
Pod documented
122 0 my ( $self, $args ) = @_;
123 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
124 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
125 0 ▶ assert ( is_HashRef $args );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_HashRef($args) 0 0 0
126 0 $self->{options} |= ofCentered;
127 0 my $aPalette = $args->{pal};
128 0 ▶ $self->{pal} = $aPalette->clone()
Branch: 1 branch
BranchTrueFalseTotal
if $aPalette 0 0 0
129 if $aPalette;
130
131 0 my $sb = TScrollBar->new(
132 bounds => TRect->new( ax => 27, ay => 3, bx => 28, by => 14 ),
133 );
134 0 $self->insert( $sb );
135
136 0 my $aGroups = $args->{groups};
137 0 $self->{groups} = TColorGroupList->new(
138 bounds => TRect->new( ax => 3, ay => 3, bx => 27, by => 14 ),
139 scrollBar => $sb,
140 groups => $aGroups,
141 );
142 0 $self->insert( $self->{groups} );
143 $self->insert(
144 TLabel->new(
145 bounds => TRect->new( ax => 3, ay => 2, bx => 10, by => 3 ),
146 text => $groupText,
147 link => $self->{groups},
148 )
149 0 );
150
151 0 $sb = TScrollBar->new(
152 bounds => TRect->new( ax => 59, ay => 3, bx => 60, by => 14 ),
153 );
154 0 $self->insert( $sb );
155
156 my $p = TColorItemList->new(
157 bounds => TRect->new( ax => 30, ay => 3, bx => 59, by => 14 ),
158 scrollBar => $sb,
159 items => $aGroups->{items}
160 0 );
161 0 $self->insert( $p );
162 0 $self->insert(
163 TLabel->new(
164 bounds => TRect->new( ax => 30, ay => 2, bx => 36, by => 3 ),
165 text => $itemText,
166 link => $p,
167 )
168 );
169
170 0 $self->{forSel} = TColorSelector->new(
171 bounds => TRect->new( ax => 63, ay => 3, bx => 75, by => 7 ),
172 selType => csForeground,
173 );
174 0 $self->insert( $self->{forSel} );
175 $self->{forLabel} = TLabel->new(
176 bounds => TRect->new( ax => 63, ay => 2, bx => 75, by => 3 ),
177 text => $forText,
178 link => $self->{forSel},
179 0 );
180 0 $self->insert( $self->{forLabel} );
181
182 0 $self->{bakSel} = TColorSelector->new(
183 bounds => TRect->new( ax => 63, ay => 9, bx => 75, by => 11 ),
184 selType => csBackground,
185 );
186 0 $self->insert( $self->{bakSel} );
187 $self->{bakLabel} = TLabel->new(
188 bounds => TRect->new( ax => 63, ay => 8, bx => 75, by => 9 ),
189 text => $bakText,
190 link => $self->{bakSel},
191 0 );
192 0 $self->insert( $self->{bakLabel} );
193
194 0 $self->{display} = TColorDisplay->new(
195 bounds => TRect->new( ax => 62, ay => 12, bx => 76, by => 14 ),
196 text => $textText,
197 );
198 0 $self->insert( $self->{display} );
199
200 0 $self->{monoSel} = TMonoSelector->new(
201 bounds => TRect->new( ax => 62, ay => 3, bx => 77, by => 7 ),
202 );
203 0 $self->{monoSel}->hide();
204 0 $self->insert( $self->{monoSel} );
205 $self->{monoLabel} = TLabel->new(
206 bounds => TRect->new( ax => 62, ay => 2, bx => 77, by => 3 ),
207 text => $colorText,
208 link => $self->{monoSel},
209 0 );
210 0 $self->{monoLabel}->hide();
211 0 $self->insert( $self->{monoLabel} );
212
213 0 $self->insert( TButton->new(
214 bounds => TRect->new( ax => 51, ay => 15, bx => 61, by => 17 ),
215 title => $okText,
216 command => cmOK,
217 flags => bfDefault,
218 ));
219 0 $self->insert( TButton->new(
220 bounds => TRect->new( ax => 35, ay => 15, bx => 45, by => 17 ),
221 title => $cancelText,
222 command => cmCancel,
223 flags => bfNormal,
224 ));
225 0 $self->selectNext( false );
226
227 $self->setData( $self->{pal} )
228 0 ▶ if $self->{pal};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"pal"} 0 0 0
229 0 return;
230 }
231
232 0 ▶sub from { # $obj ($aPalette|undef, $aGroups|undef)
Subroutine from: not called CC=1 SCAR=6.9
Pod undocumented
233 0 state $sig = signature(
234 method => 1,
235 pos => [Maybe[Object], Maybe[Object]],
236 );
237 0 my ( $class, @args ) = $sig->( @_ );
238 0 return $class->new( pal => $args[0], groups => $args[1] );
239 }
240
241 0 ▶sub dataSize { # $dSize ()
Subroutine dataSize: not called CC=1 SCAR=6.9
Pod documented
242 0 state $sig = signature(
243 method => Object,
244 pos => [],
245 );
246 0 $sig->( @_ );
247 0 return 1;
248 }
249
250 0 ▶sub getData { # void (\@rec)
Subroutine getData: not called CC=1 SCAR=6.9
Pod documented
251 0 state $sig = signature(
252 method => Object,
253 pos => [ArrayLike],
254 );
255 0 my ( $self, $rec ) = $sig->( @_ );
256 0 $self->getIndexes( $colorIndexes );
257 0 $rec->[0] = $self->{pal}->clone();
258 0 return;
259 }
260
261 0 ▶sub handleEvent { # void ($event)
Subroutine handleEvent: not called CC=5 SCAR=34.0
Pod documented
262 0 state $sig = signature(
263 method => Object,
264 pos => [Object],
265 );
266 0 my ( $self, $event ) = $sig->( @_ );
267 $self->{groupIndex} = $self->{groups}->focused()
268 if $event->{what} == evBroadcast
269 0 ▶ && $event->{message}{command} == cmNewColorItem;
Branch: 1 branch
BranchTrueFalseTotal
if $event->{"what"} == 512 and $event->{"message"}{"command"} == 74 0 0 0
Condition0%0/3
$event->{"what"} == 512 and $event->{"message"}{"command"} == 74
!ll&&!rl&&r
000
MC/DC0%0/2
$event->{"what"} == 512 and $event->{"message"}{"command"} == 74
$event->{"what"} == 512 $event->{"message"}{"command"} == 74
Truth table0%0/3
A and B
A= $event->{"what"} == 512B= $event->{"message"}{"command"} == 74
ABresult
0X0
100
111
270 0 $self->SUPER::handleEvent( $event );
271 $self->{display}->setColor(
272 \( $self->{pal}->[ $event->{message}{infoByte} ] )
273 ) if $event->{what} == evBroadcast
274 0 ▶ && $event->{message}{command} == cmNewColorIndex;
Branch: 1 branch
BranchTrueFalseTotal
if $event->{"what"} == 512 and $event->{"message"}{"command"} == 75 0 0 0
Condition0%0/3
$event->{"what"} == 512 and $event->{"message"}{"command"} == 75
!ll&&!rl&&r
000
MC/DC0%0/2
$event->{"what"} == 512 and $event->{"message"}{"command"} == 75
$event->{"what"} == 512 $event->{"message"}{"command"} == 75
Truth table0%0/3
A and B
A= $event->{"what"} == 512B= $event->{"message"}{"command"} == 75
ABresult
0X0
100
111
275 0 return;
276 }
277
278 0 ▶sub setData { # void (\@rec)
Subroutine setData: not called CC=2 SCAR=17.9
Pod documented
279 0 state $sig = signature(
280 method => Object,
281 pos => [ArrayLike],
282 );
283 0 my ( $self, $rec ) = $sig->( @_ );
284 0 $self->{pal} = $rec->[0]->clone();
285
286 0 $self->setIndexes( $colorIndexes );
287 $self->{display}->setColor(
288 \( $self->{pal}->[
289 $self->{groups}->getGroupIndex( $self->{groupIndex} )
290 0 ] )
291 );
292 0 $self->{groups}->focusItem( $self->{groupIndex} );
293 0 ▶ if ( $showMarkers ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($TUI::ColorSel::ColorDialog::showMarkers) 0 0 0
294 0 $self->{forLabel}->hide();
295 0 $self->{forSel}->hide();
296 0 $self->{bakLabel}->hide();
297 0 $self->{bakSel}->hide();
298 0 $self->{monoLabel}->show();
299 0 $self->{monoSel}->show();
300 }
301 0 $self->{groups}->select();
302 0 return;
303 }
304
305 0 ▶sub setIndexes { # void (\@colIdx)
Subroutine setIndexes: not called CC=5 SCAR=30.9
Pod undocumented
306 4 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
307 0 state $sig = signature(
308 method => Object,
309 pos => [ArrayLike],
310 );
311 0 my ( $self, $colIdx ) = $sig->( @_ );
312 0 my ( $numGroups, $index );
313
314 0 $numGroups = $self->{groups}->getNumGroups();
315 0 ▶ if ( $colIdx && ( $colIdx->[colorSize] != $numGroups ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($colIdx and $colIdx->[1] != $numGroups) 0 0 0
Condition0%0/3
$colIdx and $colIdx->[1] != $numGroups
!ll&&!rl&&r
000
MC/DC0%0/2
$colIdx and $colIdx->[1] != $numGroups
$colIdx $colIdx->[1] != $numGroups
Truth table0%0/3
A and B
A= $colIdxB= $colIdx->[1] != $numGroups
ABresult
0X0
100
111
316 0 @$colIdx = ()
317 }
318 0 ▶ if ( !@$colIdx ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$colIdx) 0 0 0
319 0 $colIdx->[groupIndex] = 0;
320 0 $colIdx->[colorIndex] = [ 0 .. $numGroups - 1 ],
321 $colIdx->[colorSize] = $numGroups,
322 }
323 0 ▶ for ( $index = 0 ; $index < $numGroups ; $index++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index < $numGroups) 0 0 0
324 0 $self->{groups}->setGroupIndex( $index, $colIdx->[colorIndex][$index] );
325 }
326
327 0 $self->{groupIndex} = $colIdx->[groupIndex];
328 0 return;
329 }
330
331 0 ▶sub getIndexes { # void (\@colIdx)
Subroutine getIndexes: not called CC=3 SCAR=24.8
Pod undocumented
332 0 state $sig = signature(
333 method => Object,
334 pos => [ArrayLike],
335 );
336 0 my ( $self, $colIdx ) = $sig->( @_ );
337 0 my $n = $self->{groups}->getNumGroups();
338 0 ▶ if ( !@$colIdx ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$colIdx) 0 0 0
339 0 $colIdx->[groupIndex] = 0;
340 0 $colIdx->[colorIndex] = [ 0 .. $n - 1 ],
341 $colIdx->[colorSize] = $n,
342 }
343 0 $colIdx->[groupIndex] = $self->{groupIndex};
344 0 ▶ for ( my $index = 0 ; $index < $n ; $index++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index < $n) 0 0 0
345 0 $colIdx->[colorIndex][$index] = $self->{groups}->getGroupIndex( $index );
346 }
347 0 return;
348 }
349
350 4 1
351
352 __END__
« lib/TUI/Dialogs/Util.pm ↑ Summary lib/TUI/toolkit/UO/Antlers.pm »