Facing a size mystery

Just starting out? Need help? Post your questions and find answers here.
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Facing a size mystery

Post 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
    
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4995
Joined: Sun Apr 12, 2009 6:27 am

Re: Facing a size mystery

Post 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
    
Egypt my love
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: Facing a size mystery

Post 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).
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4995
Joined: Sun Apr 12, 2009 6:27 am

Re: Facing a size mystery

Post by RASHAD »

Ah
It's working fine with PB 6.04
Egypt my love
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: Facing a size mystery

Post by charvista »

Not here. Using Windows 11 Home 64-bit, PB 6.04 LTS (x64)

Image
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4995
Joined: Sun Apr 12, 2009 6:27 am

Re: Facing a size mystery

Post 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))
Egypt my love
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: Facing a size mystery

Post 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.
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4995
Joined: Sun Apr 12, 2009 6:27 am

Re: Facing a size mystery

Post 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
Egypt my love
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4995
Joined: Sun Apr 12, 2009 6:27 am

Re: Facing a size mystery

Post 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
    
Egypt my love
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: Facing a size mystery

Post 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
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
Post Reply