Browse Source

Merge pull request #307 from blackberry-gaming/next-ablake

Optimizing drawImages() on UI controls.
Steve Grenier 13 years ago
parent
commit
030dd484ca

+ 24 - 41
gameplay/src/CheckBox.cpp

@@ -101,7 +101,7 @@ bool CheckBox::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int cont
 
 
 void CheckBox::update(const Rectangle& clip)
 void CheckBox::update(const Rectangle& clip)
 {
 {
-    Control::update(clip);
+    Label::update(clip);
 
 
     Vector2 size;
     Vector2 size;
     if (_imageSize.isZero())
     if (_imageSize.isZero())
@@ -125,60 +125,43 @@ void CheckBox::update(const Rectangle& clip)
 
 
     _textBounds.x += iconWidth + 5;
     _textBounds.x += iconWidth + 5;
     _textBounds.width -= iconWidth + 5;
     _textBounds.width -= iconWidth + 5;
+
+    if (_checked)
+    {
+        _image = getImage("checked", _state);
+    }
+    else
+    {
+        _image = getImage("unchecked", _state);
+    }
 }
 }
 
 
 void CheckBox::drawImages(SpriteBatch* spriteBatch, const Rectangle& clip)
 void CheckBox::drawImages(SpriteBatch* spriteBatch, const Rectangle& clip)
 {
 {
     // Left, v-center.
     // Left, v-center.
     // TODO: Set an alignment for icons.
     // TODO: Set an alignment for icons.
-    const Theme::Border border = getBorder(_state);
+    const Theme::Border& border = getBorder(_state);
     const Theme::Padding padding = getPadding();
     const Theme::Padding padding = getPadding();
-    float opacity = getOpacity(_state);
+    
+    const Rectangle& region = _image->getRegion();
+    const Theme::UVs& uvs = _image->getUVs();
+    Vector4 color = _image->getColor();
+    color.w *= _opacity;
 
 
-    if (_checked)
+    Vector2 size;
+    if (_imageSize.isZero())
     {
     {
-        const Rectangle& selectedRegion = getImageRegion("checked", _state);
-        const Theme::UVs& selected = getImageUVs("checked", _state);
-        Vector4 selectedColor = getImageColor("checked", _state);
-        selectedColor.w *= opacity;
-
-        Vector2 size;
-        if (_imageSize.isZero())
-        {
-            size.set(selectedRegion.width, selectedRegion.height);
-        }
-        else
-        {
-            size.set(_imageSize);
-        }
-
-        Vector2 pos(clip.x + _bounds.x + border.left + padding.left,
-            clip.y + _bounds.y + (_clipBounds.height - border.bottom - padding.bottom) / 2.0f - size.y / 2.0f);
-
-        spriteBatch->draw(pos.x, pos.y, size.x, size.y, selected.u1, selected.v1, selected.u2, selected.v2, selectedColor, _clip);
+        size.set(region.width, region.height);
     }
     }
     else
     else
     {
     {
-        const Rectangle& unselectedRegion = getImageRegion("unchecked", _state);
-        const Theme::UVs& unselected = getImageUVs("unchecked", _state);
-        Vector4 unselectedColor = getImageColor("unchecked", _state);
-        unselectedColor.w *= opacity;
-
-        Vector2 size;
-        if (_imageSize.isZero())
-        {
-            size.set(unselectedRegion.width, unselectedRegion.height);
-        }
-        else
-        {
-            size.set(_imageSize);
-        }
+        size.set(_imageSize);
+    }
 
 
-        Vector2 pos(clip.x + _bounds.x + border.left + padding.left,
-            clip.y + _bounds.y + (_clipBounds.height - border.bottom - padding.bottom) / 2.0f - size.y / 2.0f);
+    Vector2 pos(clip.x + _bounds.x + border.left + padding.left,
+        clip.y + _bounds.y + (_clipBounds.height - border.bottom - padding.bottom) / 2.0f - size.y / 2.0f);
 
 
-        spriteBatch->draw(pos.x, pos.y, size.x, size.y, unselected.u1, unselected.v1, unselected.u2, unselected.v2, unselectedColor, _clip);
-    }
+    spriteBatch->draw(pos.x, pos.y, size.x, size.y, uvs.u1, uvs.v1, uvs.u2, uvs.v2, color, _clip);
 }
 }
 
 
 }
 }

+ 1 - 0
gameplay/src/CheckBox.h

@@ -127,6 +127,7 @@ protected:
 
 
     bool _checked;      // Whether this checkbox is currently checked.
     bool _checked;      // Whether this checkbox is currently checked.
     Vector2 _imageSize;  // The size to draw the checkbox icon, if different from its size in the texture.
     Vector2 _imageSize;  // The size to draw the checkbox icon, if different from its size in the texture.
+    Theme::ThemeImage* _image;
 
 
 private:
 private:
 
 

+ 27 - 15
gameplay/src/Control.cpp

@@ -681,32 +681,34 @@ namespace gameplay
             y = clip.y;
             y = clip.y;
 
 
         _clip.set(x, y, width, height);
         _clip.set(x, y, width, height);
