| 1 | package TUI::ColorSel::ColorDisplay; | ||||||||||
| 2 | # ABSTRACT: color preview view for the color selection dialog | ||||||||||
| 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.000002'; | |||||||||
| 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 | TColorDisplay | ||||||||||
| 15 | new_TColorDisplay | ||||||||||
| 16 | ); | ||||||||||
| 17 | |||||||||||
| 18 | 5 | ▶ | use TUI::toolkit; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 5 | ▶ | use TUI::toolkit::Types qw( | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | :is | ||||||||||
| 21 | :types | ||||||||||
| 22 | 5 | ); | |||||||||
| 23 | |||||||||||
| 24 | 5 | ▶ | use TUI::Drivers::Const qw( evBroadcast ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | 5 | ▶ | use TUI::Drivers::ColorAttr; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 5 | ▶ | use TUI::ColorSel::Const qw( :cmXXXX ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 5 | ▶ | use TUI::Views::DrawBuffer; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 5 | ▶ | use TUI::Views::View; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 5 | ▶ | use TUI::Views::Util qw( message ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | |||||||||||
| 31 | sub TColorDisplay() { __PACKAGE__ } | ||||||||||
| 32 | sub name() { 'TColorDisplay' } | ||||||||||
| 33 | 0 | ▶ | sub new_TColorDisplay { __PACKAGE__->from(@_) } | ||||||||
|
Subroutine
new_TColorDisplay: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 34 | |||||||||||
| 35 | 5 | extends TView; | |||||||||
| 36 | |||||||||||
| 37 | # import global variables | ||||||||||
| 38 | 5 | ▶ | use vars qw( | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 39 | $errorAttr | ||||||||||
| 40 | 5 | ); | |||||||||
| 41 | { | ||||||||||
| 42 | 5 | ▶ | no strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 43 | 5 | *errorAttr = \${ TView . '::errorAttr' }; | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | # protected attributes | ||||||||||
| 47 | 0 | ▶ | has color => ( is => 'ro', default => sub { my $color = 0; \$color } ); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||
| 48 | 0 | ▶ | has text => ( is => 'ro', default => sub { die 'required' } ); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 49 | |||||||||||
| 50 | 0 | ▶ | sub BUILDARGS { # \%args (%args) | ||||||||
|
Subroutine
BUILDARGS: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 51 | 0 | state $sig = signature( | |||||||||
| 52 | method => 1, | ||||||||||
| 53 | named => [ | ||||||||||
| 54 | bounds => Object, | ||||||||||
| 55 | text => Str, { alias => 'aText' }, | ||||||||||
| 56 | ], | ||||||||||
| 57 | caller_level => +1, | ||||||||||
| 58 | ); | ||||||||||
| 59 | 0 | my ( $class, $args ) = $sig->( @_ ); | |||||||||
| 60 | 0 | return { %$args }; | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 0 | ▶ | sub BUILD { # void (\%args) | ||||||||
|
Subroutine
BUILD: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 64 | 0 | my ( $self, $args ) = @_; | |||||||||
| 65 | 0 | ▶ | assert ( @_ == 2 ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 0 | ▶ | assert ( is_Object $self ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 0 | $self->{eventMask} |= evBroadcast; | |||||||||
| 68 | 0 | return; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 0 | ▶ | sub from { # $obj ($bounds, $aText) | ||||||||
|
Subroutine
from: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 72 | 0 | state $sig = signature( | |||||||||
| 73 | method => 1, | ||||||||||
| 74 | pos => [Object, Str], | ||||||||||
| 75 | ); | ||||||||||
| 76 | 0 | my ( $class, @args ) = $sig->( @_ ); | |||||||||
| 77 | 0 | return $class->new( bounds => $args[0], text => $args[1] ); | |||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | 0 | ▶ | sub DEMOLISH { # void ($in_global_destruction) | ||||||||
|
Subroutine
DEMOLISH: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 81 | 0 | my ( $self, $in_global_destruction ) = @_; | |||||||||
| 82 | 0 | ▶ | assert ( @_ == 2 ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | 0 | ▶ | assert ( is_Object $self ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 84 | 0 | $self->{text} = undef; | |||||||||
| 85 | 0 | return; | |||||||||
| 86 | } | ||||||||||
| 87 | |||||||||||
| 88 | 0 | ▶ | sub draw { # void () | ||||||||
|
Subroutine
draw: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 89 | 0 | state $sig = signature( | |||||||||
| 90 | method => Object, | ||||||||||
| 91 | pos => [], | ||||||||||
| 92 | ); | ||||||||||
| 93 | 0 | my ( $self ) = $sig->( @_ ); | |||||||||
| 94 | 0 | my $c = 0 + ${ $self->{color} }; | |||||||||
| 95 | 0 | my $b = TDrawBuffer->new(); | |||||||||
| 96 | 0 | ▶ | $c = $errorAttr | ||||||||
|
Branch: 1 branch
| |||||||||||
| 97 | if $c == 0; | ||||||||||
| 98 | 0 | my $len = length( $self->{text} ); | |||||||||
| 99 | 0 | ▶ | for ( my $i = 0; $i <= int( $self->{size}{x} / $len ); $i++ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 100 | 0 | $b->moveStr( $i * $len, $self->{text}, $c ); | |||||||||
| 101 | } | ||||||||||
| 102 | 0 | $self->writeLine( 0, 0, $self->{size}{x}, $self->{size}{y}, $b ); | |||||||||
| 103 | 0 | return; | |||||||||
| 104 | } | ||||||||||
| 105 | |||||||||||
| 106 | 0 | ▶ | sub handleEvent { # void ($event) | ||||||||
|
Subroutine
handleEvent: not called CC=7 SCAR=38.2
Pod
documented
| |||||||||||
| 107 | 5 | ▶ | no warnings 'uninitialized'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 108 | 0 | state $sig = signature( | |||||||||
| 109 | method => Object, | ||||||||||
| 110 | pos => [Object], | ||||||||||
| 111 | ); | ||||||||||
| 112 | 0 | my ( $self, $event ) = $sig->( @_ ); | |||||||||
| 113 | 0 | $self->SUPER::handleEvent( $event ); | |||||||||
| 114 | 0 | ▶ | if ( $event->{what} == evBroadcast ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 115 | 0 | SWITCH: for ( $event->{message}{command} ) { | |||||||||
| 116 | 0 | ▶ | cmColorBackgroundChanged == $_ and do { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 117 | 0 | ▶ | if ( ref ${ $self->{color} } ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 118 | 0 | ${ $self->{color} }->setBackground( | |||||||||
| 119 | 0 | $event->{message}{infoByte} & 0xf | |||||||||
| 120 | ); | ||||||||||
| 121 | } | ||||||||||
| 122 | else { | ||||||||||
| 123 | 0 | ${ $self->{color} } = ( ${ $self->{color} } & 0x0f ) | |||||||||
| 124 | 0 | | ( ( $event->{message}{infoByte} & 0xf ) << 4 ); | |||||||||
| 125 | } | ||||||||||
| 126 | 0 | $self->drawView(); | |||||||||
| 127 | 0 | last; | |||||||||
| 128 | }; | ||||||||||
| 129 | 0 | ▶ | cmColorForegroundChanged == $_ and do { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 130 | 0 | ▶ | if ( ref ${ $self->{color} } ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 131 | 0 | ${ $self->{color} }->setForeground( | |||||||||
| 132 | 0 | $event->{message}{infoByte} & 0xf | |||||||||
| 133 | ); | ||||||||||
| 134 | } | ||||||||||
| 135 | else { | ||||||||||
| 136 | 0 | ${ $self->{color} } = ( ${ $self->{color} } & 0xf0 ) | |||||||||
| 137 | 0 | | ( $event->{message}{infoByte} & 0xf ); | |||||||||
| 138 | } | ||||||||||
| 139 | 0 | $self->drawView(); | |||||||||
| 140 | 0 | last; | |||||||||
| 141 | }; | ||||||||||
| 142 | } | ||||||||||
| 143 | } | ||||||||||
| 144 | 0 | return; | |||||||||
| 145 | } | ||||||||||
| 146 | |||||||||||
| 147 | 0 | ▶ | sub setColor { # void (\$aColor) | ||||||||
|
Subroutine
setColor: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 148 | 0 | state $sig = signature( | |||||||||
| 149 | method => Object, | ||||||||||
| 150 | pos => [ScalarRef], | ||||||||||
| 151 | ); | ||||||||||
| 152 | 0 | my ( $self, $aColor ) = $sig->( @_ ); | |||||||||
| 153 | 0 | $self->{color} = $aColor; | |||||||||
| 154 | 0 | message( $self->{owner}, evBroadcast, cmColorSet, 0 + $$aColor ); | |||||||||
| 155 | 0 | $self->drawView(); | |||||||||
| 156 | 0 | return; | |||||||||
| 157 | } | ||||||||||
| 158 | |||||||||||
| 159 | 5 | 1 | |||||||||
| 160 | |||||||||||
| 161 | __END__ | ||||||||||