Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Customizable Program Display
#1
Here's a little showcase of something which I'm working on for a personal little project of mine, which I thought folks might like to take a look at -- an user customizable-display program.

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
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 = 0
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
    Cls , 0
    Print _Width(DisplayScreen), _Height(DisplayScreen)

    _PutImage , WorkScreen, DisplayScreen, (0, 0)-Step(_Width(DisplayScreen), _Height(DisplayScreen))
    _Limit 60
    _Display
Loop

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 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

            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


            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


''$INCLUDE:'Keyboard Library.BM'


Now, since I couldn't get $RESIZE:ON to work the way I was wanting, with a limit for size, I took it out of this program.  Instead, the user here now has several options, all of which are keyboard operated:

CTRL + Arrow Keys = Resize the screen.  You can make this program bigger or smaller, on the fly.

ALT + Left/Right Arrow = Increase or Decrease the size of the font on the screen.  Notice that this can also change the size of the screen slightly to suit the new fontwidth and fontheight.

ALT + Up/Down Arrow = Increase or Decrease the brightness of the text on the screen.  Late at night, I tend to do things with the lights off and while sitting in the dark a lot of the times, and a bright display ends up hurting my eyes.  This corrects that issue by allowing us to adjust the brightness of the text so that we can might it more intense in times of high surrounding light, or turn it waaay down, if we prefer, for use in the dark.

Now, we're not actually doing anything with this program as of yet, but it does use two distinct screens for us -- a WorkScreen and a DisplayScreen.  The WorkScreen is 32000 pixels in height, so we can print multiple pages of text upon it, and then display segments upon the DisplayScreen, for ease of scrolling up and down with screens which hold more than a single page of information.

I'll be adding word wrap along with the auto-resizing features, and then the basic interface will more-or-less be done for my needs.  If you guys want, I'll post a version of this with a nice long page of junk and word wrap to bring it all together, but I thought I'd go ahead and share it as it is, in case anyone else would ever be interested in making use of this type of user-interactive interface.  Personally, I think it'd make a nice little way to allow the user some display options for something like a text-adventure game, or any type of program which would be heavy on text usage.  

As I get older, I find it's always nice to be able to make text a little bigger/smaller and brighter/dimmer, depending on the state of my poor eyes.  What we have here is basically just a little plug-in routine which is ready built to handle most of that for us already.  With just a few minor enhancements, I imagine this will be something which I might end up making a lot of use of in the future.  Smile
Reply
#2
"As I get older, I find it's always nice to be able to make text a little bigger/smaller and brighter/dimmer, depending on the state of my poor eyes. What we have here is basically just a little plug-in routine which is ready built to handle most of that for us already. With just a few minor enhancements, I imagine this will be something which I might end up making a lot of use of in the future. Smile"

yah!
b = b + ...
Reply
#3
Updated to showcase how this little interface would work with actual screens of information:

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.)
Reply
#4
This reminded me of a routine I wrote for some member here who wanted to calculate the largest font possible on a changing size screen to print a random sentence. That was fun.

Oh, I found it: https://qb64phoenix.com/forum/showthread.php?tid=337

This is the stuff SCREEN 0 was made for, but if one wanted to get more of a Windows style appearance, this is the way to go.

It looks like you need to revisit the word-wrap routine, though. Some words wrap, but others break. The only other thing that would need tweaking on my system would be the scrolling. I experienced terrible lag while trying to scroll.

The coolest unique feature, over a SCREEN 0 text app, is the brightness control; although I suppose using palette and out commands some of this could be feature could be implemented or by using Win API, it could be accomplished completely with Win API calls.

Good luck with it. If you can figure out a way to get the speed up, so it's more responsive, that would be great. Funny, I actually thought about making a graphics version of my word program a few weeks ago.

Pete
Reply
#5
@Pete -- Wordwrap works fine; view the code...

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. Wink", -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


Notice two different methods at play in the demo, to showcase the difference you noticed? Those last few lines are deliberately non-wrapping. Wink
Reply
#6
@Pete More Responsive? At what? Where are you seeing sluggishness at work?
Reply
#7
Okay on the word-wrap. I was expecting the entire page to wrap, not just the demo text.

No okay on the scrolling. Tried it again and very sluggish. I had to close it out and restart it a couple of times when I scrolled the text off the screen and it wouldn't come back after waiting a couple of minutes.

How fast does it scroll for you? It takes me 6 seconds holding sown the arrow key to scroll the text up until the bottom line if off the screen.

Pete

EDIT: Okay, I added _KEYCLEAR after ReDrawScreen = -1 in both the scroll routines and that helped a bunch. Still one thing I think needs to be addressed, which is the text should stop being scrolled up when the last line is scrolled past the top of the screen. Without _KEYCLEAR, the buffer would keep pushing up the text so it appeared several key down presses had no effect. Also, when the buffer gets that full, the delay in the ESC key makes it seem like the program is locked-up.
Reply
#8
Aye. A 32000 length page at 20 pixels per line gives us 1600 lines of text to scroll down, if we just hold the arrow and let it go -- and out of those, we're only printing on about 20 of them. When I start my actual text adventure, I'm going to add in a simple variable to the DisplayPage routine which counts total lines used on it, and then it can set that as the page bottom. At that point you won't be able to scroll past the text and those lost presses won't affect you anymore. That should eliminate most of the issue which you're talking about.

PageUp/PageDown to navigate a whole page of text at once would also be nice. (CTRL + PageUp/PageDown to jump to top/bottom as well.)

And if you look, I don't actually need a _KEYCLEAR. I use my custom keyboard library normally, so it takes care of that. Wink
Reply
#9
In my word program I use...

Arrow up/down to scroll to top and bottom of text page.
Page up/down
Ctrl+Home to go to the start of the text.
Ctrl+End to place the last line of the text on the bottom line, provided there is a page or more of text.

Also, the mouse wheel is great for scrolling, along with right side scroll bars with clickable arrows and dragable thumb.

Fun stuff!

Pete
Shoot first and shoot people who ask questions, later.
Reply
#10
Give this a shot and see if it doesn't correct the unresponsiveness you noticed:

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 , _RGB32(0, 0, 0)

    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 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: 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
                If PageTop <= PageBottom - _Height(DisplayScreen) Then PageTop = PageTop + _FontHeight: 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)
        PageBottom = PageBottom + 1
        WordWrap LTrim$(Mid$(text, lineend + 1)), newline
    End If
End Sub



''$INCLUDE:'Keyboard Library.BM'

Of course, now you'll have to make the screen smaller than the text printed on it, or the text larger, if you want to scroll down. There's no longer any chance to scroll past the end of the page and keep going off into the great unknown like before. LOL!
Reply




Users browsing this thread: 8 Guest(s)