' Text rows/columns per screen resolution test
' Version 1.03 by madscijr
' boolean constants:
' global variables
' LOCAL VARIABLES
' ****************************************************************************************************************************************************************
' ACTIVATE DEBUGGING WINDOW
_Echo "Started " + m_ProgramName$
' ****************************************************************************************************************************************************************
' =============================================================================
' START THE MAIN ROUTINE
main
' =============================================================================
' FINISH
Print m_ProgramName$
+ " finished." Input "Press <ENTER> to continue", in$
' ****************************************************************************************************************************************************************
' DEACTIVATE DEBUGGING WINDOW
' ****************************************************************************************************************************************************************
System ' return control to the operating system
' /////////////////////////////////////////////////////////////////////////////
ErrHandler:
' /////////////////////////////////////////////////////////////////////////////
Print "Screen resolution tests" Print "1. Count text width/height (windowed)" Print "2. Count text width/height (full screen)" Print "What to do? ('q' to exit)"
result$ = GetTextWidthHeight$(FALSE)
result$ = GetTextWidthHeight$(TRUE)
' /////////////////////////////////////////////////////////////////////////////
' dynamically detect available # of text rows+columns under a custom screen size?
' https://qb64forum.alephc.xyz/index.php?topic=4550.0
' Petr:
' In graphical mode text use font (default is _FONT 16),
' so what you need is _FontHeight, _FontWidth and _PrintWidth.
' How much columns is on graphic screen:
' _Width \ _FontWidth, for rows _Height \ _FontHeight.
' If you use other fonts, use MONOSPACE type.
' Let say on screen 640 x 480 and default font
' it is 640 \ 8 = 80 columns and 480 \ 16 = 30 rows
' GetNextTextWidthHeight$ 640, 480, "VGA (4:3)"
' GetNextTextWidthHeight$ 720, 480, "480p (4:3, 16:9)"
' GetNextTextWidthHeight$ 800, 600, "SVGA (4:3)"
' GetNextTextWidthHeight$ 1024, 768, "XGA (4:3)"
' GetNextTextWidthHeight$ 1280, 1024, "SXGA (5:4)"
' GetNextTextWidthHeight$ 1920, 1080, "FHD (16:9)"
' GetNextTextWidthHeight$ 2048, 1152, "QWXGA (16:9)"
' GetNextTextWidthHeight$ 3840, 2160, "4K UHD (16:9)"
' GetNextTextWidthHeight$ 7680, 4320, "8K UHD (16:9)"
' currently set up to not try to change screen resolution to less than VGA or bigger than 4k
' ONLY TEST FOR ALLOWED RESOLUTIONS
If (iScreenWidth
>= iMinWidth
) And (iScreenWidth
<= iMaxWidth
) And (iScreenHeight
>= iMinHeight
) And (iScreenHeight
<= iMaxHeight
) Then ' =============================================================================
' SHOW RESOLUTION AND EXPECTED # OF CHARACTERS TO FIT
'PRINT "Screen size:"
'PRINT " _WIDTH(0) = " + _TRIM$(STR$( _WIDTH(0) ))
'PRINT " _HEIGHT(0) = " + _TRIM$(STR$( _HEIGHT(0) ))
'Print "Font size:"
'Print " _FontWidth = " + _Trim$(Str$(_FontWidth))
'Print " _FontHeight = " + _Trim$(Str$(_FontHeight))
' To measure actual available columns/rows:
'iCols = _WIDTH(0) \ _FontWidth
'iRows = _HEIGHT(0) \ _FontHeight
'PRINT "Current characters per screen:"
'PRINT " # columns = _WIDTH(0) \ _FontWidth = " + _TRIM$(STR$( _WIDTH(0) )) + " \ " + _TRIM$(STR$(_FontWidth)) + " = " + _TRIM$(STR$(iCols))
'PRINT " # rows = _HEIGHT(0) \ _FontHeight = " + _TRIM$(STR$( _HEIGHT(0) )) + " \ " + _TRIM$(STR$(_FontHeight)) + " = " + _TRIM$(STR$(iRows))
' Calculate for a hypothetical resolution: (thanks bplus and petr!)
'iCols = iScreenWidth \ _FontWidth
'iRows = iScreenHeight \ _FontHeight
Print "ENTER continue to next resolution" Print "Q quit testing resolutions" Input "What to do? "; in$
' -----------------------------------------------------------------------------
' TEST TO SEE IF THE # OF ROWS WE EXPECT REALLY DO FIT ON THE SCREEN
For iLoopRows
= 1 To iRows
iX = 0 ' _FontWidth * (iLoopCols - 1)
Print _Trim$(Str$(iRows
)) + " rows expected at resolution " + cstr$
(iScreenWidth
) + "x" + cstr$
(iScreenHeight
) Input "Press <ENTER> to continue"; in$
' -----------------------------------------------------------------------------
' TEST TO SEE IF THE # OF COLUMNS WE EXPECT REALLY DO FIT ON THE SCREEN
Print _Trim$(Str$(iCols
)) + " columns expected at resolution " + cstr$
(iScreenWidth
) + "x" + cstr$
(iScreenHeight
)
' print hundreds
iCount = 0
For iLoopCols
= 1 To iCols
iCount = iCount + 1
' print tens
iCount = 0
For iLoopCols
= 1 To iCols
iCount = iCount + 1
' print ones
iCount = 0
For iLoopCols
= 1 To iCols
iCount = iCount + 1
Input "Press <ENTER> to continue"; in$
' -----------------------------------------------------------------------------
' EXIT + MOVE ON TO THE NEXT RESOLUTION
m_sError = ""
m_sCode = ""
' ASK THE USER IF THEY WANT TO MOVE ON TO THE NEXT RESOLUTION OR QUIT
Input "Q to quit, or <ENTER> to continue to next resolution"; in$
sResult = "q"
CleanupAndExit:
GetNextTextWidthHeight$ = sResult
' /////////////////////////////////////////////////////////////////////////////
If sResult
<> "q" Then sResult
= GetNextTextWidthHeight$
(640, 480, "VGA (4:3)") If sResult
<> "q" Then sResult
= GetNextTextWidthHeight$
(720, 480, "480p (4:3, 16:9)") If sResult
<> "q" Then sResult
= GetNextTextWidthHeight$
(800, 600, "SVGA (4:3)") If sResult
<> "q" Then sResult
= GetNextTextWidthHeight$
(1024, 768, "XGA (4:3)") If sResult
<> "q" Then sResult
= GetNextTextWidthHeight$
(1280, 1024, "SXGA (5:4)") If sResult
<> "q" Then sResult
= GetNextTextWidthHeight$
(1920, 1080, "FHD (16:9)") If sResult
<> "q" Then sResult
= GetNextTextWidthHeight$
(2048, 1152, "QWXGA (16:9)") If sResult
<> "q" Then sResult
= GetNextTextWidthHeight$
(3840, 2160, "4K UHD (16:9)") If sResult
<> "q" Then sResult
= GetNextTextWidthHeight$
(7680, 4320, "8K UHD (16:9)")
GetTextWidthHeight$ = ""
' /////////////////////////////////////////////////////////////////////////////
' Convert a value to string and trim it (because normal Str$ adds spaces)
'cstr$ = LTRIM$(RTRIM$(STR$(myValue)))
' /////////////////////////////////////////////////////////////////////////////