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

Setting opacity, visibility, and enabled/disabled on a Container now affects the container's children.
Setting control properties now affects STATE_DISABLED correctly.
Text color is now affected by a control's current opacity.
The LightTest was used to test these changes.

Adam Blake пре 13 година
родитељ
комит
a82c415660
3 измењених фајлова са 23 додато и 20 уклоњено
  1. 3 0
      gameplay/src/Container.cpp
  2. 19 19
      gameplay/src/Control.cpp
  3. 1 1
      gameplay/src/Label.cpp

+ 3 - 0
gameplay/src/Container.cpp

@@ -462,6 +462,9 @@ void Container::draw(SpriteBatch* spriteBatch, const Rectangle& clip, bool needs
         needsClear = true;
     }
 
+    if (!_visible)
+        return;
+
     spriteBatch->start();
     Control::drawBorder(spriteBatch, clip);
     spriteBatch->finish();

+ 19 - 19
gameplay/src/Control.cpp

@@ -249,13 +249,11 @@ void Control::setVisible(bool visible)
 {
     if (visible && !_visible)
     {
-        setEnabled(true);
         _visible = true;
         _dirty = true;
     }
     else if (!visible && _visible)
     {
-        setEnabled(false);
         _visible = false;
         _dirty = true;
     }
@@ -272,7 +270,7 @@ void Control::setOpacity(float opacity, unsigned char states)
     Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
     getOverlays(states, overlays);
 
-    for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
+    for (int i = 0; i < Theme::Style::OVERLAY_MAX && overlays[i]; ++i)
     {
         overlays[i]->setOpacity(opacity);
     }
@@ -311,7 +309,7 @@ void Control::setBorder(float top, float bottom, float left, float right, unsign
     Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
     getOverlays(states, overlays);
 
-    for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
+    for (int i = 0; i < Theme::Style::OVERLAY_MAX && overlays[i]; ++i)
     {
         overlays[i]->setBorder(top, bottom, left, right);
     }
@@ -332,7 +330,7 @@ void Control::setSkinRegion(const Rectangle& region, unsigned char states)
     Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
     getOverlays(states, overlays);
 
-    for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
+    for (int i = 0; i < Theme::Style::OVERLAY_MAX && overlays[i]; ++i)
     {
         overlays[i]->setSkinRegion(region, _style->_tw, _style->_th);
     }
@@ -352,7 +350,7 @@ void Control::setSkinColor(const Vector4& color, unsigned char states)
     Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
     getOverlays(states, overlays);
 
-    for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
+    for (int i = 0; i < Theme::Style::OVERLAY_MAX && overlays[i]; ++i)
     {
         overlays[i]->setSkinColor(color);
     }
@@ -401,7 +399,7 @@ void Control::setImageRegion(const char* id, const Rectangle& region, unsigned c
     Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
     getOverlays(states, overlays);
 
-    for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
+    for (int i = 0; i < Theme::Style::OVERLAY_MAX && overlays[i]; ++i)
     {
         overlays[i]->setImageRegion(id, region, _style->_tw, _style->_th);
     }
@@ -422,7 +420,7 @@ void Control::setImageColor(const char* id, const Vector4& color, unsigned char
     Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
     getOverlays(states, overlays);
 
-    for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
+    for (int i = 0; i < Theme::Style::OVERLAY_MAX && overlays[i]; ++i)
     {
         overlays[i]->setImageColor(id, color);
     }
@@ -450,7 +448,7 @@ void Control::setCursorRegion(const Rectangle& region, unsigned char states)
     Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
     getOverlays(states, overlays);
 
-    for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
+    for (int i = 0; i < Theme::Style::OVERLAY_MAX && overlays[i]; ++i)
     {
         overlays[i]->setCursorRegion(region, _style->_tw, _style->_th);
     }
@@ -471,7 +469,7 @@ void Control::setCursorColor(const Vector4& color, unsigned char states)
     Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
     getOverlays(states, overlays);
 
-    for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
+    for (int i = 0; i < Theme::Style::OVERLAY_MAX && overlays[i]; ++i)
     {
         overlays[i]->setCursorColor(color);
     }
@@ -499,7 +497,7 @@ void Control::setFont(Font* font, unsigned char states)
     Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
     getOverlays(states, overlays);
 
-    for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
+    for (int i = 0; i < Theme::Style::OVERLAY_MAX && overlays[i]; ++i)
     {
         overlays[i]->setFont(font);
     }
@@ -520,7 +518,7 @@ void Control::setFontSize(unsigned int fontSize, unsigned char states)
     Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
     getOverlays(states, overlays);
 
-    for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
+    for (int i = 0; i < Theme::Style::OVERLAY_MAX && overlays[i]; ++i)
     {
         overlays[i]->setFontSize(fontSize);
     }
@@ -541,7 +539,7 @@ void Control::setTextColor(const Vector4& color, unsigned char states)
     Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
     getOverlays(states, overlays);
 
-    for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
+    for (int i = 0; i < Theme::Style::OVERLAY_MAX && overlays[i]; ++i)
     {
         overlays[i]->setTextColor(color);
     }
@@ -562,7 +560,7 @@ void Control::setTextAlignment(Font::Justify alignment, unsigned char states)
     Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
     getOverlays(states, overlays);
 
-    for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
+    for (int i = 0; i < Theme::Style::OVERLAY_MAX && overlays[i]; ++i)
     {
         overlays[i]->setTextAlignment(alignment);
     }
@@ -583,7 +581,7 @@ void Control::setTextRightToLeft(bool rightToLeft, unsigned char states)
     Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
     getOverlays(states, overlays);
 
-    for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
+    for (int i = 0; i < Theme::Style::OVERLAY_MAX && overlays[i]; ++i)
     {
         overlays[i]->setTextRightToLeft(rightToLeft);
     }
@@ -969,7 +967,9 @@ void Control::update(const Control* container, const Vector2& offset)
 
     // Cache themed attributes for performance.
     _skin = getSkin(_state);
-    _opacity = getOpacity(_state);
+
+    // Current opacity should be multiplied by that of the parent container.
+    _opacity = getOpacity(_state) * container->_opacity;
 }
 
 void Control::drawBorder(SpriteBatch* spriteBatch, const Rectangle& clip)
@@ -1338,7 +1338,7 @@ void Control::setImageList(Theme::ImageList* imageList, unsigned char states)
     Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
     getOverlays(states, overlays);
 
-    for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
+    for (int i = 0; i < Theme::Style::OVERLAY_MAX && overlays[i]; ++i)
     {
         overlays[i]->setImageList(imageList);
     }
@@ -1352,7 +1352,7 @@ void Control::setCursor(Theme::ThemeImage* cursor, unsigned char states)
     Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
     getOverlays(states, overlays);
 
-    for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
+    for (int i = 0; i < Theme::Style::OVERLAY_MAX && overlays[i]; ++i)
     {
         overlays[i]->setCursor(cursor);
     }
@@ -1366,7 +1366,7 @@ void Control::setSkin(Theme::Skin* skin, unsigned char states)
     Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
     getOverlays(states, overlays);
 
-    for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
+    for (int i = 0; i < Theme::Style::OVERLAY_MAX && overlays[i]; ++i)
     {
         overlays[i]->setSkin(skin);
     }

+ 1 - 1
gameplay/src/Label.cpp

@@ -87,7 +87,7 @@ void Label::update(const Control* container, const Vector2& offset)
 
     _font = getFont(_state);
     _textColor = getTextColor(_state);
-    _textColor.w *= getOpacity(_state);
+    _textColor.w *= _opacity;
 }
 
 void Label::drawText(const Rectangle& clip)