| 1 | package TUI::Drivers::Screen; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Global screen and video mode management | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 135 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 135 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 135 | our $VERSION = '2.000003'; | |||||||||||||||||||||||||||
| 8 | 135 | $VERSION =~ tr/_//d; | |||||||||||||||||||||||||||
| 9 | 135 | our $AUTHORITY = 'cpan:BRICKPOOL'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 135 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 135 | our @EXPORT = qw( | |||||||||||||||||||||||||||
| 13 | TScreen | ||||||||||||||||||||||||||||
| 14 | ); | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 135 | ▶ | use PerlX::Assert::PP; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 135 | ▶ | use Scalar::Util qw( looks_like_number ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 135 | ▶ | use TUI::toolkit::boolean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 135 | ▶ | use TUI::Drivers::Const qw( :smXXXX ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 135 | ▶ | use TUI::Drivers::Display; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 135 | ▶ | use TUI::Drivers::HardwareInfo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 135 | ▶ | use TUI::Drivers::Mouse; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | sub TScreen() { __PACKAGE__ } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 135 | ▶ | use parent TDisplay; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 135 | our $startupMode = 0xffff; | |||||||||||||||||||||||||||
| 30 | 135 | our $startupCursor = 0; | |||||||||||||||||||||||||||
| 31 | 135 | our $screenMode = 0; | |||||||||||||||||||||||||||
| 32 | 135 | our $screenWidth = 0; | |||||||||||||||||||||||||||
| 33 | 135 | our $screenHeight = 0; | |||||||||||||||||||||||||||
| 34 | 135 | our $hiResScreen = false; | |||||||||||||||||||||||||||
| 35 | 135 | our $checkSnow = true; | |||||||||||||||||||||||||||
| 36 | 135 | our $screenBuffer = []; | |||||||||||||||||||||||||||
| 37 | 135 | our $cursorLines = 0; | |||||||||||||||||||||||||||
| 38 | 135 | our $clearOnSuspend = true; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 1 | ▶ | INIT { | ||||||||||||||||||||||||||
|
Subroutine
INIT: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 41 | 1 | $startupMode = TScreen->getCrtMode(); | |||||||||||||||||||||||||||
| 42 | 1 | $startupCursor = TScreen->getCursorType(); | |||||||||||||||||||||||||||
| 43 | 1 | ▶ | $screenBuffer = THardwareInfo->allocateScreenBuffer() | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | if THardwareInfo->can('allocateScreenBuffer'); | ||||||||||||||||||||||||||||
| 45 | 1 | TScreen->setCrtData(); | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 135 | ▶ | sub END { | ||||||||||||||||||||||||||
|
Subroutine
END: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||
| 49 | 135 | TScreen->suspend(); | |||||||||||||||||||||||||||
| 50 | 1 | ▶ | THardwareInfo->freeScreenBuffer( $screenBuffer ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | if THardwareInfo->can('freeScreenBuffer'); | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 1 | ▶ | sub resume { # void ($class) | ||||||||||||||||||||||||||
|
Subroutine
resume: called CC=4 SCAR=15.0
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 56 | 1 | ▶ | assert ( $class and !ref $class ); | ||||||||||||||||||||||||||
|
Condition33%1/3
$class && !ref($class)
MC/DC0%0/2
$class && !ref($class)
$class
!ref($class)
Truth table33%1/3
A && not(B)
A= $classB= !ref($class)
| |||||||||||||||||||||||||||||
| 57 | 1 | ▶ | THardwareInfo->setUpConsole() | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | if THardwareInfo->can('setUpConsole'); | ||||||||||||||||||||||||||||
| 59 | 1 | $startupMode = $class->getCrtMode(); | |||||||||||||||||||||||||||
| 60 | 1 | $startupCursor = $class->getCursorType(); | |||||||||||||||||||||||||||
| 61 | 1 | ▶ | if ( $screenMode != $startupMode ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 0 | $class->setCrtMode( $screenMode ); | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 1 | $class->setCrtData(); | |||||||||||||||||||||||||||
| 65 | 1 | return; | |||||||||||||||||||||||||||
| 66 | } #/ sub resume | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 136 | ▶ | sub suspend { # void ($class) | ||||||||||||||||||||||||||
|
Subroutine
suspend: called CC=5 SCAR=17.8
Pod
documented
| |||||||||||||||||||||||||||||
| 69 | 136 | my $class = shift; | |||||||||||||||||||||||||||
| 70 | 136 | ▶ | assert ( $class and !ref $class ); | ||||||||||||||||||||||||||
|
Condition33%1/3
$class && !ref($class)
MC/DC0%0/2
$class && !ref($class)
$class
!ref($class)
Truth table33%1/3
A && not(B)
A= $classB= !ref($class)
| |||||||||||||||||||||||||||||
| 71 | 136 | ▶ | if ( $startupMode != $class->getCrtMode() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 0 | $class->setCrtMode( $startupMode ); | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | 2 | ▶ | if ( $clearOnSuspend ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 2 | $class->clearScreen(); | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | 2 | $class->setCursorType( $startupCursor ); | |||||||||||||||||||||||||||
| 78 | 2 | ▶ | THardwareInfo->restoreConsole() | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | if THardwareInfo->can('restoreConsole'); | ||||||||||||||||||||||||||||
| 80 | 2 | return; | |||||||||||||||||||||||||||
| 81 | } #/ sub suspend | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 2 | ▶ | sub fixCrtMode { # $mode ($class, $mode) | ||||||||||||||||||||||||||
|
Subroutine
fixCrtMode: called CC=7 SCAR=26.3
Pod
documented
| |||||||||||||||||||||||||||||
| 84 | 2 | my ( $class, $mode ) = @_; | |||||||||||||||||||||||||||
| 85 | 2 | ▶ | assert ( $class and !ref $class ); | ||||||||||||||||||||||||||
|
Condition33%1/3
$class && !ref($class)
MC/DC0%0/2
$class && !ref($class)
$class
!ref($class)
Truth table33%1/3
A && not(B)
A= $classB= !ref($class)
| |||||||||||||||||||||||||||||
| 86 | 2 | assert ( looks_like_number $mode ); | |||||||||||||||||||||||||||
| 87 | 2 | ▶ | if ( THardwareInfo->isa( 'TUI::Drivers::HardwareInfo::Win32' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | $mode = ( $mode & smFont8x8 ) ? smCO80 | smFont8x8 : smCO80; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | return $mode; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | 2 | ▶ | if ( ( $mode & 0xff ) == smMono ) { # Strip smFont8x8 if necessary. | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 0 | return smMono; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | 2 | ▶ | if ( ( $mode & 0xff ) != smCO80 && ( $mode & 0xff ) != smBW80 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
($mode & 255) != 3 and ($mode & 255) != 2
MC/DC0%0/2
($mode & 255) != 3 and ($mode & 255) != 2
($mode & 255) != 3
($mode & 255) != 2
Truth table33%1/3
A and B
A= ($mode & 255) != 3B= ($mode & 255) != 2
| |||||||||||||||||||||||||||||
| 95 | 0 | $mode = ( $mode & smFont8x8 ) | smCO80; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | 2 | return $mode; | |||||||||||||||||||||||||||
| 98 | } #/ sub fixCrtMode | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 4 | ▶ | sub setCrtData { # void ($class) | ||||||||||||||||||||||||||
|
Subroutine
setCrtData: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 101 | 4 | my $class = shift; | |||||||||||||||||||||||||||
| 102 | 4 | ▶ | assert ( $class and !ref $class ); | ||||||||||||||||||||||||||
|
Condition33%1/3
$class && !ref($class)
MC/DC0%0/2
$class && !ref($class)
$class
!ref($class)
Truth table33%1/3
A && not(B)
A= $classB= !ref($class)
| |||||||||||||||||||||||||||||
| 103 | 4 | $screenMode = $class->getCrtMode(); | |||||||||||||||||||||||||||
| 104 | 4 | $screenWidth = $class->getCols(); | |||||||||||||||||||||||||||
| 105 | 4 | $screenHeight = $class->getRows(); | |||||||||||||||||||||||||||
| 106 | 4 | $hiResScreen = $screenHeight > 25; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 4 | $cursorLines = $class->getCursorType(); | |||||||||||||||||||||||||||
| 109 | 4 | $class->setCursorType( 0 ); | |||||||||||||||||||||||||||
| 110 | 4 | return; | |||||||||||||||||||||||||||
| 111 | } #/ sub setCrtData | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 3 | ▶ | sub clearScreen { # void ($class) | ||||||||||||||||||||||||||
|
Subroutine
clearScreen: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||
| 114 | 3 | ▶ | assert ( $_[0] and !ref $_[0] ); | ||||||||||||||||||||||||||
|
Condition33%1/3
$_[0] && !ref($_[0])
MC/DC0%0/2
$_[0] && !ref($_[0])
$_[0]
!ref($_[0])
Truth table33%1/3
A && not(B)
A= $_[0]B= !ref($_[0])
| |||||||||||||||||||||||||||||
| 115 | 3 | TDisplay->clearScreen( $screenWidth, $screenHeight ); | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 1 | ▶ | sub setVideoMode { # void ($class, $mode) | ||||||||||||||||||||||||||
|
Subroutine
setVideoMode: called CC=4 SCAR=15.5
Pod
documented
| |||||||||||||||||||||||||||||
| 119 | 1 | my ( $class, $mode ) = @_; | |||||||||||||||||||||||||||
| 120 | 1 | ▶ | assert ( $class and !ref $class ); | ||||||||||||||||||||||||||
|
Condition33%1/3
$class && !ref($class)
MC/DC0%0/2
$class && !ref($class)
$class
!ref($class)
Truth table33%1/3
A && not(B)
A= $classB= !ref($class)
| |||||||||||||||||||||||||||||
| 121 | 1 | assert ( looks_like_number $mode ); | |||||||||||||||||||||||||||
| 122 | 1 | ▶ | if ( $mode != smUpdate ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 1 | $class->setCrtMode( $class->fixCrtMode( $mode ) ); | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | else { | ||||||||||||||||||||||||||||
| 126 | 0 | THardwareInfo->freeScreenBuffer( $screenBuffer ); | |||||||||||||||||||||||||||
| 127 | 0 | $screenBuffer = THardwareInfo->allocateScreenBuffer(); | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | 1 | $class->setCrtData(); | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 1 | ▶ | TMouse->setRange( $class->getCols() - 1, $class->getRows() - 1 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | if TMouse->present(); | ||||||||||||||||||||||||||||
| 133 | 1 | return; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 135 | 1 | |||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | __END__ | ||||||||||||||||||||||||||||