Page 1 of 1

DrawText() — New Line Support (#CRLF$)

Posted: Thu Feb 06, 2014 6:15 pm
by Phantomas
Hello. It would be nice if DrawText() function support New Line, like TextGadget() with #CRLF$.
Example (set #enable constant to 0 or 1):

Code: Select all

#enable = 1 ;1 or 0

OpenWindow(0, #PB_Ignore, #PB_Ignore, 320, 280, "2D Text")
CreateImage(0, 320, 280)
StartDrawing(ImageOutput(0))


CompilerIf #enable
  DrawText(0, 0, "Hello")
  DrawText(0, TextHeight("Hello"), "World!")
CompilerElse
  DrawText(0, 0, "Hello" + #CRLF$ + "World!")
CompilerEndIf

StopDrawing()
ImageGadget(0, 0, 0, 320, 280, ImageID(0))
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver

Re: DrawText() — New Line Support (#CRLF$)

Posted: Thu Feb 06, 2014 6:36 pm
by STARGÅTE
It is easy to create a function:

Code: Select all


Procedure DrawTextEx(X.i, Y.i, Text.s)
	Protected I.i, Max = CountString(Text, #CRLF$)+1
	Protected Line.s
	For I = 1 To Max
		Line = StringField(Text, I, #CRLF$)
		DrawText(X, Y, Line)
		Y + TextHeight(" ")
	Next 
EndProcedure

OpenWindow(0, #PB_Ignore, #PB_Ignore, 320, 280, "2D Text")
CreateImage(0, 320, 280)
StartDrawing(ImageOutput(0))

DrawTextEx(0, 0, "Hello" + #CRLF$ + "World!" + #CRLF$ + #CRLF$ + "Nice!")

StopDrawing()
ImageGadget(0, 0, 0, 320, 280, ImageID(0))
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver

Re: DrawText() — New Line Support (#CRLF$)

Posted: Thu Feb 06, 2014 9:46 pm
by Phantomas
Yes, but native will be better.
For example, with DrawTextEx() you also need to create "Ex" functions of TextWidth/Height, something else :).
Just my wish...

Re: DrawText() — New Line Support (#CRLF$)

Posted: Tue Feb 20, 2018 12:42 am
by Taz
quite confusing function name, thought that NewLine is supported, but now that I needed it I had to realize that's not the case.

The function is called DrawText, would be better DrawString, or add Newline support to DrawText :lol: :D

Re: DrawText() — New Line Support (#CRLF$)

Posted: Tue Feb 20, 2018 9:54 am
by walbus
The DrawText function is very limited in its functionality
There is a better solution, with CR-LF support - and many more :wink:

DrawText_EX and DrawText_BF

http://www.purebasic.fr/english/viewtop ... 12&t=69145

Re: DrawText() — New Line Support (#CRLF$)

Posted: Tue Feb 20, 2018 7:09 pm
by mk-soft

Re: DrawText() — New Line Support (#CRLF$)

Posted: Wed Feb 21, 2018 6:03 am
by Taz
Thank you guys