mirror of
https://github.com/edubart/otclient.git
synced 2025-10-20 06:23:26 +02:00
rework on graphics.cpp, implement some GFX with lua
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include <graphics/fontmanager.h>
|
||||
#include <ui/ui.h>
|
||||
#include <net/protocol.h>
|
||||
#include <core/eventdispatcher.h>
|
||||
|
||||
void LuaInterface::registerFunctions()
|
||||
{
|
||||
@@ -21,6 +22,8 @@ void LuaInterface::registerFunctions()
|
||||
g_lua.bindClassMemberField<UIWidget>("width", &UIWidget::getWidth, &UIWidget::setWidth);
|
||||
g_lua.bindClassMemberField<UIWidget>("height", &UIWidget::getHeight, &UIWidget::setHeight);
|
||||
g_lua.bindClassMemberField<UIWidget>("parent", &UIWidget::getParent, &UIWidget::setParent);
|
||||
g_lua.bindClassMemberField<UIWidget>("color", &UIWidget::getColor, &UIWidget::setColor);
|
||||
g_lua.bindClassMemberField<UIWidget>("opacity", &UIWidget::getOpacity, &UIWidget::setOpacity);
|
||||
g_lua.bindClassMemberField<UIWidget>("marginTop", &UIWidget::getMarginTop, &UIWidget::setMarginTop);
|
||||
g_lua.bindClassMemberField<UIWidget>("marginBottom", &UIWidget::getMarginBottom, &UIWidget::setMarginBottom);
|
||||
g_lua.bindClassMemberField<UIWidget>("marginLeft", &UIWidget::getMarginLeft, &UIWidget::setMarginLeft);
|
||||
@@ -57,8 +60,10 @@ void LuaInterface::registerFunctions()
|
||||
|
||||
// global functions
|
||||
g_lua.bindGlobalFunction("importFont", std::bind(&FontManager::importFont, &g_fonts, _1));
|
||||
g_lua.bindGlobalFunction("setDefaultFont", std::bind(&FontManager::setDefaultFont, &g_fonts, _1));
|
||||
g_lua.bindGlobalFunction("importStyles", std::bind(&UIManager::importStyles, &g_ui, _1));
|
||||
g_lua.bindGlobalFunction("setDefaultFont", std::bind(&FontManager::setDefaultFont, &g_fonts, _1));
|
||||
g_lua.bindGlobalFunction("loadUI", std::bind(&UIManager::loadUI, &g_ui, _1));
|
||||
g_lua.bindGlobalFunction("getRootWidget", std::bind(&UIManager::getRootWidget, &g_ui));
|
||||
g_lua.bindGlobalFunction("addEvent", std::bind(&EventDispatcher::addEvent, &g_dispatcher, _1, false));
|
||||
g_lua.bindGlobalFunction("scheduleEvent", std::bind(&EventDispatcher::scheduleEvent, &g_dispatcher, _1, _2));
|
||||
}
|
||||
|
@@ -192,4 +192,34 @@ luavalue_cast(int index, std::function<Ret(Args...)>& o) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// additional casts
|
||||
|
||||
|
||||
inline void push_luavalue(const Color& v) {
|
||||
g_lua.newTable();
|
||||
g_lua.pushInteger(v.r());
|
||||
g_lua.setField("r");
|
||||
g_lua.pushInteger(v.g());
|
||||
g_lua.setField("g");
|
||||
g_lua.pushInteger(v.b());
|
||||
g_lua.setField("b");
|
||||
g_lua.pushInteger(v.a());
|
||||
g_lua.setField("a");
|
||||
}
|
||||
|
||||
inline bool luavalue_cast(int index, Color& o) {
|
||||
if(!g_lua.isTable(index))
|
||||
return false;
|
||||
|
||||
g_lua.getField("r", index);
|
||||
o.setRed(g_lua.popInteger());
|
||||
g_lua.getField("g", index);
|
||||
o.setGreen(g_lua.popInteger());
|
||||
g_lua.getField("b", index);
|
||||
o.setBlue(g_lua.popInteger());
|
||||
g_lua.getField("a", index);
|
||||
o.setAlpha(g_lua.popInteger());
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user