/* * Copyright (c) 2010-2012 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 #include #include #include #include #include #include #include #include #include void Application::registerLuaFunctions() { // conversion globals g_lua.bindGlobalFunction("torect", [](const std::string& v) { return Fw::fromstring(v); }); g_lua.bindGlobalFunction("topoint", [](const std::string& v) { return Fw::fromstring(v); }); g_lua.bindGlobalFunction("tocolor", [](const std::string& v) { return Fw::fromstring(v); }); g_lua.bindGlobalFunction("tosize", [](const std::string& v) { return Fw::fromstring(v); }); g_lua.bindGlobalFunction("recttostring", [](const Rect& v) { return Fw::tostring(v); }); g_lua.bindGlobalFunction("pointtostring", [](const Point& v) { return Fw::tostring(v); }); g_lua.bindGlobalFunction("colortostring", [](const Color& v) { return Fw::tostring(v); }); g_lua.bindGlobalFunction("sizetostring", [](const Size& v) { return Fw::tostring(v); }); // UIWidget g_lua.registerClass(); g_lua.bindClassStaticFunction("create", []{ return UIWidgetPtr(new UIWidget); } ); g_lua.bindClassMemberFunction("destroy", &UIWidget::destroy); g_lua.bindClassMemberFunction("setVisible", &UIWidget::setVisible); g_lua.bindClassMemberFunction("setEnabled", &UIWidget::setEnabled); g_lua.bindClassMemberFunction("setChecked", &UICheckBox::setChecked); g_lua.bindClassMemberFunction("setOn", &UICheckBox::setOn); g_lua.bindClassMemberFunction("setPressed", &UIWidget::setPressed); g_lua.bindClassMemberFunction("setId", &UIWidget::setId); g_lua.bindClassMemberFunction("setFocusable", &UIWidget::setFocusable); g_lua.bindClassMemberFunction("setPhantom", &UIWidget::setPhantom); g_lua.bindClassMemberFunction("setStyle", &UIWidget::setStyle); g_lua.bindClassMemberFunction("setStyleFromNode", &UIWidget::setStyleFromNode); g_lua.bindClassMemberFunction("setLayout", &UIWidget::setLayout); g_lua.bindClassMemberFunction("setParent", &UIWidget::setParent); g_lua.bindClassMemberFunction("setRect", &UIWidget::setRect); g_lua.bindClassMemberFunction("setX", &UIWidget::setX); g_lua.bindClassMemberFunction("setY", &UIWidget::setY); g_lua.bindClassMemberFunction("setWidth", &UIWidget::setWidth); g_lua.bindClassMemberFunction("setHeight", &UIWidget::setHeight); g_lua.bindClassMemberFunction("setIcon", &UIWidget::setIcon); g_lua.bindClassMemberFunction("setOpacity", &UIWidget::setOpacity); g_lua.bindClassMemberFunction("setBackgroundColor", &UIWidget::setBackgroundColor); g_lua.bindClassMemberFunction("setForegroundColor", &UIWidget::setForegroundColor); g_lua.bindClassMemberFunction("setMarginTop", &UIWidget::setMarginTop); g_lua.bindClassMemberFunction("setMarginRight", &UIWidget::setMarginRight); g_lua.bindClassMemberFunction("setMarginBottom", &UIWidget::setMarginBottom); g_lua.bindClassMemberFunction("setMarginLeft", &UIWidget::setMarginLeft); g_lua.bindClassMemberFunction("setText", &UIWidget::setText); g_lua.bindClassMemberFunction("setTextAlign", &UIWidget::setTextAlign); g_lua.bindClassMemberFunction("setTextOffset", &UIWidget::setTextOffset); g_lua.bindClassMemberFunction("setFont", &UIWidget::setFont); g_lua.bindClassMemberFunction("setSizeFixed", &UIWidget::setSizeFixed); g_lua.bindClassMemberFunction("setLastFocusReason", &UIWidget::setLastFocusReason); g_lua.bindClassMemberFunction("bindRectToParent", &UIWidget::bindRectToParent); g_lua.bindClassMemberFunction("resize", &UIWidget::resize); g_lua.bindClassMemberFunction("resizeToText", &UIWidget::resizeToText); g_lua.bindClassMemberFunction("moveTo", &UIWidget::moveTo); g_lua.bindClassMemberFunction("hide", &UIWidget::hide); g_lua.bindClassMemberFunction("show", &UIWidget::show); g_lua.bindClassMemberFunction("disable", &UIWidget::disable); g_lua.bindClassMemberFunction("enable", &UIWidget::enable); g_lua.bindClassMemberFunction("lock", &UIWidget::lock); g_lua.bindClassMemberFunction("unlock", &UIWidget::unlock); g_lua.bindClassMemberFunction("focus", &UIWidget::focus); g_lua.bindClassMemberFunction("grabMouse", &UIWidget::grabMouse); g_lua.bindClassMemberFunction("ungrabMouse", &UIWidget::ungrabMouse); g_lua.bindClassMemberFunction("grabKeyboard", &UIWidget::grabKeyboard); g_lua.bindClassMemberFunction("ungrabKeyboard", &UIWidget::ungrabKeyboard); g_lua.bindClassMemberFunction("clearText", &UIWidget::clearText); g_lua.bindClassMemberFunction("isActive", &UIWidget::isActive); g_lua.bindClassMemberFunction("isEnabled", &UIWidget::isEnabled); g_lua.bindClassMemberFunction("isDisabled", &UIWidget::isDisabled); g_lua.bindClassMemberFunction("isFocused", &UIWidget::isFocused); g_lua.bindClassMemberFunction("isHovered", &UIWidget::isHovered); g_lua.bindClassMemberFunction("isPressed", &UIWidget::isPressed); g_lua.bindClassMemberFunction("isFirst", &UIWidget::isFirst); g_lua.bindClassMemberFunction("isMiddle", &UIWidget::isMiddle); g_lua.bindClassMemberFunction("isLast", &UIWidget::isLast); g_lua.bindClassMemberFunction("isAlternate", &UIWidget::isAlternate); g_lua.bindClassMemberFunction("isVisible", &UIWidget::isVisible); g_lua.bindClassMemberFunction("isOn", &UICheckBox::isOn); g_lua.bindClassMemberFunction("isChecked", &UICheckBox::isChecked); g_lua.bindClassMemberFunction("isHidden", &UIWidget::isHidden); g_lua.bindClassMemberFunction("isExplicitlyEnabled", &UIWidget::isExplicitlyEnabled); g_lua.bindClassMemberFunction("isExplicitlyVisible", &UIWidget::isExplicitlyVisible); g_lua.bindClassMemberFunction("isFocusable", &UIWidget::isFocusable); g_lua.bindClassMemberFunction("isPhantom", &UIWidget::isPhantom); g_lua.bindClassMemberFunction("isSizeFixed", &UIWidget::isSizeFixed); g_lua.bindClassMemberFunction("containsPoint", &UIWidget::containsPoint); g_lua.bindClassMemberFunction("hasChildren", &UIWidget::hasChildren); g_lua.bindClassMemberFunction("hasChild", &UIWidget::hasChild); g_lua.bindClassMemberFunction("getId", &UIWidget::getId); g_lua.bindClassMemberFunction("getChildCount", &UIWidget::getChildCount); g_lua.bindClassMemberFunction("getLayout", &UIWidget::getLayout); g_lua.bindClassMemberFunction("getParent", &UIWidget::getParent); g_lua.bindClassMemberFunction("getRootParent", &UIWidget::getRootParent); g_lua.bindClassMemberFunction("getPos", &UIWidget::getPos); g_lua.bindClassMemberFunction("getSize", &UIWidget::getSize); g_lua.bindClassMemberFunction("getRect", &UIWidget::getRect); g_lua.bindClassMemberFunction("getX", &UIWidget::getX); g_lua.bindClassMemberFunction("getY", &UIWidget::getY); g_lua.bindClassMemberFunction("getWidth", &UIWidget::getWidth); g_lua.bindClassMemberFunction("getHeight", &UIWidget::getHeight); g_lua.bindClassMemberFunction("getForegroundColor", &UIWidget::getForegroundColor); g_lua.bindClassMemberFunction("getBackgroundColor", &UIWidget::getBackgroundColor); g_lua.bindClassMemberFunction("getOpacity", &UIWidget::getOpacity); g_lua.bindClassMemberFunction("getMarginTop", &UIWidget::getMarginTop); g_lua.bindClassMemberFunction("getMarginRight", &UIWidget::getMarginRight); g_lua.bindClassMemberFunction("getMarginBottom", &UIWidget::getMarginBottom); g_lua.bindClassMemberFunction("getMarginLeft", &UIWidget::getMarginLeft); g_lua.bindClassMemberFunction("getText", &UIWidget::getText); g_lua.bindClassMemberFunction("getTextAlign", &UIWidget::getTextAlign); g_lua.bindClassMemberFunction("getTextOffset", &UIWidget::getTextOffset); g_lua.bindClassMemberFunction("getFont", &UIWidget::getFont); g_lua.bindClassMemberFunction("getTextSize", &UIWidget::getTextSize); g_lua.bindClassMemberFunction("getLastFocusReason", &UIWidget::getLastFocusReason); g_lua.bindClassMemberFunction("getStyle", &UIWidget::getStyle); g_lua.bindClassMemberFunction("getStyleName", &UIWidget::getStyleName); g_lua.bindClassMemberFunction("getChildren", &UIWidget::getChildren); g_lua.bindClassMemberFunction("getFocusedChild", &UIWidget::getFocusedChild); g_lua.bindClassMemberFunction("getChildAfter", &UIWidget::getChildAfter); g_lua.bindClassMemberFunction("getChildBefore", &UIWidget::getChildBefore); g_lua.bindClassMemberFunction("getChildById", &UIWidget::getChildById); g_lua.bindClassMemberFunction("getChildByPos", &UIWidget::getChildByPos); g_lua.bindClassMemberFunction("getChildByIndex", &UIWidget::getChildByIndex); g_lua.bindClassMemberFunction("getFirstChild", &UIWidget::getFirstChild); g_lua.bindClassMemberFunction("getLastChild", &UIWidget::getLastChild); g_lua.bindClassMemberFunction("recursiveGetChildById", &UIWidget::recursiveGetChildById); g_lua.bindClassMemberFunction("recursiveGetChildByPos", &UIWidget::recursiveGetChildByPos); g_lua.bindClassMemberFunction("backwardsGetWidgetById", &UIWidget::backwardsGetWidgetById); g_lua.bindClassMemberFunction("addChild", &UIWidget::addChild); g_lua.bindClassMemberFunction("insertChild", &UIWidget::insertChild); g_lua.bindClassMemberFunction("removeChild", &UIWidget::removeChild); g_lua.bindClassMemberFunction("focusChild", &UIWidget::focusChild); g_lua.bindClassMemberFunction("focusNextChild", &UIWidget::focusNextChild); g_lua.bindClassMemberFunction("focusPreviousChild", &UIWidget::focusPreviousChild); g_lua.bindClassMemberFunction("moveChildToTop", &UIWidget::moveChildToTop); g_lua.bindClassMemberFunction("moveChildToIndex", &UIWidget::moveChildToIndex); g_lua.bindClassMemberFunction("lockChild", &UIWidget::lockChild); g_lua.bindClassMemberFunction("unlockChild", &UIWidget::unlockChild); g_lua.bindClassMemberFunction("isChildLocked", &UIWidget::isChildLocked); g_lua.bindClassMemberFunction("getChildIndex", &UIWidget::getChildIndex); g_lua.bindClassMemberFunction("updateParentLayout", &UIWidget::updateParentLayout); g_lua.bindClassMemberFunction("updateLayout", &UIWidget::updateLayout); g_lua.bindClassMemberFunction("applyStyle", &UIWidget::applyStyle); // UILayout g_lua.registerClass(); g_lua.bindClassMemberFunction("applyStyle", &UILayout::applyStyle); g_lua.bindClassMemberFunction("update", &UILayout::update); g_lua.bindClassMemberFunction("addWidget", &UILayout::addWidget); g_lua.bindClassMemberFunction("removeWidget", &UILayout::removeWidget); g_lua.bindClassMemberFunction("getParentWidget", &UILayout::getParentWidget); // UIVerticalLayout g_lua.registerClass(); g_lua.bindClassStaticFunction("create", [](UIWidgetPtr parent){ return UIVerticalLayoutPtr(new UIVerticalLayout(parent)); } ); g_lua.bindClassMemberFunction("setFitParent", &UIVerticalLayout::setFitParent); // UIAnchorLayout g_lua.registerClass(); g_lua.bindClassStaticFunction("create", [](UIWidgetPtr parent){ return UIAnchorLayoutPtr(new UIAnchorLayout(parent)); } ); g_lua.bindClassMemberFunction("removeAnchors", &UIAnchorLayout::removeAnchors); g_lua.bindClassMemberFunction("centerIn", &UIAnchorLayout::centerIn); g_lua.bindClassMemberFunction("fill", &UIAnchorLayout::fill); // UIProgressBar g_lua.registerClass(); g_lua.bindClassStaticFunction("create", []{ return UIProgressBarPtr(new UIProgressBar); } ); g_lua.bindClassMemberFunction("getPercent", &UIProgressBar::getPercent); g_lua.bindClassMemberFunction("setPercent", &UIProgressBar::setPercent); // UILineEdit g_lua.registerClass(); g_lua.bindClassStaticFunction("create", []{ return UILineEditPtr(new UILineEdit); } ); g_lua.bindClassMemberFunction("setTextHorizontalMargin", &UILineEdit::setTextHorizontalMargin); g_lua.bindClassMemberFunction("setCursorPos", &UILineEdit::setCursorPos); g_lua.bindClassMemberFunction("setCursorEnabled", &UILineEdit::setCursorEnabled); g_lua.bindClassMemberFunction("setTextHidden", &UILineEdit::setTextHidden); g_lua.bindClassMemberFunction("setAlwaysActive", &UILineEdit::setAlwaysActive); g_lua.bindClassMemberFunction("moveCursor", &UILineEdit::moveCursor); g_lua.bindClassMemberFunction("appendText", &UILineEdit::appendText); g_lua.bindClassMemberFunction("removeCharacter", &UILineEdit::removeCharacter); g_lua.bindClassMemberFunction("getDisplayedText", &UILineEdit::getDisplayedText); g_lua.bindClassMemberFunction("getTextPos", &UILineEdit::getTextPos); g_lua.bindClassMemberFunction("getTextHorizontalMargin", &UILineEdit::getTextHorizontalMargin); g_lua.bindClassMemberFunction("getCursorPos", &UILineEdit::getCursorPos); g_lua.bindClassMemberFunction("isCursorEnabled", &UILineEdit::isCursorEnabled); g_lua.bindClassMemberFunction("isAlwaysActive", &UILineEdit::isAlwaysActive); g_lua.bindClassMemberFunction("isTextHidden", &UILineEdit::isTextHidden); // UICheckBox g_lua.registerClass(); g_lua.bindClassStaticFunction("create", []{ return UICheckBoxPtr(new UICheckBox); } ); // UIWindow g_lua.registerClass(); g_lua.bindClassStaticFunction("create", []{ return UIWindowPtr(new UIWindow); } ); g_lua.bindClassMemberFunction("getTitle", &UIWindow::getTitle); g_lua.bindClassMemberFunction("setTitle", &UIWindow::setTitle); // UIFrameCounter g_lua.registerClass(); g_lua.bindClassStaticFunction("create", []{ return UIFrameCounterPtr(new UIFrameCounter); } ); g_lua.bindClassMemberFunction("getFrameCount", &UIFrameCounter::getFrameCount); // Protocol g_lua.registerClass(); // Application g_lua.registerStaticClass("g_app"); g_lua.bindClassStaticFunction("g_app", "exit", std::bind(&Application::exit, g_app)); // ConfigManager g_lua.registerStaticClass("g_configs"); g_lua.bindClassStaticFunction("g_configs", "set", std::bind(&ConfigManager::set, &g_configs, _1, _2)); g_lua.bindClassStaticFunction("g_configs", "get", std::bind(&ConfigManager::get, &g_configs, _1)); g_lua.bindClassStaticFunction("g_configs", "exists", std::bind(&ConfigManager::exists, &g_configs, _1)); g_lua.bindClassStaticFunction("g_configs", "remove", std::bind(&ConfigManager::remove, &g_configs, _1)); // PlatformWindow g_lua.registerStaticClass("g_window"); g_lua.bindClassStaticFunction("g_window", "move", std::bind(&PlatformWindow::move, &g_window, _1)); g_lua.bindClassStaticFunction("g_window", "resize", std::bind(&PlatformWindow::resize, &g_window, _1)); g_lua.bindClassStaticFunction("g_window", "show", std::bind(&PlatformWindow::show, &g_window)); g_lua.bindClassStaticFunction("g_window", "hide", std::bind(&PlatformWindow::hide, &g_window)); g_lua.bindClassStaticFunction("g_window", "maximize", std::bind(&PlatformWindow::maximize, &g_window)); g_lua.bindClassStaticFunction("g_window", "showMouse", std::bind(&PlatformWindow::showMouse, &g_window)); g_lua.bindClassStaticFunction("g_window", "hideMouse", std::bind(&PlatformWindow::hideMouse, &g_window)); g_lua.bindClassStaticFunction("g_window", "setTitle", std::bind(&PlatformWindow::setTitle, &g_window, _1)); g_lua.bindClassStaticFunction("g_window", "setMinimumSize", std::bind(&PlatformWindow::setMinimumSize, &g_window, _1)); g_lua.bindClassStaticFunction("g_window", "setFullscreen", std::bind(&PlatformWindow::setFullscreen, &g_window, _1)); g_lua.bindClassStaticFunction("g_window", "setVerticalSync", std::bind(&PlatformWindow::setVerticalSync, &g_window, _1)); g_lua.bindClassStaticFunction("g_window", "setIcon", std::bind(&PlatformWindow::setIcon, &g_window, _1)); g_lua.bindClassStaticFunction("g_window", "setClipboardText", std::bind(&PlatformWindow::setClipboardText, &g_window, _1)); g_lua.bindClassStaticFunction("g_window", "getDisplaySize", std::bind(&PlatformWindow::getDisplaySize, &g_window)); g_lua.bindClassStaticFunction("g_window", "getClipboardText", std::bind(&PlatformWindow::getClipboardText, &g_window)); g_lua.bindClassStaticFunction("g_window", "getPlatformType", std::bind(&PlatformWindow::getPlatformType, &g_window)); g_lua.bindClassStaticFunction("g_window", "getDisplayWidth", std::bind(&PlatformWindow::getDisplayWidth, &g_window)); g_lua.bindClassStaticFunction("g_window", "getDisplayHeight", std::bind(&PlatformWindow::getDisplayHeight, &g_window)); g_lua.bindClassStaticFunction("g_window", "getUnmaximizedSize", std::bind(&PlatformWindow::getUnmaximizedSize, &g_window)); g_lua.bindClassStaticFunction("g_window", "getSize", std::bind(&PlatformWindow::getSize, &g_window)); g_lua.bindClassStaticFunction("g_window", "getWidth", std::bind(&PlatformWindow::getWidth, &g_window)); g_lua.bindClassStaticFunction("g_window", "getHeight", std::bind(&PlatformWindow::getHeight, &g_window)); g_lua.bindClassStaticFunction("g_window", "getUnmaximizedPos", std::bind(&PlatformWindow::getUnmaximizedPos, &g_window)); g_lua.bindClassStaticFunction("g_window", "getPos", std::bind(&PlatformWindow::getPos, &g_window)); g_lua.bindClassStaticFunction("g_window", "getX", std::bind(&PlatformWindow::getX, &g_window)); g_lua.bindClassStaticFunction("g_window", "getY", std::bind(&PlatformWindow::getY, &g_window)); g_lua.bindClassStaticFunction("g_window", "getMousePos", std::bind(&PlatformWindow::getMousePos, &g_window)); g_lua.bindClassStaticFunction("g_window", "getKeyboardModifiers", std::bind(&PlatformWindow::getKeyboardModifiers, &g_window)); g_lua.bindClassStaticFunction("g_window", "isVisible", std::bind(&PlatformWindow::isVisible, &g_window)); g_lua.bindClassStaticFunction("g_window", "isFullscreen", std::bind(&PlatformWindow::isFullscreen, &g_window)); g_lua.bindClassStaticFunction("g_window", "isMaximized", std::bind(&PlatformWindow::isMaximized, &g_window)); g_lua.bindClassStaticFunction("g_window", "hasFocus", std::bind(&PlatformWindow::hasFocus, &g_window)); // Logger g_lua.registerClass(); g_lua.bindClassStaticFunction("log", std::bind(&Logger::log, &g_logger, _1, _2)); g_lua.bindClassStaticFunction("fireOldMessages", std::bind(&Logger::fireOldMessages, &g_logger)); g_lua.bindClassStaticFunction("setOnLog", std::bind(&Logger::setOnLog, &g_logger, _1)); // UI g_lua.registerStaticClass("g_ui"); g_lua.bindClassStaticFunction("g_ui", "importStyle", std::bind(&UIManager::importStyle, &g_ui, _1)); g_lua.bindClassStaticFunction("g_ui", "getStyle", std::bind(&UIManager::getStyle, &g_ui, _1)); g_lua.bindClassStaticFunction("g_ui", "getStyleClass", std::bind(&UIManager::getStyleClass, &g_ui, _1)); g_lua.bindClassStaticFunction("g_ui", "loadUI", std::bind(&UIManager::loadUI, &g_ui, _1, _2)); g_lua.bindClassStaticFunction("g_ui", "getRootWidget", std::bind(&UIManager::getRootWidget, &g_ui)); // FontManager g_lua.registerStaticClass("g_fonts"); g_lua.bindClassStaticFunction("g_fonts", "importFont", std::bind(&FontManager::importFont, &g_fonts, _1)); g_lua.bindClassStaticFunction("g_fonts", "fontExists", std::bind(&FontManager::fontExists, &g_fonts, _1)); g_lua.bindClassStaticFunction("g_fonts", "setDefaultFont", std::bind(&FontManager::setDefaultFont, &g_fonts, _1)); // EventDispatcher g_lua.registerStaticClass("g_dispatcher"); g_lua.bindClassStaticFunction("g_dispatcher", "addEvent", std::bind(&EventDispatcher::addEvent, &g_dispatcher, _1, _2)); g_lua.bindClassStaticFunction("g_dispatcher", "scheduleEvent", std::bind(&EventDispatcher::scheduleEvent, &g_dispatcher, _1, _2)); }