Layout questions (letterbox, fill, float)

About Monkey 2 Forums Monkey 2 Programming Help Layout questions (letterbox, fill, float)

This topic contains 8 replies, has 3 voices, and was last updated by  Xaron 2 years, 1 month ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #7348

    Xaron
    Participant

    Hey all,

    there are several Layout options for the view. But I actually miss a Layout like “letterbox-x” and “letterbox-y” like “fill-x” and “fill-y”. What I want to achieve is the scaling of the letterbox but with a floating size on one axis. I need that for all the different aspect ratios for mobile devices.

    With Monkey 1 I did this by myself using PushMatrix() and PopMatrix() and scaling.

    #7358

    Xaron
    Participant

    Am I really the only one having this issue? How do you solve that for all these different aspect ratios? I prefer to have a fixed virtual resolution but with a floating x or y size so that parts of the background are cropped.

    #7371

    Ethernaut
    Participant

    I do think it would be useful, allowing one of the axis to be preserved while the other one increases/decreases in size as needed, effectively changing the aspect ratio. I also had that working in Monkey1, but haven’t done it in M2 yet.

    I’m away from my laptop now, but maybe you can use Window.OnMeasure() and adjust the virtual resolution to always match the aspect ratio of the device? Simply return a new Vec2i with the desired virtual resolution that matches the device’s aspect. Will try later tonight.

    #7372

    Ethernaut
    Participant

    I just remembered I don’t know how to get the Device’s dimensions, which makes my suggestion hard to test…

    I also don’t know how to get the letterboxed dimensions, using Window.Width and Height seems to return the Window size, not the “cropped” size.

    Any clues on how to do those things?

    #7382

    Mark Sibly
    Keymaster

    What I want to achieve is the scaling of the letterbox but with a floating size on one axis.

    Don’t quite understand this – you want a letterbox *without* the same aspect ratio as returned by OnMeasure?

    Letter box does ‘float’ on the minor axis, ie: the axis where the border appears, so you can use View.Gravity to control where letterbox is positioned horizontally/vertically within it’s border. This is shown in the view_layout banana I think.

    But letterbox will always fill the major axis, and it’s aspect ratio will always be the same as the aspect ratio returned by OnMeasure.

    You may also be able to achieve what you want by nesting a letterbox view within a ‘normal’ view, or vice versa.

    #7392

    Xaron
    Participant

    Hi there and many thanks. To clarify even more what I want to achieve I have attached a screenshot.

    1. Let’s assume I want to use landscape format.
    2. I never want to stretch anything in only one axis (so no distortion but proportional scaling of course)
    3. I don’t want to have black borders anywhere

    Let’s also assume a virtual resolution of 512×288 (for this example!). This is a 16:9 aspect ratio. On devices using this ratio they will always see my background image of 512×288 stretched to the native resolution of course.

    For devices like iPads the visible size would be 384×288 of that background image. So the remaining 128 pixel of that background would simply not be visible but cropped. Scaling is always done using the y axis ratio. So when the native resolution of the device is 768×576, my background image would be scaled up to 1024×576 but cropped so that only 768×576 would be visible.

    Is there a way to get the native resolution? Width and Height return my virtual resolution using the letterbox Layout.

    Attachments:
    #7394

    Xaron
    Participant

    Apparently it works the same way as with Monkey 1:

    OnMeasure is not needed in that case.

    #7399

    Mark Sibly
    Keymaster

    I don’t know if I’d call this ‘letterbox’ anymore – IMO, ‘letterbox’ implies (optional) borders – but I think I see what you mean. You just want a fixed virtual height and to preserve aspect ratio, correct?

    Here’s my attempt at something similar using OnMeasure and “stretch” Layout. The main benefit to doing it this way is that mouse/touch etc coords are already scaled for you, and of course no need to scale inside OnRender.

    I have often thought about adding something like a ‘UIMatrix’ to View. This would be an additional post transform matrix that would be applied to rendering, but also to mouse/touch etc coords. So you could do something like this in OnRender to achieve what your version does:

    UIMatrix=AffineMat3f.Scaling( scaleRatio )

    Is this a good idea? Each thing I add seems to confuse things a bit!

    Also: Use Window Frame.Width, Frame.Height or Frame.Size etc to get ‘physical’ window size. Rect.Width, Rect.Height will return ‘virtual’ size as you’ve noticed.

    #7403

    Xaron
    Participant

    Perfect Mark, thanks so much. That’s exactly what I wanted to achieve!

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.