+
+        _skin = getSkin(_state);
+        _opacity = getOpacity(_state);
     }
     }
 
 
     void Control::drawBorder(SpriteBatch* spriteBatch, const Rectangle& clip)
     void Control::drawBorder(SpriteBatch* spriteBatch, const Rectangle& clip)
     {
     {
-        if (_bounds.width <= 0 || _bounds.height <= 0)
+        if (!_skin || _bounds.width <= 0 || _bounds.height <= 0)
             return;
             return;
 
 
         Vector2 pos(clip.x + _bounds.x, clip.y + _bounds.y);
         Vector2 pos(clip.x + _bounds.x, clip.y + _bounds.y);
 
 
         // Get the border and background images for this control's current state.
         // Get the border and background images for this control's current state.
-        //Theme::UVs topLeft, top, topRight, left, center, right, bottomLeft, bottom, bottomRight;
-        const Theme::UVs& topLeft = getSkinUVs(Theme::Skin::TOP_LEFT, _state);
-        const Theme::UVs& top = getSkinUVs(Theme::Skin::TOP, _state);
-        const Theme::UVs& topRight = getSkinUVs(Theme::Skin::TOP_RIGHT, _state);
-        const Theme::UVs& left = getSkinUVs(Theme::Skin::LEFT, _state);
-        const Theme::UVs& center = getSkinUVs(Theme::Skin::CENTER, _state);
-        const Theme::UVs& right = getSkinUVs(Theme::Skin::RIGHT, _state);
-        const Theme::UVs& bottomLeft = getSkinUVs(Theme::Skin::BOTTOM_LEFT, _state);
-        const Theme::UVs& bottom = getSkinUVs(Theme::Skin::BOTTOM, _state);
-        const Theme::UVs& bottomRight = getSkinUVs(Theme::Skin::BOTTOM_RIGHT, _state);
+        const Theme::UVs& topLeft = _skin->getUVs(Theme::Skin::TOP_LEFT);
+        const Theme::UVs& top = _skin->getUVs(Theme::Skin::TOP);
+        const Theme::UVs& topRight = _skin->getUVs(Theme::Skin::TOP_RIGHT);
+        const Theme::UVs& left = _skin->getUVs(Theme::Skin::LEFT);
+        const Theme::UVs& center = _skin->getUVs(Theme::Skin::CENTER);
+        const Theme::UVs& right = _skin->getUVs(Theme::Skin::RIGHT);
+        const Theme::UVs& bottomLeft = _skin->getUVs(Theme::Skin::BOTTOM_LEFT);
+        const Theme::UVs& bottom = _skin->getUVs(Theme::Skin::BOTTOM);
+        const Theme::UVs& bottomRight = _skin->getUVs(Theme::Skin::BOTTOM_RIGHT);
 
 
         // Calculate screen-space positions.
         // Calculate screen-space positions.
         const Theme::Border& border = getBorder(_state);
         const Theme::Border& border = getBorder(_state);
         const Theme::Padding& padding = getPadding();
         const Theme::Padding& padding = getPadding();
-        Vector4 skinColor = getSkinColor(_state);
-        skinColor.w *= getOpacity(_state);
+        Vector4 skinColor = _skin->getColor();
+        skinColor.w *= _opacity;
 
 
         float midWidth = _bounds.width - border.left - border.right;
         float midWidth = _bounds.width - border.left - border.right;
         float midHeight = _bounds.height - border.top - border.bottom;
         float midHeight = _bounds.height - border.top - border.bottom;
@@ -790,6 +792,11 @@ namespace gameplay
         return NORMAL;
         return NORMAL;
     }
     }
 
 
