Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Customizable Program Display
#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


Messages In This Thread
Customizable Program Display - by SMcNeill - 08-02-2022, 05:00 AM
RE: Customizable Program Display - by bplus - 08-02-2022, 03:40 PM
RE: Customizable Program Display - by SMcNeill - 08-03-2022, 01:20 AM
RE: Customizable Program Display - by Pete - 08-03-2022, 03:29 AM
RE: Customizable Program Display - by admin - 08-03-2022, 03:56 AM
RE: Customizable Program Display - by admin - 08-03-2022, 03:58 AM
RE: Customizable Program Display - by Pete - 08-03-2022, 04:22 AM
RE: Customizable Program Display - by SMcNeill - 08-03-2022, 05:13 AM
RE: Customizable Program Display - by Pete - 08-03-2022, 05:31 AM
RE: Customizable Program Display - by SMcNeill - 08-03-2022, 05:57 AM
RE: Customizable Program Display - by Pete - 08-03-2022, 06:46 AM
RE: Customizable Program Display - by SMcNeill - 08-03-2022, 07:17 AM
RE: Customizable Program Display - by Pete - 08-03-2022, 07:54 AM
RE: Customizable Program Display - by SMcNeill - 08-03-2022, 08:17 AM
RE: Customizable Program Display - by Pete - 08-03-2022, 04:30 PM



Users browsing this thread: 6 Guest(s)