Beispiel #1
0
    bool ClickableWidget::setProperty(std::string property, const std::string& value)
    {
        property = toLower(property);

        if (property == "callback")
        {
            Widget::setProperty(property, value);

            std::vector<sf::String> callbacks;
            decodeList(value, callbacks);

            for (auto it = callbacks.begin(); it != callbacks.end(); ++it)
            {
                if ((*it == "LeftMousePressed") || (*it == "leftmousepressed"))
                    bindCallback(LeftMousePressed);
                else if ((*it == "LeftMouseReleased") || (*it == "leftmousereleased"))
                    bindCallback(LeftMouseReleased);
                else if ((*it == "LeftMouseClicked") || (*it == "leftmouseclicked"))
                    bindCallback(LeftMouseClicked);
            }
        }
        else // The property didn't match
            return Widget::setProperty(property, value);

        // You pass here when one of the properties matched
        return true;
    }
Beispiel #2
0
    bool AnimatedPicture::setProperty(std::string property, const std::string& value)
    {
        property = toLower(property);

        if (property == "playing")
        {
            if ((value == "true") || (value == "True"))
                m_Playing = true;
            else if ((value == "false") || (value == "False"))
                m_Playing = false;
            else
                TGUI_OUTPUT("TGUI error: Failed to parse 'Playing' property.");
        }
        else if (property == "looping")
        {
            if ((value == "true") || (value == "True"))
                m_Looping = true;
            else if ((value == "false") || (value == "False"))
                m_Looping = false;
            else
                TGUI_OUTPUT("TGUI error: Failed to parse 'Looping' property.");
        }
        else if (property == "callback")
        {
            ClickableWidget::setProperty(property, value);

            std::vector<sf::String> callbacks;
            decodeList(value, callbacks);

            for (auto it = callbacks.begin(); it != callbacks.end(); ++it)
            {
                if ((*it == "AnimationFinished") || (*it == "animationfinished"))
                    bindCallback(AnimationFinished);
            }
        }
        else // The property didn't match
            return ClickableWidget::setProperty(property, value);

        // You pass here when one of the properties matched
        return true;
    }
Beispiel #3
0
    bool Widget::setProperty(std::string property, const std::string& value)
    {
        property = toLower(property);

        if (property == "left")
        {
            setPosition(static_cast<float>(atof(value.c_str())), getPosition().y);
        }
        else if (property == "top")
        {
            setPosition(getPosition().x, static_cast<float>(atof(value.c_str())));
        }
        else if (property == "width")
        {
            setSize(static_cast<float>(atof(value.c_str())), getSize().y);
        }
        else if (property == "height")
        {
            setSize(getSize().x, static_cast<float>(atof(value.c_str())));
        }
        else if (property == "visible")
        {
            if ((value == "true") || (value == "True"))
                m_Visible = true;
            else if ((value == "false") || (value == "False"))
                m_Visible = false;
            else
                TGUI_OUTPUT("TGUI error: Failed to parse 'Visible' property.");
        }
        else if (property == "enabled")
        {
            if ((value == "true") || (value == "True"))
                m_Enabled = true;
            else if ((value == "false") || (value == "False"))
                m_Enabled = false;
            else
                TGUI_OUTPUT("TGUI error: Failed to parse 'Enabled' property.");
        }
        else if (property == "transparency")
        {
            setTransparency(static_cast<char>(atoi(value.c_str())));
        }
        else if (property == "callbackid")
        {
            m_Callback.id = static_cast<unsigned int>(std::atoi(value.c_str()));
        }
        else if (property == "callback")
        {
            std::vector<sf::String> callbacks;
            decodeList(value, callbacks);

            for (auto it = callbacks.begin(); it != callbacks.end(); ++it)
            {
                if ((*it == "Focused") || (*it == "focused"))
                    bindCallback(Focused);
                else if ((*it == "Unfocused") || (*it == "unfocused"))
                    bindCallback(Unfocused);
                else if ((*it == "MouseEntered") || (*it == "mouseentered"))
                    bindCallback(MouseEntered);
                else if ((*it == "MouseLeft") || (*it == "mouseleft"))
                    bindCallback(MouseLeft);
            }
        }
        else // The property didn't match
            return false;

        // You pass here when one of the properties matched
        return true;
    }
