Page 1 of 1

Facing a size mystery

Posted: Sun Jan 21, 2024 12:29 pm
by charvista
I am currently facing a size mystery, perhaps I know the answer to it, but for now I am in trouble.
In the code below, why is the red background not filling the whole window, as they have the same size (WinW and WinH) ?

Code: Select all

EnableExplicit
Define.i BtnOk,Event,F,ImCre,ImGad,Quit,Win,WinH,WinW
F=LoadFont(#PB_Any,"Courier New",32)
WinW=800
WinH=300
Win.i=OpenWindow(#PB_Any,0,0,WinW,WinH,"ERROR",#PB_Window_ScreenCentered)
    ImCre.i=CreateImage(#PB_Any,WinW,WinH)
    ImGad.i=ImageGadget(#PB_Any,0,0,WinW,WinH,ImageID(ImCre))
    StartDrawing(ImageOutput(ImCre))
        DrawingMode(#PB_2DDrawing_Transparent)
        Box(0,0,WinW,WinH,#Red)
        DrawingFont(FontID(F))
        DrawText(40,50,"!ERROR=47",#Yellow)
    StopDrawing()
    SetGadgetState(ImGad,ImageID(ImCre))
    BtnOk.i=ButtonGadget(#PB_Any,40,255,80,25,"OK",#PB_Button_Default)
    Repeat
        Event=WaitWindowEvent()
        Select Event
            Case #PB_Event_CloseWindow
                Quit=#True
            Case #PB_Event_Gadget
                Select EventGadget()
                    Case BtnOk
                        Quit=#True
                EndSelect
        EndSelect    
    Until Quit
    

Re: Facing a size mystery

Posted: Sun Jan 21, 2024 12:54 pm
by RASHAD
Hi
You can't colorize the Caption Bar(Title Bar) it's hard coded
You can only change it to Dark mode (Windows 10 & 11)

Code: Select all

EnableExplicit
Define.i BtnOk,Event,F,ImCre,ImGad,Quit,Win,WinH,WinW
F=LoadFont(#PB_Any,"Courier New",32)
WinW=800
WinH=300
Win.i=OpenWindow(#PB_Any,0,0,WinW,WinH,"ERROR",#PB_Window_ScreenCentered |#PB_Window_BorderLess)
    ImCre.i=CreateImage(#PB_Any,WinW,WinH)
    ImGad.i=ImageGadget(#PB_Any,0,0,WinW,WinH,ImageID(ImCre))
    StartDrawing(ImageOutput(ImCre))
        DrawingMode(#PB_2DDrawing_Transparent)
        Box(0,0,WinW,WinH,#Red)
        DrawingFont(FontID(F))
        DrawText(40,50,"!ERROR=47",#Yellow)
    StopDrawing()
    SetGadgetState(ImGad,ImageID(ImCre))
    DisableGadget(ImGad,1)
    BtnOk.i=ButtonGadget(#PB_Any,40,255,80,25,"OK",#PB_Button_Default)
    Repeat
        Event=WaitWindowEvent()
        Select Event
            Case #PB_Event_CloseWindow
                Quit=#True
            Case #PB_Event_Gadget
                Select EventGadget()
                    Case BtnOk
                        Quit=#True
                EndSelect
        EndSelect    
    Until Quit
    

Re: Facing a size mystery

Posted: Sun Jan 21, 2024 1:52 pm
by charvista
Thanks RASHAD, but it is not what I asked.
It is the Box (coloured red) that has the same size as the window (size under the caption), it is an Image that should cover the window.
Of course, I could use SetWindowColor(), but here it is the drawing of the Box that intrigues me, because it is partially covered, despite the fact it has the same size (800x300).

Re: Facing a size mystery

Posted: Sun Jan 21, 2024 2:01 pm
by RASHAD
Ah
It's working fine with PB 6.04

Re: Facing a size mystery

Posted: Sun Jan 21, 2024 2:26 pm
by charvista
Not here. Using Windows 11 Home 64-bit, PB 6.04 LTS (x64)

Image

Re: Facing a size mystery

Posted: Sun Jan 21, 2024 2:43 pm
by RASHAD
Not here Windows 11 Pro x64 PB 6.04 x64 :D
I guess it's DPI problem
Are you using DPI different than the normal ?
Try

Code: Select all

ImGad.i=ImageGadget(#PB_Any,0,0,0,0,ImageID(ImCre))

Re: Facing a size mystery

Posted: Sun Jan 21, 2024 3:03 pm
by charvista
Are you using DPI different than the normal ?
You guessed right !!! Indeed, my computer was set to DPI 150%, and reverting back to 100% it covered the whole window ! :D

All right, I am glad to know WHY this "bug" happens.
Now, how to make it universal :?:
The Box function seems not to be DPI aware.

Re: Facing a size mystery

Posted: Sun Jan 21, 2024 3:10 pm
by RASHAD
1- Enable DPI aware in the compiler Option
2- dpix.d = DesktopResolutionX() ,dpiy.d = DesktopResolutionY()
3- Multiply the image width and the image gadget width by dpix
4- Multiply the image height and the image gadget height by dpiy

Re: Facing a size mystery

Posted: Sun Jan 21, 2024 3:23 pm
by RASHAD

Code: Select all

;EnableExplicit
Define.i BtnOk,Event,F,ImCre,ImGad,Quit,Win,WinH,WinW
dpix.d = DesktopResolutionX()
dpiy.d = DesktopResolutionY()

F=LoadFont(#PB_Any,"Courier New",32)
WinW=800
WinH=300
Win.i=OpenWindow(#PB_Any,0,0,WinW,WinH,"ERROR",#PB_Window_ScreenCentered )
    ImCre.i=CreateImage(#PB_Any,WinW*dpix,WinH*dpiy)
    ImGad.i=ImageGadget(#PB_Any,0,0,WinW*dpix,WinH*dpiy,ImageID(ImCre))
    StartDrawing(ImageOutput(ImCre))
        DrawingMode(#PB_2DDrawing_Transparent)
        Box(0,0,WinW*dpix,WinH*dpiy,#Red)
        DrawingFont(FontID(F))
        DrawText(40,50,"!ERROR=47",#Yellow)
    StopDrawing()
    SetGadgetState(ImGad,ImageID(ImCre))
    DisableGadget(ImGad,1)
    BtnOk.i=ButtonGadget(#PB_Any,40,255,80,25,"OK",#PB_Button_Default)
    Repeat
        Event=WaitWindowEvent()
        Select Event
            Case #PB_Event_CloseWindow
                Quit=#True
            Case #PB_Event_Gadget
                Select EventGadget()
                    Case BtnOk
                        Quit=#True
                EndSelect
        EndSelect    
    Until Quit
    

Re: Facing a size mystery

Posted: Sun Jan 21, 2024 3:44 pm
by charvista
How nice to see it SOLVED !
To make it more universal, I will transform this in a Procedure to make it DPI aware.
I have also added DisableGadget(ImGad,#True), otherwise the OK-button will not work.
Many thanks for your help, RASHAD. :wink:
Edit: you are faster than me to post the code! haha

Code: Select all

EnableExplicit
Define.i BtnOk,Event,F,ImCre,ImGad,Quit,Win,WinH,WinW
Define.d DpiX,DpiY
F=LoadFont(#PB_Any,"Courier New",32)
WinW=800
WinH=300
DpiX.d=DesktopResolutionX()
DpiY.d=DesktopResolutionY()
Win.i=OpenWindow(#PB_Any,0,0,WinW,WinH,"ERROR",#PB_Window_ScreenCentered)
    ImCre.i=CreateImage(#PB_Any,WinW*DpiX,WinH*DpiY)
    ImGad.i=ImageGadget(#PB_Any,0,0,WinW*DpiX,WinH*DpiY,ImageID(ImCre))
    StartDrawing(ImageOutput(ImCre))
        DrawingMode(#PB_2DDrawing_Transparent)
        Box(0,0,WinW*DpiX,WinH*DpiY,#Red)
        DrawingFont(FontID(F))
        DrawText(40,50,"!ERROR=47",#Yellow)
    StopDrawing()
    SetGadgetState(ImGad,ImageID(ImCre))
    DisableGadget(ImGad,#True)
    BtnOk.i=ButtonGadget(#PB_Any,40,255,80,25,"OK",#PB_Button_Default)
    Repeat
        Event=WaitWindowEvent()
        Select Event
            Case #PB_Event_CloseWindow
                Quit=#True
            Case #PB_Event_Gadget
                Select EventGadget()
                    Case BtnOk
                        Quit=#True
                EndSelect
        EndSelect    
    Until Quit
    

Image