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

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Phantomas
User
User
Posts: 96
Joined: Wed Jul 01, 2009 12:59 pm

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

Post 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
User avatar
STARGÅTE
Addict
Addict
Posts: 2067
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

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

Post 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
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Phantomas
User
User
Posts: 96
Joined: Wed Jul 01, 2009 12:59 pm

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

Post 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...
Taz
User
User
Posts: 52
Joined: Sat Jan 20, 2018 5:28 pm
Location: Germany

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

Post 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
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

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

Post 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
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

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

Post by mk-soft »

My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Taz
User
User
Posts: 52
Joined: Sat Jan 20, 2018 5:28 pm
Location: Germany

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

Post by Taz »

Thank you guys
Post Reply