Drawtext and PB

Just starting out? Need help? Post your questions and find answers here.
loulou2522
Enthusiast
Enthusiast
Posts: 553
Joined: Tue Oct 14, 2014 12:09 pm

Drawtext and PB

Post by loulou2522 »

Since the new version

Code: Select all

Procedure updateProgressBar(barNum, imageNum, amount, max, fColor, bColor, tColor, txt.s )
    Protected iw = ImageWidth(imageNum), ih = ImageHeight(imageNum), tw, th
    StartDrawing(ImageOutput(imageNum))
    Box(0, 0, iw, ih, fColor)
    Box(0, 0, amount / (max / iw), ih, bColor)
    DrawingMode(#PB_2DDrawing_Transparent)         
    ; txt + " " + LSet(Str(amount * 100/max), 2, "0") + "%"
    tw = TextWidth(txt)
    th = TextHeight(txt)         
    DrawText((iw - tw) >> 1, (ih - th) >> 1, txt, tColor)
    StopDrawing()
    SetGadgetState(barNum, ImageID(imageNum))
  EndProcedure
DrawText((iw - tw) >> 1, (ih - th) >> 1, txt, tColor)
return this error message when compiling
[12 :58 :53] [COMPILER] Ligne 1116: Les operateurs suivants sont indisponibles avec les nombres flottants: <<, >>, &, |, !, %.
With PB 6.10 Beta 6 there was not problem with this instruction
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Drawtext and PB

Post by Fred »

True, the parameters are now double, so you can't use '>>' (just use /2 and it will be fine).
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Drawtext and PB

Post by infratec »

Or ... an other bracket

Code: Select all

 DrawText(((iw - tw) >> 1), ((ih - th) >> 1), txt, tColor)
BarryG
Addict
Addict
Posts: 4219
Joined: Thu Apr 18, 2019 8:17 am

Re: Drawtext and PB

Post by BarryG »

Fred wrote: Tue Mar 05, 2024 1:55 pmthe parameters are now double, so you can't use '>>' (just use /2 and it will be fine)
Wait, what? So if our sources have ">>" anywhere in 6.10, we need to change them to "/2" to make them work?

Is this why my app is crashing since switching from 6.04 to 6.10 recently? I do have ">>" in some calculations.
User avatar
STARGÅTE
Addict
Addict
Posts: 2260
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Drawtext and PB

Post by STARGÅTE »

BarryG wrote: Wed Mar 06, 2024 2:24 am
Fred wrote: Tue Mar 05, 2024 1:55 pmthe parameters are now double, so you can't use '>>' (just use /2 and it will be fine)
Wait, what? So if our sources have ">>" anywhere in 6.10, we need to change them to "/2" to make them work?

Is this why my app is crashing since switching from 6.04 to 6.10 recently? I do have ">>" in some calculations.
Not anywhere, only in context with floating point numbers. Also before PB 6.0 it was not allowed to use the bit operators (<<, >>, |, &, !) together with floating point numbers or operators.
So nothing has changed here.
The only change is in DrawText, from DrawText(X.i, Y.i) to DrawText(X.d, Y.d), but I don't know the reason.
The 2DDrawing library is a pixel perfect drawing engine, why changing here to doubles?
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
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Drawtext and PB

Post by infratec »

Do you get compiler warnings or errors?
If not, your code is not affected.

In this case it happens, because the parameters x and y from DrawText() are changed from integres to doubles.
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Drawtext and PB

Post by Fred »

STARGÅTE wrote: Wed Mar 06, 2024 7:50 am
BarryG wrote: Wed Mar 06, 2024 2:24 am
Fred wrote: Tue Mar 05, 2024 1:55 pmthe parameters are now double, so you can't use '>>' (just use /2 and it will be fine)
Wait, what? So if our sources have ">>" anywhere in 6.10, we need to change them to "/2" to make them work?

Is this why my app is crashing since switching from 6.04 to 6.10 recently? I do have ">>" in some calculations.
Not anywhere, only in context with floating point numbers. Also before PB 6.0 it was not allowed to use the bit operators (<<, >>, |, &, !) together with floating point numbers or operators.
So nothing has changed here.
The only change is in DrawText, from DrawText(X.i, Y.i) to DrawText(X.d, Y.d), but I don't know the reason.
The 2DDrawing library is a pixel perfect drawing engine, why changing here to doubles?
OSX needs double for x,y, you can check more here: https://www.purebasic.fr/english/viewtopic.php?t=71429
juergenkulow
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 25, 2019 10:18 am

Re: Drawtext and PB

Post by juergenkulow »

Documentation 2DDrawing.txt Line 922
@Function Result = DrawText(x, y, Text$ [, FrontColor [, BackColor]])

Code: Select all

@Function Result = DrawText(x.d, y.d, Text$ [, FrontColor [, BackColor]])
                              ^    ^
TOP 2: Is there the same problem with DrawRotatedText on MAC OS?
BarryG
Addict
Addict
Posts: 4219
Joined: Thu Apr 18, 2019 8:17 am

Re: Drawtext and PB

Post by BarryG »

infratec wrote: Wed Mar 06, 2024 7:52 amDo you get compiler warnings or errors?
If not, your code is not affected.
No, my app just exits silently without warning. See here -> https://www.purebasic.fr/english/viewtopic.php?t=83721
Post Reply