lib/TUI/ColorSel/ColorDialog.pm

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