+    Theme::ThemeImage* Control::getImage(const char* id, State state)
+    {
+        return getOverlay(state)->getImageList()->getImage(id);
+    }
+
     // Implementation of AnimationHandler
     // Implementation of AnimationHandler
     unsigned int Control::getAnimationPropertyComponentCount(int propertyId) const
     unsigned int Control::getAnimationPropertyComponentCount(int propertyId) const
     {
     {
@@ -996,7 +1003,7 @@ namespace gameplay
     void Control::overrideThemedProperties(Properties* properties, unsigned char states)
     void Control::overrideThemedProperties(Properties* properties, unsigned char states)
     {
     {
         Theme::ImageList* imageList = NULL;
         Theme::ImageList* imageList = NULL;
-        Theme::Image* cursor = NULL;
+        Theme::ThemeImage* cursor = NULL;
         Theme::Skin* skin = NULL;
         Theme::Skin* skin = NULL;
         _style->_theme->lookUpSprites(properties, &imageList, &cursor, &skin);
         _style->_theme->lookUpSprites(properties, &imageList, &cursor, &skin);
 
 
@@ -1064,7 +1071,7 @@ namespace gameplay
         _dirty = true;
         _dirty = true;
     }
     }
 
 
-    void Control::setCursor(Theme::Image* cursor, unsigned char states)
+    void Control::setCursor(Theme::ThemeImage* cursor, unsigned char states)
     {
     {
         overrideStyle();
         overrideStyle();
         Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
         Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
@@ -1092,6 +1099,11 @@ namespace gameplay
         _dirty = true;
         _dirty = true;
     }
     }
 
 
+    Theme::Skin* Control::getSkin(State state)
+    {
+        return getOverlay(state)->getSkin();
+    }
+
     Control::Alignment Control::getAlignment(const char* alignment)
     Control::Alignment Control::getAlignment(const char* alignment)
     {
     {
         if (!alignment)
         if (!alignment)

+ 9 - 2
gameplay/src/Control.h

@@ -777,6 +777,8 @@ protected:
      */
      */
     static State getState(const char* state);
     static State getState(const char* state);
 
 
+    Theme::ThemeImage* getImage(const char* id, State state);
+
     /**
     /**
      * Notify this control's listeners of a specific event.
      * Notify this control's listeners of a specific event.
      *
      *
@@ -800,6 +802,8 @@ protected:
     Theme::Style* _style;
     Theme::Style* _style;
     std::map<Listener::EventType, std::list<Listener*>*>* _listeners;
     std::map<Listener::EventType, std::list<Listener*>*>* _listeners;
 
 
+    float _opacity;         // Current opacity.
+
 private:
 private:
 
 
     static const char ANIMATION_POSITION_X_BIT = 0x01;
     static const char ANIMATION_POSITION_X_BIT = 0x01;
@@ -833,10 +837,12 @@ private:
 
 
     void setImageList(Theme::ImageList* imageList, unsigned char states = STATE_ALL);
     void setImageList(Theme::ImageList* imageList, unsigned char states = STATE_ALL);
 
 
-    void setCursor(Theme::Image* cursor, unsigned char states = STATE_ALL);
+    void setCursor(Theme::ThemeImage* cursor, unsigned char states = STATE_ALL);
 
 
     void setSkin(Theme::Skin* skin, unsigned char states = STATE_ALL);
     void setSkin(Theme::Skin* skin, unsigned char states = STATE_ALL);
-    
+
+    Theme::Skin* getSkin(State state);
+
     void addSpecificListener(Control::Listener* listener, Listener::EventType eventType);
     void addSpecificListener(Control::Listener* listener, Listener::EventType eventType);
     
     
     /**
     /**
@@ -848,6 +854,7 @@ private:
     virtual void drawBorder(SpriteBatch* spriteBatch, const Rectangle& clip);
     virtual void drawBorder(SpriteBatch* spriteBatch, const Rectangle& clip);
     
     
     bool _styleOverridden;
     bool _styleOverridden;
+    Theme::Skin* _skin;
 };
 };
 
 
 }
 }

+ 10 - 11
gameplay/src/Form.h

@@ -15,17 +15,7 @@ namespace gameplay
 class Theme;
 class Theme;
 
 
 /**
 /**
- * Top-level container of UI controls.
- */
-class Form : public Container
-{
-    friend class Platform;
-
-public:
-
-    /**
-     * Create from properties file.
-     * The top-most namespace in the file must be named 'form'.  The following properties are available for forms:
+ * Top-level container of UI controls.  The following properties are available for forms:
 
 
  @verbatim
  @verbatim
     form <formID>
     form <formID>
@@ -52,7 +42,16 @@ public:
         slider { }
         slider { }
     }
     }
  @endverbatim
  @endverbatim
+ */
+class Form : public Container
+{
+    friend class Platform;
 
 
+public:
+
+    /**
+     * Create from properties file.
+     *
      * @param path Path to the properties file to create a new form from.
      * @param path Path to the properties file to create a new form from.
      */
      */
     static Form* create(const char* path);
     static Form* create(const char* path);

+ 14 - 6
gameplay/src/Label.cpp

@@ -3,7 +3,7 @@
 
 
 namespace gameplay
 namespace gameplay
 {
 {
-    Label::Label() : _text("")
+    Label::Label() : _text(""), _font(NULL)
     {
     {
     }
     }
 
 
@@ -64,17 +64,25 @@ namespace gameplay
         return _text.c_str();
         return _text.c_str();
     }
     }
 
 
+    void Label::update(const Rectangle& clip)
+    {
+        Control::update(clip);
+
+        _font = getFont(_state);
+        _textColor = getTextColor(_state);
+        _textColor.w *= getOpacity(_state);
+    }
+
     void Label::drawText(const Rectangle& clip)
     void Label::drawText(const Rectangle& clip)
     {
     {
         if (_text.size() <= 0)
         if (_text.size() <= 0)
             return;
             return;
 
 
-        Font* font = getFont(_state);
-        Vector4 textColor = getTextColor(_state);
-        textColor.w *= getOpacity(_state);
-
         // Draw the text.
         // Draw the text.
-        font->drawText(_text.c_str(), _textBounds, textColor, getFontSize(_state), getTextAlignment(_state), true, getTextRightToLeft(_state), &_clip);
+        if (_font)
+        {
+            _font->drawText(_text.c_str(), _textBounds, _textColor, getFontSize(_state), getTextAlignment(_state), true, getTextRightToLeft(_state), &_clip);
+        }
 
 
         _dirty = false;
         _dirty = false;
     }
     }

+ 4 - 0
gameplay/src/Label.h

@@ -86,6 +86,8 @@ protected:
      */
      */
     virtual void initialize(Theme::Style* style, Properties* properties);
     virtual void initialize(Theme::Style* style, Properties* properties);
 
 
+    void update(const Rectangle& clip);
+
     /**
     /**
      * Draw this label's text.
      * Draw this label's text.
      *
      *
@@ -94,6 +96,8 @@ protected:
     void drawText(const Rectangle& clip);
     void drawText(const Rectangle& clip);
 
 
     std::string _text;      // The text displayed by this label.
     std::string _text;      // The text displayed by this label.
+    Font* _font;
+    Vector4 _textColor;
 
 
 private:
 private:
 
 

+ 35 - 52
gameplay/src/RadioButton.cpp

@@ -120,86 +120,69 @@ void RadioButton::clearSelected(const std::string& groupId)
     }
     }
 }
 }
 
 
-void RadioButton::drawImages(SpriteBatch* spriteBatch, const Rectangle& clip)
+void RadioButton::update(const Rectangle& clip)
 {
 {
-    // Left, v-center.
-    // TODO: Set an alignment for radio button images.
-    const Theme::Border border = getBorder(_state);
-    const Theme::Padding padding = getPadding();
-    float opacity = getOpacity(_state);
+    Label::update(clip);
 
 
-    if (_selected)
+    Vector2 size;
+    if (_imageSize.isZero())
     {
     {
-        const Rectangle& selectedRegion = getImageRegion("selected", _state);
-        const Theme::UVs& selected = getImageUVs("selected", _state);
-        Vector4 selectedColor = getImageColor("selected", _state);
-        selectedColor.w *= opacity;
-
-        Vector2 size;
-        if (_imageSize.isZero())
+        if (_selected)
         {
         {
+            const Rectangle& selectedRegion = getImageRegion("selected", _state);
             size.set(selectedRegion.width, selectedRegion.height);
             size.set(selectedRegion.width, selectedRegion.height);
         }
         }
         else
         else
         {
         {
-            size.set(_imageSize);
+            const Rectangle& unselectedRegion = getImageRegion("unselected", _state);
+            size.set(unselectedRegion.width, unselectedRegion.height);
         }
         }
-
-        Vector2 pos(clip.x + _bounds.x + border.left + padding.left,
-            clip.y + _bounds.y + (_clipBounds.height - border.bottom - padding.bottom) / 2.0f - size.y / 2.0f);
-
-        spriteBatch->draw(pos.x, pos.y, size.x, size.y, selected.u1, selected.v1, selected.u2, selected.v2, selectedColor, _clip);
     }
     }
     else
     else
     {
     {
-        const Rectangle& unselectedRegion = getImageRegion("unselected", _state);
-        const Theme::UVs& unselected = getImageUVs("unselected", _state);
-        Vector4 unselectedColor = getImageColor("unselected", _state);
-        unselectedColor.w *= opacity;
-
-        Vector2 size;
-        if (_imageSize.isZero())
-        {
-            size.set(unselectedRegion.width, unselectedRegion.height);
-        }
-        else
-        {
-            size.set(_imageSize);
-        }
+        size.set(_imageSize);
+    }
+    float iconWidth = size.x;
 
 
-        Vector2 pos(clip.x + _bounds.x + border.left + padding.left,
-            clip.y + _bounds.y + (_clipBounds.height - border.bottom - padding.bottom) / 2.0f - size.y / 2.0f);
+    _textBounds.x += iconWidth + 5;
+    _textBounds.width -= iconWidth + 5;
 
 
-        spriteBatch->draw(pos.x, pos.y, size.x, size.y, unselected.u1, unselected.v1, unselected.u2, unselected.v2, unselectedColor, _clip);
+    if (_selected)
+    {
+        _image = getImage("selected", _state);
+    }
+    else
+    {
+        _image = getImage("unselected", _state);
     }
     }
 }
 }
 
 
-void RadioButton::update(const Rectangle& clip)
+void RadioButton::drawImages(SpriteBatch* spriteBatch, const Rectangle& clip)
 {
 {
-    Control::update(clip);
+    // Left, v-center.
+    // TODO: Set an alignment for radio button images.
+    const Theme::Border& border = getBorder(_state);
+    const Theme::Padding padding = getPadding();
+    
+    const Rectangle& region = _image->getRegion();
+    const Theme::UVs& uvs = _image->getUVs();
+    Vector4 color = _image->getColor();
+    color.w *= _opacity;
 
 
     Vector2 size;
     Vector2 size;
     if (_imageSize.isZero())
     if (_imageSize.isZero())
     {
     {
-        if (_selected)
-        {
-            const Rectangle& selectedRegion = getImageRegion("selected", _state);
-            size.set(selectedRegion.width, selectedRegion.height);
-        }
-        else
-        {
-            const Rectangle& unselectedRegion = getImageRegion("unselected", _state);
-            size.set(unselectedRegion.width, unselectedRegion.height);
-        }
+        size.set(region.width, region.height);
     }
     }
     else
     else
     {
     {
         size.set(_imageSize);
         size.set(_imageSize);
     }
     }
-    float iconWidth = size.x;
 
 
-    _textBounds.x += iconWidth + 5;
-    _textBounds.width -= iconWidth + 5;
+    Vector2 pos(clip.x + _bounds.x + border.left + padding.left,
+        clip.y + _bounds.y + (_clipBounds.height - border.bottom - padding.bottom) / 2.0f - size.y / 2.0f);
+
+    spriteBatch->draw(pos.x, pos.y, size.x, size.y, uvs.u1, uvs.v1, uvs.u2, uvs.v2, color, _clip);
 }
 }
 
 
 }
 }

+ 1 - 0
gameplay/src/RadioButton.h

@@ -134,6 +134,7 @@ protected:
     std::string _groupId;
     std::string _groupId;
     bool _selected;
     bool _selected;
     Vector2 _imageSize;
     Vector2 _imageSize;
+    Theme::ThemeImage* _image;
 
 
 private:
 private:
 
 

+ 29 - 20
gameplay/src/Slider.cpp

@@ -141,6 +141,16 @@ bool Slider::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contac
     return Control::touchEvent(evt, x, y, contactIndex);
     return Control::touchEvent(evt, x, y, contactIndex);
 }
 }
 
 
+void Slider::update(const Rectangle& clip)
+{
+    Label::update(clip);
+
+    _minImage = getImage("minCap", _state);
+    _maxImage = getImage("maxCap", _state);
+    _markerImage = getImage("marker", _state);
+    _trackImage = getImage("track", _state);
+}
+
 void Slider::drawImages(SpriteBatch* spriteBatch, const Rectangle& clip)
 void Slider::drawImages(SpriteBatch* spriteBatch, const Rectangle& clip)
 {
 {
     // TODO: Vertical slider.
     // TODO: Vertical slider.
@@ -151,26 +161,25 @@ void Slider::drawImages(SpriteBatch* spriteBatch, const Rectangle& clip)
     const Theme::Border& border = getBorder(_state);
     const Theme::Border& border = getBorder(_state);
     const Theme::Padding& padding = getPadding();
     const Theme::Padding& padding = getPadding();
 
 
-    const Rectangle& minCapRegion = getImageRegion("minCap", _state);
-    const Rectangle& maxCapRegion = getImageRegion("maxCap", _state);
-    const Rectangle& markerRegion = getImageRegion("marker", _state);
-    const Rectangle& trackRegion = getImageRegion("track", _state);
-
-    const Theme::UVs minCap = getImageUVs("minCap", _state);
-    const Theme::UVs maxCap = getImageUVs("maxCap", _state);
-    const Theme::UVs marker = getImageUVs("marker", _state);
-    const Theme::UVs track = getImageUVs("track", _state);
-
-    Vector4 minCapColor = getImageColor("minCap", _state);
-    Vector4 maxCapColor = getImageColor("maxCap", _state);
-    Vector4 markerColor = getImageColor("marker", _state);
-    Vector4 trackColor = getImageColor("track", _state);
-
-    float opacity = getOpacity(_state);
-    minCapColor.w *= opacity;
-    maxCapColor.w *= opacity;
-    markerColor.w *= opacity;
-    trackColor.w *= opacity;
+    const Rectangle& minCapRegion = _minImage->getRegion();
+    const Rectangle& maxCapRegion = _maxImage->getRegion();
+    const Rectangle& markerRegion = _markerImage->getRegion();
+    const Rectangle& trackRegion = _trackImage->getRegion();
+
+    const Theme::UVs minCap = _minImage->getUVs();
+    const Theme::UVs maxCap = _maxImage->getUVs();
+    const Theme::UVs marker = _markerImage->getUVs();
+    const Theme::UVs track = _trackImage->getUVs();
+
+    Vector4 minCapColor = _minImage->getColor();
+    Vector4 maxCapColor = _maxImage->getColor();
+    Vector4 markerColor = _markerImage->getColor();
+    Vector4 trackColor = _trackImage->getColor();
+
+    minCapColor.w *= _opacity;
+    maxCapColor.w *= _opacity;
+    markerColor.w *= _opacity;
+    trackColor.w *= _opacity;
 
 
     // Draw order: track, caps, marker.
     // Draw order: track, caps, marker.
     float midY = clip.y + _clipBounds.y + (_clipBounds.height - border.bottom - padding.bottom) / 2.0f;
     float midY = clip.y + _clipBounds.y + (_clipBounds.height - border.bottom - padding.bottom) / 2.0f;

+ 7 - 0
gameplay/src/Slider.h

@@ -149,11 +149,18 @@ protected:
      */
      */
     void drawImages(SpriteBatch* spriteBatch, const Rectangle& clip);
     void drawImages(SpriteBatch* spriteBatch, const Rectangle& clip);
 
 
+    void update(const Rectangle& clip);
+
     float _min;
     float _min;
     float _max;
     float _max;
     float _step;
     float _step;
     float _value;
     float _value;
 
 
+    Theme::ThemeImage* _minImage;
+    Theme::ThemeImage* _maxImage;
+    Theme::ThemeImage* _trackImage;
+    Theme::ThemeImage* _markerImage;
+
 private:
 private:
 
 
     /**
     /**

+ 10 - 7
gameplay/src/TextBox.cpp

@@ -274,7 +274,7 @@ void TextBox::keyEvent(Keyboard::KeyEvent evt, int key)
 
 
 void TextBox::update(const Rectangle& clip)
 void TextBox::update(const Rectangle& clip)
 {
 {
-    Control::update(clip);
+    Label::update(clip);
 
 
     // Get index into string and cursor location from the last recorded touch location.
     // Get index into string and cursor location from the last recorded touch location.
     if (_state == FOCUS)
     if (_state == FOCUS)
@@ -287,6 +287,9 @@ void TextBox::update(const Rectangle& clip)
         font->getIndexAtLocation(_text.c_str(), _clip, fontSize, _caretLocation, &_caretLocation,
         font->getIndexAtLocation(_text.c_str(), _clip, fontSize, _caretLocation, &_caretLocation,
             textAlignment, true, rightToLeft);
             textAlignment, true, rightToLeft);
     }
     }
+
+    _fontSize = getFontSize(_state);
+    _caretImage = getImage("textCaret", _state);
 }
 }
 
 
 void TextBox::drawImages(SpriteBatch* spriteBatch, const Rectangle& clip)
 void TextBox::drawImages(SpriteBatch* spriteBatch, const Rectangle& clip)
@@ -294,14 +297,14 @@ void TextBox::drawImages(SpriteBatch* spriteBatch, const Rectangle& clip)
     if (_state == FOCUS)
     if (_state == FOCUS)
     {
     {
         // Draw the cursor at its current location.
         // Draw the cursor at its current location.
-        const Rectangle& region = getImageRegion("textCaret", _state);
+        const Rectangle& region = _caretImage->getRegion();
         if (!region.isEmpty())
         if (!region.isEmpty())
         {
         {
-            const Vector4& color = getImageColor("textCaret", _state);
-            const Theme::UVs uvs = getImageUVs("textCaret", _state);
-            unsigned int fontSize = getFontSize(_state);
+            const Theme::UVs uvs = _caretImage->getUVs();
+            Vector4 color = _caretImage->getColor();
+            color.w *= _opacity;
 
 
-            spriteBatch->draw(_caretLocation.x - (region.width / 2.0f), _caretLocation.y, region.width, fontSize, uvs.u1, uvs.v1, uvs.u2, uvs.v2, color);
+            spriteBatch->draw(_caretLocation.x - (region.width / 2.0f), _caretLocation.y, region.width, _fontSize, uvs.u1, uvs.v1, uvs.u2, uvs.v2, color);
         }
         }
     }
     }
 
 
@@ -310,7 +313,7 @@ void TextBox::drawImages(SpriteBatch* spriteBatch, const Rectangle& clip)
 
 
 void TextBox::setCaretLocation(int x, int y)
 void TextBox::setCaretLocation(int x, int y)
 {
 {
-    Theme::Border border = getBorder(_state);
+    const Theme::Border& border = getBorder(_state);
     Theme::Padding padding = getPadding();
     Theme::Padding padding = getPadding();
 
 
     _caretLocation.set(x - border.left - padding.left + _clip.x,
     _caretLocation.set(x - border.left - padding.left + _clip.x,

+ 2 - 0
gameplay/src/TextBox.h

@@ -125,6 +125,8 @@ protected:
     Vector2 _caretLocation;
     Vector2 _caretLocation;
     unsigned int textIndex;
     unsigned int textIndex;
     int _lastKeypress;
     int _lastKeypress;
+    unsigned int _fontSize;
+    Theme::ThemeImage* _caretImage;
 
 
 private:
 private:
 
 

+ 23 - 23
gameplay/src/Theme.cpp

@@ -25,7 +25,7 @@ namespace gameplay
 
 
         for (unsigned int i = 0, count = _images.size(); i < count; ++i)
         for (unsigned int i = 0, count = _images.size(); i < count; ++i)
         {
         {
-            Image* image = _images[i];
+            ThemeImage* image = _images[i];
             SAFE_RELEASE(image);
             SAFE_RELEASE(image);
         }
         }
 
 
@@ -106,7 +106,7 @@ namespace gameplay
             
             
             if (strcmp(spacename, "image") == 0)
             if (strcmp(spacename, "image") == 0)
             {
             {
-                theme->_images.push_back(Image::create(tw, th, space, Vector4::one()));
+                theme->_images.push_back(ThemeImage::create(tw, th, space, Vector4::one()));
             }
             }
             else if (strcmp(spacename, "imageList") == 0)
             else if (strcmp(spacename, "imageList") == 0)
             {
             {
@@ -196,7 +196,7 @@ namespace gameplay
                         }
                         }
 
 
                         ImageList* imageList = NULL;
                         ImageList* imageList = NULL;
-                        Image* cursor = NULL;
+                        ThemeImage* cursor = NULL;
                         Skin* skin = NULL;
                         Skin* skin = NULL;
                         theme->lookUpSprites(innerSpace, &imageList, &cursor, &skin);
                         theme->lookUpSprites(innerSpace, &imageList, &cursor, &skin);
 
 
@@ -307,7 +307,7 @@ namespace gameplay
                         }
                         }
 
 
                         ImageList* imageList = NULL;
                         ImageList* imageList = NULL;
-                        Image* cursor = NULL;
+                        ThemeImage* cursor = NULL;
                         Skin* skin = NULL;
                         Skin* skin = NULL;
                         theme->lookUpSprites(innerSpace, &imageList, &cursor, &skin);
                         theme->lookUpSprites(innerSpace, &imageList, &cursor, &skin);
 
 
@@ -468,19 +468,19 @@ namespace gameplay
     }
     }
 
 
     /****************
     /****************
-     * Theme::Image *
+     * Theme::ThemeImage *
      ****************/
      ****************/
-    Theme::Image::Image(float tw, float th, const Rectangle& region, const Vector4& color)
+    Theme::ThemeImage::ThemeImage(float tw, float th, const Rectangle& region, const Vector4& color)
         : _region(region), _color(color)
         : _region(region), _color(color)
     {
     {
         generateUVs(tw, th, region.x, region.y, region.width, region.height, &_uvs);
         generateUVs(tw, th, region.x, region.y, region.width, region.height, &_uvs);
     }
     }
 
 
-    Theme::Image::~Image()
+    Theme::ThemeImage::~ThemeImage()
     {
     {
     }
     }
 
 
-    Theme::Image* Theme::Image::create(float tw, float th, Properties* properties, const Vector4& defaultColor)
+    Theme::ThemeImage* Theme::ThemeImage::create(float tw, float th, Properties* properties, const Vector4& defaultColor)
     {
     {
         Vector4 regionVector;                
         Vector4 regionVector;                
         properties->getVector4("region", &regionVector);
         properties->getVector4("region", &regionVector);
@@ -496,7 +496,7 @@ namespace gameplay
             color.set(defaultColor);
             color.set(defaultColor);
         }
         }
 
 
-        Image* image = new Image(tw, th, region, color);
+        ThemeImage* image = new ThemeImage(tw, th, region, color);
         const char* id = properties->getId();
         const char* id = properties->getId();
         if (id)
         if (id)
         {
         {
@@ -506,22 +506,22 @@ namespace gameplay
         return image;
         return image;
     }
     }
 
 
-    const char* Theme::Image::getId() const
+    const char* Theme::ThemeImage::getId() const
     {
     {
         return _id.c_str();
         return _id.c_str();
     }
     }
 
 
-    const Theme::UVs& Theme::Image::getUVs() const
+    const Theme::UVs& Theme::ThemeImage::getUVs() const
     {
     {
         return _uvs;
         return _uvs;
     }
     }
 
 
-    const Rectangle& Theme::Image::getRegion() const
+    const Rectangle& Theme::ThemeImage::getRegion() const
     {
     {
         return _region;
         return _region;
     }
     }
 
 
-    const Vector4& Theme::Image::getColor() const
+    const Vector4& Theme::ThemeImage::getColor() const
     {
     {
         return _color;
         return _color;
     }
     }
@@ -538,20 +538,20 @@ namespace gameplay
         _id = copy._id;
         _id = copy._id;
         _color = copy._color;
         _color = copy._color;
 
 
-        std::vector<Image*>::const_iterator it;
+        std::vector<ThemeImage*>::const_iterator it;
         for (it = copy._images.begin(); it != copy._images.end(); it++)
         for (it = copy._images.begin(); it != copy._images.end(); it++)
         {
         {
-            Image* image = *it;
-            _images.push_back(new Image(*image));
+            ThemeImage* image = *it;
+            _images.push_back(new ThemeImage(*image));
         }
         }
     }
     }
 
 
     Theme::ImageList::~ImageList()
     Theme::ImageList::~ImageList()
     {
     {
-        std::vector<Image*>::const_iterator it;
+        std::vector<ThemeImage*>::const_iterator it;
         for (it = _images.begin(); it != _images.end(); it++)
         for (it = _images.begin(); it != _images.end(); it++)
         {
         {
-            Image* image = *it;
+            ThemeImage* image = *it;
             SAFE_RELEASE(image);
             SAFE_RELEASE(image);
         }
         }
     }
     }
@@ -575,7 +575,7 @@ namespace gameplay
         Properties* space = properties->getNextNamespace();
         Properties* space = properties->getNextNamespace();
         while (space != NULL)
         while (space != NULL)
         {
         {
-            Image* image = Image::create(tw, th, space, color);
+            ThemeImage* image = ThemeImage::create(tw, th, space, color);
             imageList->_images.push_back(image);
             imageList->_images.push_back(image);
             space = properties->getNextNamespace();
             space = properties->getNextNamespace();
         }
         }
@@ -588,12 +588,12 @@ namespace gameplay
         return _id.c_str();
         return _id.c_str();
     }
     }
 
 
-    Theme::Image* Theme::ImageList::getImage(const char* imageId) const
+    Theme::ThemeImage* Theme::ImageList::getImage(const char* imageId) const
     {
     {
-        std::vector<Image*>::const_iterator it;
+        std::vector<ThemeImage*>::const_iterator it;
         for (it = _images.begin(); it != _images.end(); it++)
         for (it = _images.begin(); it != _images.end(); it++)
         {
         {
-            Image* image = *it;
+            ThemeImage* image = *it;
             if (strcmp(image->getId(), imageId) == 0)
             if (strcmp(image->getId(), imageId) == 0)
             {
             {
                 return image;
                 return image;
@@ -724,7 +724,7 @@ namespace gameplay
         uvs->v2 = 1.0f - ((y + height) * th);
         uvs->v2 = 1.0f - ((y + height) * th);
     }
     }
 
 
-    void Theme::lookUpSprites(const Properties* overlaySpace, ImageList** imageList, Image** cursor, Skin** Skin)
+    void Theme::lookUpSprites(const Properties* overlaySpace, ImageList** imageList, ThemeImage** cursor, Skin** Skin)
     {
     {
         const char* imageListString = overlaySpace->getString("imageList");
         const char* imageListString = overlaySpace->getString("imageList");
         if (imageListString)
         if (imageListString)

+ 10 - 10
gameplay/src/Theme.h

@@ -183,14 +183,12 @@ public:
         float right;
         float right;
     } Margin, Border, Padding;
     } Margin, Border, Padding;
 
 
-private:
-
     /**
     /**
      * Class representing an image within the theme's texture atlas.
      * Class representing an image within the theme's texture atlas.
      * An image has a region and a blend color in addition to an ID.
      * An image has a region and a blend color in addition to an ID.
      * UV coordinates are calculated from the region and can be retrieved.
      * UV coordinates are calculated from the region and can be retrieved.
      */
      */
-    class Image : public Ref
+    class ThemeImage : public Ref
     {
     {
         friend class Theme;
         friend class Theme;
         friend class Control;
         friend class Control;
@@ -207,11 +205,11 @@ private:
 
 
     private:
     private:
 
 
-        Image(float tw, float th, const Rectangle& region, const Vector4& color);
+        ThemeImage(float tw, float th, const Rectangle& region, const Vector4& color);
 
 
-        ~Image();
+        ~ThemeImage();
 
 
-        static Image* create(float tw, float th, Properties* properties, const Vector4& defaultColor);
+        static ThemeImage* create(float tw, float th, Properties* properties, const Vector4& defaultColor);
 
 
         std::string _id;
         std::string _id;
         UVs _uvs;
         UVs _uvs;
@@ -219,6 +217,8 @@ private:
         Vector4 _color;
         Vector4 _color;
     };
     };
 
 
+private:
+
     /**
     /**
      * Class representing a collection of theme images.  An image list
      * Class representing a collection of theme images.  An image list
      * can be assigned to each overlay of a style, and controls
      * can be assigned to each overlay of a style, and controls
@@ -233,7 +233,7 @@ private:
 
 
         const char* getId() const;
         const char* getId() const;
 
 
-        Image* getImage(const char* imageId) const;
+        ThemeImage* getImage(const char* imageId) const;
 
 
     private:
     private:
 
 
@@ -246,7 +246,7 @@ private:
         static ImageList* create(float tw, float th, Properties* properties);
         static ImageList* create(float tw, float th, Properties* properties);
 
 
         std::string _id;
         std::string _id;
-        std::vector<Image*> _images;
+        std::vector<ThemeImage*> _images;
         Vector4 _color;
         Vector4 _color;
     };
     };
 
 
@@ -346,13 +346,13 @@ private:
 
 
     static void generateUVs(float tw, float th, float x, float y, float width, float height, UVs* uvs);
     static void generateUVs(float tw, float th, float x, float y, float width, float height, UVs* uvs);
 
 
-    void lookUpSprites(const Properties* overlaySpace, ImageList** imageList, Image** mouseCursor, Skin** skin);
+    void lookUpSprites(const Properties* overlaySpace, ImageList** imageList, ThemeImage** mouseCursor, Skin** skin);
 
 
     std::string _path;
     std::string _path;
     Texture* _texture;
     Texture* _texture;
     SpriteBatch* _spriteBatch;
     SpriteBatch* _spriteBatch;
     std::vector<Style*> _styles;
     std::vector<Style*> _styles;
-    std::vector<Image*> _images;
+    std::vector<ThemeImage*> _images;
     std::vector<ImageList*> _imageLists;
     std::vector<ImageList*> _imageLists;
     std::vector<Skin*> _skins;
     std::vector<Skin*> _skins;
     std::set<Font*> _fonts;
     std::set<Font*> _fonts;

+ 8 - 8
gameplay/src/ThemeStyle.cpp

@@ -96,7 +96,7 @@ Theme::Style::Overlay::Overlay(const Overlay& copy) : _skin(NULL), _cursor(NULL)
     }
     }
     if (copy._cursor)
     if (copy._cursor)
     {
     {
-        _cursor = new Image(*copy._cursor);
+        _cursor = new ThemeImage(*copy._cursor);
     }
     }
     if (copy._imageList)
     if (copy._imageList)
     {
     {
@@ -263,7 +263,7 @@ void Theme::Style::Overlay::setTextColor(const Vector4& color)
 
 
 const Rectangle& Theme::Style::Overlay::getImageRegion(const char* id) const
 const Rectangle& Theme::Style::Overlay::getImageRegion(const char* id) const
 {
 {
-    Image* image = _imageList->getImage(id);
+    ThemeImage* image = _imageList->getImage(id);
     if (image)
     if (image)
     {
     {
         return image->getRegion();
         return image->getRegion();
@@ -276,7 +276,7 @@ const Rectangle& Theme::Style::Overlay::getImageRegion(const char* id) const
     
     
 void Theme::Style::Overlay::setImageRegion(const char* id, const Rectangle& region, float tw, float th)
 void Theme::Style::Overlay::setImageRegion(const char* id, const Rectangle& region, float tw, float th)
 {
 {
-    Image* image = _imageList->getImage(id);
+    ThemeImage* image = _imageList->getImage(id);
     assert(image);
     assert(image);
     image->_region.set(region);
     image->_region.set(region);
     generateUVs(tw, th, region.x, region.y, region.width, region.height, &(image->_uvs));
     generateUVs(tw, th, region.x, region.y, region.width, region.height, &(image->_uvs));
@@ -284,7 +284,7 @@ void Theme::Style::Overlay::setImageRegion(const char* id, const Rectangle& regi
 
 
 const Vector4& Theme::Style::Overlay::getImageColor(const char* id) const
 const Vector4& Theme::Style::Overlay::getImageColor(const char* id) const
 {
 {
-    Image* image = _imageList->getImage(id);
+    ThemeImage* image = _imageList->getImage(id);
     if (image)
     if (image)
     {
     {
         return image->getColor();
         return image->getColor();
@@ -297,14 +297,14 @@ const Vector4& Theme::Style::Overlay::getImageColor(const char* id) const
 
 
 void Theme::Style::Overlay::setImageColor(const char* id, const Vector4& color)
 void Theme::Style::Overlay::setImageColor(const char* id, const Vector4& color)
 {
 {
-    Image* image = _imageList->getImage(id);
+    ThemeImage* image = _imageList->getImage(id);
     assert(image);
     assert(image);
     image->_color.set(color);
     image->_color.set(color);
 }
 }
 
 
 const Theme::UVs& Theme::Style::Overlay::getImageUVs(const char* id) const
 const Theme::UVs& Theme::Style::Overlay::getImageUVs(const char* id) const
 {
 {
-    Image* image = _imageList->getImage(id);
+    ThemeImage* image = _imageList->getImage(id);
     if (image)
     if (image)
     {
     {
         return image->getUVs();
         return image->getUVs();
@@ -383,7 +383,7 @@ Theme::Skin* Theme::Style::Overlay::getSkin() const
     return _skin;
     return _skin;
 }
 }
 
 
-void Theme::Style::Overlay::setCursor(Image* cursor)
+void Theme::Style::Overlay::setCursor(ThemeImage* cursor)
 {
 {
     if (_cursor != cursor)
     if (_cursor != cursor)
     {
     {
@@ -397,7 +397,7 @@ void Theme::Style::Overlay::setCursor(Image* cursor)
     }
     }
 }
 }
 
 
-Theme::Image* Theme::Style::Overlay::getCursor() const
+Theme::ThemeImage* Theme::Style::Overlay::getCursor() const
 {
 {
     return _cursor;
     return _cursor;
 }
 }

+ 3 - 3
gameplay/src/ThemeStyle.h

@@ -138,9 +138,9 @@ private:
 
 
         Theme::Skin* getSkin() const;
         Theme::Skin* getSkin() const;
 
 
-        void setCursor(Theme::Image* cursor);
+        void setCursor(Theme::ThemeImage* cursor);
             
             
-        Theme::Image* getCursor() const;
+        Theme::ThemeImage* getCursor() const;
             
             
         void setImageList(Theme::ImageList* imageList);
         void setImageList(Theme::ImageList* imageList);
             
             
@@ -149,7 +149,7 @@ private:
         void applyAnimationValueOpacity(float opacity, float blendWeight);
         void applyAnimationValueOpacity(float opacity, float blendWeight);
 
 
         Skin* _skin;
         Skin* _skin;
-        Theme::Image* _cursor;
+        Theme::ThemeImage* _cursor;
         Theme::ImageList* _imageList;
         Theme::ImageList* _imageList;
         Font* _font;
         Font* _font;
         unsigned int _fontSize;
         unsigned int _fontSize;