Page 1 of 1

Drawtext and PB

Posted: Tue Mar 05, 2024 1:01 pm
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

Re: Drawtext and PB

Posted: Tue Mar 05, 2024 1:55 pm
by Fred
True, the parameters are now double, so you can't use '>>' (just use /2 and it will be fine).

Re: Drawtext and PB

Posted: Tue Mar 05, 2024 2:11 pm
by infratec
Or ... an other bracket

Code: Select all

 DrawText(((iw - tw) >> 1), ((ih - th) >> 1), txt, tColor)

Re: Drawtext and PB

Posted: Wed Mar 06, 2024 2:24 am
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.

Re: Drawtext and PB

Posted: Wed Mar 06, 2024 7:50 am
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?

Re: Drawtext and PB

Posted: Wed Mar 06, 2024 7:52 am
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.

Re: Drawtext and PB

Posted: Wed Mar 06, 2024 9:11 am
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

Re: Drawtext and PB

Posted: Wed Mar 06, 2024 9:40 am
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?

Re: Drawtext and PB

Posted: Wed Mar 06, 2024 10:10 am
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