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

applying rest of UI modifications from my fork

Andrew Karpushin пре 10 година
родитељ
комит
eca12f60a7
2 измењених фајлова са 13 додато и 10 уклоњено
  1. 3 2
      gameplay/src/Container.cpp
  2. 10 8
      gameplay/src/Control.cpp

+ 3 - 2
gameplay/src/Container.cpp

@@ -425,6 +425,7 @@ const Vector2& Container::getScrollPosition() const
 void Container::setScrollPosition(const Vector2& scrollPosition)
 void Container::setScrollPosition(const Vector2& scrollPosition)
 {
 {
     _scrollPosition = scrollPosition;
     _scrollPosition = scrollPosition;
+    setDirty(DIRTY_BOUNDS);
     setChildrenDirty(DIRTY_BOUNDS, true);
     setChildrenDirty(DIRTY_BOUNDS, true);
 }
 }
 
 
@@ -553,7 +554,7 @@ void Container::updateBounds()
             for (size_t i = 0, count = _controls.size(); i < count; ++i)
             for (size_t i = 0, count = _controls.size(); i < count; ++i)
             {
             {
                 Control* ctrl = _controls[i];
                 Control* ctrl = _controls[i];
-                if (ctrl->isVisible() && !ctrl->isXPercentage() && !ctrl->isWidthPercentage())
+                if (ctrl->isVisible() && !ctrl->isWidthPercentage())
                 {
                 {
                     float w = ctrl->getWidth() + ctrl->getMargin().right;
                     float w = ctrl->getWidth() + ctrl->getMargin().right;
                     if (!ctrl->isXPercentage())
                     if (!ctrl->isXPercentage())
@@ -573,7 +574,7 @@ void Container::updateBounds()
             for (size_t i = 0, count = _controls.size(); i < count; ++i)
             for (size_t i = 0, count = _controls.size(); i < count; ++i)
             {
             {
                 Control* ctrl = _controls[i];
                 Control* ctrl = _controls[i];
-                if (ctrl->isVisible() && !ctrl->isYPercentage() && !ctrl->isHeightPercentage())
+                if (ctrl->isVisible() && !ctrl->isHeightPercentage())
                 {
                 {
                     float h = ctrl->getHeight() + ctrl->getMargin().bottom;
                     float h = ctrl->getHeight() + ctrl->getMargin().bottom;
                     if (!ctrl->isYPercentage())
                     if (!ctrl->isYPercentage())

+ 10 - 8
gameplay/src/Control.cpp

@@ -1132,15 +1132,15 @@ bool Control::updateBoundsInternal(const Vector2& offset)
         _dirtyBits &= ~DIRTY_STATE;
         _dirtyBits &= ~DIRTY_STATE;
     }
     }
 
 
-    // Clear our dirty bounds bit
-    bool dirtyBounds = (_dirtyBits & DIRTY_BOUNDS) != 0;
-    _dirtyBits &= ~DIRTY_BOUNDS;
-
     // If we are a container, always update child bounds first
     // If we are a container, always update child bounds first
     bool changed = false;
     bool changed = false;
     if (isContainer())
     if (isContainer())
         changed = static_cast<Container*>(this)->updateChildBounds();
         changed = static_cast<Container*>(this)->updateChildBounds();
 
 
+    // Clear our dirty bounds bit
+    bool dirtyBounds = (_dirtyBits & DIRTY_BOUNDS) != 0;
+    _dirtyBits &= ~DIRTY_BOUNDS;
+
     if (dirtyBounds)
     if (dirtyBounds)
     {
     {
         // Store old bounds so we can determine if they change
         // Store old bounds so we can determine if they change
@@ -1172,12 +1172,14 @@ void Control::updateBounds()
 
 
     const Rectangle parentAbsoluteBounds = _parent ? _parent->_viewportBounds : Rectangle(0, 0, game->getViewport().width, game->getViewport().height);
     const Rectangle parentAbsoluteBounds = _parent ? _parent->_viewportBounds : Rectangle(0, 0, game->getViewport().width, game->getViewport().height);
 
 
+    const Theme::Margin& margin = _style->getMargin();
+
     // Calculate local unclipped bounds.
     // Calculate local unclipped bounds.
     _bounds.set(_relativeBounds);
     _bounds.set(_relativeBounds);
     if (isXPercentage())
     if (isXPercentage())
-        _bounds.x *= parentAbsoluteBounds.width;
+        _bounds.x = _bounds.x * parentAbsoluteBounds.width + margin.left;
     if (isYPercentage())
     if (isYPercentage())
-        _bounds.y *= parentAbsoluteBounds.height;
+        _bounds.y = _bounds.y * parentAbsoluteBounds.height + margin.top;
     if (isWidthPercentage())
     if (isWidthPercentage())
         _bounds.width *= parentAbsoluteBounds.width;
         _bounds.width *= parentAbsoluteBounds.width;
     if (isHeightPercentage())
     if (isHeightPercentage())
@@ -1212,7 +1214,7 @@ void Control::updateBounds()
         }
         }
         else if ((_alignment & Control::ALIGN_VCENTER) == Control::ALIGN_VCENTER)
         else if ((_alignment & Control::ALIGN_VCENTER) == Control::ALIGN_VCENTER)
         {
         {
-            _bounds.y = clipHeight * 0.5f - _bounds.height * 0.5f;
+            _bounds.y = clipHeight * 0.5f - _bounds.height * 0.5f + (margin.top - margin.bottom) * 0.5f;
         }
         }
         else if ((_alignment & Control::ALIGN_TOP) == Control::ALIGN_TOP)
         else if ((_alignment & Control::ALIGN_TOP) == Control::ALIGN_TOP)
         {
         {
@@ -1226,7 +1228,7 @@ void Control::updateBounds()
         }
         }
         else if ((_alignment & Control::ALIGN_HCENTER) == Control::ALIGN_HCENTER)
         else if ((_alignment & Control::ALIGN_HCENTER) == Control::ALIGN_HCENTER)
         {
         {
-            _bounds.x = clipWidth * 0.5f - _bounds.width * 0.5f;
+            _bounds.x = clipWidth * 0.5f - _bounds.width * 0.5f + (margin.left - margin.right) * 0.5f;
         }
         }
         else if ((_alignment & Control::ALIGN_LEFT) == Control::ALIGN_LEFT)
         else if ((_alignment & Control::ALIGN_LEFT) == Control::ALIGN_LEFT)
         {
         {