rework on graphics.cpp, implement some GFX with lua

This commit is contained in:
Eduardo Bart
2011-08-14 14:45:25 -03:00
parent 2abe962aa9
commit afc197f2dc
28 changed files with 250 additions and 128 deletions

View File

@@ -24,8 +24,9 @@ void UIButton::loadStyleFromOTML(const OTMLNodePtr& styleNode)
UIWidget::loadStyleFromOTML(styleNode);
for(int i=0; i<3; ++i) {
m_statesStyle[i].image = getImage();
m_statesStyle[i].color = getColor();
m_statesStyle[i].image = m_image;
m_statesStyle[i].color = m_color;
m_statesStyle[i].fontColor = m_fontColor;
m_statesStyle[i].textTranslate = Point(0,0);
}
@@ -51,7 +52,8 @@ void UIButton::loadStateStyle(ButtonStateStyle& stateStyle, const OTMLNodePtr& s
if(OTMLNodePtr node = stateStyleNode->get("image"))
stateStyle.image = Image::loadFromOTML(node);
stateStyle.textTranslate = stateStyleNode->readAt("text-translate", Point());
stateStyle.color = stateStyleNode->readAt("color", getColor());
stateStyle.color = stateStyleNode->readAt("font-color", m_fontColor);
stateStyle.color = stateStyleNode->readAt("color", m_color);
}
void UIButton::render()
@@ -63,7 +65,7 @@ void UIButton::render()
currentStyle.image->draw(textRect);
textRect.translate(currentStyle.textTranslate);
getFont()->renderText(m_text, textRect, AlignCenter, currentStyle.color);
getFont()->renderText(m_text, textRect, AlignCenter, currentStyle.fontColor);
}
void UIButton::onHoverChange(UIHoverEvent& event)

View File

@@ -8,6 +8,7 @@ class UIButton : public UIWidget
struct ButtonStateStyle {
ImagePtr image;
Point textTranslate;
Color fontColor;
Color color;
};

View File

@@ -30,7 +30,7 @@ void UILabel::loadStyleFromOTML(const OTMLNodePtr& styleNode)
void UILabel::render()
{
getFont()->renderText(m_text, getGeometry(), m_align, getColor());
getFont()->renderText(m_text, getGeometry(), m_align, m_fontColor);
}
void UILabel::resizeToText()

View File

@@ -37,7 +37,7 @@ void UILineEdit::render()
int textLength = m_text.length();
const TexturePtr& texture = m_font->getTexture();
for(int i=0;i<textLength;++i) {
g_graphics.drawTexturedRect(m_glyphsCoords[i], texture, m_glyphsTexCoords[i], m_color);
g_graphics.drawTexturedRect(m_glyphsCoords[i], texture, m_glyphsTexCoords[i]);
}
// render cursor

View File

@@ -8,6 +8,7 @@
#include <graphics/borderimage.h>
#include <graphics/fontmanager.h>
#include <otml/otmlnode.h>
#include <graphics/graphics.h>
UIWidget::UIWidget(UIWidgetType type)
{
@@ -18,8 +19,10 @@ UIWidget::UIWidget(UIWidgetType type)
m_focusable = false;
m_destroyed = false;
m_updateScheduled = false;
m_opacity = 255;
m_marginLeft = m_marginRight = m_marginTop = m_marginBottom = 0;
m_color = Color::white;
m_fontColor = Color::white;
// generate an unique id, this is need because anchored layouts find widgets by id
static unsigned long id = 1;
@@ -116,10 +119,18 @@ void UIWidget::loadStyleFromOTML(const OTMLNodePtr& styleNode)
else if(node->tag() == "font") {
setFont(g_fonts.getFont(node->value()));
}
// font color
else if(node->tag() == "font-color") {
setFontColor(node->read<Color>());
}
// color
else if(node->tag() == "color") {
setColor(node->read<Color>());
}
// opacity
else if(node->tag() == "opacity") {
setOpacity(node->read<int>());
}
// size
else if(node->tag() == "size") {
resize(node->read<Size>());
@@ -199,8 +210,16 @@ void UIWidget::render()
m_image->draw(getGeometry());
for(const UIWidgetPtr& child : m_children) {
if(child->isVisible())
if(child->isVisible()) {
int oldOpacity = g_graphics.getOpacity();
if(child->getOpacity() < oldOpacity)
g_graphics.setOpacity(child->getOpacity());
g_graphics.bindColor(child->getColor());
child->render();
g_graphics.setOpacity(oldOpacity);
}
}
}

View File

@@ -49,7 +49,9 @@ public:
void setImage(const ImagePtr& image) { m_image = image; }
virtual void setFont(const FontPtr& font) { m_font = font; }
void setOpacity(int opacity) { m_opacity = opacity; }
void setColor(const Color& color) { m_color = color; }
void setFontColor(const Color& color) { m_fontColor = color; }
void setMarginLeft(int margin) { m_marginLeft = margin; updateGeometry(); }
void setMarginRight(int margin) { m_marginRight = margin; updateGeometry(); }
void setMarginTop(int margin) { m_marginTop = margin; updateGeometry(); }
@@ -86,7 +88,9 @@ public:
ImagePtr getImage() const { return m_image; }
FontPtr getFont() const { return m_font; }
Color getFontColor() const { return m_fontColor; }
Color getColor() const { return m_color; }
int getOpacity() const { return m_opacity; }
int getMarginLeft() const { return m_marginLeft; }
int getMarginRight() const { return m_marginRight; }
int getMarginTop() const { return m_marginTop; }
@@ -164,7 +168,9 @@ protected:
// basic style components used by all widgets
ImagePtr m_image;
FontPtr m_font;
int m_opacity;
Color m_color;
Color m_fontColor;
int m_marginLeft;
int m_marginRight;
int m_marginTop;

View File

@@ -55,7 +55,7 @@ void UIWindow::render()
headTextRect.addLeft(-m_headMargin);
else if(m_titleAlign & AlignRight)
headTextRect.addRight(-m_headMargin);
getFont()->renderText(m_title, headTextRect, m_titleAlign, getColor());
m_font->renderText(m_title, headTextRect, m_titleAlign, m_fontColor);
}
// draw window body