Better opacity support for TextComponent

This commit is contained in:
Aloshi 2013-10-10 16:14:33 -05:00
parent 2aad9cbdeb
commit e247326b51
4 changed files with 36 additions and 4 deletions

View file

@ -149,6 +149,10 @@ unsigned char GuiComponent::getOpacity() const
void GuiComponent::setOpacity(unsigned char opacity)
{
mOpacity = opacity;
for(auto it = mChildren.begin(); it != mChildren.end(); it++)
{
(*it)->setOpacity(opacity);
}
}
const Eigen::Affine3f GuiComponent::getTransform()

View file

@ -48,8 +48,8 @@ public:
unsigned int getChildCount() const;
GuiComponent* getChild(unsigned int i) const;
unsigned char getOpacity() const;
void setOpacity(unsigned char opacity);
virtual unsigned char getOpacity() const;
virtual void setOpacity(unsigned char opacity);
const Eigen::Affine3f getTransform();

View file

@ -32,8 +32,24 @@ void TextComponent::setFont(std::shared_ptr<Font> font)
void TextComponent::setColor(unsigned int color)
{
mColor = color;
mOpacity = mColor & 0x000000FF;
onTextChanged();
unsigned char opacity = mColor & 0x000000FF;
GuiComponent::setOpacity(opacity);
onColorChanged();
}
void TextComponent::setOpacity(unsigned char opacity)
{
mColor = (mColor & 0xFFFFFF00) | opacity;
onColorChanged();
GuiComponent::setOpacity(opacity);
}
unsigned char TextComponent::getOpacity() const
{
return mColor & 0x000000FF;
}
void TextComponent::setText(const std::string& text)
@ -104,6 +120,14 @@ void TextComponent::onTextChanged()
mTextCache = std::shared_ptr<TextCache>(f->buildTextCache(f->wrapText(mText, mSize.x()), 0, 0, (mColor >> 8 << 8) | mOpacity));
}
void TextComponent::onColorChanged()
{
if(mTextCache)
{
mTextCache->setColor(mColor);
}
}
void TextComponent::setValue(const std::string& value)
{
setText(value);

View file

@ -21,12 +21,16 @@ public:
std::string getValue() const override;
void setValue(const std::string& value) override;
unsigned char getOpacity() const override;
void setOpacity(unsigned char opacity) override;
std::shared_ptr<Font> getFont() const;
private:
void calculateExtent();
void onTextChanged();
void onColorChanged();
unsigned int mColor;
std::shared_ptr<Font> mFont;