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

@ -61,13 +61,14 @@ void LocalPlayer::draw(const Point& dest, float scaleFactor, bool animate, Light
{ {
Creature::draw(dest, scaleFactor, animate, lightView); Creature::draw(dest, scaleFactor, animate, lightView);
// This is a test to rotation, translate and scale transformations.
/* /*
// This is a test to rotation, translate and scale transformations.
Point rotateOffset = dest; Point rotateOffset = dest;
rotateOffset += ((animate ? m_walkOffset : Point(0,0)) + Point(16,16)) * scaleFactor; rotateOffset += ((animate ? m_walkOffset : Point(0,0)) + Point(16,16)) * scaleFactor;
g_painter->pushTransformMatrix();
g_painter->rotate(rotateOffset, Fw::pi * std::sin(g_clock.millis()/1000.0f)); g_painter->rotate(rotateOffset, Fw::pi * std::sin(g_clock.millis()/1000.0f));
Creature::draw(dest, scaleFactor, animate, lightView); Creature::draw(dest, scaleFactor, animate, lightView);
g_painter->resetTransformMatrix(); g_painter->popTransformMatrix();
*/ */
} }

View File

@ -226,6 +226,19 @@ void Painter::rotate(float x, float y, float angle)
translate(x, y); translate(x, y);
} }
void Painter::pushTransformMatrix()
{
m_transformMatrixStack.push_back(m_transformMatrix);
assert(m_transformMatrixStack.size() < 100);
}
void Painter::popTransformMatrix()
{
assert(m_transformMatrixStack.size() > 0);
setTransformMatrix(m_transformMatrixStack.back());
m_transformMatrixStack.pop_back();
}
void Painter::updateGlTexture() void Painter::updateGlTexture()
{ {
if(m_glTextureId != 0) if(m_glTextureId != 0)

View File

@ -106,6 +106,9 @@ public:
void rotate(float x, float y, float angle); void rotate(float x, float y, float angle);
void rotate(const Point& p, float angle) { rotate(p.x, p.y, angle); } void rotate(const Point& p, float angle) { rotate(p.x, p.y, angle); }
void pushTransformMatrix();
void popTransformMatrix();
Matrix3 getTransformMatrix() { return m_transformMatrix; } Matrix3 getTransformMatrix() { return m_transformMatrix; }
Matrix3 getProjectionMatrix() { return m_projectionMatrix; } Matrix3 getProjectionMatrix() { return m_projectionMatrix; }
Matrix3 getTextureMatrix() { return m_textureMatrix; } Matrix3 getTextureMatrix() { return m_textureMatrix; }
@ -137,6 +140,7 @@ protected:
CoordsBuffer m_coordsBuffer; CoordsBuffer m_coordsBuffer;
std::vector<Matrix3> m_transformMatrixStack;
Matrix3 m_transformMatrix; Matrix3 m_transformMatrix;
Matrix3 m_projectionMatrix; Matrix3 m_projectionMatrix;
Matrix3 m_textureMatrix; Matrix3 m_textureMatrix;

View File

@ -89,8 +89,10 @@ TexturePtr TextureManager::getTexture(const std::string& fileName)
texture = g_textures.getEmptyTexture(); texture = g_textures.getEmptyTexture();
} }
if(texture) if(texture) {
texture->setSmooth(true);
m_textures[filePath] = texture; m_textures[filePath] = texture;
}
} }
return texture; return texture;

View File

