mirror of
https://github.com/edubart/otclient.git
synced 2025-10-15 03:54:54 +02:00
new widget, UICheckBox
This commit is contained in:
@@ -246,12 +246,16 @@ namespace Fw
|
||||
};
|
||||
|
||||
enum WidgetState {
|
||||
InvalidState = -1,
|
||||
DefaultState = 0,
|
||||
ActiveState = 1,
|
||||
FocusState = 2,
|
||||
HoverState = 4,
|
||||
PressedState = 8,
|
||||
DisabledState = 16
|
||||
DisabledState = 16,
|
||||
CheckedState = 32,
|
||||
OnState = 64,
|
||||
LastState = 128
|
||||
//FirstState,
|
||||
//MiddleState,
|
||||
//LastState,
|
||||
|
@@ -44,7 +44,6 @@ void ResourceManager::init(const char* argv0, const char *appName)
|
||||
|
||||
bool found = false;
|
||||
for(const std::string& dir : possibleDirs) {
|
||||
dump << dir;
|
||||
if(g_resources.addToSearchPath(dir)) {
|
||||
logInfo("Using modules directory '", dir.c_str(), "'");
|
||||
found = true;
|
||||
|
@@ -64,7 +64,6 @@
|
||||
// additional utilities
|
||||
#include "util/types.h"
|
||||
#include "util/tools.h"
|
||||
#include "util/translator.h"
|
||||
#include "util/point.h"
|
||||
#include "util/color.h"
|
||||
#include "util/rect.h"
|
||||
|
@@ -129,6 +129,10 @@ void LuaInterface::registerFunctions()
|
||||
g_lua.bindClassMemberFunction<UILineEdit>("clearText", &UILineEdit::clearText);
|
||||
g_lua.bindClassMemberFunction<UILineEdit>("getCursorPos", &UILineEdit::getCursorPos);
|
||||
|
||||
// UICheckBox
|
||||
g_lua.registerClass<UICheckBox, UIWidget>();
|
||||
g_lua.bindClassStaticFunction<UICheckBox>("create", &UIWidget::create<UICheckBox>);
|
||||
|
||||
// UIWindow
|
||||
g_lua.registerClass<UIWindow, UIWidget>();
|
||||
g_lua.bindClassStaticFunction<UIWindow>("create", &UIWidget::create<UIWindow>);
|
||||
|
@@ -24,15 +24,16 @@
|
||||
#define FRAMEWORK_UI_DECLARATIONS_H
|
||||
|
||||
#include <framework/global.h>
|
||||
#include <framework/platform/platformevent.h>
|
||||
|
||||
class UIManager;
|
||||
class UIWidget;
|
||||
class UILabel;
|
||||
class UIButton;
|
||||
class UILineEdit;
|
||||
class UIWindow;
|
||||
class UICheckBox;
|
||||
class UIProgressBar;
|
||||
class UIFrameCounter;
|
||||
class UIWindow;
|
||||
class UILayout;
|
||||
class UIVerticalLayout;
|
||||
class UIAnchorLayout;
|
||||
@@ -43,8 +44,10 @@ typedef std::weak_ptr<UIWidget> UIWidgetWeakPtr;
|
||||
typedef std::shared_ptr<UILabel> UILabelPtr;
|
||||
typedef std::shared_ptr<UIButton> UIButtonPtr;
|
||||
typedef std::shared_ptr<UILineEdit> UILineEditPtr;
|
||||
typedef std::shared_ptr<UICheckBox> UICheckBoxPtr;
|
||||
typedef std::shared_ptr<UIProgressBar> UIProgressBarPtr;
|
||||
typedef std::shared_ptr<UIFrameCounter> UIFrameCounterPtr;
|
||||
typedef std::shared_ptr<UIWindow> UIWindowPtr;
|
||||
typedef std::shared_ptr<UIWindow> UIFrameCounterPtr;
|
||||
typedef std::shared_ptr<UILayout> UILayoutPtr;
|
||||
typedef std::shared_ptr<UIVerticalLayout> UIVerticalLayoutPtr;
|
||||
typedef std::shared_ptr<UIAnchorLayout> UIAnchorLayoutPtr;
|
||||
|
@@ -31,5 +31,6 @@
|
||||
#include "uiwindow.h"
|
||||
#include "uiframecounter.h"
|
||||
#include "uiprogressbar.h"
|
||||
#include "uicheckbox.h"
|
||||
|
||||
#endif
|
||||
|
@@ -40,7 +40,7 @@ void UIButton::render()
|
||||
{
|
||||
UIWidget::render();
|
||||
Rect textRect = m_rect;
|
||||
textRect.translate(m_textTranslate);
|
||||
textRect.translate(m_textOffset);
|
||||
m_font->renderText(m_text, textRect, Fw::AlignCenter, m_foregroundColor);
|
||||
}
|
||||
|
||||
@@ -49,8 +49,8 @@ void UIButton::onStyleApply(const OTMLNodePtr& styleNode)
|
||||
UIWidget::onStyleApply(styleNode);
|
||||
|
||||
for(OTMLNodePtr node : styleNode->children()) {
|
||||
if(node->tag() == "text-translate") {
|
||||
m_textTranslate = node->value<Point>();
|
||||
if(node->tag() == "text-offset") {
|
||||
m_textOffset = node->value<Point>();
|
||||
} else if(node->tag() == "text") {
|
||||
m_text = node->value();
|
||||
}
|
||||
|
@@ -44,7 +44,7 @@ protected:
|
||||
virtual void onMouseRelease(const Point& mousePos, Fw::MouseButton button);
|
||||
|
||||
SimpleCallback m_onClick;
|
||||
Point m_textTranslate;
|
||||
Point m_textOffset;
|
||||
std::string m_text;
|
||||
};
|
||||
|
||||
|
66
src/framework/ui/uicheckbox.cpp
Normal file
66
src/framework/ui/uicheckbox.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "uicheckbox.h"
|
||||
#include <framework/otml/otmlnode.h>
|
||||
#include <framework/graphics/image.h>
|
||||
#include <framework/graphics/font.h>
|
||||
#include <framework/graphics/graphics.h>
|
||||
#include <framework/core/eventdispatcher.h>
|
||||
|
||||
void UICheckBox::render()
|
||||
{
|
||||
Rect boxRect;
|
||||
boxRect.setSize(m_boxSize);
|
||||
boxRect.moveLeft(m_rect.left());
|
||||
boxRect.moveVerticalCenter(m_rect.verticalCenter());
|
||||
g_graphics.bindColor(m_backgroundColor);
|
||||
m_image->draw(boxRect);
|
||||
|
||||
Rect textRect(m_rect);
|
||||
textRect.setTopLeft(textRect.topLeft() + m_textOffset);
|
||||
m_font->renderText(m_text, textRect, Fw::AlignLeft, m_foregroundColor);
|
||||
}
|
||||
|
||||
void UICheckBox::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
|
||||
{
|
||||
if(isPressed() && getRect().contains(mousePos))
|
||||
setState(Fw::CheckedState, !isChecked());
|
||||
}
|
||||
|
||||
void UICheckBox::onStyleApply(const OTMLNodePtr& styleNode)
|
||||
{
|
||||
UIWidget::onStyleApply(styleNode);
|
||||
|
||||
for(OTMLNodePtr node : styleNode->children()) {
|
||||
if(node->tag() == "text-offset")
|
||||
m_textOffset = node->value<Point>();
|
||||
else if(node->tag() == "text")
|
||||
m_text = node->value();
|
||||
else if(node->tag() == "box-size")
|
||||
m_boxSize = node->value<Size>();
|
||||
else if(node->tag() == "checked") {
|
||||
// must be scheduled because setChecked can change the style again
|
||||
g_dispatcher.addEvent(std::bind(&UICheckBox::setChecked, asUICheckBox(), node->value<bool>()));
|
||||
}
|
||||
}
|
||||
}
|
50
src/framework/ui/uicheckbox.h
Normal file
50
src/framework/ui/uicheckbox.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef UICHECKBOX_H
|
||||
#define UICHECKBOX_H
|
||||
|
||||
#include "uiwidget.h"
|
||||
|
||||
class UICheckBox : public UIWidget
|
||||
{
|
||||
public:
|
||||
void render();
|
||||
|
||||
bool isChecked() { return hasState(Fw::CheckedState); }
|
||||
void setChecked(bool checked) { setState(Fw::CheckedState, checked); }
|
||||
|
||||
void setText(const std::string& text) { m_text = text; }
|
||||
std::string getText() { return m_text; }
|
||||
|
||||
UICheckBoxPtr asUICheckBox() { return std::static_pointer_cast<UICheckBox>(shared_from_this()); }
|
||||
|
||||
protected:
|
||||
virtual void onStyleApply(const OTMLNodePtr& styleNode);
|
||||
virtual void onMouseRelease(const Point& mousePos, Fw::MouseButton button);
|
||||
|
||||
std::string m_text;
|
||||
Size m_boxSize;
|
||||
Point m_textOffset;
|
||||
};
|
||||
|
||||
#endif
|
@@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "uiframecounter.h"
|
||||
#include "uitranslator.h"
|
||||
#include <framework/graphics/font.h>
|
||||
#include <framework/otml/otmlnode.h>
|
||||
#include <framework/platform/platform.h>
|
||||
|
@@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "uilabel.h"
|
||||
#include "uitranslator.h"
|
||||
#include <framework/graphics/font.h>
|
||||
#include <framework/otml/otmlnode.h>
|
||||
|
||||
|
90
src/framework/ui/uitranslator.cpp
Normal file
90
src/framework/ui/uitranslator.cpp
Normal file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "uitranslator.h"
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
Fw::AlignmentFlag Fw::translateAlignment(std::string aligment)
|
||||
{
|
||||
boost::to_lower(aligment);
|
||||
boost::erase_all(aligment, " ");
|
||||
if(aligment == "topleft")
|
||||
return Fw::AlignTopLeft;
|
||||
else if(aligment == "topright")
|
||||
return Fw::AlignTopRight;
|
||||
else if(aligment == "bottomleft")
|
||||
return Fw::AlignBottomLeft;
|
||||
else if(aligment == "bottomright")
|
||||
return Fw::AlignBottomRight;
|
||||
else if(aligment == "left")
|
||||
return Fw::AlignLeftCenter;
|
||||
else if(aligment == "right")
|
||||
return Fw::AlignRightCenter;
|
||||
else if(aligment == "top")
|
||||
return Fw::AlignTopCenter;
|
||||
else if(aligment == "bottom")
|
||||
return Fw::AlignBottomCenter;
|
||||
else if(aligment == "center")
|
||||
return Fw::AlignCenter;
|
||||
return Fw::AlignNone;
|
||||
}
|
||||
|
||||
Fw::AnchorEdge Fw::translateAnchorEdge(std::string anchorEdge)
|
||||
{
|
||||
boost::to_lower(anchorEdge);
|
||||
boost::erase_all(anchorEdge, " ");
|
||||
if(anchorEdge == "left")
|
||||
return Fw::AnchorLeft;
|
||||
else if(anchorEdge == "right")
|
||||
return Fw::AnchorRight;
|
||||
else if(anchorEdge == "top")
|
||||
return Fw::AnchorTop;
|
||||
else if(anchorEdge == "bottom")
|
||||
return Fw::AnchorBottom;
|
||||
else if(anchorEdge == "horizontalcenter")
|
||||
return Fw::AnchorHorizontalCenter;
|
||||
else if(anchorEdge == "verticalcenter")
|
||||
return Fw::AnchorVerticalCenter;
|
||||
return Fw::AnchorNone;
|
||||
}
|
||||
|
||||
Fw::WidgetState Fw::translateState(std::string state)
|
||||
{
|
||||
boost::to_lower(state);
|
||||
boost::erase_all(state, " ");
|
||||
if(state == "active")
|
||||
return Fw::ActiveState;
|
||||
else if(state == "focus")
|
||||
return Fw::FocusState;
|
||||
else if(state == "hover")
|
||||
return Fw::HoverState;
|
||||
else if(state == "pressed")
|
||||
return Fw::PressedState;
|
||||
else if(state == "checked")
|
||||
return Fw::CheckedState;
|
||||
else if(state == "disabled")
|
||||
return Fw::DisabledState;
|
||||
else if(state == "on")
|
||||
return Fw::OnState;
|
||||
else
|
||||
return Fw::InvalidState;
|
||||
}
|
37
src/framework/ui/uitranslator.h
Normal file
37
src/framework/ui/uitranslator.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef TRANSLATOR_H
|
||||
#define TRANSLATOR_H
|
||||
|
||||
#include "../const.h"
|
||||
#include <string>
|
||||
|
||||
namespace Fw {
|
||||
|
||||
AlignmentFlag translateAlignment(std::string aligment);
|
||||
AnchorEdge translateAnchorEdge(std::string anchorEdge);
|
||||
WidgetState translateState(std::string state);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
@@ -24,6 +24,7 @@
|
||||
#include "uimanager.h"
|
||||
#include "uianchorlayout.h"
|
||||
#include "uiverticallayout.h"
|
||||
#include "uitranslator.h"
|
||||
|
||||
#include <framework/core/eventdispatcher.h>
|
||||
#include <framework/graphics/image.h>
|
||||
@@ -36,6 +37,7 @@
|
||||
UIWidget::UIWidget()
|
||||
{
|
||||
m_updateEventScheduled = false;
|
||||
m_firstOnStyle = true;
|
||||
m_states = Fw::DefaultState;
|
||||
|
||||
// generate an unique id, this is need because anchored layouts find widgets by id
|
||||
@@ -611,6 +613,28 @@ void UIWidget::updateLayout()
|
||||
m_layout->update();
|
||||
}
|
||||
|
||||
void UIWidget::setState(Fw::WidgetState state, bool on)
|
||||
{
|
||||
if(state == Fw::InvalidState)
|
||||
return;
|
||||
|
||||
int oldStates = m_states;
|
||||
if(on)
|
||||
m_states |= state;
|
||||
else
|
||||
m_states &= ~state;
|
||||
|
||||
if(oldStates != m_states)
|
||||
updateStyle();
|
||||
}
|
||||
|
||||
bool UIWidget::hasState(Fw::WidgetState state)
|
||||
{
|
||||
if(state == Fw::InvalidState)
|
||||
return false;
|
||||
return (m_states & state);
|
||||
}
|
||||
|
||||
void UIWidget::updateState(Fw::WidgetState state)
|
||||
{
|
||||
bool newStatus = true;
|
||||
@@ -675,12 +699,7 @@ void UIWidget::updateState(Fw::WidgetState state)
|
||||
}
|
||||
|
||||
if(newStatus != oldStatus) {
|
||||
if(newStatus)
|
||||
m_states |= state;
|
||||
else
|
||||
m_states &= ~state;
|
||||
|
||||
updateStyle();
|
||||
setState(state, newStatus);
|
||||
|
||||
if(state == Fw::FocusState) {
|
||||
g_dispatcher.addEvent(std::bind(&UIWidget::onFocusChange, asUIWidget(), newStatus, m_lastFocusReason));
|
||||
@@ -691,10 +710,8 @@ void UIWidget::updateState(Fw::WidgetState state)
|
||||
|
||||
void UIWidget::updateStates()
|
||||
{
|
||||
updateState(Fw::ActiveState);
|
||||
updateState(Fw::FocusState);
|
||||
updateState(Fw::DisabledState);
|
||||
updateState(Fw::HoverState);
|
||||
for(int state = 1; state != Fw::LastState; state <<= 1)
|
||||
updateState((Fw::WidgetState)state);
|
||||
}
|
||||
|
||||
void UIWidget::updateStyle()
|
||||
@@ -712,26 +729,32 @@ void UIWidget::updateStyle()
|
||||
}
|
||||
}
|
||||
|
||||
// merge states styles, NOTE: order does matter
|
||||
OTMLNodePtr style = m_style->get("state.active");
|
||||
if(style && hasState(Fw::ActiveState))
|
||||
newStateStyle->merge(style);
|
||||
// checks for states combination
|
||||
for(const OTMLNodePtr& style : m_style->children()) {
|
||||
if(boost::starts_with(style->tag(), "$")) {
|
||||
std::string statesStr = style->tag().substr(1);
|
||||
std::vector<std::string> statesSplit;
|
||||
boost::split(statesSplit, statesStr, boost::is_any_of(std::string(" ")));
|
||||
|
||||
style = m_style->get("state.focus");
|
||||
if(style && hasState(Fw::FocusState))
|
||||
newStateStyle->merge(style);
|
||||
bool match = true;
|
||||
for(std::string stateStr : statesSplit) {
|
||||
if(stateStr.length() == 0)
|
||||
continue;
|
||||
|
||||
style = m_style->get("state.hover");
|
||||
if(style && hasState(Fw::HoverState))
|
||||
newStateStyle->merge(style);
|
||||
bool notstate = (stateStr[0] == '!');
|
||||
if(notstate)
|
||||
stateStr = stateStr.substr(1);
|
||||
|
||||
style = m_style->get("state.pressed");
|
||||
if(style && hasState(Fw::PressedState))
|
||||
newStateStyle->merge(style);
|
||||
bool stateOn = hasState(Fw::translateState(stateStr));
|
||||
if((!notstate && !stateOn) || (notstate && stateOn))
|
||||
match = false;
|
||||
}
|
||||
|
||||
style = m_style->get("state.disabled");
|
||||
if(style && hasState(Fw::DisabledState))
|
||||
newStateStyle->merge(style);
|
||||
// merge states styles
|
||||
if(match)
|
||||
newStateStyle->merge(style);
|
||||
}
|
||||
}
|
||||
|
||||
applyStyle(newStateStyle);
|
||||
m_stateStyle = newStateStyle;
|
||||
@@ -886,13 +909,25 @@ void UIWidget::onStyleApply(const OTMLNodePtr& styleNode)
|
||||
|
||||
anchorLayout->addAnchor(asUIWidget(), anchoredEdge, hookedWidgetId, hookedEdge);
|
||||
}
|
||||
} else if(node->tag() == "onClick" ||
|
||||
node->tag() == "onMousePress" ||
|
||||
node->tag() == "onHoverChange") {
|
||||
g_lua.loadFunction(node->value(), "@" + node->source() + "[" + node->tag() + "]");
|
||||
luaSetField(node->tag());
|
||||
// lua functions
|
||||
} else if(boost::starts_with(node->tag(), "@")) {
|
||||
// on 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(boost::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);
|
||||
}
|
||||
}
|
||||
|
||||
m_firstOnStyle = false;
|
||||
}
|
||||
|
||||
void UIWidget::onGeometryUpdate(const Rect& oldRect, const Rect& newRect)
|
||||
|
@@ -80,49 +80,48 @@ public:
|
||||
void unlock();
|
||||
void focus();
|
||||
|
||||
bool isActive() const { return hasState(Fw::ActiveState); }
|
||||
bool isEnabled() const { return !hasState(Fw::DisabledState); }
|
||||
bool isDisabled() const { return hasState(Fw::DisabledState); }
|
||||
bool isFocused() const { return hasState(Fw::FocusState); }
|
||||
bool isHovered() const { return hasState(Fw::HoverState); }
|
||||
bool isPressed() const { return hasState(Fw::PressedState); }
|
||||
bool isActive() { return hasState(Fw::ActiveState); }
|
||||
bool isEnabled() { return !hasState(Fw::DisabledState); }
|
||||
bool isDisabled() { return hasState(Fw::DisabledState); }
|
||||
bool isFocused() { return hasState(Fw::FocusState); }
|
||||
bool isHovered() { return hasState(Fw::HoverState); }
|
||||
bool isPressed() { return hasState(Fw::PressedState); }
|
||||
bool isVisible();
|
||||
bool isHidden() { return !isVisible(); }
|
||||
bool isExplicitlyEnabled() const { return m_enabled; }
|
||||
bool isExplicitlyVisible() const { return m_visible; }
|
||||
bool isFocusable() const { return m_focusable; }
|
||||
bool isPhantom() const { return m_phantom; }
|
||||
bool isSizeFixed() const { return m_fixedSize; }
|
||||
bool hasChildren() const { return m_children.size() > 0; }
|
||||
bool isExplicitlyEnabled() { return m_enabled; }
|
||||
bool isExplicitlyVisible() { return m_visible; }
|
||||
bool isFocusable() { return m_focusable; }
|
||||
bool isPhantom() { return m_phantom; }
|
||||
bool isSizeFixed() { return m_fixedSize; }
|
||||
bool hasChildren() { return m_children.size() > 0; }
|
||||
bool hasChild(const UIWidgetPtr& child);
|
||||
bool hasState(Fw::WidgetState state) const { return m_states & state; }
|
||||
|
||||
std::string getId() const { return m_id; }
|
||||
int getChildCount() const { return m_children.size(); }
|
||||
UILayoutPtr getLayout() const { return m_layout; }
|
||||
UIWidgetPtr getParent() const { return m_parent.lock(); }
|
||||
std::string getId() { return m_id; }
|
||||
int getChildCount() { return m_children.size(); }
|
||||
UILayoutPtr getLayout() { return m_layout; }
|
||||
UIWidgetPtr getParent() { return m_parent.lock(); }
|
||||
UIWidgetPtr getRootParent();
|
||||
Point getPosition() const { return m_rect.topLeft(); }
|
||||
Size getSize() const { return m_rect.size(); }
|
||||
Rect getRect() const { return m_rect; }
|
||||
int getX() const { return m_rect.x(); }
|
||||
int getY() const { return m_rect.y(); }
|
||||
int getWidth() const { return m_rect.width(); }
|
||||
int getHeight() const { return m_rect.height(); }
|
||||
ImagePtr getImage() const { return m_image; }
|
||||
FontPtr getFont() const { return m_font; }
|
||||
Color getForegroundColor() const { return m_foregroundColor; }
|
||||
Color getBackgroundColor() const { return m_backgroundColor; }
|
||||
int getOpacity() const { return m_opacity; }
|
||||
int getMarginLeft() const { return m_marginLeft; }
|
||||
int getMarginRight() const { return m_marginRight; }
|
||||
int getMarginTop() const { return m_marginTop; }
|
||||
int getMarginBottom() const { return m_marginBottom; }
|
||||
Fw::FocusReason getLastFocusReason() const { return m_lastFocusReason; }
|
||||
OTMLNodePtr getStyle() const { return m_style; }
|
||||
Point getPosition() { return m_rect.topLeft(); }
|
||||
Size getSize() { return m_rect.size(); }
|
||||
Rect getRect() { return m_rect; }
|
||||
int getX() { return m_rect.x(); }
|
||||
int getY() { return m_rect.y(); }
|
||||
int getWidth() { return m_rect.width(); }
|
||||
int getHeight() { return m_rect.height(); }
|
||||
ImagePtr getImage() { return m_image; }
|
||||
FontPtr getFont() { return m_font; }
|
||||
Color getForegroundColor() { return m_foregroundColor; }
|
||||
Color getBackgroundColor() { return m_backgroundColor; }
|
||||
int getOpacity() { return m_opacity; }
|
||||
int getMarginLeft() { return m_marginLeft; }
|
||||
int getMarginRight() { return m_marginRight; }
|
||||
int getMarginTop() { return m_marginTop; }
|
||||
int getMarginBottom() { return m_marginBottom; }
|
||||
Fw::FocusReason getLastFocusReason() { return m_lastFocusReason; }
|
||||
OTMLNodePtr getStyle() { return m_style; }
|
||||
|
||||
UIWidgetList getChildren() const { return m_children; }
|
||||
UIWidgetPtr getFocusedChild() const { return m_focusedChild; }
|
||||
UIWidgetList getChildren() { return m_children; }
|
||||
UIWidgetPtr getFocusedChild() { return m_focusedChild; }
|
||||
UIWidgetPtr getChildAfter(const UIWidgetPtr& relativeChild);
|
||||
UIWidgetPtr getChildBefore(const UIWidgetPtr& relativeChild);
|
||||
UIWidgetPtr getChildById(const std::string& childId);
|
||||
@@ -147,16 +146,17 @@ public:
|
||||
|
||||
void updateParentLayout();
|
||||
void updateLayout();
|
||||
virtual void updateState(Fw::WidgetState state);
|
||||
|
||||
void updateStates();
|
||||
virtual void updateStyle();
|
||||
virtual void updateState(Fw::WidgetState state);
|
||||
void setState(Fw::WidgetState state, bool on);
|
||||
bool hasState(Fw::WidgetState state);
|
||||
|
||||
void updateStyle();
|
||||
void applyStyle(const OTMLNodePtr& styleNode);
|
||||
|
||||
UIWidgetPtr asUIWidget() { return std::static_pointer_cast<UIWidget>(shared_from_this()); }
|
||||
|
||||
private:
|
||||
bool m_updateEventScheduled;
|
||||
|
||||
protected:
|
||||
/// Triggered when widget style is changed
|
||||
virtual void onStyleApply(const OTMLNodePtr& styleNode);
|
||||
@@ -190,6 +190,8 @@ protected:
|
||||
bool m_fixedSize;
|
||||
bool m_pressed;
|
||||
bool m_phantom;
|
||||
bool m_updateEventScheduled;
|
||||
bool m_firstOnStyle;
|
||||
Rect m_rect;
|
||||
UILayoutPtr m_layout;
|
||||
UIWidgetWeakPtr m_parent;
|
||||
@@ -198,7 +200,7 @@ protected:
|
||||
UIWidgetPtr m_focusedChild;
|
||||
OTMLNodePtr m_style;
|
||||
OTMLNodePtr m_stateStyle;
|
||||
uint m_states;
|
||||
int m_states;
|
||||
|
||||
// basic style components used by all widgets
|
||||
ImagePtr m_image;
|
||||
|
@@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "uiwindow.h"
|
||||
#include "uitranslator.h"
|
||||
#include <framework/graphics/borderimage.h>
|
||||
#include <framework/graphics/font.h>
|
||||
#include <framework/graphics/graphics.h>
|
||||
|
Reference in New Issue
Block a user