08-03-2022, 01:20 AM
Updated to showcase how this little interface would work with actual screens of information:
I don't think it'd be hard for anyone to sort out how to use this as a quick base for their own little routines, but if anybody has any questions over it, just speak up and I'll be happy to answer them. We've got wordwrap. We've got adjustable screen size. We've got adjustable font size. We can dim or brighten our text on the screen. We can display an extra large wall of text and then scroll up and down it with the arrow keys.
As far as a tool to quickly display and customize text of any sort (such as a help menu, novel, or text-based adventure game), I can't think of anything else much that we'd need to incorporate into this little framework. Is there something obvious that I'm missing here that you guys can see? If not, then I'd call this little "Work-In-Progress", "Finished" -- at least it's finished for all it's supposed to do here. Now all I need to do is use it for my other needs (I'm thinking of using it basically to create a text game with, as I haven't written one of them in ages, and they seem like something simple just to pass the time and not strain the brain while waiting to find out more about when my surgery is going to be.)
Code: (Select All)
'Set compiler and global progeam options
'All variables and arrays are dynamic by default
'$Dynamic
'Allow the use of color names for 32-bit screen mode
$Color:32
''$INCLUDE:'Keyboard Library.BI'
_Define A-Z As LONG 'default variable type is long
_Title "Title TBD"
'Types and global variables
Dim Shared As Long ScreenWidth, ScreenHeight, DisplayScreen, WorkScreen, ReDrawScreen
Dim Shared As Long Font(10), FontSize, Brightness, PageTop
Dim Shared As Long True, False
'Defaut vaues for global variables
ScreenWidth = 1280
ScreenHeight = 720
DisplayScreen = _NewImage(ScreenWidth, ScreenHeight, 32)
WorkScreen = _NewImage(ScreenWidth, 32000, 32)
True = -1: False = 0
ReDrawScreen = -1 'Draw our initial screen
Font(0) = _LoadFont("courbd.ttf", 6, "monospace")
Font(1) = _LoadFont("courbd.ttf", 8, "monospace")
Font(2) = _LoadFont("courbd.ttf", 10, "monospace")
Font(3) = _LoadFont("courbd.ttf", 12, "monospace")
Font(4) = _LoadFont("courbd.ttf", 14, "monospace")
Font(5) = _LoadFont("courbd.ttf", 16, "monospace")
Font(6) = _LoadFont("courbd.ttf", 18, "monospace")
Font(7) = _LoadFont("courbd.ttf", 22, "monospace")
Font(8) = _LoadFont("courbd.ttf", 28, "monospace")
Font(9) = _LoadFont("courbd.ttf", 36, "monospace")
Font(10) = _LoadFont("courbd.ttf", 48, "monospace")
FontSize = 8 'starting font size
Brightness = 5
Screen DisplayScreen
_Delay .2
_Dest WorkScreen
_Font Font(FontSize)
Color _RGB32(255 \ Brightness), 0
Do
ProcessInput
If ReDrawScreen Then DisplayPage (0)
_Limit 60
Loop
Sub DisplayPage (Page)
Cls , _RGB32(0, 0, 0)
Select Case Page 'which page of information do we wish to display?
Case 0
WordWrap "This is a demo of a nice long length of text which I'm just tossing up to the screen to show how it'll manually resize itself and fit on the screen nice and properly for us. I really don't have anything important to say here, so I'm just going to ramble on for a paragraph or two, just to make certain there's enough text on the screen to look all pretty.", -1
WordWrap "As you can see, there's no issue with printing and resizing our text.", -1
WordWrap "Using CTRL or ALT, in conjection with our arrow keys, you can easily resize the text on this screen, brighten or dim it, or even resize the screen itself, ", 0
WordWrap "which I think should be more than enough to showcase what this little framework can do for us. ;)", -1
End Select
Print "CTRL + Arrow Key => Resize Screen"
Print "ALT + Left/Right => Change FontSize"
Print "ALT + Up/Down ====> Brighten/Dim the Screen"
Print "CTRL + F =========> Full Screen"
Print "ESC ==============> Exit the Program"
Print "Up/Down Arrows ===> Scroll the text up or down to view more of the screen"
Print
Print "(Note, you'll only need more than one screenfull of information with the largest fonts.)"
ReDrawScreen = 0
_PutImage , WorkScreen, DisplayScreen, (0, PageTop)-Step(_Width(DisplayScreen), _Height(DisplayScreen))
_Display
End Sub
Sub ProcessInput
While _MouseInput: MouseScroll = MouseScroll + _MouseWheel: Wend
K = _KeyHit
If _KeyDown(100306) Or _KeyDown(100305) Then CTRL = True Else CTRL = False
If _KeyDown(100304) Or _KeyDown(100303) Then SHIFT = True Else SHIFT = False
If _KeyDown(100308) Or _KeyDown(100307) Then ALT = True Else ALT = False
Select Case K
Case Asc("F"), Asc("f")
If CTRL Then
ScreenWidth = _DesktopWidth: ScreenHeight = _DesktopHeight - 80 'take a little off for windows taskbar and title bar size
AutoResize
_ScreenMove 0, 0
End If
Case 19200 'left
If CTRL Then
If ScreenWidth >= 650 Then ScreenWidth = ScreenWidth - _FontWidth: AutoResize
ElseIf ALT Then
If FontSize > 0 Then FontSize = FontSize - 1: _Font Font(FontSize): AutoResize
End If
Case 18432 'up
If CTRL Then
If ScreenHeight >= 410 Then ScreenHeight = ScreenHeight - _FontHeight: AutoResize
ElseIf ALT Then
If Brightness > 1 Then Brightness = Brightness - 1: Color _RGB32(255 \ Brightness), 0: ReDrawScreen = -1
Else
PageTop = PageTop - _FontHeight: If PageTop < 0 Then PageTop = 0
ReDrawScreen = -1
End If
Case 19712 'right
If CTRL Then
If ScreenWidth <= _DesktopWidth - 10 Then ScreenWidth = ScreenWidth + _FontWidth: AutoResize
ElseIf ALT Then
If FontSize < 10 Then FontSize = FontSize + 1: _Font Font(FontSize): AutoResize
End If
Case 20480 'down
If CTRL Then
If ScreenHeight <= _DesktopHeight - 10 Then ScreenHeight = ScreenHeight + _FontHeight: AutoResize
ElseIf ALT Then
If Brightness < 10 Then Brightness = Brightness + 1: Color _RGB32(255 \ Brightness), 0: ReDrawScreen = -1
Else
PageTop = PageTop + _FontHeight: If PAgetaop > 32000 - _Height(DisplayScreen) Then PageTop = 32000 - _Height(DisplayScreen)
ReDrawScreen = -1
End If
Case 27
System
End Select
End Sub
Sub AutoResize
Static OldFontSize
W = _Width(DisplayScreen): H = _Height(DisplayScreen)
FW = _FontWidth: FH = _FontHeight
RW = ScreenWidth: RH = ScreenHeight
RW = _Round(RW / FW) * FW
RH = _Round(RH / FH) * FH
ScreenWidth = RW: ScreenHeight = RH
tempscreen = _NewImage(RW, RH, 32)
Screen tempscreen
_FreeImage DisplayScreen
DisplayScreen = tempscreen
tempscreen = _NewImage(RW, 32000, 32) 'create the newly sized WorkScreen
_Dest tempscreen 'can't freeimage a screen if it's in use?
_FreeImage WorkScreen 'free the old WorkScreen
WorkScreen = tempscreen
_Dest WorkScreen
_Font Font(FontSize)
Color _RGB32(255 \ Brightness), 0
OldFontSize = FontSize
ReDrawScreen = -1
End Sub
Sub WordWrap (text As String, newline)
Dim BreakPoint As String
BreakPoint = ",./- ;:!" 'I consider all these to be valid breakpoints. If you want something else, change them.
w = ScreenWidth
pw = _PrintWidth(text)
x = Pos(0): y = CsrLin
If _PixelSize <> 0 Then x = x * _FontWidth
firstlinewidth = w - x + 1
If pw <= firstlinewidth Then
Print text;
If newline Then Print
Else
'first find the natural length of the line
For i = 1 To Len(text)
p = _PrintWidth(Left$(text, i))
If p > firstlinewidth Then Exit For
Next
lineend = i - 1
t$ = RTrim$(Left$(text, lineend)) 'at most, our line can't be any longer than what fits the screen.
For i = lineend To 1 Step -1
If InStr(BreakPoint, Mid$(text, i, 1)) Then lineend = i: Exit For
Next
Print Left$(text, lineend)
WordWrap LTrim$(Mid$(text, lineend + 1)), newline
End If
End Sub
''$INCLUDE:'Keyboard Library.BM'
I don't think it'd be hard for anyone to sort out how to use this as a quick base for their own little routines, but if anybody has any questions over it, just speak up and I'll be happy to answer them. We've got wordwrap. We've got adjustable screen size. We've got adjustable font size. We can dim or brighten our text on the screen. We can display an extra large wall of text and then scroll up and down it with the arrow keys.
As far as a tool to quickly display and customize text of any sort (such as a help menu, novel, or text-based adventure game), I can't think of anything else much that we'd need to incorporate into this little framework. Is there something obvious that I'm missing here that you guys can see? If not, then I'd call this little "Work-In-Progress", "Finished" -- at least it's finished for all it's supposed to do here. Now all I need to do is use it for my other needs (I'm thinking of using it basically to create a text game with, as I haven't written one of them in ages, and they seem like something simple just to pass the time and not strain the brain while waiting to find out more about when my surgery is going to be.)