Browse Source

adds 3 new horizontal relative gui entries for dealing with swapping elements between 4:3 and 16:9 aspect ratios. "relativeToYL" maintains the initial aspect ratio, keeping the leftmost edge the same, "relativeToYR" also shifts it so the right hand side is shifted over so that edge would match, and "relativeToYC" takes/adds space from both sides

Azaezel 10 years ago
parent
commit
6b0c6ae8ac
2 changed files with 36 additions and 0 deletions
  1. 33 0
      Engine/source/gui/core/guiControl.cpp
  2. 3 0
      Engine/source/gui/core/guiControl.h

+ 33 - 0
Engine/source/gui/core/guiControl.cpp

@@ -175,6 +175,9 @@ ImplementEnumType( GuiHorizontalSizing,
 	{ GuiControl::horizResizeLeft,            "left"      },
 	{ GuiControl::horizResizeLeft,            "left"      },
    { GuiControl::horizResizeCenter,          "center"    },
    { GuiControl::horizResizeCenter,          "center"    },
    { GuiControl::horizResizeRelative,        "relative"  },
    { GuiControl::horizResizeRelative,        "relative"  },
+   { GuiControl::horizResizeRelativeToYL,     "relativeToYL" },
+   { GuiControl::horizResizeRelativeToYR,     "relativeToYR" },
+   { GuiControl::horizResizeRelativeToYC,     "relativeToYC" },
 	{ GuiControl::horizResizeWindowRelative,  "windowRelative"  }
 	{ GuiControl::horizResizeWindowRelative,  "windowRelative"  }
 EndImplementEnumType;
 EndImplementEnumType;
 
 
@@ -1366,6 +1369,36 @@ void GuiControl::parentResized(const RectI &oldParentRect, const RectI &newParen
       newPosition.x = newLeft;
       newPosition.x = newLeft;
       newExtent.x = newWidth;
       newExtent.x = newWidth;
    }
    }
+   else if (mHorizSizing == horizResizeRelativeToYL && oldParentRect.extent.x != 0)
+   {
+      S32 newLeft = mRoundToNearest((F32(newPosition.x) / F32(oldParentRect.extent.x)) * F32(newParentRect.extent.x));
+      S32 newWidth = mRoundToNearest((F32(newExtent.x) / F32(oldParentRect.extent.y)) * F32(newParentRect.extent.y));
+
+      newPosition.x = newLeft;
+      newExtent.x = newWidth;
+   }
+   else if (mHorizSizing == horizResizeRelativeToYR && oldParentRect.extent.x != 0)
+   {
+      S32 newLeft = mRoundToNearest((F32(newPosition.x) / F32(oldParentRect.extent.x)) * F32(newParentRect.extent.x));
+      S32 newWidth = mRoundToNearest((F32(newExtent.x) / F32(oldParentRect.extent.y)) * F32(newParentRect.extent.y)); //origional aspect ratio corrected width
+      S32 rWidth = mRoundToNearest((F32(newExtent.x) / F32(oldParentRect.extent.x)) * F32(newParentRect.extent.x)); //parent aspect ratio relative width
+
+      S32 offset = rWidth - newWidth; // account for change in relative width
+      newLeft += offset;
+      newPosition.x = newLeft;
+      newExtent.x = newWidth;
+   }
+   else if (mHorizSizing == horizResizeRelativeToYC && oldParentRect.extent.x != 0)
+   {
+      S32 newLeft = mRoundToNearest((F32(newPosition.x) / F32(oldParentRect.extent.x)) * F32(newParentRect.extent.x));
+      S32 newWidth = mRoundToNearest((F32(newExtent.x) / F32(oldParentRect.extent.y)) * F32(newParentRect.extent.y)); //origional aspect ratio corrected width
+      S32 rWidth = mRoundToNearest((F32(newExtent.x) / F32(oldParentRect.extent.x)) * F32(newParentRect.extent.x)); //parent aspect ratio relative width
+
+      S32 offset = rWidth - newWidth; // account for change in relative width
+      newLeft += offset/2;
+      newPosition.x = newLeft;
+      newExtent.x = newWidth;
+   }
 
 
 	if (mVertSizing == vertResizeCenter)
 	if (mVertSizing == vertResizeCenter)
 	   newPosition.y = (newParentRect.extent.y - getHeight()) >> 1;
 	   newPosition.y = (newParentRect.extent.y - getHeight()) >> 1;

+ 3 - 0
Engine/source/gui/core/guiControl.h

@@ -121,6 +121,9 @@ class GuiControl : public SimGroup
          horizResizeLeft,        ///< fixed on the right and width
          horizResizeLeft,        ///< fixed on the right and width
          horizResizeCenter,
          horizResizeCenter,
          horizResizeRelative,     ///< resize relative
          horizResizeRelative,     ///< resize relative
+         horizResizeRelativeToYL,     ///< resize relative to hieght delta (offset Left)
+         horizResizeRelativeToYR,     ///< resize relative to hieght delta (offset Right)
+         horizResizeRelativeToYC,     ///< resize relative to hieght delta (offset Right)
          horizResizeWindowRelative ///< resize window relative
          horizResizeWindowRelative ///< resize window relative
       };
       };
       enum vertSizingOptions
       enum vertSizingOptions