tibia-client/src/framework/ui/uibutton.cpp

73 lines
2.5 KiB
C++
Raw Normal View History

2011-08-28 15:17:58 +02:00
/*
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
2011-08-14 04:09:11 +02:00
#include "uibutton.h"
2011-08-15 16:06:15 +02:00
#include <framework/graphics/borderimage.h>
#include <framework/graphics/font.h>
#include <framework/otml/otmlnode.h>
#include <framework/luascript/luainterface.h>
2011-08-20 22:30:41 +02:00
#include <framework/graphics/graphics.h>
2011-11-16 18:58:42 +01:00
#include <framework/graphics/texture.h>
#include <framework/graphics/texturemanager.h>
2011-04-08 07:10:00 +02:00
2011-11-17 18:43:41 +01:00
UIButton::UIButton()
2011-04-08 11:50:26 +02:00
{
2011-11-17 18:43:41 +01:00
m_focusable = false;
2011-08-14 04:09:11 +02:00
}
void UIButton::render()
{
2011-08-20 22:30:41 +02:00
UIWidget::render();
2011-11-16 18:58:42 +01:00
if(m_icon) {
Rect iconRect;
2011-12-07 01:31:55 +01:00
iconRect.resize(m_icon->getSize());
2011-11-16 18:58:42 +01:00
iconRect.moveCenter(m_rect.center());
2011-12-07 01:31:55 +01:00
g_painter.drawTexturedRect(iconRect, m_icon);
2011-11-16 18:58:42 +01:00
}
Rect textRect = m_rect;
2011-11-16 00:47:32 +01:00
textRect.translate(m_textOffset);
m_font->renderText(m_text, textRect, Fw::AlignCenter, m_foregroundColor);
2011-08-14 04:09:11 +02:00
}
void UIButton::onStyleApply(const OTMLNodePtr& styleNode)
2011-08-14 04:09:11 +02:00
{
UIWidget::onStyleApply(styleNode);
2011-08-14 04:09:11 +02:00
for(OTMLNodePtr node : styleNode->children()) {
2011-11-16 18:58:42 +01:00
if(node->tag() == "text-offset")
2011-11-16 00:47:32 +01:00
m_textOffset = node->value<Point>();
2011-11-16 18:58:42 +01:00
else if(node->tag() == "text")
m_text = node->value();
2011-11-16 18:58:42 +01:00
else if(node->tag() == "icon")
m_icon = g_textures.getTexture(node->value());
2011-08-22 14:44:26 +02:00
}
2011-08-14 04:09:11 +02:00
}
2011-11-13 06:11:47 +01:00
void UIButton::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
2011-08-14 04:09:11 +02:00
{
2011-11-16 18:58:42 +01:00
if(isPressed() && getRect().contains(mousePos)) {
callLuaField("onClick");
2011-08-22 14:44:26 +02:00
}
2011-04-08 11:50:26 +02:00
}