« tools/lib/Term/Fabulous/Screenshot/Scene.pm
↑ Summary
blib/lib/Term/Fabulous/Widget/Table/Style.pm »
| 1 | package Term::Fabulous::Render::Rectangle; | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use v5.32; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use feature 'signatures'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | no warnings 'experimental::signatures'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||
| 8 | 1 | our $VERSION = '0.05'; | |||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Object::Pad 0.825; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||
| 12 | role Term::Fabulous::Render::Rectangle { | ||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Term::Fabulous::Termbox qw(TB_DEFAULT TB_REVERSE); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Term::Fabulous::Render::Attr qw(color_attr clay_color blended_bg_attr blended_fg_attr); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Term::Fabulous::Render::Geometry qw(visible_cell_rect); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Term::Fabulous::Unicode qw(cluster_columns); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||
| 18 | # The cells the command being painted may touch (Term::Fabulous::Render). | ||||||||||||||||||||||||||||||||||
| 19 | 1 | method clip_rect; | |||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||
| 21 | # The cell target the frame is painted into (Term::Fabulous::Render). | ||||||||||||||||||||||||||||||||||
| 22 | 1 | method cell_target; | |||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||
| 24 | # Paints the visible (clipped) part of the box in the background color | ||||||||||||||||||||||||||||||||||
| 25 | # and records the resulting background of every cell in the shadow | ||||||||||||||||||||||||||||||||||
| 26 | # buffer. An opaque color fills the rows; a translucent one is blended | ||||||||||||||||||||||||||||||||||
| 27 | # with what the shadow buffer holds below it, and either covers the | ||||||||||||||||||||||||||||||||||
| 28 | # glyphs there or leaves them showing through, as the widget asks. | ||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | method render_rectangle ( $command, $widget, $buffer ) { | ||||||||||||||||||||||||||||||||
|
Subroutine
render_rectangle: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 30 | 0 | my ( $x0, $y0, $x1, $y1 ) = visible_cell_rect( $command->{boundingBox}, $self->clip_rect ); | |||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | return unless defined $x0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||
| 33 | 0 | my $color = clay_color( $command->{renderData}{backgroundColor} ); | |||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | my $style = _reverse_video($widget) ? TB_REVERSE : 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | my $paint_row = !$color->is_translucent ? \&_paint_opaque_row : _glyphs_show_through($widget) ? \&_paint_tinted_row : \&_paint_covered_row; | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 36 | 0 | my $target = $self->cell_target; | |||||||||||||||||||||||||||||||||
| 37 | 0 | foreach my $y ( $y0 .. $y1 - 1 ) { | |||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | $paint_row->( $target, $color, $style, $buffer->[$y] //= [], $x0, $x1, $y ); | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$buffer->[$y] //= []
MC/DC0%0/1
$buffer->[$y] //= []
$buffer->[$y]
Truth table0%0/2
A
A= $buffer->[$y]
| |||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||
| 40 | 0 | return; | |||||||||||||||||||||||||||||||||
| 41 | 1 | } | |||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub _glyphs_show_through ($widget) { | ||||||||||||||||||||||||||||||||
|
Subroutine
_glyphs_show_through: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | return defined $widget && $widget->isa('Term::Fabulous::Widget') && $widget->glyphs_show_through; | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
defined $widget && $widget->isa('Term::Fabulous::Widget') && $widget->glyphs_show_through
defined $widget and $widget->isa("Term::Fabulous::Widget")
MC/DC0%0/3
defined $widget && $widget->isa('Term::Fabulous::Widget') && $widget->glyphs_show_through
defined $widget
$widget->isa("Term::Fabulous::Widget")
$widget->glyphs_show_through
Truth table0%0/4
A and B && C
A= defined $widgetB= $widget->isa("Term::Fabulous::Widget")C= $widget->glyphs_show_through
| |||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||
| 47 | # A widget drawn in reverse video puts TB_REVERSE into the background of | ||||||||||||||||||||||||||||||||||
| 48 | # its cells; the text and borders painted on top inherit it, so the | ||||||||||||||||||||||||||||||||||
| 49 | # whole widget swaps its colors. | ||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | sub _reverse_video ($widget) { | ||||||||||||||||||||||||||||||||
|
Subroutine
_reverse_video: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | return defined $widget && $widget->isa('Term::Fabulous::Widget') && $widget->reverse_video; | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
defined $widget && $widget->isa('Term::Fabulous::Widget') && $widget->reverse_video
defined $widget and $widget->isa("Term::Fabulous::Widget")
MC/DC0%0/3
defined $widget && $widget->isa('Term::Fabulous::Widget') && $widget->reverse_video
defined $widget
$widget->isa("Term::Fabulous::Widget")
$widget->reverse_video
Truth table0%0/4
A and B && C
A= defined $widgetB= $widget->isa("Term::Fabulous::Widget")C= $widget->reverse_video
| |||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub _paint_opaque_row ( $target, $color, $style, $row, $x0, $x1, $y ) { | ||||||||||||||||||||||||||||||||
|
Subroutine
_paint_opaque_row: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 55 | 0 | my $bg_attr = color_attr($color) | $style; | |||||||||||||||||||||||||||||||||
| 56 | 0 | my $columns = $x1 - $x0; | |||||||||||||||||||||||||||||||||
| 57 | 0 | @{$row}[ $x0 .. $x1 - 1 ] = ($bg_attr) x $columns; | |||||||||||||||||||||||||||||||||
| 58 | 0 | $target->fill_row( $x0, $y, $columns, $bg_attr ); | |||||||||||||||||||||||||||||||||
| 59 | 0 | return; | |||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||
| 62 | # Covers the cells with spaces in the blended color, one fill per run | ||||||||||||||||||||||||||||||||||
| 63 | # of equal color. | ||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub _paint_covered_row ( $target, $color, $style, $row, $x0, $x1, $y ) { | ||||||||||||||||||||||||||||||||
|
Subroutine
_paint_covered_row: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | my @blended = map { blended_bg_attr( $color, $row->[$_] // TB_DEFAULT ) | $style } $x0 .. $x1 - 1; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$row->[$_] // 0
MC/DC0%0/1
$row->[$_] // 0
$row->[$_]
Truth table0%0/2
A
A= $row->[$_]
| |||||||||||||||||||||||||||||||||||
| 66 | 0 | @{$row}[ $x0 .. $x1 - 1 ] = @blended; | |||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||
| 68 | 0 | my $run_start = 0; | |||||||||||||||||||||||||||||||||
| 69 | 0 | foreach my $index ( 1 .. $#blended + 1 ) { | |||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | next if $index <= $#blended && $blended[$index] == $blended[$run_start]; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$index <= $#blended and $blended[$index] == $blended[$run_start]
MC/DC0%0/2
$index <= $#blended and $blended[$index] == $blended[$run_start]
$index <= $#blended
$blended[$index] == $blended[$run_start]
Truth table0%0/3
A and B
A= $index <= $#blendedB= $blended[$index] == $blended[$run_start]
| |||||||||||||||||||||||||||||||||||
| 71 | 0 | $target->fill_row( $x0 + $run_start, $y, $index - $run_start, $blended[$run_start] ); | |||||||||||||||||||||||||||||||||
| 72 | 0 | $run_start = $index; | |||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||
| 74 | 0 | return; | |||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||
| 77 | # Repaints every cell with the glyph the target holds there, its | ||||||||||||||||||||||||||||||||||
| 78 | # foreground tinted; a cell without a glyph becomes a space. The cells | ||||||||||||||||||||||||||||||||||
| 79 | # a wide glyph covers are skipped, like the target does for them. | ||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub _paint_tinted_row ( $target, $color, $style, $row, $x0, $x1, $y ) { | ||||||||||||||||||||||||||||||||
|
Subroutine
_paint_tinted_row: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||
| 81 | 0 | my $covered_until = $x0; | |||||||||||||||||||||||||||||||||
| 82 | 0 | foreach my $x ( $x0 .. $x1 - 1 ) { | |||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | my $bg_attr = $row->[$x] = blended_bg_attr( $color, $row->[$x] // TB_DEFAULT ) | $style; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$row->[$x] // 0
MC/DC0%0/1
$row->[$x] // 0
$row->[$x]
Truth table0%0/2
A
A= $row->[$x]
| |||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | next if $x < $covered_until; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||
| 86 | 0 | my ( $glyph, $fg_attr ) = $target->painted_cell( $x, $y ); | |||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | if ( !defined $glyph || $glyph eq ' ' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $glyph or $glyph eq " "
MC/DC0%0/2
not defined $glyph or $glyph eq " "
not defined $glyph
$glyph eq " "
Truth table0%0/3
not(A) or B
A= not defined $glyphB= $glyph eq " "
| |||||||||||||||||||||||||||||||||||
| 88 | 0 | $target->set_cell( $x, $y, ' ', TB_DEFAULT, $bg_attr ); | |||||||||||||||||||||||||||||||||
| 89 | 0 | next; | |||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||
| 91 | 0 | my ( $base, @extenders ) = split //, $glyph; | |||||||||||||||||||||||||||||||||
| 92 | 0 | $target->set_cell( $x, $y, $base, blended_fg_attr( $color, $fg_attr ), $bg_attr ); | |||||||||||||||||||||||||||||||||
| 93 | 0 | $target->extend_cell( $x, $y, $_ ) foreach @extenders; | |||||||||||||||||||||||||||||||||
| 94 | 0 | $covered_until = $x + cluster_columns($glyph); | |||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||
| 96 | 0 | return; | |||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||
| 100 | 1 | 1; | |||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||
| 102 | __END__ | ||||||||||||||||||||||||||||||||||