Forcing a windows resize resolution to be 16 x 9

I want to bounce this off you experts. I want a way to force a Window to always be in a 16 x 9 ( movie format style ) resolution when it is resized. Is there a simple way to figure this out?

Thanks

You probably need to address this in the resizing event.
Then, decide whether the height or the width has changed.

if height has changed, adjust the width to be :

self.height * 16/9

if width has changed, adjust the height to be
self.width * 9/16

It may jerk about - you might be better doing this in resized so that it only happens at the end

Jeff thanks, but is that proper math for this?

I tried this in resized…

me.height = me.height * 16/9
me.width = me.width * 9/16

It crashes Xojo

I said adjust the width to be : self.height * 16/9
You are changing the height.

me.width= me.height * 16/9
or
me.height= me.width * 9/16

If you’re on a Mac you can get the OS to do it for you. But for Windows, I don’t know.

Add a module to your project and then add a structure, name it “NSSize”. Then add two properties to it.

width as CGFloat height as CGFloat

Now in the open event of your window, add the following code.

[code]#if TargetMacOS and TargetCocoa then
declare sub NSWindowAspectRatio lib “Cocoa” selector “setAspectRatio:” ( NSWindowInstance as integer, assigns aspectRatio as NSSize )

Dim nsize as NSSize
nSize.width = 16
nSize.height = 9

NSWindowAspectRatio( me.handle ) = nSize
#endif[/code]

Run your application and resize the window.

Edit: This works for 32-Bit and 64-Bit macOS applications.

elegant!

Thanks guys, tonight I’m on Windows. Jeff code works great on WIndows 10. I’ll try Sam’s tomorrow on a Mac and see the grace of OS X!

I spoke to soon the app crashed in WIndows when I used the Maximize button, but the manually resize was working great. Off to brainstorm. Thanks again!

If you want to be really clever… Add the following method to same module you added the structure to.

[code]Public Sub setAspectRatio(extends w as window, inWidth as double, inHeight as double)
#if TargetMacOS and TargetCocoa then
declare sub NSWindowAspectRatio lib “Cocoa” selector “setAspectRatio:” ( NSWindowInstance as integer, assigns aspectRatio as NSSize )

Dim nsize as NSSize
nSize.width = inWidth
nSize.height = inHeight

NSWindowAspectRatio( w.handle ) = nSize

#elseif targetWin32 then
// — Insert Jeff’s code here.

#endif
End Sub
[/code]

Then when you want to set the aspect ratio of a window, you simply say…

me.setAspectRatio( 16, 9 )

And Xojo will use the right solution for each platform.

Pretty cool Sam, I realized my Windows issue I am using a 16 x 10 monitor most people use 16 x 9. When I maximized my screen the math did not work out and crashed the app. So instead of basing the width on the height, I switched to using the height based on the width.

me.height= me.width * 9/16

If anyone ever uses a portrait setting with the height larger than the width, it will crash again. so for Windows I will have to determine some limits before using the code. I look forward to trying your code out in OS X.

Thanks again

You cant really allow a window to ‘genuinely’ maximise if you are setting the ratio.
Thats like saying you must be 16 x 10 AND you must be 16 x 9 at the same time.
Something has to give…

One simple solution:
Allow the window to be any shape the user likes, including full screen.
Draw your content into a canvas which is on the window, and shaped in a 16 : 9 format

[quote=336223:@Jeff Tullin]You cant really allow a window to ‘genuinely’ maximise if you are setting the ratio.
Thats like saying you must be 16 x 10 AND you must be 16 x 9 at the same time.
Something has to give…

One simple solution:
Allow the window to be any shape the user likes, including full screen.
Draw your content into a canvas which is on the window, and shaped in a 16 : 9 format[/quote]

Thanks. I get that… I was trying to find a way to bypass the forced resize on maximize or fullscreen, still looking for a solution.

The reason I am working on this at an Xojo Window level is the control in the Window is an html viewer and need it to match 100% of the Xojo Window and no way to force the embedded player to resize. So by resizing Xojo Window I can get the result I need combined some html markup.

OK

nah. You probably don’t.

Right now, you probably have this control locked on all 4 sides.
Lock it on the left and right only
Change the height in the 16:9 ratio when the window resizes.
Let the window show below /around it.

Its only an issue if you try to make the HTML viewer the same shape as the window.
Consider this: