animated texture

This commit is contained in:
Eduardo Bart
2011-05-12 20:24:57 -03:00
parent c6753747fb
commit 42eae9afd8
32 changed files with 289 additions and 146 deletions

View File

@@ -37,7 +37,7 @@ void UIButton::onInputEvent(const InputEvent& event)
g_dispatcher.addTask(boost::bind(&Scriptable::callLuaTableField, shared_from_this(), "onClick"));
}
} else if(event.type == EV_MOUSE_MOVE && m_state != ButtonDown) {
if(getRect().contains(event.mousePos) && UIContainer::getRoot()->recursiveGetChildByPos(event.mousePos) == asUIElement())
if(isMouseOver())
m_state = ButtonMouseOver;
else
m_state = ButtonUp;

View File

@@ -213,6 +213,13 @@ void UIContainer::onInputEvent(const InputEvent& event)
}
} else {
shouldFire = true;
if(event.type == EV_MOUSE_MOVE) {
if(child->getRect().contains(event.mousePos) && UIContainer::getRoot()->recursiveGetChildByPos(event.mousePos) == child)
child->setMouseOver(true);
else
child->setMouseOver(false);
}
}
}
}

View File

@@ -35,6 +35,7 @@ UIElement::UIElement(UI::ElementType type) :
m_type(type),
m_visible(true),
m_enabled(true),
m_mouseOver(false),
m_marginLeft(0),
m_marginRight(0),
m_marginTop(0),

View File

@@ -83,6 +83,9 @@ public:
void setFocused(bool focused);
bool isFocused() const;
void setMouseOver(bool mouseOver) { m_mouseOver = mouseOver; }
bool isMouseOver() const { return m_mouseOver; }
void setVisible(bool visible) { m_visible = visible; }
bool isVisible() const { return m_visible; }
@@ -123,6 +126,7 @@ private:
std::string m_id;
bool m_visible;
bool m_enabled;
bool m_mouseOver;
Rect m_rect;
int m_marginLeft;

View File

@@ -92,6 +92,8 @@ ImagePtr UIElementSkin::loadImage(const YAML::Node& node)
texture = g_textures.get("skins/" + yamlRead<std::string>(node, "image"));
if(texture)
image = ImagePtr(new Image(texture));
if(!m_defaultSize.isValid())
m_defaultSize = texture->getSize();
if(!image)
logError(yamlErrorDesc(node["image"], "failed to load image"));

View File

@@ -34,8 +34,7 @@ class UILabel : public UIElement
public:
UILabel() :
UIElement(UI::Label),
m_align(AlignTopLeft),
m_color(Color::white) { }
m_align(AlignLeftCenter) { }
void setText(const std::string& text);
std::string getText() const { return m_text; }
@@ -48,7 +47,6 @@ public:
private:
std::string m_text;
AlignmentFlag m_align;
Color m_color;
};
typedef boost::shared_ptr<UILabel> UILabelPtr;

View File

@@ -232,7 +232,7 @@ void UILoader::loadElement(const UIElementPtr& element, const YAML::Node& node)
else if(element->getElementType() == UI::Label) {
UILabelPtr label = boost::static_pointer_cast<UILabel>(element);
label->setText(yamlRead(node, "text", std::string()));
label->setAlign(parseAlignment(yamlRead(node, "align", std::string())));
label->setAlign(parseAlignment(yamlRead(node, "align", std::string("left"))));
}
}