@ -399,6 +399,7 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIWidget>("backwardsGetWidgetById", &UIWidget::backwardsGetWidgetById); g_lua.bindClassMemberFunction<UIWidget>("backwardsGetWidgetById", &UIWidget::backwardsGetWidgetById);
g_lua.bindClassMemberFunction<UIWidget>("resize", &UIWidget::resize); g_lua.bindClassMemberFunction<UIWidget>("resize", &UIWidget::resize);
g_lua.bindClassMemberFunction<UIWidget>("move", &UIWidget::move); g_lua.bindClassMemberFunction<UIWidget>("move", &UIWidget::move);
g_lua.bindClassMemberFunction<UIWidget>("rotate", &UIWidget::rotate);
g_lua.bindClassMemberFunction<UIWidget>("hide", &UIWidget::hide); g_lua.bindClassMemberFunction<UIWidget>("hide", &UIWidget::hide);
g_lua.bindClassMemberFunction<UIWidget>("show", &UIWidget::show); g_lua.bindClassMemberFunction<UIWidget>("show", &UIWidget::show);
g_lua.bindClassMemberFunction<UIWidget>("disable", &UIWidget::disable); g_lua.bindClassMemberFunction<UIWidget>("disable", &UIWidget::disable);
@ -493,6 +494,7 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIWidget>("setPaddingBottom", &UIWidget::setPaddingBottom); g_lua.bindClassMemberFunction<UIWidget>("setPaddingBottom", &UIWidget::setPaddingBottom);
g_lua.bindClassMemberFunction<UIWidget>("setPaddingLeft", &UIWidget::setPaddingLeft); g_lua.bindClassMemberFunction<UIWidget>("setPaddingLeft", &UIWidget::setPaddingLeft);
g_lua.bindClassMemberFunction<UIWidget>("setOpacity", &UIWidget::setOpacity); g_lua.bindClassMemberFunction<UIWidget>("setOpacity", &UIWidget::setOpacity);
g_lua.bindClassMemberFunction<UIWidget>("setRotation", &UIWidget::setRotation);
g_lua.bindClassMemberFunction<UIWidget>("getX", &UIWidget::getX); g_lua.bindClassMemberFunction<UIWidget>("getX", &UIWidget::getX);
g_lua.bindClassMemberFunction<UIWidget>("getY", &UIWidget::getY); g_lua.bindClassMemberFunction<UIWidget>("getY", &UIWidget::getY);
g_lua.bindClassMemberFunction<UIWidget>("getPosition", &UIWidget::getPosition); g_lua.bindClassMemberFunction<UIWidget>("getPosition", &UIWidget::getPosition);
@ -535,6 +537,7 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIWidget>("getPaddingBottom", &UIWidget::getPaddingBottom); g_lua.bindClassMemberFunction<UIWidget>("getPaddingBottom", &UIWidget::getPaddingBottom);
g_lua.bindClassMemberFunction<UIWidget>("getPaddingLeft", &UIWidget::getPaddingLeft); g_lua.bindClassMemberFunction<UIWidget>("getPaddingLeft", &UIWidget::getPaddingLeft);
g_lua.bindClassMemberFunction<UIWidget>("getOpacity", &UIWidget::getOpacity); g_lua.bindClassMemberFunction<UIWidget>("getOpacity", &UIWidget::getOpacity);
g_lua.bindClassMemberFunction<UIWidget>("getRotation", &UIWidget::getRotation);
g_lua.bindClassMemberFunction<UIWidget>("setImageSource", &UIWidget::setImageSource); g_lua.bindClassMemberFunction<UIWidget>("setImageSource", &UIWidget::setImageSource);
g_lua.bindClassMemberFunction<UIWidget>("setImageClip", &UIWidget::setImageClip); g_lua.bindClassMemberFunction<UIWidget>("setImageClip", &UIWidget::setImageClip);
g_lua.bindClassMemberFunction<UIWidget>("setImageOffsetX", &UIWidget::setImageOffsetX); g_lua.bindClassMemberFunction<UIWidget>("setImageOffsetX", &UIWidget::setImageOffsetX);

View File

@ -58,6 +58,11 @@ void UIWidget::draw(const Rect& visibleRect, Fw::DrawPane drawPane)
if(m_clipping) if(m_clipping)
g_painter->setClipRect(visibleRect); 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); drawSelf(drawPane);
if(m_children.size() > 0) { if(m_children.size() > 0) {
@ -67,6 +72,9 @@ void UIWidget::draw(const Rect& visibleRect, Fw::DrawPane drawPane)
drawChildren(visibleRect, drawPane); drawChildren(visibleRect, drawPane);
} }
if(m_rotation != 0.0f)
g_painter->popTransformMatrix();
if(m_clipping) if(m_clipping)
g_painter->resetClipRect(); g_painter->resetClipRect();
} }

View File

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

View File

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