mirror of
https://github.com/edubart/otclient.git
synced 2025-10-15 12:04:55 +02:00
scrollbar, options and widgets changes
* complete scrollbar skin * implement scrollbar functionality (scrolling with mouse) * fix onMouseClick issues * add tabs in options (graphics and general tab) * add new option for limiting frame rate using scrollbar * add new widget property "clipping" that will be used on scrollable areas
This commit is contained in:
@@ -57,6 +57,7 @@ Application::Application(const std::string& appName)
|
||||
g_app = this;
|
||||
m_appName = appName;
|
||||
m_pollCycleDelay = POLL_CYCLE_DELAY;
|
||||
m_frameSleep = 0;
|
||||
}
|
||||
|
||||
Application::~Application()
|
||||
@@ -200,6 +201,9 @@ void Application::run()
|
||||
// sleeps until next poll to avoid massive cpu usage
|
||||
g_clock.sleep(POLL_CYCLE_DELAY+1);
|
||||
}
|
||||
|
||||
if(m_frameSleep > 0)
|
||||
g_clock.sleep(m_frameSleep);
|
||||
}
|
||||
|
||||
m_stopping = false;
|
||||
|
@@ -43,10 +43,13 @@ public:
|
||||
virtual void poll();
|
||||
virtual void close();
|
||||
|
||||
void setFrameSleep(int delay) { m_frameSleep = delay; }
|
||||
void setPollCycleDelay(int delay) { m_pollCycleDelay = delay; }
|
||||
|
||||
bool isRunning() { return m_running; }
|
||||
bool isStopping() { return m_stopping; }
|
||||
int getFrameSleep() { return m_frameSleep; }
|
||||
int getPollCycleDelay() { return m_pollCycleDelay; }
|
||||
const std::string& getName() { return m_appName; }
|
||||
const std::string& getVersion() { return m_appVersion; }
|
||||
|
||||
@@ -64,6 +67,7 @@ protected:
|
||||
std::string m_appVersion;
|
||||
std::string m_appBuildDate;
|
||||
int m_appFlags;
|
||||
int m_frameSleep;
|
||||
int m_pollCycleDelay;
|
||||
Boolean<false> m_initialized;
|
||||
Boolean<false> m_running;
|
||||
|
@@ -104,8 +104,10 @@ void Application::registerLuaFunctions()
|
||||
g_lua.bindClassMemberFunction<UIWidget>("setPhantom", &UIWidget::setPhantom);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("setDragable", &UIWidget::setDragable);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("setFixedSize", &UIWidget::setFixedSize);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("setClipping", &UIWidget::setClipping);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("setLastFocusReason", &UIWidget::setLastFocusReason);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("setAutoRepeatDelay", &UIWidget::setAutoRepeatDelay);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("setVirtualOffset", &UIWidget::setVirtualOffset);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("isVisible", &UIWidget::isVisible);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("isChildLocked", &UIWidget::isChildLocked);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("hasChild", &UIWidget::hasChild);
|
||||
@@ -149,6 +151,7 @@ void Application::registerLuaFunctions()
|
||||
g_lua.bindClassMemberFunction<UIWidget>("isPhantom", &UIWidget::isPhantom);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("isDragable", &UIWidget::isDragable);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("isFixedSize", &UIWidget::isFixedSize);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("isClipping", &UIWidget::isClipping);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("isDestroyed", &UIWidget::isDestroyed);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("hasChildren", &UIWidget::hasChildren);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("containsPoint", &UIWidget::containsPoint);
|
||||
@@ -163,6 +166,7 @@ void Application::registerLuaFunctions()
|
||||
g_lua.bindClassMemberFunction<UIWidget>("getChildCount", &UIWidget::getChildCount);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("getLastFocusReason", &UIWidget::getLastFocusReason);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("getAutoRepeatDelay", &UIWidget::getAutoRepeatDelay);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("getVirtualOffset", &UIWidget::getVirtualOffset);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("getStyleName", &UIWidget::getStyleName);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("setX", &UIWidget::setX);
|
||||
g_lua.bindClassMemberFunction<UIWidget>("setY", &UIWidget::setY);
|
||||
@@ -418,8 +422,12 @@ void Application::registerLuaFunctions()
|
||||
// Application
|
||||
g_lua.registerStaticClass("g_app");
|
||||
g_lua.bindClassStaticFunction("g_app", "exit", std::bind(&Application::exit, g_app));
|
||||
g_lua.bindClassStaticFunction("g_app", "setFrameSleep", std::bind(&Application::setFrameSleep, g_app, _1));
|
||||
g_lua.bindClassStaticFunction("g_app", "setPollCycleDelay", std::bind(&Application::setPollCycleDelay, g_app, _1));
|
||||
g_lua.bindClassStaticFunction("g_app", "isRunning", std::bind(&Application::isRunning, g_app));
|
||||
g_lua.bindClassStaticFunction("g_app", "isStopping", std::bind(&Application::isStopping, g_app));
|
||||
g_lua.bindClassStaticFunction("g_app", "getFrameSleep", std::bind(&Application::getFrameSleep, g_app));
|
||||
g_lua.bindClassStaticFunction("g_app", "getPollCycleDelay", std::bind(&Application::getPollCycleDelay, g_app));
|
||||
g_lua.bindClassStaticFunction("g_app", "getName", std::bind(&Application::getName, g_app));
|
||||
g_lua.bindClassStaticFunction("g_app", "getVersion", std::bind(&Application::getVersion, g_app));
|
||||
g_lua.bindClassStaticFunction("g_app", "getBuildCompiler", std::bind(&Application::getBuildCompiler, g_app));
|
||||
|
@@ -40,6 +40,7 @@ public:
|
||||
template<typename R, typename... T>
|
||||
R callLuaField(const std::string& field, const T&... args);
|
||||
|
||||
/// Returns true if the lua field exists
|
||||
bool hasLuaField(const std::string& field);
|
||||
|
||||
/// Sets a field in this lua object
|
||||
|
@@ -53,20 +53,14 @@ UIWidget::~UIWidget()
|
||||
|
||||
void UIWidget::draw(const Rect& visibleRect)
|
||||
{
|
||||
if(m_clipping)
|
||||
g_graphics.beginClipping(visibleRect);
|
||||
|
||||
drawSelf();
|
||||
if(m_children.size() > 0) {
|
||||
bool clip = true;
|
||||
if(this == g_ui.getRootWidget().get())
|
||||
clip = false;
|
||||
drawChildren(visibleRect);
|
||||
|
||||
if(clip)
|
||||
g_graphics.beginClipping(visibleRect);
|
||||
|
||||
drawChildren(visibleRect);
|
||||
|
||||
if(clip)
|
||||
g_graphics.endClipping();
|
||||
}
|
||||
if(m_clipping)
|
||||
g_graphics.endClipping();
|
||||
}
|
||||
|
||||
void UIWidget::drawSelf()
|
||||
@@ -1325,12 +1319,20 @@ bool UIWidget::onMouseWheel(const Point& mousePos, Fw::MouseWheelDirection direc
|
||||
|
||||
bool UIWidget::onClick(const Point& mousePos)
|
||||
{
|
||||
return callLuaField<bool>("onClick", mousePos);
|
||||
if(hasLuaField("onClick")) {
|
||||
callLuaField("onClick", mousePos);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UIWidget::onDoubleClick(const Point& mousePos)
|
||||
{
|
||||
return callLuaField<bool>("onDoubleClick", mousePos);
|
||||
if(hasLuaField("onDoubleClick")) {
|
||||
callLuaField("onDoubleClick", mousePos);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UIWidget::propagateOnKeyText(const std::string& keyText)
|
||||
|
@@ -41,6 +41,8 @@ struct EdgeGroup {
|
||||
T left;
|
||||
};
|
||||
|
||||
// generate lua bindings for this class running:
|
||||
// ./tools/lua-binding-generator/generate_lua_bindings.lua src/framework/ui/uiwidget.h
|
||||
class UIWidget : public LuaObject
|
||||
{
|
||||
// widget core
|
||||
@@ -65,6 +67,7 @@ protected:
|
||||
Boolean<false> m_phantom;
|
||||
Boolean<false> m_dragable;
|
||||
Boolean<false> m_destroyed;
|
||||
Boolean<false> m_clipping;
|
||||
UILayoutPtr m_layout;
|
||||
UIWidgetWeakPtr m_parent;
|
||||
UIWidgetList m_children;
|
||||
@@ -120,6 +123,7 @@ public:
|
||||
void setPhantom(bool phantom);
|
||||
void setDragable(bool dragable);
|
||||
void setFixedSize(bool fixed);
|
||||
void setClipping(bool clipping) { m_clipping = clipping; }
|
||||
void setLastFocusReason(Fw::FocusReason reason);
|
||||
void setAutoRepeatDelay(int delay) { m_autoRepeatDelay = delay; }
|
||||
void setVirtualOffset(const Point& offset);
|
||||
@@ -226,6 +230,7 @@ public:
|
||||
bool isPhantom() { return m_phantom; }
|
||||
bool isDragable() { return m_dragable; }
|
||||
bool isFixedSize() { return m_fixedSize; }
|
||||
bool isClipping() { return m_clipping; }
|
||||
bool isDestroyed() { return m_destroyed; }
|
||||
|
||||
bool hasChildren() { return m_children.size() > 0; }
|
||||
|
@@ -120,6 +120,8 @@ void UIWidget::parseBaseStyle(const OTMLNodePtr& styleNode)
|
||||
setSize(node->value<Size>());
|
||||
else if(node->tag() == "fixed-size")
|
||||
setFixedSize(node->value<bool>());
|
||||
else if(node->tag() == "clipping")
|
||||
setClipping(node->value<bool>());
|
||||
else if(node->tag() == "border") {
|
||||
auto split = Fw::split(node->value(), " ");
|
||||
if(split.size() == 2) {
|
||||
|
Reference in New Issue
Block a user