[Implemented] Center Windows

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

[Implemented] Center Windows

Post by BackupUser »

Restored from previous forum. Originally posted by blueb.

I've seen this method used in other languages and I think would be
handy in PureBasic as well.

Instead of "having" to enter the x and y values to position a window..
Example:
If OpenWindow(0,150,150,450,200,#PB_Window_SystemMenu,"Test")

Set PureBasic so that if the user leaves x and y 'blank'
it is assumed that he/she wants the window centered on the screen.
Example:
If OpenWindow(0,,,450,200,#PB_Window_SystemMenu,"Test")
centers the window in the users screen.

This would save a lot of time calculating (and allowing)
for different screens, etc. The window placement would be 'automatic'.

Thanks,
blueb
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> This would save a lot of time calculating (and allowing) for different
> screens, etc. The window placement would be 'automatic'.

I know what you're saying, but in Windows you can always have the window
centered, with no need for calculations, by opening it like so:

Code: Select all

WinW=450 : WinH=200 ; Window sizes.
If OpenWindow(0,GetSystemMetrics_(#SM_CXSCREEN)-WinW)/2,GetSystemMetrics_(#SM_CYSCREEN)-WinH)/2,WinW,WinH,#PB_Window_SystemMenu,"Test")
You can also move it to the center at any time using those API calls.
Still, this isn't a solution for Amiga/Linux compatibility, but I'm
sure they both have screen size commands which would easily adapt.


PB - Registered PureBasic Coder
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

Good idea, which is already on my todo list :). It will have two centered methods:

#PB_Window_WindowCentered ; center inside the parent window
#PB_Window_ScreenCentered ; center inside the whole screen

for both x,y

Is the constants name ok or should them be different ? (PB_Window_ prefix must remain of course).

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.

Hi Fred
Mhhh... GetSystemMetrics_() is really easy to use... still wonder a bit that this will now implent to as standard... but ok... :wink:

I would prefer:

- #PB_WindowCentered ; center inside the parent window
- #PB_ScreenCentered ; center inside the whole screen

Still looking forward for something like OpenMDIWindow() for future versions...

Keep on ya work...

PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...

greetz
MrVainSCL! aka Thorsten
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.
Originally posted by MrVainSCL

- #PB_WindowCentered ; center inside the parent window
- #PB_ScreenCentered ; center inside the whole screen
Are you blind or what ? :)

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> Fred wrote: #PB_Window_ScreenCentered
> MrVainSCL wrote: #PB_ScreenCentered

So I don't think MrVainSCL is blind, Fred... :)


PB - Registered PureBasic Coder
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

Yes and I wrote : (PB_Window_ prefix must remain of course) :). So it's the same.

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> Yes and I wrote : (PB_Window_ prefix must remain of course) :). So it's the same.

Okay. :) I thought you didn't realise, that's all.


PB - Registered PureBasic Coder
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by blueb.

Sorry Guys,
The simplest method has to be:
If OpenWindow(0,,,450,200,#PB_Window_SystemMenu,"Test")

Other than blanking the 2 above fields...nothing to remember.

No - GetSystemMetrics_(#SM_CXSCREEN)-WinW
No - #PB_Window_ScreenCentered


Regards,
--blueb
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.

Hi blueb
Sorry guy.. but i personaly dont like the idea of "(0,,,450)" ... Have you ever seen any other coding language where you will write ",,,,," ??? not for me... sorry, i dont agree with this!

If you want something optional what about:

OpenWindow(0,150,150,450,200,#PB_Window_SystemMenu,"Test",[#flag],[flag])

If the flag is set to "-1" or whatever, your window will automatical centered... Fred, what do you think about this? But in my opinion the optional feature is not really needed... (due fact i dont know why you dont use the SystemMetrics_() command - very easy!)

PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...

greetz
MrVainSCL! aka Thorsten
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by plouf.

A bit out of topic ,sorry guys,but wondering
how could this be made with a constand ?????
i mean constands are tranformed to a number/string
if am not wrong after compilation ,the screen can change resolution whenerever the user likes to !?!?!?


Christos
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

The constant is for example "-30000".

Now in the ASM code for OpenWindow, it checks for -30000.
If found -30000, the Command automatically calculates
the right position to center the window on screen.

Using ",,," without values is a syntax error in the PureBasic language.
This are rules that cant/shouldnt be changed easily.
(there must be rules for syntax)

cya,
...Danilo

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by freak.

> OpenWindow(0,150,150,450,200,#PB_Window_SystemMenu,"Test",[#flag],[flag])

Why more Flags, OpenWindow allready has a Flags parameter.

Fred, why not add #PB_Window_WindowCentered and #PB_Window_ScreenCentered to those Flags, and
if they are set, just ignore the x,y parameters?

Could look like this:

OpenWindow(0,0,0,450,200,#PB_Window_SystemMenu | #PB_Window_WindowCentered,"Test")

Would make more sense to me.

Timo
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

freak: Exactly what I will do. Good idea.

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fweil.

Fred ... and everybody,

I agree with freak's idea you made yours.

This allow parametric call of OpenWindow using a variable containgin optional flag. I think it is a good way to have either sized or centered windows with a simple formula.

Rgrds

Francois Weil
14, rue Douer
F64100 Bayonne
Post Reply