예제 #1
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;
    }
예제 #2
0
    bool Label::load(const std::string& configFileFilename)
    {
        m_LoadedConfigFile = configFileFilename;

        // Open the config file
        ConfigFile configFile;
        if (!configFile.open(configFileFilename))
        {
            TGUI_OUTPUT("TGUI error: Failed to open " + configFileFilename + ".");
            return false;
        }

        // Read the properties and their values (as strings)
        std::vector<std::string> properties;
        std::vector<std::string> values;
        if (!configFile.read("Label", properties, values))
        {
            TGUI_OUTPUT("TGUI error: Failed to parse " + configFileFilename + ".");
            return false;
        }

        // Close the config file
        configFile.close();

        // Handle the read properties
        for (unsigned int i = 0; i < properties.size(); ++i)
        {
            std::string property = properties[i];
            std::string value = values[i];

            if (property == "textcolor")
            {
                setTextColor(extractColor(value));
            }
            else
                TGUI_OUTPUT("TGUI warning: Unrecognized property '" + property + "' in section Label in " + configFileFilename + ".");
        }

        return false;
    }
예제 #3
0
    bool Label::setProperty(std::string property, const std::string& value)
    {
        property = toLower(property);

        if (property == "configfile")
        {
            load(value);
        }
        else if (property == "text")
        {
            std::string text;
            decodeString(value, text);
            setText(text);
        }
        else if (property == "textcolor")
        {
            setTextColor(extractColor(value));
        }
        else if (property == "textsize")
        {
            setTextSize(atoi(value.c_str()));
        }
        else if (property == "backgroundcolor")
        {
            setBackgroundColor(extractColor(value));
        }
        else if (property == "autosize")
        {
            if ((value == "true") || (value == "True"))
                setAutoSize(true);
            else if ((value == "false") || (value == "False"))
                setAutoSize(false);
            else
                TGUI_OUTPUT("TGUI error: Failed to parse 'AutoSize' property.");
        }
        else // The property didn't match
            return ClickableWidget::setProperty(property, value);

        // You pass here when one of the properties matched
        return true;
    }
예제 #4
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;
    }
예제 #5
0
    bool Checkbox::load(const std::string pathname)
    {
        // When everything is loaded successfully, this will become true.
        m_Loaded = false;

        // Make sure that the pathname isn't empty
        if (pathname.empty())
            return false;

        // Store the pathname
        m_LoadedPathname = pathname;

        // When the pathname does not end with a "/" then we will add it
        if (m_LoadedPathname.at(m_LoadedPathname.length()-1) != '/')
            m_LoadedPathname.push_back('/');

        // Open the info file
        InfoFileParser infoFile;
        if (infoFile.openFile(m_LoadedPathname + "info.txt") == false)
        {
            TGUI_OUTPUT((((std::string("TGUI: Failed to open ")).append(m_LoadedPathname)).append("info.txt")).c_str());
            return false;
        }

        std::string property;
        std::string value;

        std::string imageExtension = "png";

        // Read untill the end of the file
        while (infoFile.readProperty(property, value))
        {
            // Check what the property is
            if (property.compare("phases") == 0)
            {
                // Get and store the different phases
                extractPhases(value);
            }
            else if (property.compare("textcolor") == 0)
            {
                m_Text.setColor(extractColor(value));
            }
            else if (property.compare("extension") == 0)
            {
                imageExtension = value;
            }
        }

        // Close the info file
        infoFile.closeFile();

        // If the checkbox was loaded before then remove the old textures
        if (m_TextureUnchecked != NULL)   TGUI_TextureManager.removeTexture(m_TextureUnchecked);
        if (m_TextureChecked != NULL)     TGUI_TextureManager.removeTexture(m_TextureChecked);
        if (m_TextureMouseHover != NULL)  TGUI_TextureManager.removeTexture(m_TextureMouseHover);
        if (m_TextureFocused != NULL)     TGUI_TextureManager.removeTexture(m_TextureFocused);

        // load the required textures
        if ((TGUI_TextureManager.getTexture(m_LoadedPathname + "Checked." + imageExtension, m_TextureChecked))
         && (TGUI_TextureManager.getTexture(m_LoadedPathname + "Unchecked." + imageExtension, m_TextureUnchecked)))
        {
            m_SpriteChecked.setTexture(*m_TextureChecked, true);
            m_SpriteUnchecked.setTexture(*m_TextureUnchecked, true);
        }
        else
            return false;

        bool error = false;

        // load the optional textures
        if (m_ObjectPhase & objectPhase::focused)
        {
            if (TGUI_TextureManager.getTexture(m_LoadedPathname + "Focus." + imageExtension, m_TextureFocused))
            {
                m_SpriteFocused.setTexture(*m_TextureFocused, true);
                m_AllowFocus = true;
            }
            else
                error = true;
        }

        if (m_ObjectPhase & objectPhase::hover)
        {
            if (TGUI_TextureManager.getTexture(m_LoadedPathname + "Hover." + imageExtension, m_TextureMouseHover))
                m_SpriteMouseHover.setTexture(*m_TextureMouseHover, true);
            else
                error = true;
        }

        // When there is no error we will return true
        m_Loaded = !error;
        return !error;
    }
