2012-01-10 23:13:40 +01:00
|
|
|
/*
|
2016-07-10 03:10:27 +02:00
|
|
|
* Copyright (c) 2010-2016 OTClient <https://github.com/edubart/otclient>
|
2012-01-10 23:13:40 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "uiwidget.h"
|
2012-01-15 14:57:42 +01:00
|
|
|
#include "uihorizontallayout.h"
|
2012-01-10 23:13:40 +01:00
|
|
|
#include "uiverticallayout.h"
|
2012-01-12 20:20:18 +01:00
|
|
|
#include "uigridlayout.h"
|
|
|
|
#include "uianchorlayout.h"
|
2012-01-10 23:13:40 +01:00
|
|
|
#include "uitranslator.h"
|
|
|
|
|
|
|
|
#include <framework/graphics/painter.h>
|
|
|
|
#include <framework/graphics/texture.h>
|
|
|
|
#include <framework/graphics/texturemanager.h>
|
|
|
|
|
|
|
|
void UIWidget::initBaseStyle()
|
|
|
|
{
|
2012-03-20 16:17:10 +01:00
|
|
|
m_backgroundColor = Color::alpha;
|
|
|
|
m_borderColor.set(Color::black);
|
|
|
|
m_iconColor = Color::white;
|
|
|
|
m_color = Color::white;
|
2012-01-10 23:13:40 +01:00
|
|
|
m_opacity = 1.0f;
|
2013-01-19 17:44:07 +01:00
|
|
|
m_rotation = 0.0f;
|
2013-01-08 21:01:47 +01:00
|
|
|
m_iconAlign = Fw::AlignNone;
|
2012-01-10 23:13:40 +01:00
|
|
|
|
|
|
|
// generate an unique id, this is need because anchored layouts find widgets by id
|
|
|
|
static unsigned long id = 1;
|
2013-01-23 19:55:10 +01:00
|
|
|
m_id = stdext::format("widget%d", id++);
|
2012-01-10 23:13:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void UIWidget::parseBaseStyle(const OTMLNodePtr& styleNode)
|
|
|
|
{
|
2013-01-26 21:40:03 +01:00
|
|
|
// parse lua variables and callbacks first
|
|
|
|
for(const OTMLNodePtr& node : styleNode->children()) {
|
|
|
|
// lua functions
|
|
|
|
if(stdext::starts_with(node->tag(), "@")) {
|
|
|
|
// load once
|
|
|
|
if(m_firstOnStyle) {
|
|
|
|
std::string funcName = node->tag().substr(1);
|
|
|
|
std::string funcOrigin = "@" + node->source() + ": [" + node->tag() + "]";
|
|
|
|
g_lua.loadFunction(node->value(), funcOrigin);
|
|
|
|
luaSetField(funcName);
|
|
|
|
}
|
|
|
|
// lua fields value
|
|
|
|
} else if(stdext::starts_with(node->tag(), "&")) {
|
|
|
|
std::string fieldName = node->tag().substr(1);
|
|
|
|
std::string fieldOrigin = "@" + node->source() + ": [" + node->tag() + "]";
|
|
|
|
|
|
|
|
g_lua.evaluateExpression(node->value(), fieldOrigin);
|
|
|
|
luaSetField(fieldName);
|
|
|
|
}
|
|
|
|
}
|
2012-01-10 23:13:40 +01:00
|
|
|
// load styles used by all widgets
|
|
|
|
for(const OTMLNodePtr& node : styleNode->children()) {
|
|
|
|
if(node->tag() == "color")
|
|
|
|
setColor(node->value<Color>());
|
|
|
|
else if(node->tag() == "x")
|
|
|
|
setX(node->value<int>());
|
|
|
|
else if(node->tag() == "y")
|
|
|
|
setY(node->value<int>());
|
|
|
|
else if(node->tag() == "pos")
|
2012-01-30 01:00:12 +01:00
|
|
|
setPosition(node->value<Point>());
|
2012-01-10 23:13:40 +01:00
|
|
|
else if(node->tag() == "width")
|
|
|
|
setWidth(node->value<int>());
|
|
|
|
else if(node->tag() == "height")
|
|
|
|
setHeight(node->value<int>());
|
|
|
|
else if(node->tag() == "rect")
|
|
|
|
setRect(node->value<Rect>());
|
|
|
|
else if(node->tag() == "background")
|
|
|
|
setBackgroundColor(node->value<Color>());
|
|
|
|
else if(node->tag() == "background-color")
|
|
|
|
setBackgroundColor(node->value<Color>());
|
|
|
|
else if(node->tag() == "background-offset-x")
|
|
|
|
setBackgroundOffsetX(node->value<int>());
|
|
|
|
else if(node->tag() == "background-offset-y")
|
|
|
|
setBackgroundOffsetY(node->value<int>());
|
|
|
|
else if(node->tag() == "background-offset")
|
|
|
|
setBackgroundOffset(node->value<Point>());
|
|
|
|
else if(node->tag() == "background-width")
|
|
|
|
setBackgroundWidth(node->value<int>());
|
|
|
|
else if(node->tag() == "background-height")
|
|
|
|
setBackgroundHeight(node->value<int>());
|
|
|
|
else if(node->tag() == "background-size")
|
|
|
|
setBackgroundSize(node->value<Size>());
|
|
|
|
else if(node->tag() == "background-rect")
|
|
|
|
setBackgroundRect(node->value<Rect>());
|
|
|
|
else if(node->tag() == "icon")
|
2012-05-28 15:06:26 +02:00
|
|
|
setIcon(stdext::resolve_path(node->value(), node->source()));
|
2012-01-10 23:13:40 +01:00
|
|
|
else if(node->tag() == "icon-source")
|
2012-05-28 15:06:26 +02:00
|
|
|
setIcon(stdext::resolve_path(node->value(), node->source()));
|
2012-01-10 23:13:40 +01:00
|
|
|
else if(node->tag() == "icon-color")
|
|
|
|
setIconColor(node->value<Color>());
|
|
|
|
else if(node->tag() == "icon-offset-x")
|
|
|
|
setIconOffsetX(node->value<int>());
|
|
|
|
else if(node->tag() == "icon-offset-y")
|
|
|
|
setIconOffsetY(node->value<int>());
|
|
|
|
else if(node->tag() == "icon-offset")
|
|
|
|
setIconOffset(node->value<Point>());
|
|
|
|
else if(node->tag() == "icon-width")
|
|
|
|
setIconWidth(node->value<int>());
|
|
|
|
else if(node->tag() == "icon-height")
|
|
|
|
setIconHeight(node->value<int>());
|
|
|
|
else if(node->tag() == "icon-size")
|
|
|
|
setIconSize(node->value<Size>());
|
|
|
|
else if(node->tag() == "icon-rect")
|
|
|
|
setIconRect(node->value<Rect>());
|
2012-07-12 21:16:23 +02:00
|
|
|
else if(node->tag() == "icon-clip")
|
|
|
|
setIconClip(node->value<Rect>());
|
2013-01-08 21:01:47 +01:00
|
|
|
else if(node->tag() == "icon-align")
|
|
|
|
setIconAlign(Fw::translateAlignment(node->value()));
|
2012-01-10 23:13:40 +01:00
|
|
|
else if(node->tag() == "opacity")
|
|
|
|
setOpacity(node->value<float>());
|
2013-01-19 17:44:07 +01:00
|
|
|
else if(node->tag() == "rotation")
|
|
|
|
setRotation(node->value<float>());
|
2012-01-10 23:13:40 +01:00
|
|
|
else if(node->tag() == "enabled")
|
|
|
|
setEnabled(node->value<bool>());
|
|
|
|
else if(node->tag() == "visible")
|
|
|
|
setVisible(node->value<bool>());
|
|
|
|
else if(node->tag() == "checked")
|
|
|
|
setChecked(node->value<bool>());
|
2013-01-08 21:01:47 +01:00
|
|
|
else if(node->tag() == "draggable")
|
2012-08-07 01:43:14 +02:00
|
|
|
setDraggable(node->value<bool>());
|
2012-01-10 23:13:40 +01:00
|
|
|
else if(node->tag() == "on")
|
|
|
|
setOn(node->value<bool>());
|
|
|
|
else if(node->tag() == "focusable")
|
|
|
|
setFocusable(node->value<bool>());
|
2013-01-26 20:06:25 +01:00
|
|
|
else if(node->tag() == "auto-focus")
|
|
|
|
setAutoFocusPolicy(Fw::translateAutoFocusPolicy(node->value()));
|
2012-01-10 23:13:40 +01:00
|
|
|
else if(node->tag() == "phantom")
|
|
|
|
setPhantom(node->value<bool>());
|
|
|
|
else if(node->tag() == "size")
|
|
|
|
setSize(node->value<Size>());
|
|
|
|
else if(node->tag() == "fixed-size")
|
|
|
|
setFixedSize(node->value<bool>());
|
2012-03-25 16:10:15 +02:00
|
|
|
else if(node->tag() == "clipping")
|
|
|
|
setClipping(node->value<bool>());
|
2012-01-10 23:13:40 +01:00
|
|
|
else if(node->tag() == "border") {
|
2012-05-28 15:06:26 +02:00
|
|
|
auto split = stdext::split(node->value(), " ");
|
2012-02-08 14:44:06 +01:00
|
|
|
if(split.size() == 2) {
|
2012-05-28 15:06:26 +02:00
|
|
|
setBorderWidth(stdext::safe_cast<int>(split[0]));
|
|
|
|
setBorderColor(stdext::safe_cast<Color>(split[1]));
|
2012-02-08 14:44:06 +01:00
|
|
|
} else
|
2012-08-31 06:56:10 +02:00
|
|
|
throw OTMLException(node, "border param must have its width followed by its color");
|
2012-01-10 23:13:40 +01:00
|
|
|
}
|
|
|
|
else if(node->tag() == "border-width")
|
|
|
|
setBorderWidth(node->value<int>());
|
|
|
|
else if(node->tag() == "border-width-top")
|
|
|
|
setBorderWidthTop(node->value<int>());
|
|
|
|
else if(node->tag() == "border-width-right")
|
|
|
|
setBorderWidthRight(node->value<int>());
|
|
|
|
else if(node->tag() == "border-width-bottom")
|
|
|
|
setBorderWidthBottom(node->value<int>());
|
|
|
|
else if(node->tag() == "border-width-left")
|
|
|
|
setBorderWidthLeft(node->value<int>());
|
|
|
|
else if(node->tag() == "border-color")
|
|
|
|
setBorderColor(node->value<Color>());
|
|
|
|
else if(node->tag() == "border-color-top")
|
|
|
|
setBorderColorTop(node->value<Color>());
|
|
|
|
else if(node->tag() == "border-color-right")
|
|
|
|
setBorderColorRight(node->value<Color>());
|
|
|
|
else if(node->tag() == "border-color-bottom")
|
|
|
|
setBorderColorBottom(node->value<Color>());
|
|
|
|
else if(node->tag() == "border-color-left")
|
|
|
|
setBorderColorLeft(node->value<Color>());
|
|
|
|
else if(node->tag() == "margin-top")
|
|
|
|
setMarginTop(node->value<int>());
|
|
|
|
else if(node->tag() == "margin-right")
|
|
|
|
setMarginRight(node->value<int>());
|
|
|
|
else if(node->tag() == "margin-bottom")
|
|
|
|
setMarginBottom(node->value<int>());
|
|
|
|
else if(node->tag() == "margin-left")
|
|
|
|
setMarginLeft(node->value<int>());
|
|
|
|
else if(node->tag() == "margin") {
|
|
|
|
std::string marginDesc = node->value();
|
2012-08-01 09:49:09 +02:00
|
|
|
std::vector<std::string> split = stdext::split(marginDesc, " ");
|
2012-01-10 23:13:40 +01:00
|
|
|
if(split.size() == 4) {
|
2012-05-28 15:06:26 +02:00
|
|
|
setMarginTop(stdext::safe_cast<int>(split[0]));
|
|
|
|
setMarginRight(stdext::safe_cast<int>(split[1]));
|
|
|
|
setMarginBottom(stdext::safe_cast<int>(split[2]));
|
|
|
|
setMarginLeft(stdext::safe_cast<int>(split[3]));
|
2012-01-10 23:13:40 +01:00
|
|
|
} else if(split.size() == 3) {
|
2012-05-28 15:06:26 +02:00
|
|
|
int marginTop = stdext::safe_cast<int>(split[0]);
|
|
|
|
int marginHorizontal = stdext::safe_cast<int>(split[1]);
|
|
|
|
int marginBottom = stdext::safe_cast<int>(split[2]);
|
2012-01-10 23:13:40 +01:00
|
|
|
setMarginTop(marginTop);
|
|
|
|
setMarginRight(marginHorizontal);
|
|
|
|
setMarginBottom(marginBottom);
|
|
|
|
setMarginLeft(marginHorizontal);
|
|
|
|
} else if(split.size() == 2) {
|
2012-05-28 15:06:26 +02:00
|
|
|
int marginVertical = stdext::safe_cast<int>(split[0]);
|
|
|
|
int marginHorizontal = stdext::safe_cast<int>(split[1]);
|
2012-01-10 23:13:40 +01:00
|
|
|
setMarginTop(marginVertical);
|
|
|
|
setMarginRight(marginHorizontal);
|
|
|
|
setMarginBottom(marginVertical);
|
|
|
|
setMarginLeft(marginHorizontal);
|
|
|
|
} else if(split.size() == 1) {
|
2012-05-28 15:06:26 +02:00
|
|
|
int margin = stdext::safe_cast<int>(split[0]);
|
2012-01-10 23:13:40 +01:00
|
|
|
setMarginTop(margin);
|
|
|
|
setMarginRight(margin);
|
|
|
|
setMarginBottom(margin);
|
|
|
|
setMarginLeft(margin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(node->tag() == "padding-top")
|
|
|
|
setPaddingTop(node->value<int>());
|
|
|
|
else if(node->tag() == "padding-right")
|
|
|
|
setPaddingRight(node->value<int>());
|
|
|
|
else if(node->tag() == "padding-bottom")
|
|
|
|
setPaddingBottom(node->value<int>());
|
|
|
|
else if(node->tag() == "padding-left")
|
|
|
|
setPaddingLeft(node->value<int>());
|
|
|
|
else if(node->tag() == "padding") {
|
|
|
|
std::string paddingDesc = node->value();
|
2012-08-01 09:49:09 +02:00
|
|
|
std::vector<std::string> split = stdext::split(paddingDesc, " ");
|
2012-01-10 23:13:40 +01:00
|
|
|
if(split.size() == 4) {
|
2012-05-28 15:06:26 +02:00
|
|
|
setPaddingTop(stdext::safe_cast<int>(split[0]));
|
|
|
|
setPaddingRight(stdext::safe_cast<int>(split[1]));
|
|
|
|
setPaddingBottom(stdext::safe_cast<int>(split[2]));
|
|
|
|
setPaddingLeft(stdext::safe_cast<int>(split[3]));
|
2012-01-10 23:13:40 +01:00
|
|
|
} else if(split.size() == 3) {
|
2012-05-28 15:06:26 +02:00
|
|
|
int paddingTop = stdext::safe_cast<int>(split[0]);
|
|
|
|
int paddingHorizontal = stdext::safe_cast<int>(split[1]);
|
|
|
|
int paddingBottom = stdext::safe_cast<int>(split[2]);
|
2012-01-10 23:13:40 +01:00
|
|
|
setPaddingTop(paddingTop);
|
|
|
|
setPaddingRight(paddingHorizontal);
|
|
|
|
setPaddingBottom(paddingBottom);
|
|
|
|
setPaddingLeft(paddingHorizontal);
|
|
|
|
} else if(split.size() == 2) {
|
2012-05-28 15:06:26 +02:00
|
|
|
int paddingVertical = stdext::safe_cast<int>(split[0]);
|
|
|
|
int paddingHorizontal = stdext::safe_cast<int>(split[1]);
|
2012-01-10 23:13:40 +01:00
|
|
|
setPaddingTop(paddingVertical);
|
|
|
|
setPaddingRight(paddingHorizontal);
|
|
|
|
setPaddingBottom(paddingVertical);
|
|
|
|
setPaddingLeft(paddingHorizontal);
|
|
|
|
} else if(split.size() == 1) {
|
2012-05-28 15:06:26 +02:00
|
|
|
int padding = stdext::safe_cast<int>(split[0]);
|
2012-01-10 23:13:40 +01:00
|
|
|
setPaddingTop(padding);
|
|
|
|
setPaddingRight(padding);
|
|
|
|
setPaddingBottom(padding);
|
|
|
|
setPaddingLeft(padding);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// layouts
|
|
|
|
else if(node->tag() == "layout") {
|
|
|
|
std::string layoutType;
|
|
|
|
if(node->hasValue())
|
|
|
|
layoutType = node->value();
|
|
|
|
else
|
|
|
|
layoutType = node->valueAt<std::string>("type", "");
|
|
|
|
|
|
|
|
if(!layoutType.empty()) {
|
|
|
|
UILayoutPtr layout;
|
2012-01-15 14:57:42 +01:00
|
|
|
if(layoutType == "horizontalBox")
|
2012-08-01 09:49:09 +02:00
|
|
|
layout = UIHorizontalLayoutPtr(new UIHorizontalLayout(static_self_cast<UIWidget>()));
|
2012-01-15 14:57:42 +01:00
|
|
|
else if(layoutType == "verticalBox")
|
2012-08-01 09:49:09 +02:00
|
|
|
layout = UIVerticalLayoutPtr(new UIVerticalLayout(static_self_cast<UIWidget>()));
|
2012-01-12 20:20:18 +01:00
|
|
|
else if(layoutType == "grid")
|
2012-08-01 09:49:09 +02:00
|
|
|
layout = UIGridLayoutPtr(new UIGridLayout(static_self_cast<UIWidget>()));
|
2012-01-10 23:13:40 +01:00
|
|
|
else if(layoutType == "anchor")
|
2012-08-01 09:49:09 +02:00
|
|
|
layout = UIAnchorLayoutPtr(new UIAnchorLayout(static_self_cast<UIWidget>()));
|
2012-01-10 23:13:40 +01:00
|
|
|
else
|
|
|
|
throw OTMLException(node, "cannot determine layout type");
|
|
|
|
setLayout(layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(node->hasChildren())
|
|
|
|
m_layout->applyStyle(node);
|
|
|
|
}
|
|
|
|
// anchors
|
2012-08-01 09:49:09 +02:00
|
|
|
else if(stdext::starts_with(node->tag(), "anchors.")) {
|
2012-01-10 23:13:40 +01:00
|
|
|
UIWidgetPtr parent = getParent();
|
|
|
|
if(!parent) {
|
|
|
|
if(m_firstOnStyle)
|
|
|
|
throw OTMLException(node, "cannot create anchor, there is no parent widget!");
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-07-29 05:34:40 +02:00
|
|
|
UILayoutPtr layout = parent->getLayout();
|
|
|
|
UIAnchorLayoutPtr anchorLayout;
|
|
|
|
if(layout->isUIAnchorLayout())
|
2012-08-01 09:49:09 +02:00
|
|
|
anchorLayout = layout->static_self_cast<UIAnchorLayout>();
|
2012-07-29 05:34:40 +02:00
|
|
|
|
2012-01-10 23:13:40 +01:00
|
|
|
if(!anchorLayout)
|
|
|
|
throw OTMLException(node, "cannot create anchor, the parent widget doesn't use anchor layout!");
|
|
|
|
|
|
|
|
std::string what = node->tag().substr(8);
|
|
|
|
if(what == "fill") {
|
|
|
|
fill(node->value());
|
|
|
|
} else if(what == "centerIn") {
|
|
|
|
centerIn(node->value());
|
|
|
|
} else {
|
|
|
|
Fw::AnchorEdge anchoredEdge = Fw::translateAnchorEdge(what);
|
|
|
|
|
2012-04-06 00:46:53 +02:00
|
|
|
if(node->value() == "none") {
|
|
|
|
removeAnchor(anchoredEdge);
|
|
|
|
} else {
|
2012-05-28 15:06:26 +02:00
|
|
|
std::vector<std::string> split = stdext::split(node->value(), ".");
|
2012-04-06 00:46:53 +02:00
|
|
|
if(split.size() != 2)
|
|
|
|
throw OTMLException(node, "invalid anchor description");
|
2012-01-10 23:13:40 +01:00
|
|
|
|
2012-04-06 00:46:53 +02:00
|
|
|
std::string hookedWidgetId = split[0];
|
|
|
|
Fw::AnchorEdge hookedEdge = Fw::translateAnchorEdge(split[1]);
|
2012-01-10 23:13:40 +01:00
|
|
|
|
2012-04-06 00:46:53 +02:00
|
|
|
if(anchoredEdge == Fw::AnchorNone)
|
|
|
|
throw OTMLException(node, "invalid anchor edge");
|
2012-01-10 23:13:40 +01:00
|
|
|
|
2012-04-06 00:46:53 +02:00
|
|
|
if(hookedEdge == Fw::AnchorNone)
|
|
|
|
throw OTMLException(node, "invalid anchor target edge");
|
2012-01-10 23:13:40 +01:00
|
|
|
|
2012-04-06 00:46:53 +02:00
|
|
|
addAnchor(anchoredEdge, hookedWidgetId, hookedEdge);
|
|
|
|
}
|
2012-01-10 23:13:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIWidget::drawBackground(const Rect& screenCoords)
|
|
|
|
{
|
2012-04-05 21:08:46 +02:00
|
|
|
if(m_backgroundColor.aF() > 0.0f) {
|
2012-01-10 23:13:40 +01:00
|
|
|
Rect drawRect = screenCoords;
|
|
|
|
drawRect.translate(m_backgroundRect.topLeft());
|
|
|
|
if(m_backgroundRect.isValid())
|
|
|
|
drawRect.resize(m_backgroundRect.size());
|
2012-04-19 01:03:43 +02:00
|
|
|
g_painter->setColor(m_backgroundColor);
|
|
|
|
g_painter->drawFilledRect(drawRect);
|
2012-01-10 23:13:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIWidget::drawBorder(const Rect& screenCoords)
|
|
|
|
{
|
|
|
|
// top
|
2012-04-05 21:08:46 +02:00
|
|
|
if(m_borderWidth.top > 0) {
|
2012-04-19 01:03:43 +02:00
|
|
|
g_painter->setColor(m_borderColor.top);
|
2012-01-10 23:13:40 +01:00
|
|
|
|
|
|
|
Rect borderRect(screenCoords.topLeft(), screenCoords.width(), m_borderWidth.top);
|
2012-04-19 01:03:43 +02:00
|
|
|
g_painter->drawFilledRect(borderRect);
|
2012-01-10 23:13:40 +01:00
|
|
|
}
|
|
|
|
// right
|
2012-04-05 21:08:46 +02:00
|
|
|
if(m_borderWidth.right > 0) {
|
2012-04-19 01:03:43 +02:00
|
|
|
g_painter->setColor(m_borderColor.right);
|
2012-01-10 23:13:40 +01:00
|
|
|
|
|
|
|
Rect borderRect(screenCoords.topRight() - Point(m_borderWidth.right - 1, 0), m_borderWidth.right, screenCoords.height());
|
2012-04-19 01:03:43 +02:00
|
|
|
g_painter->drawFilledRect(borderRect);
|
2012-01-10 23:13:40 +01:00
|
|
|
}
|
|
|
|
// bottom
|
2012-04-05 21:08:46 +02:00
|
|
|
if(m_borderWidth.bottom > 0) {
|
2012-04-19 01:03:43 +02:00
|
|
|
g_painter->setColor(m_borderColor.bottom);
|
2012-01-10 23:13:40 +01:00
|
|
|
|
|
|
|
Rect borderRect(screenCoords.bottomLeft() - Point(0, m_borderWidth.bottom - 1), screenCoords.width(), m_borderWidth.bottom);
|
2012-04-19 01:03:43 +02:00
|
|
|
g_painter->drawFilledRect(borderRect);
|
2012-01-10 23:13:40 +01:00
|
|
|
}
|
|
|
|
// left
|
2012-04-05 21:08:46 +02:00
|
|
|
if(m_borderWidth.left > 0) {
|
2012-04-19 01:03:43 +02:00
|
|
|
g_painter->setColor(m_borderColor.left);
|
2012-01-10 23:13:40 +01:00
|
|
|
|
|
|
|
Rect borderRect(screenCoords.topLeft(), m_borderWidth.left, screenCoords.height());
|
2012-04-19 01:03:43 +02:00
|
|
|
g_painter->drawFilledRect(borderRect);
|
2012-01-10 23:13:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIWidget::drawIcon(const Rect& screenCoords)
|
|
|
|
{
|
2012-04-05 21:08:46 +02:00
|
|
|
if(m_icon) {
|
2012-01-10 23:13:40 +01:00
|
|
|
Rect drawRect;
|
|
|
|
if(m_iconRect.isValid()) {
|
|
|
|
drawRect = screenCoords;
|
|
|
|
drawRect.translate(m_iconRect.topLeft());
|
|
|
|
drawRect.resize(m_iconRect.size());
|
|
|
|
} else {
|
2012-07-12 21:16:23 +02:00
|
|
|
drawRect.resize(m_iconClipRect.size());
|
2013-01-08 21:01:47 +01:00
|
|
|
|
|
|
|
if(m_iconAlign == Fw::AlignNone)
|
|
|
|
drawRect.moveCenter(screenCoords.center());
|
|
|
|
else
|
|
|
|
drawRect.alignIn(screenCoords, m_iconAlign);
|
2012-01-10 23:13:40 +01:00
|
|
|
}
|
2013-02-06 21:48:23 +01:00
|
|
|
drawRect.translate(m_iconOffset);
|
2012-04-19 01:03:43 +02:00
|
|
|
g_painter->setColor(m_iconColor);
|
2012-07-12 21:16:23 +02:00
|
|
|
g_painter->drawTexturedRect(drawRect, m_icon, m_iconClipRect);
|
2012-01-10 23:13:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIWidget::setIcon(const std::string& iconFile)
|
|
|
|
{
|
2013-02-06 20:35:59 +01:00
|
|
|
if(iconFile.empty())
|
|
|
|
m_icon = nullptr;
|
|
|
|
else
|
|
|
|
m_icon = g_textures.getTexture(iconFile);
|
2013-01-08 21:01:47 +01:00
|
|
|
if(m_icon && !m_iconClipRect.isValid())
|
2012-07-12 21:16:23 +02:00
|
|
|
m_iconClipRect = Rect(0, 0, m_icon->getSize());
|
2013-02-18 17:16:22 +01:00
|
|
|
}
|