Widgets can now rotate :O

This commit is contained in:
Eduardo Bart
2013-01-19 14:44:07 -02:00
parent 2fcaf2cc40
commit f389c3b3fe
8 changed files with 41 additions and 3 deletions

View File

@@ -58,6 +58,11 @@ void UIWidget::draw(const Rect& visibleRect, Fw::DrawPane drawPane)
if(m_clipping)
g_painter->setClipRect(visibleRect);
if(m_rotation != 0.0f) {
g_painter->pushTransformMatrix();
g_painter->rotate(m_rect.center(), m_rotation * (Fw::pi / 180.0));
}
drawSelf(drawPane);
if(m_children.size() > 0) {
@@ -67,6 +72,9 @@ void UIWidget::draw(const Rect& visibleRect, Fw::DrawPane drawPane)
drawChildren(visibleRect, drawPane);
}
if(m_rotation != 0.0f)
g_painter->popTransformMatrix();
if(m_clipping)
g_painter->resetClipRect();
}

View File

@@ -214,6 +214,7 @@ protected:
public:
void resize(int width, int height) { setRect(Rect(getPosition(), Size(width, height))); }
void move(int x, int y) { setRect(Rect(x, y, getSize())); }
void rotate(float degrees) { setRotation(degrees); }
void hide() { setVisible(false); }
void show() { setVisible(true); }
void disable() { setEnabled(false); }
@@ -287,6 +288,7 @@ protected:
EdgeGroup<int> m_margin;
EdgeGroup<int> m_padding;
float m_opacity;
float m_rotation;
int m_autoRepeatDelay;
Point m_lastClickPosition;
@@ -342,6 +344,7 @@ public:
void setPaddingBottom(int padding) { m_padding.bottom = padding; updateLayout(); }
void setPaddingLeft(int padding) { m_padding.left = padding; updateLayout(); }
void setOpacity(float opacity) { m_opacity = std::min(std::max(opacity, 0.0f), 1.0f); }
void setRotation(float degrees) { m_rotation = degrees; }
int getX() { return m_rect.x(); }
int getY() { return m_rect.y(); }
@@ -385,6 +388,7 @@ public:
int getPaddingBottom() { return m_padding.bottom; }
int getPaddingLeft() { return m_padding.left; }
float getOpacity() { return m_opacity; }
float getRotation() { return m_rotation; }
// image

View File

@@ -38,6 +38,7 @@ void UIWidget::initBaseStyle()
m_iconColor = Color::white;
m_color = Color::white;
m_opacity = 1.0f;
m_rotation = 0.0f;
m_iconAlign = Fw::AlignNone;
// generate an unique id, this is need because anchored layouts find widgets by id
@@ -107,6 +108,8 @@ void UIWidget::parseBaseStyle(const OTMLNodePtr& styleNode)
setIconAlign(Fw::translateAlignment(node->value()));
else if(node->tag() == "opacity")
setOpacity(node->value<float>());
else if(node->tag() == "rotation")
setRotation(node->value<float>());
else if(node->tag() == "enabled")
setEnabled(node->value<bool>());
else if(node->tag() == "visible")