Posts: 2,171
Threads: 222
Joined: Apr 2022
Reputation:
103
Pages up and down without scrolling off the screen now, good!
_KEYCLEAR still helps but you said your custom key input routine will take care of the buffering, so that's a moot point.
Scrolling speed is still sluggish. Maybe graphics screens are just slower? Sees like it should be the other way around. It prints the text instead of using _putimage. I don't know if changing the way the text is placed on the screen would speed things up or not, I just know text scrolling in SCREEN 0 is faster.
Pete
Posts: 2,696
Threads: 327
Joined: Apr 2022
Reputation:
217
One more test for you @Pete :
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, PageBottom
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 , Black
PageBottom = 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
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.)"
PageBottom = PageBottom + 15
End Select
ReDrawScreen = 0
PageBottom = PageBottom * _FontHeight
If PageBottom > 32000 Then PageBottom = 32000
If PageTop < _FontHeight Then PageTop = 0 'a little safety check to make certain we can scroll up completely
_PutImage , WorkScreen, DisplayScreen, (0, PageTop)-Step(_Width(DisplayScreen), _Height(DisplayScreen))
_Display
End Sub
Sub ScrollPage
_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
If PageTop >= _FontHeight Then PageTop = PageTop - _FontHeight: ScrollPage
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
If PageTop <= PageBottom - ScreenHeight Then PageTop = PageTop + _FontHeight: ScrollPage
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)
PageBottom = PageBottom + 1
WordWrap LTrim$(Mid$(text, lineend + 1)), newline
End If
End Sub
''$INCLUDE:'Keyboard Library.BM'
Instead of redrawing the screen with an up/down keypress, we now simply scroll the screen instead. The new scroll routine is all of this simple:
Code: (Select All) Sub ScrollPage
_PutImage , WorkScreen, DisplayScreen, (0, PageTop)-Step(_Width(DisplayScreen), _Height(DisplayScreen))
_Display
End Sub
The only way we'd get any faster than this is if I either A) Reduce the page height from 32000 pixels to something a little more reasonable OR B) swap everything over to hardware images instead.
Posts: 2,171
Threads: 222
Joined: Apr 2022
Reputation:
103
Much improved on scrolling speed! No need for hardware image restructuring, although it would be interesting to see how much faster that would be.
As for the word-wrap, I thought I saw something before that did not involve the instructions not being part of the wrap routine. This happened with resizing to the largest font and smallest screen size.
Also note (not pictured above) that at these dimensions, the scrolling distance is affected and the user is unable to scroll the last line back to the screen. It was close, but the last line I could get was Up/Down Arrows ===> Two more lines at that font size were unable to be scrolled up.
Pete
Posts: 2,696
Threads: 327
Joined: Apr 2022
Reputation:
217
08-03-2022, 08:17 AM
(This post was last modified: 08-03-2022, 08:18 AM by SMcNeill.)
Aye. Our PRINT statements don't wordwrap, so we don't count them true for how many lines they can use. There's only 8 print statements in the demo, but I counted them as 15 lines arbitrarily. At that screensize and font size, I'm certain there's more than that number of lines actually used. Truly, PRINT shouldn't ever be used, but it's just here to showcase the wrap vs non-wrap issues.
As for the break at the whic_h, I'll have to look closer into it. There was a line which I didn't end with a newline character to test continuous printing, and I think that was the place I did so. If so, it's a glitch in the merging of text that needs a wee little tweaking. Either that, or you aren't using the latest version of QB64PE! Old versions have a glitch in them with printing to that last character on some lines, but it should now be fixed for latest editions. Try to update versions and see if the bug is still there.
Posts: 2,171
Threads: 222
Joined: Apr 2022
Reputation:
103
I'm using v2.1.
Usually these wrap in graphics glitches are caused by fractions that need just a bit of tweaking to fit all possible sizes so the conditions are met correctly in all instances. You could try tweaking, I would, or you could just wait until Windows Star Trek Self-Coding Edition comes on line. Then, we could just say, "Computer, write graphics text program with word-wrap resizing capabilities." Oh screw that. No coding, no fun, but if there was coding available, and if Windows remains the dominate system going into the future, we will probably all be coding in Klingon.
Pete
|