Преглед изворни кода

Almost missed adding Layout.cpp

Adam Blake пре 13 година
родитељ
комит
387e8f9337
1 измењених фајлова са 51 додато и 0 уклоњено
  1. 51 0
      gameplay/src/Layout.cpp

+ 51 - 0
gameplay/src/Layout.cpp

@@ -0,0 +1,51 @@
+#include "Base.h"
+#include "Layout.h"
+#include "Control.h"
+#include "Container.h"
+
+namespace gameplay
+{
+    void Layout::align(Control* control, const Container* container)
+    {
+        if (control->_alignment != Control::ALIGN_TOP_LEFT ||
+            control->_autoWidth || control->_autoHeight)
+        {
+            Rectangle controlBounds = control->getBounds();
+            const Rectangle& containerBounds = container->getClip();
+            const Theme::Border& containerBorder = container->getBorder(container->getState());
+            const Theme::Padding& containerPadding = container->getPadding();
+
+            if (control->_autoWidth)
+            {
+                controlBounds.width = containerBounds.width;
+            }
+
+            if (control->_autoHeight)
+            {
+                controlBounds.height = containerBounds.height;
+            }
+
+            // Vertical alignment
+            if ((control->_alignment & Control::ALIGN_BOTTOM) == Control::ALIGN_BOTTOM)
+            {
+                controlBounds.y = containerBounds.height - controlBounds.height;
+            }
+            else if ((control->_alignment & Control::ALIGN_VCENTER) == Control::ALIGN_VCENTER)
+            {
+                controlBounds.y = containerBounds.height * 0.5f - controlBounds.height * 0.5f;
+            }
+
+            // Horizontal alignment
+            if ((control->_alignment & Control::ALIGN_RIGHT) == Control::ALIGN_RIGHT)
+            {
+                controlBounds.x = containerBounds.width - controlBounds.width;
+            }
+            else if ((control->_alignment & Control::ALIGN_HCENTER) == Control::ALIGN_HCENTER)
+            {
+                controlBounds.x = containerBounds.width * 0.5f - controlBounds.width * 0.5f;
+            }
+
+            control->setBounds(controlBounds);
+        }
+    }
+}