TextGadget and DrawText inconsistency

Just starting out? Need help? Post your questions and find answers here.
RobertRioja
User
User
Posts: 71
Joined: Thu May 02, 2019 3:57 am
Location: USA
Contact:

TextGadget and DrawText inconsistency

Post by RobertRioja »

The same text displayed in a TextGadget and drawn by DrawText should look the same, but not necessarily so. The following code shows the problem:

Code: Select all

Global.s Theta = Chr($03f4)                   ; Greek symbol

Global.s TheText = "This is theta: " + Theta  ; Some text

OpenWindow(0, 0, 0, 200, 100, "Test")         ; Let's make a window.

TextGadget(0, 10, 10, 100, 30, "")            ; And a text box.
SetGadgetText(0, TheText)                     ; Display the text.

StartDrawing(WindowOutput(0))                 ; 2D drawing

DrawText(10, 50, TheText)                     ; Draw the same text

StopDrawing()

Repeat                                        ; Wait for the end.
Until WindowEvent() = #PB_Event_CloseWindow

End
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: TextGadget and DrawText inconsistency

Post by kenmo »

RobertRioja wrote:The same text displayed in a TextGadget and drawn by DrawText should look the same
Hmm? The Gadget functions and the 2D Drawing functions are unrelated, there is no guarantee they use the same font.

It works if you tell it what font to draw with, try this:

Code: Select all

DrawingFont(GetGadgetFont(#PB_Default))
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(10, 50, TheText, #Black)             ; Draw the same text
RobertRioja
User
User
Posts: 71
Joined: Thu May 02, 2019 3:57 am
Location: USA
Contact:

Re: TextGadget and DrawText inconsistency

Post by RobertRioja »

What is really confusing is that my original code works as expected when compiled with SpiderBasic. You would think that both compilers would give the same results.

So I assume that in PureBasic the two functions don't use the same default font, but in SpiderBasic they do.

I think that it would be best if all text functions started out with the same default font. That makes sense.

So it may not be a bug, but I hope that this issue is addressed.

Thank you,
Robert
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: TextGadget and DrawText inconsistency

Post by kenmo »

Ah OK, I don't use SpiderBasic much, but I imagine the drawing functions and gadgets are more closely related.

Back to PB:

If I recall correctly, on other OS (Mac and Linux) DrawText() won't even draw unless you call DrawingFont() first. It does not assume any default font. Maybe the PB team can clarify this.
RobertRioja
User
User
Posts: 71
Joined: Thu May 02, 2019 3:57 am
Location: USA
Contact:

Re: TextGadget and DrawText inconsistency

Post by RobertRioja »

I don't use the other OS's so I would not know. But if that is the case, then all the more reason to have the PB team look into this and help make it all more consistent.

I think that one of the great things about PB/SB is the ability to generate executables for many OS's. So we really need as much consistency as possible. I came across the "bug" I mentioned because I was trying to create a single app for Windows, Android and web. I did have to make some adjustments using "CompilerIf #PB_Compiler_OS = xx" but in all cases it was easy to understand the differences. The difference you mentioned I cannot find in the documentation, so I am grateful to you for that.

Robert
Fred
Administrator
Administrator
Posts: 16686
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: TextGadget and DrawText inconsistency

Post by Fred »

the OS font and 2D drawing font are not exactly the same as we don't use OS function to draw on our internal buffer. So it's close but not exactly the same.
Post Reply