Commit e247326b authored by Aloshi's avatar Aloshi

Better opacity support for TextComponent

parent 2aad9cbd
......@@ -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()
......
......@@ -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();
......
......@@ -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);
......
......@@ -20,6 +20,9 @@ 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;
......@@ -27,6 +30,7 @@ private:
void calculateExtent();
void onTextChanged();
void onColorChanged();
unsigned int mColor;
std::shared_ptr<Font> mFont;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment