Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
$RESIZE with Word-Wrap Routine.
#6
Steve wishes you'd learn to code with SUB and FUNCTION routines.  Move out of the prehistoric era already!  Tongue

Code: (Select All)
viewScreen = _NewImage(640, 480, 32)
'viewScreen = _NewImage(80, 25, 0)
Screen viewScreen
$Resize:On
_Delay .25
DoNothing = _Resize 'clear the inital resize flag from where our screen resizes itsefl at startup

Do
    Cls , 0

    Locate 1, 21 'to test a line with an offset
    test$ = "This is a very long sentence which runs on and on and one and even contains tipos and errors and goofs and mistakes and all sorts of junk, but it is good for testing if we have word breaks working properly for us!"
    WordWrap test$, -1
    Print 'to test a line from the starting point
    WordWrap test$, -1

    If _Resize Then resizeFlag = -1
    If resizeFlag And _Resize = 0 Then 'wait until user finishes resizing to adjust screen size
        resizeFlag = 0
        w = _ResizeWidth: h = _ResizeHeight
        If _PixelSize = 0 Then w = w \ _FontWidth: h = h \ _FontHeight
        tempScreen = _NewImage(w, h, 0)
        Screen tempScreen
        _FreeImage viewScreen
        viewScreen = tempScreen
    End If

    _Limit 30
    _Display
Loop

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


A few things I've noticed with what you posted:

1) $RESIZE:SMOOTH  <-- you don't want SMOOTH, since you're handling the resizing manually.  You want to just go with a basic $RESIZE:ON.  

2) S& = _NEWIMAGE(Sw, Sh, 0)   <-- you're making an awful lot of screens here.  Where's the corresponding _FREEIMAGE to go with that _NEWIMAGE???   Can someone say MEMORY LEAK??


3) You might want to consider doing like I have -- set a flag for when a resize event starts, but don't worry about any actual adjustments until after the user quits jerking around the borders with the mouse.  Sometimes you can have issues when trying to resize a screen that the user is still screwing around with.  I've found it generally best to wait until _RESIZE is zero once more, before doing my screen adjustments.
Reply


Messages In This Thread
$RESIZE with Word-Wrap Routine. - by Pete - 12-06-2022, 02:39 PM
RE: $RESIZE with Word-Wrap Routine. - by Pete - 12-06-2022, 03:36 PM
RE: $RESIZE with Word-Wrap Routine. - by Pete - 12-06-2022, 03:40 PM
RE: $RESIZE with Word-Wrap Routine. - by Pete - 12-06-2022, 10:05 PM
RE: $RESIZE with Word-Wrap Routine. - by SMcNeill - 12-06-2022, 10:32 PM
RE: $RESIZE with Word-Wrap Routine. - by Pete - 12-07-2022, 05:23 AM
RE: $RESIZE with Word-Wrap Routine. - by SMcNeill - 12-07-2022, 06:48 AM
RE: $RESIZE with Word-Wrap Routine. - by Pete - 12-07-2022, 07:49 AM
RE: $RESIZE with Word-Wrap Routine. - by Pete - 12-09-2022, 07:05 PM



Users browsing this thread: 1 Guest(s)