| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483 |
- #include "ThemeStyle.h"
- namespace gameplay
- {
- /****************
- * Theme::Style *
- ****************/
- Theme::Style::Style(Theme* theme, const char* id, float tw, float th,
- const Theme::Margin& margin, const Theme::Padding& padding,
- Theme::Style::Overlay* normal, Theme::Style::Overlay* focus, Theme::Style::Overlay* active, Theme::Style::Overlay* disabled)
- : _theme(theme), _id(id), _tw(tw), _th(th), _margin(margin), _padding(padding)
- {
- _overlays[OVERLAY_NORMAL] = normal;
- _overlays[OVERLAY_FOCUS] = focus;
- _overlays[OVERLAY_ACTIVE] = active;
- _overlays[OVERLAY_DISABLED] = disabled;
- }
- Theme::Style::Style(const Style& copy)
- {
- _id = copy._id;
- _margin = copy._margin;
- _padding = copy._padding;
- _tw = copy._tw;
- _th = copy._th;
- for (int i = 0; i < OVERLAY_MAX; i++)
- {
- GP_ASSERT(copy._overlays[i]);
- _overlays[i] = new Theme::Style::Overlay(*copy._overlays[i]);
- }
- }
- Theme::Style::~Style()
- {
- for (unsigned int i = 0; i < OVERLAY_MAX; i++)
- {
- SAFE_RELEASE(_overlays[i]);
- }
- }
- Theme* Theme::Style::getTheme() const
- {
- return _theme;
- }
-
- const char* Theme::Style::getId() const
- {
- return _id.c_str();
- }
- Theme::Style::Overlay* Theme::Style::getOverlay(OverlayType overlayType) const
- {
- return _overlays[overlayType];
- }
- void Theme::Style::setMargin(float top, float bottom, float left, float right)
- {
- _margin.top = top;
- _margin.bottom = bottom;
- _margin.left = left;
- _margin.right = right;
- }
- const Theme::Margin& Theme::Style::getMargin() const
- {
- return _margin;
- }
- void Theme::Style::setPadding(float top, float bottom, float left, float right)
- {
- _padding.top = top;
- _padding.bottom = bottom;
- _padding.left = left;
- _padding.right = right;
- }
- const Theme::Padding& Theme::Style::getPadding() const
- {
- return _padding;
- }
-
- /*************************
- * Theme::Style::Overlay *
- *************************/
- Theme::Style::Overlay* Theme::Style::Overlay::create()
- {
- Overlay* overlay = new Overlay();
- return overlay;
- }
- Theme::Style::Overlay::Overlay()
- : _skin(NULL), _cursor(NULL), _imageList(NULL), _font(NULL),
- _fontSize(0), _alignment(Font::ALIGN_TOP_LEFT), _textRightToLeft(false), _textColor(Vector4::one()), _opacity(1.0f)
- {
- }
- Theme::Style::Overlay::Overlay(const Overlay& copy) : _skin(NULL), _cursor(NULL), _imageList(NULL), _font(NULL)
- {
- if (copy._skin)
- {
- _skin = new Skin(*copy._skin);
- }
- if (copy._cursor)
- {
- _cursor = new ThemeImage(*copy._cursor);
- }
- if (copy._imageList)
- {
- _imageList = new ImageList(*copy._imageList);
- }
- _font = copy._font;
- _fontSize = copy._fontSize;
- _alignment = copy._alignment;
- _textRightToLeft = copy._textRightToLeft;
- _textColor = Vector4(copy._textColor);
- _opacity = copy._opacity;
- if (_font)
- {
- _font->addRef();
- }
- }
- Theme::Style::Overlay::~Overlay()
- {
- SAFE_RELEASE(_skin);
- SAFE_RELEASE(_imageList);
- SAFE_RELEASE(_cursor);
- SAFE_RELEASE(_font);
- }
- float Theme::Style::Overlay::getOpacity() const
- {
- return _opacity;
- }
- void Theme::Style::Overlay::setOpacity(float opacity)
- {
- _opacity = opacity;
- }
- void Theme::Style::Overlay::setBorder(float top, float bottom, float left, float right)
- {
- if (_skin)
- {
- _skin->_border.top = top;
- _skin->_border.bottom = bottom;
- _skin->_border.left = left;
- _skin->_border.right = right;
- }
- }
- const Theme::Border& Theme::Style::Overlay::getBorder() const
- {
- if (_skin)
- {
- return _skin->getBorder();
- }
- else
- {
- return Theme::Border::empty();
- }
- }
- void Theme::Style::Overlay::setSkinColor(const Vector4& color)
- {
- if (_skin)
- {
- _skin->_color.set(color);
- }
- }
- const Vector4& Theme::Style::Overlay::getSkinColor() const
- {
- if (_skin)
- {
- return _skin->getColor();
- }
- return Vector4::one();
- }
- void Theme::Style::Overlay::setSkinRegion(const Rectangle& region, float tw, float th)
- {
- GP_ASSERT(_skin);
- _skin->setRegion(region, tw, th);
- }
- const Rectangle& Theme::Style::Overlay::getSkinRegion() const
- {
- if (_skin)
- {
- return _skin->getRegion();
- }
- return Rectangle::empty();
- }
- const Theme::UVs& Theme::Style::Overlay::getSkinUVs(Theme::Skin::SkinArea area) const
- {
- if (_skin)
- {
- return _skin->_uvs[area];
- }
- return UVs::empty();
- }
- Font* Theme::Style::Overlay::getFont() const
- {
- return _font;
- }
- void Theme::Style::Overlay::setFont(Font* font)
- {
- if (_font != font)
- {
- SAFE_RELEASE(_font);
- _font = font;
- if (_font)
- {
- _font->addRef();
- }
- }
- }
- unsigned int Theme::Style::Overlay::getFontSize() const
- {
- return _fontSize;
- }
- void Theme::Style::Overlay::setFontSize(unsigned int fontSize)
- {
- _fontSize = fontSize;
- }
- Font::Justify Theme::Style::Overlay::getTextAlignment() const
- {
- return _alignment;
- }
- void Theme::Style::Overlay::setTextAlignment(Font::Justify alignment)
- {
- _alignment = alignment;
- }
- bool Theme::Style::Overlay::getTextRightToLeft() const
- {
- return _textRightToLeft;
- }
- void Theme::Style::Overlay::setTextRightToLeft(bool rightToLeft)
- {
- _textRightToLeft = rightToLeft;
- }
- const Vector4& Theme::Style::Overlay::getTextColor() const
- {
- return _textColor;
- }
- void Theme::Style::Overlay::setTextColor(const Vector4& color)
- {
- _textColor = color;
- }
- const Rectangle& Theme::Style::Overlay::getImageRegion(const char* id) const
- {
- if (!_imageList)
- {
- return Rectangle::empty();
- }
- ThemeImage* image = _imageList->getImage(id);
- if (image)
- {
- return image->getRegion();
- }
- else
- {
- return Rectangle::empty();
- }
- }
-
- void Theme::Style::Overlay::setImageRegion(const char* id, const Rectangle& region, float tw, float th)
- {
- GP_ASSERT(_imageList);
- ThemeImage* image = _imageList->getImage(id);
- GP_ASSERT(image);
- image->_region.set(region);
- generateUVs(tw, th, region.x, region.y, region.width, region.height, &(image->_uvs));
- }
- const Vector4& Theme::Style::Overlay::getImageColor(const char* id) const
- {
- GP_ASSERT(_imageList);
- ThemeImage* image = _imageList->getImage(id);
- if (image)
- {
- return image->getColor();
- }
- else
- {
- return Vector4::zero();
- }
- }
- void Theme::Style::Overlay::setImageColor(const char* id, const Vector4& color)
- {
- GP_ASSERT(_imageList);
- ThemeImage* image = _imageList->getImage(id);
- GP_ASSERT(image);
- image->_color.set(color);
- }
- const Theme::UVs& Theme::Style::Overlay::getImageUVs(const char* id) const
- {
- GP_ASSERT(_imageList);
- ThemeImage* image = _imageList->getImage(id);
- if (image)
- {
- return image->getUVs();
- }
- else
- {
- return UVs::empty();
- }
- }
- const Rectangle& Theme::Style::Overlay::getCursorRegion() const
- {
- if (_cursor)
- {
- return _cursor->getRegion();
- }
- else
- {
- return Rectangle::empty();
- }
- }
-
- void Theme::Style::Overlay::setCursorRegion(const Rectangle& region, float tw, float th)
- {
- GP_ASSERT(_cursor);
- _cursor->_region.set(region);
- generateUVs(tw, th, region.x, region.y, region.width, region.height, &(_cursor->_uvs));
- }
- const Vector4& Theme::Style::Overlay::getCursorColor() const
- {
- if (_cursor)
- {
- return _cursor->getColor();
- }
- else
- {
- return Vector4::zero();
- }
- }
- void Theme::Style::Overlay::setCursorColor(const Vector4& color)
- {
- GP_ASSERT(_cursor);
- _cursor->_color.set(color);
- }
- const Theme::UVs& Theme::Style::Overlay::getCursorUVs() const
- {
- if (_cursor)
- {
- return _cursor->getUVs();
- }
- else
- {
- return UVs::empty();
- }
- }
- void Theme::Style::Overlay::setSkin(Skin* skin)
- {
- if (_skin != skin)
- {
- SAFE_RELEASE(_skin);
- _skin = skin;
- if (skin)
- {
- skin->addRef();
- }
- }
- }
- Theme::Skin* Theme::Style::Overlay::getSkin() const
- {
- return _skin;
- }
- void Theme::Style::Overlay::setCursor(ThemeImage* cursor)
- {
- if (_cursor != cursor)
- {
- SAFE_RELEASE(_cursor);
- _cursor = cursor;
- if (cursor)
- {
- cursor->addRef();
- }
- }
- }
- Theme::ThemeImage* Theme::Style::Overlay::getCursor() const
- {
- return _cursor;
- }
-
- void Theme::Style::Overlay::setImageList(ImageList* imageList)
- {
- if (_imageList != imageList)
- {
- SAFE_RELEASE(_imageList);
- _imageList = imageList;
- if (imageList)
- {
- imageList->addRef();
- }
- }
- }
-
- Theme::ImageList* Theme::Style::Overlay::getImageList() const
- {
- return _imageList;
- }
- // Implementation of AnimationHandler
- unsigned int Theme::Style::Overlay::getAnimationPropertyComponentCount(int propertyId) const
- {
- switch(propertyId)
- {
- case Theme::Style::Overlay::ANIMATE_OPACITY:
- return 1;
- default:
- return -1;
- }
- }
- void Theme::Style::Overlay::getAnimationPropertyValue(int propertyId, AnimationValue* value)
- {
- GP_ASSERT(value);
- switch(propertyId)
- {
- case ANIMATE_OPACITY:
- value->setFloat(0, _opacity);
- break;
- default:
- break;
- }
- }
- void Theme::Style::Overlay::setAnimationPropertyValue(int propertyId, AnimationValue* value, float blendWeight)
- {
- GP_ASSERT(value);
- switch(propertyId)
- {
- case ANIMATE_OPACITY:
- {
- _opacity = Curve::lerp(blendWeight, _opacity, value->getFloat(0));
- break;
- }
- default:
- break;
- }
- }
- }
|