IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

SFML Discussion :

Deux erreurs de compilation


Sujet :

SFML

  1. #1
    Membre habitué
    Avatar de Glân von Brylân
    Homme Profil pro
    Développeur Web
    Inscrit en
    Janvier 2014
    Messages
    133
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Janvier 2014
    Messages : 133
    Points : 186
    Points
    186
    Par défaut Deux erreurs de compilation
    Bonjour,

    J'ai commencer à coder ma propre API pour GUI avec la SFML, surtout pour m'exercer en fait. Mais voilà, je bloque déjà. J'ai les erreurs suivantes :
    Button.cpp || In member function 'void Button::checkClicked()':
    Button.cpp |135| error: 'functions' was not declared in this scope

    SFML-2.1\include\SFML\System\Thread.inl || In instantiation of 'void sf::priv::ThreadFunctorWithArg<F, A>::run() [with F = void (*)(); A = MWindow*]':
    Button.cpp |145| required from here
    SFML-2.1\include\SFML\System\Thread.inl |48| error: too many arguments to function


    MWindow.h :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    #ifndef MWINDOW_H
    #define MWINDOW_H
     
     
    #include <SFML/Graphics.hpp>
     
    #include <vector>
     
     
    class MWindow;
     
    class Button : public sf::Sprite
    {
        friend class MWindow;
        public:
            Button(std::string const& adress, std::string const& adressO=std::string(), std::string const& adressL=std::string(), std::string const& adressD=std::string());
     
            virtual ~Button();
     
            bool setParent(MWindow *newParent = nullptr, void (*newFunc)() = nullptr);
            // Sets 'parent' to newParent. If newParent is null, the button is disabled and ID is set to -1. Else it is enabled.
            // Returns true if the parent has been successfully changed, else false.
     
            MWindow* getParent();
            // Returns 'parent' member.
     
            virtual void setEnabled(bool yay);
            // Sets the 'enabled' value to yay and changes de texture in consequences. An hidden button cannot be enabled.
     
            bool getEnabled();
            // Returns the 'enabled' member value
     
            virtual void setHidden(bool hide);
            // Sets the 'hidden' member to hide. If true, texture is set to 'texture', else to an empty texture.
            // An hidden button is also disabled. Unhidde a button automatically re-enables it.
     
            bool getHidden();
            // Returns the 'hidden' member value
     
            void changeTexture(std::string const& adress);
            // texture.loadFromFile(adress);
     
            void changeTextureOver(std::string const& adress=std::string());
            // Give it an empty string and  textureOver will be set with 'texture'
            void changeTextureLeaned(std::string const& adress=std::string());
            // Give it an empty string and  textureLeaned will be set with 'texture'
            void changeTextureDisabled(std::string const& adress=std::string());
            // Give it an empty string and  textureDisabled will be set with 'texture'
     
        protected:
            void checkClicked();
            // Uses the sf::Event event to verify if the mouse is over the button and if the user clicks on
     
            MWindow *parent;
            sf::Texture texture, textureOver, textureLeaned, textureDisabled;
            sf::Thread *chkClicked;
            bool enabled, mouseOver, leaned, hidden;
            int ID;
    };
     
     
     
    /////////////////////////////////////// MWindow ///////////////////////////////////////
     
    class MWindow
    {
        friend class Button;
        public:
            MWindow(int x = 800, int y = 600, std::string const& title = "Main Window", bool deletebuttons = true, sf::ContextSettings const& settings = sf::ContextSettings());
            /* Arguments :
             * 'title' is simply the title of the window.
             * 'deletebuttons' : if true, the buttons in the vector 'buttons' will be deleted in the destructor.
             * 'x' ans 'y' are respectively the width and the height of the window
            */
     
            MWindow(sf::RenderWindow *windowPtr, bool deletebuttons = true);
     
            MWindow& operator=(MWindow const& other);
     
            virtual ~MWindow();
     
            virtual void startEventLoop();
     
            bool addButton(Button *button, void (*func)());
            // Returns true if the button is successfully added, false if the button was already in the window
     
            bool removeButton(Button *button);
            // Returns true if the button is successfully removed from the window, false if the button was not in the window.
            // Note that this function does NOT delete the button.
     
            bool removeButton(int index);
            // Overload of removeButton(). Remove the Button at the 'index' position. Return true if successful, false if the 'index' position does not exist.
        protected:
            virtual void update();
            // clear-draw-display function
     
            virtual void checkButtons();
            // checks if
     
            sf::RenderWindow *window;
            sf::Thread checkBtns;
            std::vector<Button*> buttons;
            std::vector<void (*)()> functions;
            bool deleteButtons;
            sf::Event event;
    };
     
    #endif // MWINDOW_H
    MWindow.cpp :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    #include "MWindow.h"
     
    MWindow::MWindow(int x, int y, std::string const& title, bool deletebuttons, ContextSettings const& settings) : \
        window(new sf::RenderWindow(sf::VideoMode(x,y), title, sf::Style::Titlebar | sf::Style::Close, settings)), \
        checkBtns(&MWindow::checkButtons, this), buttons(), deleteButtons(deletebuttons)
    {
        checkBtns.launch();
    }
     
    MWindow::MWindow(sf::RenderWindow *windowPtr, bool deletebuttons) : window(windowPtr), checkBtns(&MWindow::checkButtons, this), buttons(), deleteButtons(deletebuttons)
    {
        checkBtns.launch();
    }
     
    MWindow::~MWindow()
    {
        if(deleteButtons)
        {
            for(int i(0) ; i < (int)buttons.size() ; i++)
                delete buttons[i];
        }
        else
        {
            for(int i(0) ; i < (int)buttons.size() ; i++)
                if(buttons[i] != nullptr)
                    buttons[i].ID=-1;
        }
    }
     
    MWindow& MWindow::operator=(const MWindow& rhs)
    {
        if (this == &rhs) return *this; // handle self assignment
        //assignment operator
        return *this;
    }
     
    void MWindow::startEventLoop()
    {
        while(window->isOpen())
        {
            update();
            while(window->pollEvent(event))
            {
                if(event.type == sf::Event::MouseButtonPressed || event.type == sf::Event::MouseButtonReleased || event.type == sf::Event::MouseMoved)
                {
                    for(int i(0) ; i < (int)buttons.size() ; i++)
                        if(buttons[i] != nullptr && buttons[i]->getEnabled())
                            buttons[i]->checkClicked(event);
                }
            }
        }
    }
     
     
    bool MWindow::addButton(Button *button, void (*func)())
    {
        for(int i(0) ; i < (int)buttons.size() ; i++)
            if(buttons[i] == button)
                return false;
     
        if(buttons.empty())
        {
            buttons.push_back(button);
            button->ID=0;
            functions.push_back(func);
            return;
        }
        for(int i(0) ; i < (int)buttons.size() ; i++)
        {
            if(buttons[i] == nullptr)
            {
                buttons[i]=button;
                button->ID=i;
                functions[i]=func;
            }
        }
        buttons.push_back(button);
        button->ID=buttons.size()-1;
        functions.push_back(func);
        return true;
    }
     
    bool MWindow::removeButton(Button *button)
    {
        for(int i(0) ; i < (int)buttons.size() ; i++)
        {
            if(buttons[i] == button)
            {
                buttons[i]->setParent(nullptr);
                buttons[i] = nullptr;
                return true;
            }
        }
        return false;
    }
     
    bool MWindow::removeButton(int index)
    {
        try
        {
            buttons.at(index)->setParent(nullptr);
            buttons.at(index) = nullptr;
        }
        catch (std::out_of_range const& exc) // My compiler (GCC 4.7.1) does not want of std::out_of_range or std::logic_error...why ?
        {
            return false;
        }
        return true;
    }
     
    void MWindow::update()
    {
        window->clear();
     
        for(int i(0) ; i < (int)buttons.size(); i++)
            if(buttons[i]!=nullptr)
                window->draw(*buttons[i]);
     
        window->display();
    }
    Button.cpp :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
     
    #include "MWindow.h"
     
    Button::Button(std::string const& adress, std::string const& adressO, std::string const& adressL, std::string const& adressD) : \
        parent(nullptr), texture(), textureOver(), textureLeaned(), textureDisabled(), chkClicked(new sf::Thread(&Button::checkClicked, this)), \
        enabled(false), mouseOver(false), leaned(false), hidden(false), ID(-1)
    {
        changeTexture(adress);
        changeTextureOver(adressO);
        changeTextureLeaned(adressL);
        changeTextureDisabled(adressD);
    }
     
    Button::~Button()
    {
        delete chkClicked;
    }
     
    bool Button::setParent(MWindow *newParent, void (*newFunc)())
    {
        if(!newParent->addButton(this, newFunc))
            return false;
     
        delete chkClicked;
        parent=newParent;
        if(parent == nullptr || newFunc == nullptr)
        {
            setEnabled(false);
            ID=-1;
            return false;
        }
        else
        {
            setEnabled(true);
            chkClicked=new sf::Thread(newFunc, parent);
        }
     
        return true;
    }
     
    MWindow* Button::getParent()
    {
        return parent;
    }
     
    void Button::setEnabled(bool yay)
    {
        if((enabled && yay) || hidden)
        {
            return;
        }
        else if(yay)
        {
            enabled=true;
            chkClicked->launch();
        }
        else
        {
            enabled=false;
            setTexture(textureDisabled);
        }
    }
     
    bool Button::getEnabled()
    {
        return enabled;
    }
     
    void Button::setHidden(bool hide)
    {
        if(hide)
        {
            setEnabled(false);
            setTexture(sf::Texture());
            hidden=true;
        }
        else
        {
            hidden=false;
            setEnabled(true);
        }
    }
     
    bool Button::getHidden()
    {
        return hidden;
    }
     
    void Button::changeTexture(std::string const& adress)
    {
        texture.loadFromFile(adress);
    }
     
    void Button::changeTextureOver(std::string const& adress)
    {
        textureOver.loadFromFile(adress);
    }
     
    void Button::changeTextureLeaned(std::string const& adress)
    {
        textureLeaned.loadFromFile(adress);
    }
     
    void Button::changeTextureDisabled(std::string const& adress)
    {
        textureDisabled.loadFromFile(adress);
    }
     
    void Button::checkClicked()
    {
        while(enabled)
        {
            if(parent->event.type == sf::Event::MouseMoved)
            {
                if(getGlobalBounds().contains(sf::Vector2<float>(parent->event.mouseMove.x, parent->event.mouseMove.y)))
                {//if the mouse is in the button...
                    mouseOver=true;
                    setTexture(textureOver);
                }
                else
                {
                    mouseOver=false;
                    setTexture(texture);
                }
            }
            else if(parent->event.type == sf::Event::MouseButtonPressed && parent->event.mouseButton.button == sf::Mouse::Right && mouseOver)
            {
                leaned=true;
                setTexture(textureLeaned);
            }
            else if(parent->event.type == sf::Event::MouseButtonReleased && parent->event.mouseButton.button == sf::Mouse::Right && leaned)
            {
                if(getGlobalBounds().contains(sf::Vector2<float>(parent->event.mouseButton.x, parent->event.mouseButton.y)))
                {
                    setTexture(textureOver);
                    (*parent.*functions[ID])(); // error: 'functions' was not declared int this scope
                }
                else
                {
                    setTexture(texture);
                    mouseOver=false;
                }
                leaned=false;
            }
        }
    } // In instantiation of 'void sf::priv::ThreadFunctorWithArg<F, A>::run() [with F = void (*)(); A = MWindow*]': required from here
    J'ai essayé plusieurs façons différentes, aucune n'a fonctionné. Quelqu'un peut m'aiguiller ? Merci d'avance.
    Les pointeurs intelligents, c'est mignon mais trop long à écrire.

  2. #2
    En attente de confirmation mail

    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Août 2004
    Messages
    1 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : France, Doubs (Franche Comté)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Août 2004
    Messages : 1 391
    Points : 3 311
    Points
    3 311
    Par défaut
    Pour la première erreur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    parent->functions[ID]();

  3. #3
    Membre habitué
    Avatar de Glân von Brylân
    Homme Profil pro
    Développeur Web
    Inscrit en
    Janvier 2014
    Messages
    133
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Janvier 2014
    Messages : 133
    Points : 186
    Points
    186
    Par défaut
    Effectivement. Par contre, pour le deuxième...Bon, je vais aller demander sur le forum de la SFML, déjà.
    Les pointeurs intelligents, c'est mignon mais trop long à écrire.

  4. #4
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 827
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 827
    Points : 218 289
    Points
    218 289
    Billets dans le blog
    117
    Par défaut
    Bonjour,

    La seconde erreur indique comme quoi une fonction reçoit trop d'argument. Par contre, on ne sait pas quel code à entrainer l'erreur.
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  5. #5
    Membre habitué
    Avatar de Glân von Brylân
    Homme Profil pro
    Développeur Web
    Inscrit en
    Janvier 2014
    Messages
    133
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Janvier 2014
    Messages : 133
    Points : 186
    Points
    186
    Par défaut
    J'ai trouvé. Button.cpp, ligne 34 : chkClicked=new sf::Thread(newFunc, parent);
    Par contre, je ne vois pas en quoi j'ai donné trop d'arguments...
    Les pointeurs intelligents, c'est mignon mais trop long à écrire.

  6. #6
    Membre émérite
    Avatar de skeud
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juin 2011
    Messages
    1 091
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2011
    Messages : 1 091
    Points : 2 724
    Points
    2 724
    Billets dans le blog
    1
    Par défaut
    re-poste ton code avec la sortis du compilo, ça sera plu simple pour nous .
    Pas de solution, pas de probleme

    Une réponse utile (ou +1) ->
    Une réponse inutile ou pas d'accord -> et expliquer pourquoi
    Une réponse à votre question


  7. #7
    Membre habitué
    Avatar de Glân von Brylân
    Homme Profil pro
    Développeur Web
    Inscrit en
    Janvier 2014
    Messages
    133
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Janvier 2014
    Messages : 133
    Points : 186
    Points
    186
    Par défaut
    Compilo :
    ||=== Build: Debug in MWindow (compiler: GNU GCC Compiler) ===|
    C:\Users\Jules\Desktop\Documents\C++\Projets SFML\SFML-2.1\include\SFML\System\Thread.inl||In instantiation of 'void sf::priv::ThreadFunctorWithArg<F, A>::run() [with F = void (*)(); A = MWindow*]':|
    C:\Users\Jules\Desktop\Documents\C++\Projets SFML\MWindow\Button.cpp|145|required from here|
    C:\Users\Jules\Desktop\Documents\C++\Projets SFML\SFML-2.1\include\SFML\System\Thread.inl|48|error: too many arguments to function|
    ||=== Build failed: 1 error(s), 2 warning(s) (0 minute(s), 0 second(s)) ===|

    Code MWindow.h : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    #ifndef MWINDOW_H
    #define MWINDOW_H
     
     
    #include <SFML/Graphics.hpp>
     
    #include <vector>
     
     
    class MWindow;
     
    class Button : public sf::Sprite
    {
        friend class MWindow;
        public:
            Button(std::string const& adress, std::string const& adressO=std::string(), std::string const& adressL=std::string(), std::string const& adressD=std::string());
     
            virtual ~Button();
     
            bool setParent(MWindow *newParent = nullptr, void (*newFunc)() = nullptr);
            // Sets 'parent' to newParent. If newParent is null, the button is disabled and ID is set to -1. Else it is enabled.
            // Returns true if the parent has been successfully changed, else false.
     
            MWindow* getParent();
            // Returns 'parent' member.
     
            virtual void setEnabled(bool yay);
            // Sets the 'enabled' value to yay and changes de texture in consequences. An hidden button cannot be enabled.
     
            bool getEnabled();
            // Returns the 'enabled' member value
     
            virtual void setHidden(bool hide);
            // Sets the 'hidden' member to hide. If true, texture is set to 'texture', else to an empty texture.
            // An hidden button is also disabled. Unhidde a button automatically re-enables it.
     
            bool getHidden();
            // Returns the 'hidden' member value
     
            void changeTexture(std::string const& adress);
            // texture.loadFromFile(adress);
     
            void changeTextureOver(std::string const& adress=std::string());
            // Give it an empty string and  textureOver will be set with 'texture'
            void changeTextureLeaned(std::string const& adress=std::string());
            // Give it an empty string and  textureLeaned will be set with 'texture'
            void changeTextureDisabled(std::string const& adress=std::string());
            // Give it an empty string and  textureDisabled will be set with 'texture'
     
        protected:
            void checkClicked();
            // Uses the sf::Event event to verify if the mouse is over the button and if the user clicks on
     
            MWindow *parent;
            sf::Texture texture, textureOver, textureLeaned, textureDisabled;
            sf::Thread *chkClicked;
            bool enabled, mouseOver, leaned, hidden;
            int ID;
    };
     
     
     
    /////////////////////////////////////// MWindow ///////////////////////////////////////
     
    class MWindow
    {
        friend class Button;
        public:
            MWindow(int x = 800, int y = 600, std::string const& title = "Main Window", bool deletebuttons = true, sf::ContextSettings const& settings = sf::ContextSettings());
            /* Arguments :
             * 'title' is simply the title of the window.
             * 'deletebuttons' : if true, the buttons in the vector 'buttons' will be deleted in the destructor.
             * 'x' ans 'y' are respectively the width and the height of the window
            */
     
            MWindow(sf::RenderWindow *windowPtr, bool deletebuttons = true);
     
            virtual ~MWindow();
     
            virtual void startEventLoop();
     
            bool addButton(Button *button, void (*func)());
            // Returns true if the button is successfully added, false if the button was already in the window
     
            bool removeButton(Button *button);
            // Returns true if the button is successfully removed from the window, false if the button was not in the window.
            // Note that this function does NOT delete the button.
     
            bool removeButton(int index);
            // Overload of removeButton(). Remove the Button at the 'index' position. Return true if successful, false if the 'index' position does not exist.
        protected:
            virtual void update();
            // clear-draw-display function
     
            virtual void checkButtons();
            // checks if
     
            sf::RenderWindow *window;
            sf::Thread checkBtns;
            std::vector<Button*> buttons;
            std::vector<void (*)()> functions;
            bool deleteButtons;
            sf::Event event;
    };
     
    #endif // MWINDOW_H
    Code MWindow.cpp : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    #include "MWindow.h"
     
    MWindow::MWindow(int x, int y, std::string const& title, bool deletebuttons, ContextSettings const& settings) : \
        window(new sf::RenderWindow(sf::VideoMode(x,y), title, sf::Style::Titlebar | sf::Style::Close, settings)), \
        checkBtns(&MWindow::checkButtons, this), buttons(), deleteButtons(deletebuttons)
    {
        checkBtns.launch();
    }
     
    MWindow::MWindow(sf::RenderWindow *windowPtr, bool deletebuttons) : window(windowPtr), checkBtns(&MWindow::checkButtons, this), buttons(), deleteButtons(deletebuttons)
    {
        checkBtns.launch();
    }
     
    MWindow::~MWindow()
    {
        if(deleteButtons)
        {
            for(int i(0) ; i < (int)buttons.size() ; i++)
                delete buttons[i];
        }
        else
        {
            for(int i(0) ; i < (int)buttons.size() ; i++)
                if(buttons[i] != nullptr)
                    buttons[i].ID=-1;
        }
    }
     
    void MWindow::startEventLoop()
    {
        while(window->isOpen())
        {
            update();
            while(window->pollEvent(event))
            {
                if(event.type == sf::Event::MouseButtonPressed || event.type == sf::Event::MouseButtonReleased || event.type == sf::Event::MouseMoved)
                {
                    for(int i(0) ; i < (int)buttons.size() ; i++)
                        if(buttons[i] != nullptr && buttons[i]->getEnabled())
                            buttons[i]->checkClicked(event);
                }
            }
        }
    }
     
     
    bool MWindow::addButton(Button *button, void (*func)())
    {
        for(int i(0) ; i < (int)buttons.size() ; i++)
            if(buttons[i] == button)
                return false;
     
        if(buttons.empty())
        {
            buttons.push_back(button);
            button->ID=0;
            functions.push_back(func);
            return;
        }
        for(int i(0) ; i < (int)buttons.size() ; i++)
        {
            if(buttons[i] == nullptr)
            {
                buttons[i]=button;
                button->ID=i;
                functions[i]=func;
            }
        }
        buttons.push_back(button);
        button->ID=buttons.size()-1;
        functions.push_back(func);
        return true;
    }
     
    bool MWindow::removeButton(Button *button)
    {
        for(int i(0) ; i < (int)buttons.size() ; i++)
        {
            if(buttons[i] == button)
            {
                buttons[i]->setParent(nullptr);
                buttons[i] = nullptr;
                return true;
            }
        }
        return false;
    }
     
    bool MWindow::removeButton(int index)
    {
        try
        {
            buttons.at(index)->setParent(nullptr);
            buttons.at(index) = nullptr;
        }
        catch (std::out_of_range const& exc) // My compiler (GCC 4.7.1) does not want of std::out_of_range or std::logic_error...why ?
        {
            return false;
        }
        return true;
    }
     
    void MWindow::update()
    {
        window->clear();
     
        for(int i(0) ; i < (int)buttons.size(); i++)
            if(buttons[i]!=nullptr)
                window->draw(*buttons[i]);
     
        window->display();
    }
    Code Button.cpp : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    #include "MWindow.h"
     
    Button::Button(std::string const& adress, std::string const& adressO, std::string const& adressL, std::string const& adressD) : \
        parent(nullptr), texture(), textureOver(), textureLeaned(), textureDisabled(), chkClicked(new sf::Thread(&Button::checkClicked, this)), \
        enabled(false), mouseOver(false), leaned(false), hidden(false), ID(-1)
    {
        changeTexture(adress);
        changeTextureOver(adressO);
        changeTextureLeaned(adressL);
        changeTextureDisabled(adressD);
    }
     
    Button::~Button()
    {
        delete chkClicked;
    }
     
    bool Button::setParent(MWindow *newParent, void (*newFunc)())
    {
        if(!newParent->addButton(this, newFunc))
            return false;
     
        delete chkClicked;
        parent=newParent;
        if(parent == nullptr || newFunc == nullptr)
        {
            setEnabled(false);
            ID=-1;
            return false;
        }
        else
        {
            setEnabled(true);
            chkClicked=new sf::Thread(newFunc, parent);
        }
     
        return true;
    }
     
    MWindow* Button::getParent()
    {
        return parent;
    }
     
    void Button::setEnabled(bool yay)
    {
        if((enabled && yay) || hidden)
        {
            return;
        }
        else if(yay)
        {
            enabled=true;
            chkClicked->launch();
        }
        else
        {
            enabled=false;
            setTexture(textureDisabled);
        }
    }
     
    bool Button::getEnabled()
    {
        return enabled;
    }
     
    void Button::setHidden(bool hide)
    {
        if(hide)
        {
            setEnabled(false);
            setTexture(sf::Texture());
            hidden=true;
        }
        else
        {
            hidden=false;
            setEnabled(true);
        }
    }
     
    bool Button::getHidden()
    {
        return hidden;
    }
     
    void Button::changeTexture(std::string const& adress)
    {
        texture.loadFromFile(adress);
    }
     
    void Button::changeTextureOver(std::string const& adress)
    {
        textureOver.loadFromFile(adress);
    }
     
    void Button::changeTextureLeaned(std::string const& adress)
    {
        textureLeaned.loadFromFile(adress);
    }
     
    void Button::changeTextureDisabled(std::string const& adress)
    {
        textureDisabled.loadFromFile(adress);
    }
     
    void Button::checkClicked()
    {
        while(enabled)
        {
            if(parent->event.type == sf::Event::MouseMoved)
            {
                if(getGlobalBounds().contains(sf::Vector2<float>(parent->event.mouseMove.x, parent->event.mouseMove.y)))
                {//if the mouse is in the button...
                    mouseOver=true;
                    setTexture(textureOver);
                }
                else
                {
                    mouseOver=false;
                    setTexture(texture);
                }
            }
            else if(parent->event.type == sf::Event::MouseButtonPressed && parent->event.mouseButton.button == sf::Mouse::Right && mouseOver)
            {
                leaned=true;
                setTexture(textureLeaned);
            }
            else if(parent->event.type == sf::Event::MouseButtonReleased && parent->event.mouseButton.button == sf::Mouse::Right && leaned)
            {
                if(getGlobalBounds().contains(sf::Vector2<float>(parent->event.mouseButton.x, parent->event.mouseButton.y)))
                {
                    setTexture(textureOver);
                    parent->functions[ID]();
                }
                else
                {
                    setTexture(texture);
                    mouseOver=false;
                }
                leaned=false;
            }
        }
    } // In instantiation of 'void sf::priv::ThreadFunctorWithArg<F, A>::run() [with F = void (*)(); A = MWindow*]': required from here
    Les pointeurs intelligents, c'est mignon mais trop long à écrire.

  8. #8
    Membre émérite
    Avatar de skeud
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juin 2011
    Messages
    1 091
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2011
    Messages : 1 091
    Points : 2 724
    Points
    2 724
    Billets dans le blog
    1
    Par défaut
    Ok pas très compliquée finalement comme erreur

    Tu n'as pas regarder le proto des thread de sfml, ils prennent en paramètre un argument, argument qu'il récupère depuis l'instanciation du thread (le new sf::Thread).

    donc dans le constructeur de ton bouton, tu créer un thread avec comme fonction verifchk et this comme argument, hors verifchk ne prend pas d'argument en paramètre, d'où l'erreur que tu as .
    Pas de solution, pas de probleme

    Une réponse utile (ou +1) ->
    Une réponse inutile ou pas d'accord -> et expliquer pourquoi
    Une réponse à votre question


  9. #9
    Membre habitué
    Avatar de Glân von Brylân
    Homme Profil pro
    Développeur Web
    Inscrit en
    Janvier 2014
    Messages
    133
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Janvier 2014
    Messages : 133
    Points : 186
    Points
    186
    Par défaut
    Effectivement. En fait j'essaie de lui passer une fonction membre sans lui dire que c'est une fonction membre ^v^'
    Bon, j'ai revu le système. Je vais bosser là-dessus, merci à tous !
    Les pointeurs intelligents, c'est mignon mais trop long à écrire.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Erreur de compilation après modification du Uses
    Par DevelOpeR13 dans le forum Langage
    Réponses: 5
    Dernier message: 30/10/2007, 15h23
  2. Réponses: 2
    Dernier message: 23/09/2003, 15h32
  3. Réponses: 10
    Dernier message: 22/09/2003, 22h58
  4. Réponses: 4
    Dernier message: 27/08/2003, 22h34
  5. Réponses: 2
    Dernier message: 05/03/2003, 00h24

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo