Results 1 to 5 of 5

Thread: Word Wrapping

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Posts
    29

    Post

    I need to do a word wrapping function, but I can't use TextBox's one, because the program is DirectDraw app. The maximum length in characters is 75 for one line, and pixel size of the area we're writing to is 509*169 pixels. My sub is this (don't laugh at me!)

    Code:
    Sub WordWrap(destRect As RECT, DDrawSurf As DirectDrawSurface7, strText As String, lngBeginX As Long, lngBeginY As Long)
    Dim row(1 To 10) As String
    Dim intBeginValue As Integer
    Dim xi As Integer
    Dim tmpval As Integer
    intBeginValue = 70
    
    tmpval = Len(strText)
    row(1) = Left(strText, intBeginValue)
    row(2) = Mid(strText, intBeginValue, intBeginValue)
    row(3) = Mid(strText, intBeginValue * 2, intBeginValue)
    row(4) = Mid(strText, intBeginValue * 3, intBeginValue)
    row(5) = Mid(strText, intBeginValue * 4, intBeginValue)
    row(6) = Mid(strText, intBeginValue * 5, intBeginValue)
    row(7) = Mid(strText, intBeginValue * 6, intBeginValue)
    row(8) = Mid(strText, intBeginValue * 7, intBeginValue)
    row(9) = Mid(strText, intBeginValue * 8, intBeginValue)
    row(10) = Mid(strText, intBeginValue * 9, intBeginValue)
    For xi = 1 To 10
    DDrawSurf.DrawText destRect.Left + lngBeginX, destRect.Top + lngBeginY + (xi * 15), row(xi), False
    Next
    
    End Sub

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    You might be able to get some ideas from my answer to another post

    ------------------
    Marty
    What did the fish say when it hit the concrete wall?
    > > > > > "Dam!"

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Posts
    29

    Post

    Works fine in Debug window, but in DirectX I should get each row of text in string. How to do that?

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    Does this work for you?

    Code:
        Dim sMyString As String
        Dim nPos As Integer
        Dim nStartPos As Integer
        Dim bDone As Boolean
        Dim row() As String
        Dim intRow As Integer
    
        sMyString = MySnapshot!MyField
        nStartPos = Len(sMyString) - 1
        nPos = nStartPos
        
        Do Until bDone
            If Len(sMyString) <= 67 Then
    '            Debug.Print sMyString
                ReDim Preserve row(intRow)
                row(intRow) = sMyString
                bDone = True
                Exit Do
            End If
            Do Until nPos <= 67
                nPos = InStrRev(sMyString, " ", nStartPos)
                nStartPos = nStartPos - 1
            Loop
            'Debug.Print Left(sMyString, nPos - 1)
            ReDim Preserve row(intRow)
            row(intRow) = Left(sMyString, nPos - 1)
            intRow = intRow + 1
            sMyString = Right(sMyString, Len(sMyString) - (nPos)) 'ok
            nStartPos = Len(sMyString) - 1
            nPos = nStartPos
        Loop
        
        For intRow = 0 To UBound(row)
            Debug.Print row(intRow)
        Next

    ------------------
    Marty
    What did the fish say when it hit the concrete wall?
    > > > > > "Dam!"

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Posts
    29

    Post

    I didn't test it, because I fixed your first subroutine so that it works now in DirectX too!

    Code:
    Private Sub Form_Load()
    intExplLen = Round(Len(zpItem.ItemInfo.IExplanation) / 75)
    End Sub
    
    Sub WordWrp(destRect As RECT, DDrawSurf As DirectDrawSurface7, strText As String, lngBeginX As Long, lngBeginY As Long, charToWrap As Integer)
    Dim row(1 To 10) As String
    Dim nPos As Integer
    Dim nStartPos As Integer
    Dim bDone As Boolean 'onko valmista
    Dim xi As Integer 'for-looppien muuttuja
    
    Dim numRows As Integer
    nStartPos = Len(strText) - 1
    nPos = nStartPos
    numRows = Round(Len(strText))
    
    
    Do Until bDone
    For xi = 1 To numRows
     If Len(strText) <= charToWrap Then
      row(xi) = strText 'row(1) = Left(strText, nPos - 1)
      DDrawSurf.DrawText lngBeginX, lngBeginY + (intExplLen * 15), strText, False 'tämä on viimeinen rivi
      'backbuffer.DrawText 360, 720, intExplLen, False 'näytä rivien määrä
      bDone = True 'lngBeginY + (xi * 15)
      Exit Do
     End If
     
      Do Until nPos <= charToWrap
       nPos = InStrRev(strText, " ", nStartPos)
       nStartPos = nStartPos - 1
      Loop
     
       row(xi) = Left(strText, nPos - 1)
       DDrawSurf.DrawText lngBeginX, lngBeginY + (xi * 15), row(xi), False 'tämä on viimeinen rivi
       
       strText = Right(strText, Len(strText) - nPos) 'ok
       nStartPos = Len(strText) - 1
       nPos = nStartPos
     Next
    Loop
    
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width