Aspect ratio when form is resized

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HaLo2FrEeEk
    Contributor
    • Feb 2007
    • 404

    Aspect ratio when form is resized

    I'm overriding the WM_SIZE message so that I can lock my form into a specific aspect ratio. I'm allowing the user to turn on and off aspect ratio locking by toggling a checkbox. So far resizing by the edges (left, right, top, bottom) works just fine, but I'm running into a problem when I get to the corners.

    I'm using Camtasia's screen recorder as my reference. In that program, when you lock the aspect ratio and resize by the corners it allows to resize both width and height, while maintaining the aspect ratio of the bounds. With my math, it's one or the other: width or height. I can't figure out how to make it do both.

    I'm testing on the top-right corner to start with. I've got a RECT structure with my form rectangle, here's the math I can use to size either the left or top:

    r.Left = r.Right - (int)(sizeRatio .Width * this.Height / sizeRatio.Heigh t);
    r.Top = r.Bottom - (int)(sizeRatio .Height * this.Width / sizeRatio.Width );

    But that only works if I've only got one active, if I use both at the same time it doesn't resize at all.

    Basically I want it so that if the user is resizing by the top left and they drag their mouse out to the left, the left edge will stay with the mouse and the top will move up; if they move their mouse up, the top will stay with the mouse and the left will move resize out. Does that make sense? Basically, with the corners, changing the width changes the height and changing the height changes the width. How can I do that?
  • hype261
    New Member
    • Apr 2010
    • 207

    #2
    I believe this should work, but I haven't been able to test it. This should work with both corners or the edges. I would compare the change in width and height of the screen to see which one is greatest. I would then use the value with the greatest delta to compute the other value.

    Comment

    • HaLo2FrEeEk
      Contributor
      • Feb 2007
      • 404

      #3
      That's what I was thinking. Basically, after each at the end of each message, when I marshall the RECT structure back to the LParam, I should update a Size object with the new size, then on the next loop check if the new-new size has a greater width or height difference than the saved size. If the width has a greater difference then I set the RECT's Top value, if the height difference is greater, I change the RECT's Left.

      I'm not home now so I can't test it, but I foresee one problem (that might not be a problem). If I only change the width when the height difference is greater, how does the height get resized? Same goes for the width if the width difference is greater. I'll have to knock it around for a bit when I get home, it sounds like it should work, but we'll see.

      If anyone else has anything they can add I would appreciate it. Maybe I'm just tired, but this has just got me stumped.

      Comment

      • hype261
        New Member
        • Apr 2010
        • 207

        #4
        I don't believe you are going to have an issue with the situation you describe.

        If old width and height were 640 by 800 and new width and height are 540 by 800 then the change in width and height is 100 by 0. So you multiply 540 by the aspect ratio to the height which in this case is 1.25. So your new height would be 675.

        Comment

        Working...