| 1 | |||||||||||||||||||||||||||||||||
| 2 | # Games-Console - a 2D quake-style console | ||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||
| 4 | package Games::Console; | ||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | # (C) by Tels <http://bloodgate.com/> | ||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use vars qw/$VERSION/; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | 2 | $VERSION = '0.04'; | |||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | ############################################################################## | ||||||||||||||||||||||||||||||||
| 14 | # methods | ||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | sub new | ||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=14 SCAR=27.6
Pod
documented
| |||||||||||||||||||||||||||||||||
| 18 | # create a new console | ||||||||||||||||||||||||||||||||
| 19 | 1 | my $class = shift; | |||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | 1 | my $self = { }; | |||||||||||||||||||||||||||||||
| 22 | 1 | bless $self, $class; | |||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 1 | my $args = $_[0]; | |||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | $args = { @_ } unless ref $args eq 'HASH'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | 1 | ▶ | $self->{background_color} = $args->{background} || [0.4, 0.6, 1]; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'background'} || [0.4, 0.6, 1]
MC/DC0%0/1
$args->{'background'} || [0.4, 0.6, 1]
$args->{'background'}
Truth table50%1/2
A
A= $args->{'background'}
| |||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | $self->{background_alpha} = $args->{background_alpha} || 0.5; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'background_alpha'} || 0.5
MC/DC0%0/1
$args->{'background_alpha'} || 0.5
$args->{'background_alpha'}
Truth table50%1/2
A
A= $args->{'background_alpha'}
| |||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | $self->{text_color} = $args->{text_color} || [ 0.4, 0.6, 0.8 ]; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'text_color'} || [0.4, 0.6, 0.8]
MC/DC0%0/1
$args->{'text_color'} || [0.4, 0.6, 0.8]
$args->{'text_color'}
Truth table50%1/2
A
A= $args->{'text_color'}
| |||||||||||||||||||||||||||||||||
| 31 | 1 | ▶ | $self->{text_alpha} = $args->{text_alpha} || 0.8; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'text_alpha'} || 0.8
MC/DC0%0/1
$args->{'text_alpha'} || 0.8
$args->{'text_alpha'}
Truth table50%1/2
A
A= $args->{'text_alpha'}
| |||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | $self->{max_msg} = $args->{backbuffer_size} || 100; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'backbuffer_size'} || 100
MC/DC0%0/1
$args->{'backbuffer_size'} || 100
$args->{'backbuffer_size'}
Truth table50%1/2
A
A= $args->{'backbuffer_size'}
| |||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | 1 | $self->{font} = $args->{font}; | |||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | # maximum height/width in percent | ||||||||||||||||||||||||||||||||
| 38 | 1 | ▶ | $self->{width} = abs($self->{width} || 100); | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'width'} || 100
MC/DC0%0/1
$self->{'width'} || 100
$self->{'width'}
Truth table50%1/2
A
A= $self->{'width'}
| |||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | $self->{height} = abs($args->{height} || 50); | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'height'} || 50
MC/DC0%0/1
$args->{'height'} || 50
$args->{'height'}
Truth table50%1/2
A
A= $args->{'height'}
| |||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | $self->{width} = 100 if $self->{width} > 100; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 41 | 1 | ▶ | $self->{height} = 100 if $self->{height} > 100; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | 1 | $self->{screen_width} = 640; | |||||||||||||||||||||||||||||||
| 44 | 1 | $self->{screen_height} = 480; | |||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | 1 | $self->{direction} = 1; | |||||||||||||||||||||||||||||||
| 47 | # in percent per second (50 means it takes 2 seconds to open console) | ||||||||||||||||||||||||||||||||
| 48 | 1 | $self->{speed} = 50; | |||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | 1 | $self->{start_percent} = 0; # started moving at this percentage | |||||||||||||||||||||||||||||||
| 51 | 1 | $self->{start_time} = 0; # and this time | |||||||||||||||||||||||||||||||
| 52 | 1 | $self->{cur_percent} = 0; # cur percent visible | |||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | 1 | $self->{messages} = []; | |||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | 1 | $self->{spacing_y} = 0; | |||||||||||||||||||||||||||||||
| 57 | 1 | $self->{border_x} = 5; | |||||||||||||||||||||||||||||||
| 58 | 1 | $self->{border_y} = 5; | |||||||||||||||||||||||||||||||
| 59 | 1 | ▶ | $self->{prompt} = $args->{prompt} || '> '; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'prompt'} || '> '
MC/DC0%0/1
$args->{'prompt'} || '> '
$args->{'prompt'}
Truth table50%1/2
A
A= $args->{'prompt'}
| |||||||||||||||||||||||||||||||||
| 60 | 1 | ▶ | $self->{cursor} = $args->{cursor} || '_'; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'cursor'} || '_'
MC/DC0%0/1
$args->{'cursor'} || '_'
$args->{'cursor'}
Truth table50%1/2
A
A= $args->{'cursor'}
| |||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | 1 | $self->{offset} = 0; | |||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | 1 | $self->{last_cursor} = 0; | |||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | $self->{cursor_time} = abs($args->{cursor_time} || 300); | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'cursor_time'} || 300
MC/DC0%0/1
$args->{'cursor_time'} || 300
$args->{'cursor_time'}
Truth table50%1/2
A
A= $args->{'cursor_time'}
| |||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | 1 | $self->{current_input} = ''; # what user entered until ENTER key is pressed | |||||||||||||||||||||||||||||||
| 68 | 1 | $self->{last_input} = [ ]; | |||||||||||||||||||||||||||||||
| 69 | 1 | $self->{last_input_pos} = 0; | |||||||||||||||||||||||||||||||
| 70 | 1 | $self->{max_last_input} = 64; | |||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | 1 | $self->{cur_height} = 0; # invisble | |||||||||||||||||||||||||||||||
| 73 | 1 | $self; | |||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | sub close | ||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
close: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 78 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | $self->{direction} = -1 if $self->{visible}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | sub open | ||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
open: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 85 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | 0 | $self->{direction} = 1; $self->{visible} = 1; | |||||||||||||||||||||||||||||||
| 88 | 0 | $self->{start_time} = shift; | |||||||||||||||||||||||||||||||
| 89 | 0 | $self->{start_percent} = $self->{cur_percent}; | |||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | sub toggle | ||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
toggle: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 94 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | if (!$self->{visible}) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 97 | { | ||||||||||||||||||||||||||||||||
| 98 | 0 | $self->{direction} = 1; $self->{visible} = 1; | |||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||
| 100 | else | ||||||||||||||||||||||||||||||||
| 101 | { | ||||||||||||||||||||||||||||||||
| 102 | 0 | $self->{direction} = - $self->{direction}; | |||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | $self->{direction} = -1 if $self->{direction} == 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||
| 105 | 0 | $self->{start_time} = shift; | |||||||||||||||||||||||||||||||
| 106 | 0 | $self->{start_percent} = $self->{cur_percent}; | |||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||
| 109 | sub visible | ||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
visible: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||
| 111 | # make immidiately visible/invisible | ||||||||||||||||||||||||||||||||
| 112 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | if (@_ > 0) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 115 | { | ||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | my $v = $_[0] ? 1 : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | if ($self->{visible} && !$v) | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$self->{"visible"} and not $v
MC/DC0%0/2
$self->{"visible"} and not $v
$self->{"visible"}
not $v
Truth table0%0/3
A and not(B)
A= $self->{"visible"}B= not $v
| |||||||||||||||||||||||||||||||||
| 118 | { | ||||||||||||||||||||||||||||||||
| 119 | 0 | $self->{direction} = 0; | |||||||||||||||||||||||||||||||
| 120 | 0 | $self->{cur_percent} = 0; | |||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||
| 122 | ▶ | elsif (!$self->{visible} && $v) | |||||||||||||||||||||||||||||||
|
Condition0%0/3
not $self->{"visible"} and $v
MC/DC0%0/2
not $self->{"visible"} and $v
not $self->{"visible"}
$v
Truth table0%0/3
not(A) and B
A= not $self->{"visible"}B= $v
| |||||||||||||||||||||||||||||||||
| 123 | { | ||||||||||||||||||||||||||||||||
| 124 | 0 | $self->{direction} = 1; | |||||||||||||||||||||||||||||||
| 125 | 0 | $self->{start_percent} = 0; | |||||||||||||||||||||||||||||||
| 126 | 0 | $self->{start_time} = shift; | |||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||
| 128 | 0 | $self->{visible} = $v; | |||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||
| 130 | 0 | $self->{visible}; | |||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||
| 133 | sub render | ||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
render: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 135 | 0 | my ($self,$current_time) = @_; | |||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | return unless $self->{visible}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | if ($self->{direction} != 0) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 140 | { | ||||||||||||||||||||||||||||||||
| 141 | $self->{cur_percent} = $self->{start_percent} + | ||||||||||||||||||||||||||||||||
| 142 | $self->{direction} * ($current_time - $self->{start_time}) * | ||||||||||||||||||||||||||||||||
| 143 | 0 | $self->{speed} / 100; | |||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | if ($self->{cur_percent} < 0) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 147 | { | ||||||||||||||||||||||||||||||||
| 148 | # fully closed | ||||||||||||||||||||||||||||||||
| 149 | 0 | $self->{cur_percent} = 0; | |||||||||||||||||||||||||||||||
| 150 | 0 | $self->{start_percent} = 0; | |||||||||||||||||||||||||||||||
| 151 | 0 | $self->{direction} = 0; | |||||||||||||||||||||||||||||||
| 152 | 0 | $self->{visible} = 0; | |||||||||||||||||||||||||||||||
| 153 | 0 | return; | |||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | if ($self->{cur_percent} > 100) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 157 | { | ||||||||||||||||||||||||||||||||
| 158 | # fully open | ||||||||||||||||||||||||||||||||
| 159 | 0 | $self->{cur_percent} = 100; | |||||||||||||||||||||||||||||||
| 160 | 0 | $self->{direction} = 0; | |||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||
| 163 | # calculate height/width | ||||||||||||||||||||||||||||||||
| 164 | 0 | my $w = $self->{width} * $self->{screen_width} / 100; | |||||||||||||||||||||||||||||||
| 165 | my $h = ($self->{cur_percent} / 100) | ||||||||||||||||||||||||||||||||
| 166 | 0 | * $self->{height} * $self->{screen_height} / 100; | |||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||
| 168 | 0 | $self->_render( 0, $self->{screen_height}, $w, $h, $current_time ); | |||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||
| 172 | sub _render | ||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
_render: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 174 | # prepare the output, render the background and the text | ||||||||||||||||||||||||||||||||
| 175 | 0 | my ($self,$x,$y,$w,$h,$time) = @_; | |||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||
| 179 | sub message | ||||||||||||||||||||||||||||||||
| 180 | 1 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
message: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 181 | 1 | my ($self,$msg) = @_; | |||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||
| 183 | 1 | my $m = $self->{messages}; # shortcut | |||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||
| 185 | 1 | push @$m, [ $msg ]; | |||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||
| 187 | 1 | ▶ | shift @$m while (scalar @$m > $self->{max_msg}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||
| 189 | 1 | $self; | |||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||
| 192 | sub screen_width | ||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
screen_width: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 194 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | if (@_ > 0) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 197 | { | ||||||||||||||||||||||||||||||||
| 198 | 0 | $self->{screen_width} = $_[0]; | |||||||||||||||||||||||||||||||
| 199 | 0 | $self->{font}->screen_width($_[0]); | |||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||
| 201 | 0 | $self->{screen_width}; | |||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||
| 204 | sub screen_height | ||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
screen_height: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 206 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | if (@_ > 0) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 209 | { | ||||||||||||||||||||||||||||||||
| 210 | 0 | $self->{screen_height} = $_[0]; | |||||||||||||||||||||||||||||||
| 211 | 0 | $self->{font}->screen_height($_[0]); | |||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||
| 213 | 0 | $self->{screen_height}; | |||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||
| 216 | sub background_color | ||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
background_color: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 218 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | $self->{background_color} = shift if @_ > 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 221 | 0 | $self->{background_color}; | |||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||
| 224 | sub text_color | ||||||||||||||||||||||||||||||||
| 225 | 1 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
text_color: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 226 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||
| 228 | 1 | ▶ | $self->{text_color} = shift if @_ > 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 229 | 1 | $self->{text_color}; | |||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||
| 232 | sub background_alpha | ||||||||||||||||||||||||||||||||
| 233 | 1 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
background_alpha: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 234 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||
| 236 | 1 | ▶ | $self->{background_alpha} = shift if @_ > 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 237 | 1 | $self->{background_alpha}; | |||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||
| 240 | sub text_alpha | ||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
text_alpha: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 242 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | $self->{text_alpha} = shift if @_ > 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 245 | 0 | $self->{text_alpha}; | |||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||
| 248 | sub width | ||||||||||||||||||||||||||||||||
| 249 | 5 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
width: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 250 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||
| 252 | 5 | ▶ | if (@_ > 0) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 253 | { | ||||||||||||||||||||||||||||||||
| 254 | 4 | $self->{width} = abs(shift); | |||||||||||||||||||||||||||||||
| 255 | 4 | ▶ | $self->{width} = 100 if $self->{width} > 100; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||
| 257 | 5 | $self->{width}; | |||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||
| 260 | sub height | ||||||||||||||||||||||||||||||||
| 261 | 4 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
height: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 262 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||
| 264 | 4 | ▶ | if (@_ > 0) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 265 | { | ||||||||||||||||||||||||||||||||
| 266 | 3 | $self->{height} = abs(shift); | |||||||||||||||||||||||||||||||
| 267 | 3 | ▶ | $self->{height} = 100 if $self->{height} > 100; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||
| 269 | 4 | $self->{height}; | |||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||
| 272 | sub speed | ||||||||||||||||||||||||||||||||
| 273 | 4 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
speed: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 274 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||
| 276 | 4 | ▶ | if (@_ > 0) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 277 | { | ||||||||||||||||||||||||||||||||
| 278 | 3 | $self->{speed} = abs(shift); | |||||||||||||||||||||||||||||||
| 279 | 3 | ▶ | $self->{speed} = 100 if $self->{speed} > 100; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||
| 281 | 4 | $self->{speed}; | |||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||
| 284 | sub backbuffer_size | ||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
backbuffer_size: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 286 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | $self->{max_msg} = abs(shift) if @_ > 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 289 | 0 | $self->{max_msg}; | |||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||
| 292 | sub cursor | ||||||||||||||||||||||||||||||||
| 293 | 2 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
cursor: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 294 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||
| 296 | 2 | ▶ | $self->{cursor} = $_[0] if @_ > 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 297 | 2 | $self->{cursor}; | |||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||
| 300 | sub prompt | ||||||||||||||||||||||||||||||||
| 301 | 2 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
prompt: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 302 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||
| 304 | 2 | ▶ | $self->{prompt} = $_[0] if @_ > 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 305 | 2 | $self->{prompt}; | |||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||
| 308 | sub backspace | ||||||||||||||||||||||||||||||||
| 309 | 4 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
backspace: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 310 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||
| 312 | 4 | ▶ | if ($self->{current_input} ne '') | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 313 | { | ||||||||||||||||||||||||||||||||
| 314 | 3 | substr($self->{current_input},-1,1) = ''; | |||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||
| 316 | 4 | $self->{current_input}; | |||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||
| 319 | sub autocomplete | ||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
autocomplete: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 321 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||
| 323 | 0 | $self->{last_input_pos} = 0; | |||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||
| 326 | sub input | ||||||||||||||||||||||||||||||||
| 327 | 5 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
input: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 328 | # get/set the current_input buffer | ||||||||||||||||||||||||||||||||
| 329 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||
| 331 | 5 | ▶ | if (@_ > 0) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 332 | { | ||||||||||||||||||||||||||||||||
| 333 | 5 | my $m = $self->{last_input}; | |||||||||||||||||||||||||||||||
| 334 | 5 | unshift @$m, $self->{current_input}; | |||||||||||||||||||||||||||||||
| 335 | 5 | ▶ | pop @$m while (scalar @$m > $self->{max_last_input}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 336 | 5 | $self->{current_input} = $_[0]; | |||||||||||||||||||||||||||||||
| 337 | 5 | $self->{last_input_pos} = 0; | |||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||
| 339 | 5 | $self->{current_input}; | |||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||
| 342 | sub last_input | ||||||||||||||||||||||||||||||||
| 343 | 1 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
last_input: called CC=8 SCAR=25.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 344 | # set the current_input buffer to the last entered input | ||||||||||||||||||||||||||||||||
| 345 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||
| 346 | 1 | ▶ | my $dir = shift || 0; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || 0
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||
| 348 | 1 | my $m = $self->{last_input}; | |||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||
| 350 | 1 | my $pos = $self->{last_input_pos}; | |||||||||||||||||||||||||||||||
| 351 | 1 | ▶ | if ($pos < 0 || $pos >= scalar @$m) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$pos < 0 or $pos >= scalar @$m
MC/DC0%0/2
$pos < 0 or $pos >= scalar @$m
$pos < 0
$pos >= scalar @$m
Truth table33%1/3
A or B
A= $pos < 0B= $pos >= scalar @$m
| |||||||||||||||||||||||||||||||||
| 352 | { | ||||||||||||||||||||||||||||||||
| 353 | 0 | $self->{current_input} = ''; | |||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||
| 355 | else | ||||||||||||||||||||||||||||||||
| 356 | { | ||||||||||||||||||||||||||||||||
| 357 | 1 | ▶ | $self->{current_input} = $m->[$pos] if scalar @$m > 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||
| 359 | 1 | ▶ | if ($dir >= 0) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 360 | { | ||||||||||||||||||||||||||||||||
| 361 | 1 | ▶ | $pos++ if $pos < scalar @$m; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||
| 363 | else | ||||||||||||||||||||||||||||||||
| 364 | { | ||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | $pos-- if $pos >= 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||
| 367 | 1 | $self->{last_input_pos} = $pos; | |||||||||||||||||||||||||||||||
| 368 | 1 | $self->{current_input}; | |||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||
| 371 | sub add_input | ||||||||||||||||||||||||||||||||
| 372 | 1 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
add_input: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 373 | # add more text to the current_input buffer | ||||||||||||||||||||||||||||||||
| 374 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||
| 376 | 1 | $self->{current_input} .= $_[0]; | |||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||
| 379 | sub scroll | ||||||||||||||||||||||||||||||||
| 380 | 1 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
scroll: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 381 | 1 | my ($self,$ofs) = @_; | |||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||
| 383 | 1 | $self->{offset} += $ofs; | |||||||||||||||||||||||||||||||
| 384 | 1 | print $self->{offset},"\n"; | |||||||||||||||||||||||||||||||
| 385 | 1 | ▶ | $self->{offset} = 0 if $self->{offset} < 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 386 | 1 | $self->{offset} = scalar @{$self->{messages}} | |||||||||||||||||||||||||||||||
| 387 | 1 | ▶ | if $self->{offset} >= scalar @{$self->{messages}}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 388 | 1 | print $self->{offset},"\n"; | |||||||||||||||||||||||||||||||
| 389 | 1 | $self->{offset}; | |||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||
| 392 | sub offset | ||||||||||||||||||||||||||||||||
| 393 | 2 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
offset: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 394 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||
| 396 | 2 | $self->{offset}; | |||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||
| 399 | sub messages | ||||||||||||||||||||||||||||||||
| 400 | 2 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
messages: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 401 | # return number of messages in backbuffer | ||||||||||||||||||||||||||||||||
| 402 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||
| 404 | 2 | scalar @{$self->{messages}}; | |||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||
| 407 | sub clear | ||||||||||||||||||||||||||||||||
| 408 | 1 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
clear: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 409 | # clear backbuffer | ||||||||||||||||||||||||||||||||
| 410 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||
| 412 | 1 | $self->{messages} = []; | |||||||||||||||||||||||||||||||
| 413 | 1 | $self; | |||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||
| 416 | 2 | 1; | |||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||
| 418 | __END__ | ||||||||||||||||||||||||||||||||