[solved] centerWindow (*window) or getFrameSize (*window)

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
es_91
Enthusiast
Enthusiast
Posts: 242
Joined: Thu Jan 27, 2011 12:00 pm
Location: DE

[solved] centerWindow (*window) or getFrameSize (*window)

Post by es_91 »

Hi Fred


PureBasic is not the newest invention on the marked. Sadly, there is still no way to achieve a proper PB-native frame-measure-return when it comes to resizing windows or centering them using desktopHeight (*desktop) and desktopWidth (*desktop).


Correct centering without using API-functions is impossible when not init-applied to the window on openWindow function.

// HideWindow and windowWidth/windowHeight do
Last edited by es_91 on Mon Mar 05, 2018 2:48 pm, edited 1 time in total.
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: centerWindow (*window) or getFrameSize (*window)

Post by kenmo »

PB already added WindowWidth(Win, #PB_Window_FrameCoordinate) and WindowHeight(Win, #PB_Window_FrameCoordinate), those can help.

But a CenterWindow() function would be nice, and maybe flags for DesktopHeight to get the USABLE heights without API (minus taskbar, etc).

Also, what the OS considers "centered" is not always mathematically centered, for example when you tell MacOS to "center" a window it places it slightly higher than center (for aesthetics).
es_91
Enthusiast
Enthusiast
Posts: 242
Joined: Thu Jan 27, 2011 12:00 pm
Location: DE

setWindowFlags (*window, flags)

Post by es_91 »

I agree, think the center function should really center on screen by default.

I am sorry, jeever, to omit remembering the #frameCoordinates constants as you mentioned.

Sorry, they DO that job.

It's by the way always sad to have no option to change the flags of a window. Apart from my previous topic titled above, changing the window flags by PB could become as crucial as replacing a window to the screen center.

Is there an approach existing in PB already?

// notice the topic-reachon change
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 538
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: centerWindow (*window) or getFrameSize (*window)

Post by Sicro »

es_91 wrote:Correct centering without using API-functions is impossible when not init-applied to the window on openWindow function.

Code: Select all

HideWindow(Window, #False, #PB_Window_ScreenCentered)
Image
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
es_91
Enthusiast
Enthusiast
Posts: 242
Joined: Thu Jan 27, 2011 12:00 pm
Location: DE

Re: centerWindow (*window) or getFrameSize (*window)

Post by es_91 »

Then I'm sorry. Very sorry not studying the changes.

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

Re: centerWindow (*window) or getFrameSize (*window)

Post by kenmo »

HideWindow(Window, #False, #PB_Window_ScreenCentered)
But this Center only works when un-hiding the window from hidden... I don't know why, OS/API reason?
User avatar
Blue
Addict
Addict
Posts: 884
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: centerWindow (*window) or getFrameSize (*window)

Post by Blue »

kenmo wrote:
HideWindow(Window, #False, #PB_Window_ScreenCentered)
But this Center only works when un-hiding the window from hidden... I don't know why, OS/API reason?
Did you try it, kenmo ?
In Windows, it works even if the window is not currently hidden.

Code: Select all

winH = 120
winW = 300

If OpenWindow(0, 100, 200, winW, winH, "PureBasic Window", #PB_Window_SystemMenu)
   SetWindowColor(0,#Yellow)
   TextGadget(0, 20,20,200,20,"Window not centered")
   SetGadgetColor(0,#PB_Gadget_BackColor, #Yellow)
   gW = 120
   gH = 20
   ButtonGadget(1,winW-gW-10,winH-gH-10, gW, gH, "Center the window")

   Repeat
      event = WaitWindowEvent()
      Select event
         Case #PB_Event_CloseWindow : Break
         Case #PB_Event_Gadget : 
            HideWindow(0, #False,#PB_Window_ScreenCentered)
            SetGadgetText(0, "the Window is now centered")
            DisableGadget(1,1)
    EndSelect
   ForEver
EndIf
End
"That's not a bug..." said the programmer. "it's a feature! "
"Oh! I see..." replied the blind man.
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: centerWindow (*window) or getFrameSize (*window)

Post by kenmo »

I did not try it :lol: Oops. That's just how I understood the help:
#PB_Window_ScreenCentered: the window will be screen centered (only valid when un-hiding the window).
Post Reply