예제 #6
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;
    }
예제 #7
0
    bool Checkbox::load(const std::string& configFileFilename)
    {
        m_LoadedConfigFile = configFileFilename;

        // When everything is loaded successfully, this will become true.
        m_Loaded = false;

        // If the checkbox was loaded before then remove the old textures
        if (m_TextureUnchecked.data != nullptr) TGUI_TextureManager.removeTexture(m_TextureUnchecked);
        if (m_TextureChecked.data != nullptr)   TGUI_TextureManager.removeTexture(m_TextureChecked);
        if (m_TextureHover.data != nullptr)     TGUI_TextureManager.removeTexture(m_TextureHover);
        if (m_TextureFocused.data != nullptr)   TGUI_TextureManager.removeTexture(m_TextureFocused);

        // Open the config file
        ConfigFile configFile;
        if (!configFile.open(configFileFilename))
        {
            TGUI_OUTPUT("TGUI error: Failed to open " + configFileFilename + ".");
            return false;
        }

        // Read the properties and their values (as strings)
        std::vector<std::string> properties;
        std::vector<std::string> values;
        if (!configFile.read("Checkbox", properties, values))
        {
            TGUI_OUTPUT("TGUI error: Failed to parse " + configFileFilename + ".");
            return false;
        }

        // Close the config file
        configFile.close();

        // Find the folder that contains the config file
        std::string configFileFolder = "";
        std::string::size_type slashPos = configFileFilename.find_last_of("/\\");
        if (slashPos != std::string::npos)
            configFileFolder = configFileFilename.substr(0, slashPos+1);

        // Handle the read properties
        for (unsigned int i = 0; i < properties.size(); ++i)
        {
            std::string property = properties[i];
            std::string value = values[i];

            if (property == "textcolor")
            {
                m_Text.setColor(configFile.readColor(value));
            }
            else if (property == "checkedimage")
            {
                if (!configFile.readTexture(value, configFileFolder, m_TextureChecked))
                {
                    TGUI_OUTPUT("TGUI error: Failed to parse value for CheckedImage in section Checkbox in " + configFileFilename + ".");
                    return false;
                }
            }
            else if (property == "uncheckedimage")
            {
                if (!configFile.readTexture(value, configFileFolder, m_TextureUnchecked))
                {
                    TGUI_OUTPUT("TGUI error: Failed to parse value for UncheckedImage in section Checkbox in " + configFileFilename + ".");
                    return false;
                }
            }
            else if (property == "hoverimage")
            {
                if (!configFile.readTexture(value, configFileFolder, m_TextureHover))
                {
                    TGUI_OUTPUT("TGUI error: Failed to parse value for HoverImage in section Checkbox in " + configFileFilename + ".");
                    return false;
                }
            }
            else if (property == "focusedimage")
            {
                if (!configFile.readTexture(value, configFileFolder, m_TextureFocused))
                {
                    TGUI_OUTPUT("TGUI error: Failed to parse value for FocusedImage in section Checkbox in " + configFileFilename + ".");
                    return false;
                }
            }
            else
                TGUI_OUTPUT("TGUI warning: Unrecognized property '" + property + "' in section Checkbox in " + configFileFilename + ".");
        }

        // Make sure the required texture was loaded
        if ((m_TextureChecked.data != nullptr) && (m_TextureUnchecked.data != nullptr))
        {
            m_Loaded = true;
            setSize(static_cast<float>(m_TextureUnchecked.getSize().x), static_cast<float>(m_TextureUnchecked.getSize().y));
        }
        else
        {
            TGUI_OUTPUT("TGUI error: Not all needed images were loaded for the checkbox. Is the Checkbox section in " + configFileFilename + " complete?");
            return false;
        }

        // Check if optional textures were loaded
        if (m_TextureFocused.data != nullptr)
        {
            m_AllowFocus = true;
            m_WidgetPhase |= WidgetPhase_Focused;
        }
        if (m_TextureHover.data != nullptr)
        {
            m_WidgetPhase |= WidgetPhase_Hover;
        }

        // When there is no error we will return true
        return true;
    }