How can I read characters from the screen? - hanness - 05-05-2022
Assume that I am initializing my display like this:
_FullScreen _Off , _Smooth
_FreeImage oldimage&
Font& = _LoadFont(FontPath$, FontSize, "MONOSPACE")
_Font Font&
Now I write a bunch of text to the screen.
Later, I want to read the character at the upper left of the screen. I tried to do this like this:
print screen(1,1)
or
MyVar$ = CHR$(screen(1,1))
However, I'm getting an illegal function call when the line with screen(1,1) is executed.
Is this only valid with screen mode 0 or am I missing something here?
If this cannot be made to work, is there any other way to read characters from the screen?
RE: How can I read characters from the screen? - Pete - 05-05-2022
(05-05-2022, 09:16 PM)hanness Wrote: Assume that I am initializing my display like this:
_FullScreen _Off , _Smooth
_FreeImage oldimage&
Font& = _LoadFont(FontPath$, FontSize, "MONOSPACE")
_Font Font&
Now I write a bunch of text to the screen.
Later, I want to read the character at the upper left of the screen. I tried to do this like this:
print screen(1,1)
or
MyVar$ = CHR$(screen(1,1))
However, I'm getting an illegal function call when the line with screen(1,1) is executed.
Is this only valid with screen mode 0 or am I missing something here?
If this cannot be made to work, is there any other way to read characters from the screen?
Post the actual code. The SCREEN function requires the SCREEN be properly sized as a multiple of the font height. Screw that up, and illegal function calls happen at the top of the screen.
Pete
RE: How can I read characters from the screen? - hanness - 05-05-2022
(05-05-2022, 10:02 PM)Pete Wrote: (05-05-2022, 09:16 PM)hanness Wrote: Assume that I am initializing my display like this:
_FullScreen _Off , _Smooth
_FreeImage oldimage&
Font& = _LoadFont(FontPath$, FontSize, "MONOSPACE")
_Font Font&
Now I write a bunch of text to the screen.
Later, I want to read the character at the upper left of the screen. I tried to do this like this:
print screen(1,1)
or
MyVar$ = CHR$(screen(1,1))
However, I'm getting an illegal function call when the line with screen(1,1) is executed.
Is this only valid with screen mode 0 or am I missing something here?
If this cannot be made to work, is there any other way to read characters from the screen?
Post the actual code. The SCREEN function requires the SCREEN be properly sized as a multiple of the font height. Screw that up, and illegal function calls happen at the top of the screen.
Pete
Pete, what you say is interesting, because in the meantime I have narrowed it down to definitely somehow being related to the font.
I didn't post code initially because the relevant pieces were scattered throughout a big program, but I now have a small test program.
Let's start with this:
Code: (Select All) FontPath$ = Environ$("SYSTEMROOT") + "\fonts\lucon.ttf"
FontSize = 20
handle& = _NewImage(800, 600, 256)
Screen handle&
_FullScreen _Off
' Font& = _LoadFont(FontPath$, FontSize, "MONOSPACE")
' _Font Font&
Locate 1, 1: Print "This is a test"
' The lines below simply display the first 4 characters located on line 1.
' In this case that would be "This".
For x = 1 To 4
Print Chr$(Screen(1, x));
Next x
If you run the above code, it runs flawlessly. But, go ahead and uncomment the lines starting with "Font&" and "_Font". Now the program will fail. Note that I'm using a fontsize of 20 and the screen width and height are exact multiples of that.
RE: How can I read characters from the screen? - hanness - 05-05-2022
Let me demonstrate why it is that I am attempting to read the text from the screen. If anyone can think of a better way to do what I'm attempting, please do let me know.
Below is a program that is in progress, based upon my all time favorite screensaver named "Word Clock" written by a Simon Heys. The program simply takes the current time and displays it as a series of words.
To get a feel for what I am doing, please run the program, then note the following:
The program will start in fullscreen. It's entirely possible that either a large part of the screen will be unoccupied, or the text may be too large to fit on the screen all at once. Adjust the size of the font by tapping either "+" or "-".
NOTE: The program ends when anything other than the acceptable hotkeys are pressed. Hotkeys are:
+ and - as described above, H or h to display help, F or f to toggle between fullscreen and windowed mode. In windowed mode, the screen can be freely sized with your pointing device.
Note that when everything fits on the screen, the upper left corner will always show the word "Saturday". If the font in use is too large, than the word Saturday will scroll off the top of the screen. By reading the contents of the upper left corner I can then automatically size the font to best fit the screen in fullscreen or windowed mode and whenever a resize of the window occurs. This would far better than having to manually tweak the font size by tapping + and -.
Code: (Select All) Option _Explicit
Option Base 1
' Hannes' Word Clock
' 2022 by Hannes Sehestedt
' Version 1.0.0.2
' May 5, 2022
Dim AM_PM As String ' This flag will be set to either "AM" or "PM"
Dim CurrentDate As String ' Hold the entire date (Month / Day / Year) as a string
Dim CurrentMode As String ' Tracks the current mode. "Y" for fullscreen mode, "N" for windowed mode.
Dim CurrentTime As String ' Hold the entire time (Hours / Minutes / Seconds) as a string
Dim Day As Integer ' Day of the month (1-31) as a number
Dim DayOfWeek As Integer ' Day of the week (1-7) as a number
Dim DayOfWeekString(7) As String ' An array holding each day of the week as an English word
Dim DayString(31) As String ' An array holding each day of the month (1-31) as a string
Dim Decade As Integer ' The numerical value of the last 2 digits of the year
Dim DeskWidth As Long ' The width of the desktop in pixels
Dim DeskHeight As Long ' The height of the desktop in pixels
Dim ff As Integer ' Used to store free file number
Dim FileLine As String ' Line read from a file
Dim Font As Long ' Handle to a font
Dim FontPath As String ' The name of the font, with path, used in windowed mode
Dim FontSize As Integer ' The fontsize used in windowed mode
Dim FullscreenFontPath As String ' The name of the font, with path, used in fullscreen mode
Dim FullscreenFontSize As Integer ' The fontsize used in fullscreen mode
Dim handle As Long ' Stores a handle to the screen
Dim Horizontal As Integer ' The horizontal resolution used in windowed mode
Dim Hour As Integer ' Numerical value holding the current hour (0-23)
Dim HourString(12) As String ' The current hour as an English word. Since we use AM / PM this holds only one through twelve.
Dim KeyPress As String ' Used to sore keystrokes from Inkey$
Dim LeapYear As Integer ' To to indicate if current year is a leap year. 1 = Leap Year, 0 = No Leap Year
Dim Minute As Integer ' The current minute as a numeral from 0 to 59
Dim MinuteString(59) As String ' An array hold minutes as English words from one to fifty-nine
Dim Month As Integer ' The current month as a number from 1 to 12
Dim MonthString(12) As String ' The current month as an English word (January, February, ... , November, December).
Dim MonthTable(12) As Integer ' A table with an offset for each month used to calculate what day of the week it is (Monday, Tuesday, etc).
Dim oldimage As Long
Dim OldSecond As Integer ' A variable that is used to determine if the seconds have changed from the last time we checked
Dim ProgramVersion As String ' Holds the current program version
Dim Result1 As Integer ' A temporary variable
Dim Result2 As Integer ' A temporary variable
Dim Result3 As Integer ' A temporary variable
Dim Second As Integer ' The current seconds as a number (0-59)
Dim SecondString(59) As String ' The current seconds as an English word from one through fifty-nine
Dim StartFullscreen As String ' Set to "Y" to start the program in fullscreen mode, "N" to start in windowed mode
Dim Temp As Integer ' A temporary variable
Dim Temp2 As Integer ' A temporary variable
Dim Vertical As Integer ' Vertical resolution used in windowed mode
Dim x As Integer ' General purpose counter used in FOR...NEXT loops
Dim Year As Integer ' Stores the current year
ProgramVersion$ = "1.0.0.2"
_Title "Hannes' Word Clock " + ProgramVersion$
$ExeIcon:'WordClock.ico'
$VersionInfo:CompanyName=Hannes Sehestedt
$VersionInfo:FILEVERSION#=1,0,0,2
$VersionInfo:ProductName=Hannes Word Clock
$VersionInfo:LegalCopyright=(c) 2022 by Hannes Sehestedt
$Resize:On
' Default values used for entries not available from a .ini file
DeskWidth = _DesktopWidth
DeskHeight = _DesktopHeight
FontPath$ = Environ$("SYSTEMROOT") + "\fonts\lucon.ttf"
FullscreenFontPath$ = Environ$("SYSTEMROOT") + "\fonts\lucon.ttf"
FontSize = 14
FullscreenFontSize = 40
Horizontal = 1024
Vertical = 768
' If a .ini file exists, open it and parse it. Values found in the .ini will override the defaults
' defined above.
If _FileExists("Hannes_Clock.ini") Then
ff = FreeFile
Open "Hannes_Clock.ini" For Input As #ff
Do Until EOF(ff)
Line Input #ff, FileLine$
' If line starts with a colon (:), it is a comment. Ignore it.
If Left$(FileLine$, 1) = ":" Then _Continue
' If line starts with "FONT:" then we are reading in the name of the font to be used. This is NOT case sensitive.
If UCase$(Left$(FileLine$, 5)) = "FONT:" Then
FontPath$ = Environ$("SYSTEMROOT") + "\fonts\" + Right$(FileLine$, (Len(FileLine$) - 5))
End If
' If line starts with "FONTSIZE:" then we are reading in the size of the font to be used. This is NOT case sensitive.
If UCase$(Left$(FileLine$, 9)) = "FONTSIZE:" Then
FontSize = Val(Right$(FileLine$, (Len(FileLine$) - 9)))
End If
' If line starts with "FULLSCREENFONT:" then we are reading in the name of the font to be used
' in fullscreen mode. This is NOT case sensitive.
If UCase$(Left$(FileLine$, 15)) = "FULLSCREENFONT:" Then
FullscreenFontPath$ = Environ$("SYSTEMROOT") + "\fonts\" + Right$(FileLine$, (Len(FileLine$) - 15))
End If
' If line starts with "FULLSCREENFONTSIZE:" then we are reading in the size of the font to be used
' in fullscreen mode. This is NOT case sensitive.
If UCase$(Left$(FileLine$, 19)) = "FULLSCREENFONTSIZE:" Then
FullscreenFontSize = Val(Right$(FileLine$, (Len(FileLine$) - 19)))
End If
' If line starts with "WINDOWHORIZONTAL:", use value to set the horizontal window size.
If UCase$(Left$(FileLine$, 17)) = "WINDOWHORIZONTAL:" Then
Horizontal = Val(Right$(FileLine$, (Len(FileLine$) - 17)))
End If
' If line starts with "WINDOWVERTICAL:", use value to set the vertical window size.
If UCase$(Left$(FileLine$, 15)) = "WINDOWVERTICAL:" Then
Vertical = Val(Right$(FileLine$, (Len(FileLine$) - 15)))
End If
' If line starts with "STARTFULLSCREEN:", read value that will determine if the program is to be
' started fullscreen or in a window.
If UCase$(Left$(FileLine$, 16)) = "STARTFULLSCREEN:" Then
StartFullscreen$ = UCase$(Right$(FileLine$, (Len(FileLine$) - 16)))
End If
Loop
Close #ff
End If
' Setup screen for either fullscreen or windowed mode
' Begin by disabling resizing so that resize events are not triggered while we
' switch between fullscreen and windows modes.
_Resize Off
If StartFullscreen$ = "Y" Then
CurrentMode$ = "FULLSCREEN"
handle& = _NewImage(_DesktopWidth, _DesktopHeight, 256)
Screen handle&
_FullScreen _Stretch , _Smooth
Font& = _LoadFont(FullscreenFontPath$, FullscreenFontSize, "MONOSPACE")
_Font Font&
Else
CurrentMode = "WINDOWED"
handle& = _NewImage(Horizontal, Vertical, 256)
Screen handle&
_FullScreen _Off
Font& = _LoadFont(FontPath$, FontSize, "MONOSPACE")
_Font Font&
End If
' Allow any switch between fullscreen and windowed mode to complete before
' we re-enable resizing by sleeping for one second. This will prevent false
' resize evenys from happening.
Sleep 1
_Resize On
' Read the spelled out version of various elements into arrays. This will save time later so that we don't have to constantly
' parse this over and over in out main program loop.
Restore DayOfWeek
For x = 1 To 7
Read DayOfWeekString$(x)
Next x
Restore Day
For x = 1 To 31
Read DayString$(x)
Next x
Restore Month
For x = 1 To 12
Read MonthString$(x)
Next x
Restore Hour
For x = 1 To 12
Read HourString$(x)
Next x
Restore Minute
For x = 1 To 59
Read MinuteString$(x)
Next x
Restore Second
For x = 1 To 59
Read SecondString$(x)
Next x
Restore MonthTable
For x = 1 To 12
Read MonthTable(x)
Next x
Cls
' Clear the keyboard buffer before we enter the main program loop.
Do While InKey$ <> ""
Loop
' This is the main loop that retrieves the date and time, breaks it down into individual components, and then
' displays the time and date in words.
Do
_Limit 60 ' Limit the number of times that we perform this loop to a maximum of 60 iterations per second
If _Resize Then
' If we are NOT running fullscreen, then resize the screen appropriately.
If Not ((_ResizeWidth = _DesktopWidth) And (_ResizeHeight = _DesktopHeight)) Then
Horizontal = _ResizeWidth: Vertical = _ResizeHeight
If Horizontal >= _DesktopWidth Then
Horizontal = _DesktopWidth - 1
End If
If Vertical >= _DesktopHeight Then
Vertical = _DesktopHeight - 1
End If
oldimage& = handle&
handle& = _NewImage(Horizontal, Vertical, 256)
Screen handle&
_FullScreen _Off , _Smooth
_FreeImage oldimage&
Font& = _LoadFont(FontPath$, FontSize, "MONOSPACE")
_Font Font&
End If
End If
' The lines below check for any keypresses. If a hotkey is pressed, then we take the appropriate action.
' Pressing any other key will exit the program. This is most useful when the program is being used as a
' screensaver.
KeyPress$ = InKey$
Select Case KeyPress$
Case ""
Exit Select
Case "+"
Cls
If CurrentMode = "WINDOWED" Then
FontSize = FontSize + 1
Font& = _LoadFont(FontPath$, FontSize, "MONOSPACE")
_Font Font&
Else
FullscreenFontSize = FullscreenFontSize + 1
Font& = _LoadFont(FullscreenFontPath$, FullscreenFontSize, "MONOSPACE")
_Font Font&
End If
Case "-"
Cls
If CurrentMode = "WINDOWED" Then
FontSize = FontSize - 1
If FontSize < 2 Then FontSize = 2
Font& = _LoadFont(FontPath$, FontSize, "MONOSPACE")
_Font Font&
Else
FullscreenFontSize = FullscreenFontSize - 1
Font& = _LoadFont(FullscreenFontPath$, FullscreenFontSize, "MONOSPACE")
_Font Font&
End If
Case "F", "f"
_Resize Off
If CurrentMode = "WINDOWED" Then
CurrentMode = "FULLSCREEN"
oldimage& = handle&
handle& = _NewImage(_DesktopWidth, _DesktopHeight, 256)
Screen handle&
_FullScreen , _Smooth
_FreeImage oldimage&
Font& = _LoadFont(FullscreenFontPath$, FullscreenFontSize, "MONOSPACE")
_Font Font&
ElseIf CurrentMode = "FULLSCREEN" Then
CurrentMode = "WINDOWED"
oldimage& = handle&
handle& = _NewImage(Horizontal, Vertical, 256)
Screen handle&
_FullScreen _Off
_FreeImage oldimage&
Font& = _LoadFont(FontPath$, FontSize, "MONOSPACE")
_Font Font&
End If
Sleep 1
_Resize On
Case "S", "s"
GoSub DisplayStats
Case "H", "h"
GoSub Help
Case Else
System
End Select
' Begin breaking down the time and date into individual components
CurrentDate$ = Date$
CurrentTime$ = Time$
Month = Val(Left$(CurrentDate$, 2))
Day = Val(Mid$(CurrentDate$, 4, 3))
Year = Val(Right$(CurrentDate$, 4))
Decade = Val(Right$(CurrentDate$, 2))
Hour = Val(Left$(CurrentTime$, 2))
Minute = Val(Mid$(CurrentTime$, 4, 2))
Second = Val(Right$(CurrentTime$, 2))
' At the end of the loop that displays the time on the screen, we set OldSecond to the current seconds. When we reach
' this point again, if the current seconds are still the same, we skip the display process since there are no changes.
' If the seconds have changed, then proceed with updating the display.
If (OldSecond = Second) Then GoTo DisplayFinished
' Calculate the day of the week
' IMPORTANT: The calculations below are valid through 2099.
' Step 1: Add the day of the month and the number from the month table. We will read the values from the month table.
Temp = Day + MonthTable(Month)
' Step 2: If the number calculated above is greater than 6, then subtract the highest multiple of 7 from this number.
If Temp > 6 Then
Temp2 = Int(Temp / 7)
Temp = Temp - (Temp2 * 7)
End If
Result1 = Temp
' Step 3: From the last two digits of the year, subtract the year that has the highest multiple of 28.
Temp = Decade
If Decade > 27 Then
Temp2 = Int(Temp / 28)
Temp = Decade - (Temp2 * 28)
End If
Result2 = Temp
' Step 4: Take the last 2 digits of the year, divide by 4, and drop anything after the decimal point. Add that value to Result2.
Temp = 0
If Decade > 3 Then
Temp = Int(Decade / 4)
End If
Result3 = Result2 + Temp
' Step 5: If the month is Jan or Feb AND the year is a leap year, subtract 1 from Result3.
If Month < 3 Then
If (Year / 4) = (Int(Year / 4)) Then
LeapYear = 1
Else
LeapYear = 0
End If
Result3 = Result3 - LeapYear
End If
' Step 6: Add Result1 and Result3. Subtract the highest multiple of 7. The result will be 0-6 with 0 being Sat, and 6 being Fri.
Result3 = Result3 + Result1
If Result3 > 6 Then
Temp = Int(Result3 / 7)
Result3 = Result3 - (Temp * 7)
End If
' To make handling easier, we will add 1 to result so that the day of the week will now be a number from 1 to 7. The
' end result is that Sat = 1, Fri = 7.
DayOfWeek = Result3 + 1
' End calculation of the day of the week.
' Set the default color of items printed to the screen to grey on black. Current values will be highlighted.
' Currently, this means white text on a red background, but we intend to allow customization later in a future
' version of the program. For now, we are simply hard coding it.
Locate 1, 1
Color 8, 0
' Print all days of the week
For x = 1 To 7
If x = DayOfWeek Then
Color 15, 4: Print DayOfWeekString$(x);: Color 8, 0: GoSub LeftJustify
Else
Print DayOfWeekString$(x);: GoSub LeftJustify
End If
Next x
' Always print the word "the" in the highlight color
Color 15, 4: Print "the";: Color 8, 0: GoSub LeftJustify
' Print the day of the month
For x = 1 To 31
If x = Day Then
Color 15, 4: Print DayString$(x);: Color 8, 0: GoSub LeftJustify
Else
Print DayString$(x);: GoSub LeftJustify
End If
Next x
' Always print the word "of" in the highlight color
Color 15, 4: Print "of";: Color 8, 0: GoSub LeftJustify
' Print the month
For x = 1 To 12
If x = Month Then
Color 15, 4: Print MonthString$(x);: Color 8, 0: GoSub LeftJustify
Else
Print MonthString$(x);: GoSub LeftJustify
End If
Next x
' Always print a comma (,) in the highlight color
Color 15, 4: Print ",";: Color 8, 0: GoSub LeftJustify
' Print the hour. Hours are numbered from 0 to 23. Since we are using AM and PM we need to manipulate the hours a little bit
' and set an AM / PM flag.
' Set an AM / PM Flag. AM_PM$ will be set to either "AM" or "PM".
Select Case Hour
Case 0 To 11
AM_PM$ = "AM"
Case Else
AM_PM$ = "PM"
End Select
' Convert 24 hour time to AM / PM (12 hour) format
Select Case Hour
Case 0
Hour = Hour + 12
Exit Select
Case 13 To 23
Hour = Hour - 12
Exit Select
End Select
For x = 1 To 12
If x = Hour Then
Color 15, 4: Print HourString$(x);: Color 8, 0: GoSub LeftJustify
Else
Print HourString$(x);: GoSub LeftJustify
End If
Next x
' If minutes are equal to zero, highlight the word "o'clock".
If (Minute = 0) Then
Color 15, 4: Print "o'clock";: Color 8, 0: GoSub LeftJustify
Else
Print "o'clock";: GoSub LeftJustify
End If
' Print the minute. Minutes are numbered from 0 to 59. If seconds are 0, then we highlight the word "precisely",
' otherwise we highlight the word "and" and the appropriate second following the minutes.
For x = 1 To 59
If x = Minute Then
Color 15, 4: Print MinuteString$(x);: Color 8, 0: GoSub LeftJustify
Else
Print MinuteString$(x);: GoSub LeftJustify
End If
Next x
' Print the AM and PM indicators.
Select Case AM_PM$
Case "AM"
Color 15, 4: Print "AM";: Color 8, 0: GoSub LeftJustify: Print "PM";: GoSub LeftJustify
Case "PM"
Print "AM";: GoSub LeftJustify: Color 15, 4: Print "PM";: Color 8, 0: GoSub LeftJustify
End Select
' If seconds are 0, then highlight the word "precisely", otherwise, highlight the word "and".
Select Case Second
Case 0
Print "and";: GoSub LeftJustify
Color 15, 4: Print "precisely";: Color 8, 0: GoSub LeftJustify
Case Else
Color 15, 4: Print "and";: Color 8, 0: GoSub LeftJustify
Print "precisely";: GoSub LeftJustify
End Select
' Print the second. Seconds are numbered from 0 to 59.
For x = 1 To 59
Select Case x
Case 1
If Second = 1 Then
Color 15, 4: Print SecondString$(x);: Color 8, 0: GoSub LeftJustify: Color 15, 4: Print "second";: Color 8, 0: GoSub LeftJustify
Else
Print SecondString$(x);: GoSub LeftJustify: Print "second";: GoSub LeftJustify
End If
Case Else
If Second = x Then
Color 15, 4: Print SecondString$(x);: Color 8, 0: GoSub LeftJustify
Else
Print SecondString$(x);: GoSub LeftJustify
End If
End Select
Next x
' Highlight the word "seconds" if Second > 1.
Select Case Second
Case 0, 1
Print "seconds";
Case Else
Color 15, 4: Print "seconds";: Color 8, 0
End Select
OldSecond = Second
DisplayFinished:
' TEST CODE
' Print Screen(1, 1);
Loop
' SUBROUTINES
LeftJustify:
' This routine ensures that spaces are not printed in the first column of a line. This has the effect
' of ensuring that all lines are left justified.
If Pos(0) > 1 Then Print " ";
Return
Help:
' Display help and usage instructions for the program.
_FullScreen _Off
Screen 0
Width 120, 30
Print "This program was inspired by a screen saver authored by Simon Heys many years ago and called Word Clock. To use the"
Print "program effectivly, you should know how about the following two items:"
Print
Print "1) The Hannes_Clock.ini file"
Print "2) Program hotkeys"
Print "3) Program defaults"
Print
Input "Press <ENTER> to continue...", Temp
Cls
Print "The Hannes_Clock.ini File"
Print "-------------------------"
Print
Print "Entries in the Hannes_Clock.ini file are not case sensitive. You can use uppercase, lowercase, or mixedcase. Any line"
Print "that starts with a colon (:) as the first character is considered a comment and will be ignored by the program. The"
Print "entries that the program recognizes are described below. Please note that the .ini file should be placed in the same"
Print "location as the program itself. Follow each entry with a colon and a value. See examples below."
Print
Print ": This is a comment - Comments are ignored by the program."
Print "font:lucon.ttf - The font to be used in windowed mode. Font name only, no path."
Print "fullscreenfont:lucon.ttf - The font to be used in fullscreen mode."
Print "fontsize:14 - Size of font used in windowed mode."
Print "fullscreenfontsize:32 - Size of font used in fullscreen mode."
Print "windowhorizontal:800 - Horizontal resolution (width) used in windowed mode."
Print "windowvertical:600 - Vertical resolution (height) used in windowed mode."
Print "startfullscreen:Y - Specify Y to start in fullscreen mode, N to start windowed."
Print
Input "Press <ENTER> to continue...", Temp
Cls
Print "Program Hotkeys"
Print "---------------"
Print
Print "Hotkeys (Note case sensitivity)"
Print
Print "+ : Increases font size. NOTE: Once screen starts flashing, you have gone too large. Back off one size on the font."
Print "- : Decreases the size of the font."
Print "H or h: Displays help for the program."
Print "F or f : Swap in and out of fullscreen mode."
Print "S or s : Display statistics / current values of options."
Print
Print "Any other Key will exit the program"
Print
Input "Press <ENTER> to continue...", Temp
Cls
Print "Program Defaults"
Print "----------------"
Print
Print "If no .ini file is present, or for any missing items the following defaults are used:"
Print
Print "Font:lucon.ttf"
Print "FullscreenFont:lucon.ttf"
Print "FontSize:14"
Print "FullscreenFontSize:40"
Print "WindowHorizontal:1024"
Print "WindowVertical:768"
Print "StartFullscreen:Y"
Print
Input "Press <ENTER> to continue...", Temp
Cls
' Set the screen back to the mode it was in before we called help.
If CurrentMode$ = "FULLSCREEN" Then
handle& = _NewImage(_DesktopWidth, _DesktopHeight, 256)
Screen handle&
_FullScreen _Stretch , _Smooth
Font& = _LoadFont(FullscreenFontPath$, FullscreenFontSize, "MONOSPACE")
_Font Font&
End If
If CurrentMode = "WINDOWED" Then
handle& = _NewImage(Horizontal, Vertical, 256)
Screen handle&
_FullScreen _Off
Font& = _LoadFont(FontPath$, FontSize, "MONOSPACE")
_Font Font&
End If
Return
DisplayStats:
' Display current settings being used in the program. This includes fullscreen / windowed height / width, etc.
' Once a user has settings dialed in where they want, this is a helpful way of getting all the values needed
' to plug into the .ini file.
_FullScreen _Off
Screen 0
Width 120, 30
Cls
Print "Below are the active settings for the program. If you have been adjusting settings to get the best results on your"
Print "system, you may want to note the below values and incorporate them into your .ini file."
Print
Print "Font used in windowed mode: "; FontPath
Print "Font used in fullscreen mode: "; FullscreenFontPath
Print "Font size in windowed mode:"; FontSize
Print "Font size in fullscreen mode:"; FullscreenFontSize
Print "Windowed mode width:"; Horizontal
Print "Windowed mode height:"; Vertical
Print "Fullscreen width (cannot be changed):"; DeskWidth
Print "Fullscreen height (cannot be changed):"; DeskHeight
Print
Input "Press <ENTER> to continue...", Temp
Cls
' Set the screen back to the mode it was in before we called help.
If CurrentMode$ = "FULLSCREEN" Then
handle& = _NewImage(_DesktopWidth, _DesktopHeight, 256)
Screen handle&
_FullScreen _Stretch , _Smooth
Font& = _LoadFont(FullscreenFontPath$, FullscreenFontSize, "MONOSPACE")
_Font Font&
End If
If CurrentMode = "WINDOWED" Then
handle& = _NewImage(Horizontal, Vertical, 256)
Screen handle&
_FullScreen _Off
Font& = _LoadFont(FontPath$, FontSize, "MONOSPACE")
_Font Font&
End If
Return
' End of subroutines
' End of main program
End
' DATA section
DayOfWeek:
Data "Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"
Day:
Data "first","second","third","fourth","fifth","sixth","seventh","eighth","ninth","tenth","eleventh","twelfth","thirteenth"
Data "fourteenth","fifteenth","sixteenth","seventeenth","eighteenth","nineteenth","twentieth","twenty-first","twenty-second"
Data "twenty-third","twenty-fourth","twenty-fifth","twenty-sixth","twenty-seventh","twenty-eighth","twenty-ninth","thirtieth","thirty-first"
Month:
Data "January","February","March","April","May","June","July","August","September","October","November","December"
Hour:
Data "one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve"
Minute:
Data "oh-one","oh-two","oh-three","oh-four","oh-five","oh-six","oh-seven","oh-eight","oh-nine","ten","eleven","twelve","thirteen"
Data "fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty","twenty-one","twenty-two","twenty-three","twenty-four"
Data "twenty-five","twenty-six","twenty-seven","twenty-eight","twenty-nine","thirty","thirty-one","thirty-two","thirty-three"
Data "thirty-four","thirty-five","thirty-six","thirty-seven","thirty-eight","thirty-nine","forty","forty-one","forty-two","forty-three"
Data "forty-four","forty-five","forty-six","forty-seven","forty-eight","forty-nine","fifty","fifty-one","fifty-two","fifty-three"
Data "fifty-four","fifty-five","fifty-six","fifty-seven","fifty-eight","fifty-nine"
Second:
Data "one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen"
Data "fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty","twenty-one","twenty-two","twenty-three","twenty-four"
Data "twenty-five","twenty-six","twenty-seven","twenty-eight","twenty-nine","thirty","thirty-one","thirty-two","thirty-three"
Data "thirty-four","thirty-five","thirty-six","thirty-seven","thirty-eight","thirty-nine","forty","forty-one","forty-two","forty-three"
Data "forty-four","forty-five","forty-six","forty-seven","forty-eight","forty-nine","fifty","fifty-one","fifty-two","fifty-three"
Data "fifty-four","fifty-five","fifty-six","fifty-seven","fifty-eight","fifty-nine"
MonthTable:
Data 0,3,3,6,1,4,6,2,5,0,3,5
' End of DATA section
Edit: A correction - My current default is to start in Windowed mode, not fullscreen.
RE: How can I read characters from the screen? - Pete - 05-05-2022
It looks correct. As such, it appears the SCREEN function works with the default font, but not with custom fonts. ttf are true type fonts. I did not try it with non-ttf styles. That's a shame if this pans out to be true. I seldom use anything other than SCREEN 0 for this type of work, bit with and without loaded fonts. No problems. I've use graphics with SCREEN(), but only using the default font.
I'd like Steve to weigh in on this one. I recall Rob abandoned SCREEN function further development, no I'm not sure if this is art of what wasn't made to fit with he load font features of QB64.
Alternatives if there is no solution to using SCREEN() with loaded fonts would be to map the screen in an array or to use _MEM.
Pete
|