Beispiel #4
0
    bool Checkbox::setProperty(std::string property, const std::string& value)
    {
        property = toLower(property);

        if (property == "configfile")
        {
            load(value);
        }
        else if (property == "checked")
        {
            if ((value == "true") || (value == "True"))
                check();
            else if ((value == "false") || (value == "False"))
                uncheck();
            else
                TGUI_OUTPUT("TGUI error: Failed to parse 'Checked' property.");
        }
        else if (property == "text")
        {
            setText(value);
        }
        else if (property == "textcolor")
        {
            setTextColor(extractColor(value));
        }
        else if (property == "textsize")
        {
            setTextSize(atoi(value.c_str()));
        }
        else if (property == "allowtextclick")
        {
            if ((value == "true") || (value == "True"))
                allowTextClick(true);
            else if ((value == "false") || (value == "False"))
                allowTextClick(false);
            else
                TGUI_OUTPUT("TGUI error: Failed to parse 'AllowTextClick' property.");
        }
        else if (property == "callback")
        {
            ClickableWidget::setProperty(property, value);

            std::vector<sf::String> callbacks;
            decodeList(value, callbacks);

            for (auto it = callbacks.begin(); it != callbacks.end(); ++it)
            {
                if ((*it == "Checked") || (*it == "checked"))
                    bindCallback(Checked);
                else if ((*it == "Unchecked") || (*it == "unchecked"))
                    bindCallback(Unchecked);
                else if ((*it == "SpaceKeyPressed") || (*it == "spacekeypressed"))
                    bindCallback(SpaceKeyPressed);
                else if ((*it == "ReturnKeyPressed") || (*it == "returnkeypressed"))
                    bindCallback(ReturnKeyPressed);
            }
        }
        else // The property didn't match
            return ClickableWidget::setProperty(property, value);

        // You pass here when one of the properties matched
        return true;
    }
Beispiel #5
0
bool CSBLoadable::onBeginBinding(CSBNode* root, CSBLoadable* owner)
{
    if (!root || !owner)
    {
        return false;
    }
    
    do {
//        TableView* tv = dynamic_cast<TableView*>(root);
//        if (tv != nullptr)
//        {
//            tv->setDataSource(dynamic_cast<TableViewDataSource*>(owner));
//            tv->setDelegate(dynamic_cast<TableViewDelegate*>(owner));
//            break;
//        }
//        
//        RichTableView* r = dynamic_cast<RichTableView*>(root);
//        if (r != nullptr)
//        {
//            r->setDataSource(dynamic_cast<TableViewDataSource*>(owner));
//            r->setDelegate(dynamic_cast<TableViewDelegate*>(owner));
//            break;
//        }
    }while(0);
    
    auto widget = dynamic_cast<Widget*>(root);
    if (widget != nullptr) {
        std::string callbackName = widget->getCallbackName();
        std::string callbackType = widget->getCallbackType();
        bindCallback(callbackName, callbackType, widget, owner);
    }
    
    auto rootname = root->getName();
    
//    CCLOG("rootname: %s", rootname.c_str());
    
    // 变量名以`_`开头为有效成员,绑定到多个成员上以`;`分开,集合以`:`以前为变量名,以后为index|key(int)
    if (!trim(rootname).empty() && rootname[0] == '_')
    {
        vector<string> names;
        stringsSplitByString(rootname, ";", names);
        
        for (auto name : names)
        {
            auto colonpos = name.find(':');
            auto varname = name;
            auto varflag = 0;
            if (colonpos != std::string::npos) {
                varname = std::move(rootname.substr(0, colonpos));
                varflag = std::stoi(rootname.substr(colonpos+1));
            }
            
            if (!trim(varname).empty() && varname[0] == '_')
            {
                bool isset = false;
                do {
                    CC_BREAK_IF(isset);
                    {
                        auto it = _outlets.find(varname);
                        if ( it != _outlets.end() ) {
                            it->second->operator = (root);
                            isset = true;
                        }
                    }
                    
                    CC_BREAK_IF(isset);
                    {
                        auto it = _outletCols.find(varname);
                        if ( it != _outletCols.end() ) {
                            if (it->second->size() <= varflag) {
                                it->second->resize(varflag+1);
                            }
                            it->second->operator[](varflag) = root;
                            isset = true;
                        }
                    }
                    
                    CC_BREAK_IF(isset);
                    {
                        auto it = _outletDics.find(varname);
                        if ( it != _outletDics.end() ) {
                            it->second->operator[](varflag) = root;
                            isset = true;
                        }
                    }
                    
                } while (false);
                
            }
        }
    }
    
    
    
    // 如果发现子结点为CSBLoadable类型,则其子结点已经绑定过,返回。
    CSBLoadable* csb = dynamic_cast<CSBLoadable*>(root);
    if (csb != nullptr && csb != owner && csb->_isUseBinding) {
        return true;
    }
    
    const auto& arrayRootChildren = root->getChildren();
    for (auto& subWidget : arrayRootChildren)
    {
        CSBNode* child = dynamic_cast<CSBNode*>(subWidget);
        if (child)
        {
            onBeginBinding(child, owner);
        }
    }
    
    return true;
}