AngleFont to FontMachine.

Jungle Ide Home Forums FontMachine FontMachine open source module AngleFont to FontMachine.

This topic contains 2 replies, has 2 voices, and was last updated by  Taiphoz 7 years, 4 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #2647


    Hay all..

    I’m enjoying Jungle so much that I am now moving all my AngleFont code over to Fontmachine, and so far this transition has been cake, which is cool means less work for me.

    But I was wondering if Fontmachine can draw text bound to a width ? like a text box, I have selection of texts I would like to display inside a small area(chat box).




    You mean a wordwrap function? so if the text with is greater than a given with, the word gets drawn on the next line? this funcition does not exists on Fontmachine but should be very easy to add. If you do write it, send it to me and I’ll gladly add it to the official source. Remember the module is an open source project so anyone can contribute!



    edit – fixed a slight problem..

    summary:This Method draws TEXT within a given Width.
    Draw’s Text inside a given width, allowing for textbox like rendering.
    Code by Taiphoz.
    Method DrawText(text:String, x#, y#, align:Int,Tai_width:Int)

    Local Tai_TextLines:String[]

    If Self.GetTxtWidth(text)>Tai_width

    Tai_TextLines = Self.SplitLines(text,Tai_width)

    ‘Render the Lines from the String Araay.
    Local Tai_Drop:Int = Self.GetFontHeight()

    Local Tai_Count:Int =0

    For Local Tai_CurLine:String = Eachin Tai_TextLines
    If Tai_CurLine<>””
    If DrawShadow Then DrawCharsText (Tai_CurLine,x,y+(Tai_Count*Tai_Drop),eDrawMode.SHADOW, align )
    If DrawBorder Then DrawCharsText (Tai_CurLine,x,y+(Tai_Count*Tai_Drop),eDrawMode.BORDER, align )
    DrawCharsText (Tai_CurLine,x,y+(Tai_Count*Tai_Drop),eDrawMode.FACE ,align)
    End if

    if DrawShadow Then DrawCharsText (text,x,y,eDrawMode.SHADOW, align )
    If DrawBorder Then DrawCharsText (text,x,y,eDrawMode.BORDER, align )
    DrawCharsText (text,x,y,eDrawMode.FACE ,align)
    End If

    End Method

    ‘summary split given text into an array of lines based on provided with.
    Code by Taiphoz
    Method SplitLines:String[](_text:String,_width:Int)

    Local Tai_textdata:String[] = _text.Split(” “)

    Local Tai_textlines:String[]

    ‘temp vars for building lines.
    Local Tai_tmptext:String=””
    Local Tai_words:Int=Tai_textdata.Length()

    Local Tai_line:Int = 0

    For Local Tai_word:Int = 0 To Tai_words-1

    Tai_tmptext+=Tai_textdata[Tai_word]+” ”

    If Self.GetTxtWidth(Tai_tmptext)<_width
    Tai_tmptext=(Tai_textdata[Tai_word]+” “)
    End If


    Return Tai_textlines
    End Method

    it’s kinda crude but works. splits a bit of text by ” ” (space’s) and then assembles them into lines as an array of lines, which is then passed back for rendering.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.