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

C++ Discussion :

probleme avec une class


Sujet :

C++

  1. #1
    Membre actif
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    502
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 502
    Points : 227
    Points
    227
    Par défaut probleme avec une class
    salut,

    j'analyse un petit programme , j'ai des difficultés a comprendre certaines fonctions :

    voici la classe

    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
    #ifndef FGEVENTHANDLER_H
    #define FGEVENTHANDLER_H 1
     
    #include <map>
    #include <osg/Quat>
    #include <osgGA/GUIEventHandler>
    #include <osgViewer/ViewerEventHandlers>
     
    #include "fg_os.hxx"
     
    namespace flightgear
    {
    class FGEventHandler : public osgGA::GUIEventHandler {
    public:
        FGEventHandler();
     
        virtual ~FGEventHandler() {}
     
        virtual const char* className() const {return "FGEventHandler"; }
    #if 0
        virtual void init(const osgGA::GUIEventAdapter& ea,
    		      osgGA::GUIActionAdapter& us);
    #endif
        virtual bool handle(const osgGA::GUIEventAdapter& ea,
    			osgGA::GUIActionAdapter& us);
     
        void setIdleHandler(fgIdleHandler idleHandler)
    	{
    	    this->idleHandler = idleHandler;
    	}
     
        fgIdleHandler getIdleHandler() const
    	{
    	    return idleHandler;
    	}
     
        void setDrawHandler(fgDrawHandler drawHandler)
    	{
    	    this->drawHandler = drawHandler;
    	}
     
        fgDrawHandler getDrawHandler() const
    	{
    	    return drawHandler;
    	}
     
        void setWindowResizeHandler(fgWindowResizeHandler windowResizeHandler)
    	{
    	    this->windowResizeHandler = windowResizeHandler;
    	}
     
        fgWindowResizeHandler getWindowResizeHandler() const
    	{
    	    return windowResizeHandler;
    	}
     
        void setKeyHandler(fgKeyHandler keyHandler)
    	{
    	    this->keyHandler = keyHandler;
    	}
     
        fgKeyHandler getKeyHandler() const
    	{
    	    return keyHandler;
    	}
     
        void setMouseClickHandler(fgMouseClickHandler mouseClickHandler)
    	{
    	    this->mouseClickHandler = mouseClickHandler;
    	}
     
        fgMouseClickHandler getMouseClickHandler()
    	{
    	    return mouseClickHandler;
    	}
     
        void setMouseMotionHandler(fgMouseMotionHandler mouseMotionHandler)
    	{
    	    this->mouseMotionHandler = mouseMotionHandler;
    	}
     
        fgMouseMotionHandler getMouseMotionHandler()
    	{
    	    return mouseMotionHandler;
    	}
     
        int getCurrentModifiers() const
    	{
    	    return currentModifiers;
    	}
     
        void setMouseWarped()
    	{
    	    mouseWarped = true;
    	}
     
        /** Whether or not resizing is supported. It might not be when
         * using multiple displays.
         */
        bool getResizable() { return resizable; }
        void setResizable(bool _resizable) { resizable = _resizable; }
     
    protected:
        osg::ref_ptr<osg::Node> _node;
        fgIdleHandler idleHandler;
        fgDrawHandler drawHandler;
        fgWindowResizeHandler windowResizeHandler;
        fgKeyHandler keyHandler;
        fgMouseClickHandler mouseClickHandler;
        fgMouseMotionHandler mouseMotionHandler;
        osg::ref_ptr<osgViewer::StatsHandler> statsHandler;
        osg::ref_ptr<osgGA::GUIEventAdapter> statsEvent;
        int statsType;
        int currentModifiers;
        std::map<int, int> numlockKeyMap;
        void handleKey(const osgGA::GUIEventAdapter& ea, int& key, int& modifiers);
        bool resizable;
        bool mouseWarped;
        // workaround for osgViewer double scroll events
        bool scrollButtonPressed;
        int release_keys[128];
        void handleStats(osgGA::GUIActionAdapter& us);
    };
     
    void eventToWindowCoords(const osgGA::GUIEventAdapter* ea, double& x, double& y);
    void eventToWindowCoordsYDown(const osgGA::GUIEventAdapter* ea,
                                  double& x, double& y);
    }
    #endif
    les classe que je ne comprends pas est :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     fgIdleHandler ;
        fgDrawHandler ;
    car ce sont des classes qui n'existent pas .

    dans
    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
    fff#ifndef _FG_OS_HXX
    #define _FG_OS_HXX
     
    #ifdef HAVE_CONFIG_H
    #  include <config.h>
    #endif
     
    #include <string>
    #include <vector>
     
    #include <osg/ref_ptr>
    #include <osg/Camera>
    #include <osg/GraphicsContext>
     
     
    enum { MOUSE_BUTTON_LEFT,
           MOUSE_BUTTON_MIDDLE,
           MOUSE_BUTTON_RIGHT };
     
    enum { MOUSE_BUTTON_DOWN,
           MOUSE_BUTTON_UP };
     
    enum { MOUSE_CURSOR_NONE,
           MOUSE_CURSOR_POINTER,
           MOUSE_CURSOR_WAIT,
           MOUSE_CURSOR_CROSSHAIR,
           MOUSE_CURSOR_LEFTRIGHT,
           MOUSE_CURSOR_TOPSIDE,
           MOUSE_CURSOR_BOTTOMSIDE,
           MOUSE_CURSOR_LEFTSIDE,
           MOUSE_CURSOR_RIGHTSIDE,
           MOUSE_CURSOR_TOPLEFT,
           MOUSE_CURSOR_TOPRIGHT,
           MOUSE_CURSOR_BOTTOMLEFT,
           MOUSE_CURSOR_BOTTOMRIGHT,
    };
     
    enum { KEYMOD_NONE     = 0,
           KEYMOD_RELEASED = 1, // Not a mod key, indicates "up" action
           KEYMOD_SHIFT    = 2,
           KEYMOD_CTRL     = 4,
           KEYMOD_ALT      = 8,
           KEYMOD_META     = 16,
           KEYMOD_SUPER    = 32,
           KEYMOD_HYPER    = 64,
           KEYMOD_MAX      = 128 };
     
    // A note on key codes: none are defined here.  FlightGear has no
    // hard-coded interpretations of codes other than modifier keys, so we
    // can get away with that.  The only firm requirement is that the
    // codes passed to the fgKeyHandler function be correctly interpreted
    // by the PUI library.  Users who need to hard-code key codes
    // (probably not a good idea in any case) can use the pu.hxx header
    // for definitions.
     
    //
    // OS integration functions
    //
     
    void fgOSInit(int* argc, char** argv);
    void fgOSOpenWindow(bool stencil);
    void fgOSFullScreen();
    void fgOSMainLoop();
    void fgOSExit(int code);
     
    void fgSetMouseCursor(int cursor);
    int  fgGetMouseCursor();
    void fgWarpMouse(int x, int y);
     
    int  fgGetKeyModifiers();
     
    void fgRequestRedraw();
     
    //
    // Callbacks and registration API
    //
     
    namespace osg { class Camera; class GraphicsContext; }
    namespace osgGA { class GUIEventAdapter; }
     
    typedef void (*fgIdleHandler)();
    typedef void (*fgDrawHandler)();
    typedef void (*fgWindowResizeHandler)(int w, int h);
     
    typedef void (*fgKeyHandler)(int key, int keymod, int mousex, int mousey);
    typedef void (*fgMouseClickHandler)(int button, int updown, int x, int y, bool mainWindow, const osgGA::GUIEventAdapter*);
    typedef void (*fgMouseMotionHandler)(int x, int y);
     
    void fgRegisterIdleHandler(fgIdleHandler func);
    void fgRegisterDrawHandler(fgDrawHandler func);
    void fgRegisterWindowResizeHandler(fgWindowResizeHandler func);
     
    void fgRegisterKeyHandler(fgKeyHandler func);
    void fgRegisterMouseClickHandler(fgMouseClickHandler func);
    void fgRegisterMouseMotionHandler(fgMouseMotionHandler func);
    #endif // _FG_OS_HXX
    il y a aussi une fonction important par rapport au sujet :

    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
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
     
    static void fgIdleFunction ( void ) {
        static osg::ref_ptr<GeneralInitOperation> genOp;
        if ( idle_state == 0 ) {
            idle_state++;
            // Pick some window on which to do queries.
            // XXX Perhaps all this graphics initialization code should be
            // moved to renderer.cxx?
            genOp = new GeneralInitOperation;
            osg::Camera* guiCamera = getGUICamera(CameraGroup::getDefault());
            WindowSystemAdapter* wsa = WindowSystemAdapter::getWSA();
            osg::GraphicsContext* gc = 0;
            if (guiCamera)
                gc = guiCamera->getGraphicsContext();
            if (gc) {
                gc->add(genOp.get());
            } else {
                wsa->windows[0]->gc->add(genOp.get());
            }
            guiStartInit(gc);
        } else if ( idle_state == 1 ) {
            if (genOp.valid()) {
                if (!genOp->isFinished())
                    return;
                genOp = 0;
            }
            if (!guiFinishInit())
                return;
            idle_state++;
            fgSplashProgress("reading aircraft list");
     
     
        } else if ( idle_state == 2 ) {
            idle_state++;
            // Read the list of available aircraft
            fgReadAircraft();
            fgSplashProgress("reading airport & navigation data");
     
     
        } else if ( idle_state == 3 ) {
            idle_state++;
            fgInitNav();
            fgSplashProgress("setting up scenery");
     
     
        } else if ( idle_state == 4 ) {
            idle_state++;
            // based on the requested presets, calculate the true starting
            // lon, lat
            fgInitPosition();
            fgInitTowerLocationListener();
     
            SGTime *t = fgInitTime();
            globals->set_time_params( t );
     
            // Do some quick general initializations
            if( !fgInitGeneral()) {
                SG_LOG( SG_GENERAL, SG_ALERT,
                    "General initialization failed ..." );
                exit(-1);
            }
     
            ////////////////////////////////////////////////////////////////////
            // Initialize the property-based built-in commands
            ////////////////////////////////////////////////////////////////////
            fgInitCommands();
     
     
            ////////////////////////////////////////////////////////////////////
            // Initialize the material manager
            ////////////////////////////////////////////////////////////////////
            globals->set_matlib( new SGMaterialLib );
            simgear::SGModelLib::init(globals->get_fg_root());
     
     
            ////////////////////////////////////////////////////////////////////
            // Initialize the TG scenery subsystem.
            ////////////////////////////////////////////////////////////////////
            globals->set_scenery( new FGScenery );
            globals->get_scenery()->init();
            globals->get_scenery()->bind();
            globals->set_tile_mgr( new FGTileMgr );
     
     
            ////////////////////////////////////////////////////////////////////
            // Initialize the general model subsystem.
            ////////////////////////////////////////////////////////////////////
            globals->set_model_mgr(new FGModelMgr);
            globals->get_model_mgr()->init();
            globals->get_model_mgr()->bind();
            fgSplashProgress("loading aircraft");
     
     
        } else if ( idle_state == 5 ) {
            idle_state++;
     
            ////////////////////////////////////////////////////////////////////
            // Initialize the 3D aircraft model subsystem (has a dependency on
            // the scenery subsystem.)
            ////////////////////////////////////////////////////////////////////
            globals->set_aircraft_model(new FGAircraftModel);
            globals->get_aircraft_model()->init();
            globals->get_aircraft_model()->bind();
     
            ////////////////////////////////////////////////////////////////////
            // Initialize the view manager subsystem.
            ////////////////////////////////////////////////////////////////////
            FGViewMgr *viewmgr = new FGViewMgr;
            globals->set_viewmgr( viewmgr );
            viewmgr->init();
            viewmgr->bind();
            fgSplashProgress("generating sky elements");
     
     
        } else if ( idle_state == 6 ) {
            idle_state++;
            // Initialize the sky
            SGPath ephem_data_path( globals->get_fg_root() );
            ephem_data_path.append( "Astro" );
            SGEphemeris *ephem = new SGEphemeris( ephem_data_path.c_str() );
            ephem->update( globals->get_time_params()->getMjd(),
                           globals->get_time_params()->getLst(),
                           0.0 );
            globals->set_ephem( ephem );
     
            // TODO: move to environment mgr
            thesky = new SGSky;
            SGPath texture_path(globals->get_fg_root());
            texture_path.append("Textures");
            texture_path.append("Sky");
            for (int i = 0; i < FGEnvironmentMgr::MAX_CLOUD_LAYERS; i++) {
                SGCloudLayer * layer = new SGCloudLayer(texture_path.str());
                thesky->add_cloud_layer(layer);
            }
     
            SGPath sky_tex_path( globals->get_fg_root() );
            sky_tex_path.append( "Textures" );
            sky_tex_path.append( "Sky" );
            thesky->texture_path( sky_tex_path.str() );
     
            // The sun and moon diameters are scaled down numbers of the
            // actual diameters. This was needed to fit both the sun and the
            // moon within the distance to the far clip plane.
            // Moon diameter:    3,476 kilometers
            // Sun diameter: 1,390,000 kilometers
            thesky->build( 80000.0, 80000.0,
                           463.3, 361.8,
                           *globals->get_ephem(),
                           fgGetNode("/environment", true));
     
            // Initialize MagVar model
            SGMagVar *magvar = new SGMagVar();
            globals->set_mag( magvar );
     
     
                                        // kludge to initialize mag compass
                                        // (should only be done for in-flight
                                        // startup)
            // update magvar model
            globals->get_mag()->update( fgGetDouble("/position/longitude-deg")
                                        * SGD_DEGREES_TO_RADIANS,
                                        fgGetDouble("/position/latitude-deg")
                                        * SGD_DEGREES_TO_RADIANS,
                                        fgGetDouble("/position/altitude-ft")
                                        * SG_FEET_TO_METER,
                                        globals->get_time_params()->getJD() );
            double var = globals->get_mag()->get_magvar() * SGD_RADIANS_TO_DEGREES;
            fgSetDouble("/instrumentation/heading-indicator/offset-deg", -var);
            fgSetDouble("/instrumentation/heading-indicator-fg/offset-deg", -var);
     
     
            // airport = new ssgBranch;
            // airport->setName( "Airport Lighting" );
            // lighting->addKid( airport );
     
            // build our custom render states
            fgSplashProgress("initializing subsystems");
     
     
        } else if ( idle_state == 7 ) {
            idle_state++;
            // Initialize audio support
    #ifdef ENABLE_AUDIO_SUPPORT
     
            // Start the intro music
            if ( fgGetBool("/sim/startup/intro-music") ) {
                SGPath mp3file( globals->get_fg_root() );
                mp3file.append( "Sounds/intro.mp3" );
     
                SG_LOG( SG_GENERAL, SG_INFO,
                    "Starting intro music: " << mp3file.str() );
     
    # if defined( __CYGWIN__ )
                string command = "start /m `cygpath -w " + mp3file.str() + "`";
    # elif defined( _WIN32 )
                string command = "start /m " + mp3file.str();
    # else
                string command = "mpg123 " + mp3file.str() + "> /dev/null 2>&1";
    # endif
     
                system ( command.c_str() );
            }
    #endif
            // This is the top level init routine which calls all the
            // other subsystem initialization routines.  If you are adding
            // a subsystem to flightgear, its initialization call should be
            // located in this routine.
            if( !fgInitSubsystems()) {
                SG_LOG( SG_GENERAL, SG_ALERT,
                    "Subsystem initialization failed ..." );
                exit(-1);
            }
            fgSplashProgress("setting up time & renderer");
     
     
        } else if ( idle_state == 8 ) {
            idle_state = 1000;
            // Initialize the time offset (warp) after fgInitSubsystem
            // (which initializes the lighting interpolation tables.)
            fgInitTimeOffset();
     
            // setup OpenGL view parameters
            globals->get_renderer()->init();
     
            SG_LOG( SG_GENERAL, SG_INFO, "Panel visible = " << fgPanelVisible() );
            globals->get_renderer()->resize( fgGetInt("/sim/startup/xsize"),
                                             fgGetInt("/sim/startup/ysize") );
     
            fgSplashProgress("loading scenery objects");
            int session = fgGetInt("/sim/session",0);
            session++;
            fgSetInt("/sim/session",session);
        }
     
        if ( idle_state == 1000 ) {
            // We've finished all our initialization steps, from now on we
            // run the main loop.
            fgSetBool("sim/sceneryloaded", false);
            fgRegisterIdleHandler( fgMainLoop );
        }
    }
     
     
    static void upper_case_property(const char *name)
    {
        using namespace simgear;
        SGPropertyNode *p = fgGetNode(name, false);
        if (!p) {
            p = fgGetNode(name, true);
            p->setStringValue("");
        } else {
            props::Type t = p->getType();
            if (t == props::NONE || t == props::UNSPECIFIED)
                p->setStringValue("");
            else
                assert(t == props::STRING);
        }
        p->addChangeListener(new FGMakeUpperCase);
    }

    est ce un rapport avec le callback, je ne comprends pas que l'on puisse crée une classe qui n'existe pas .

    au juste est ce que c'est une classe ou une fonction ?

    merci !

  2. #2
    Modérateur
    Avatar de bruno_pages
    Homme Profil pro
    ingénieur informaticien à la retraite
    Inscrit en
    Juin 2005
    Messages
    3 533
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 64
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : ingénieur informaticien à la retraite
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Juin 2005
    Messages : 3 533
    Points : 6 709
    Points
    6 709
    Par défaut
    Citation Envoyé par Asmod_D Voir le message
    les classe que je ne comprends pas est :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     fgIdleHandler ;
        fgDrawHandler ;
    car ce sont des classes qui n'existent pas .
    pourquoi dites vous qu'elles n'existent pas, vous avez un problème lors de la compilation ?

    qu'elle version de flightgear utilisez-vous ?

    je ne comprends pas que l'on puisse crée une classe qui n'existe pas .
    Par définition on crée ce qui n'existe pas, sinon ce n'est pas une création. Mais peut être voulez-vous parler de création d'instance et non de classe ?

    au juste est ce que c'est une classe ou une fonction ?
    à quoi s'applique cette question ?

    Votre message est relativement incompréhensible, si vous voulez qu'on puisse vous aider soyez plus clair
    Bruno Pagès, auteur de Bouml (freeware), mes tutoriels sur DVP (vieux, non à jour )

    N'oubliez pas de consulter les FAQ UML et les cours et tutoriels UML

  3. #3
    Membre actif
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    502
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 502
    Points : 227
    Points
    227
    Par défaut
    bonjour,

    j'utilise le code source de flightgear 2.0

    je suis désolé de mon message peu compréhensible .

    ce que j'essaye d'expliquer ce que je n'arrive pas à trouver ou est écrit la classe
    fgIdleHandler et fgDrawHandler dans le programme de flightgear.

    car fgIdleHandler et fgDrawHandler sont instanciées .


    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
    #ifndef FGEVENTHANDLER_H
    #define FGEVENTHANDLER_H 1
     
    #include <map>
    #include <osg/Quat>
    #include <osgGA/GUIEventHandler>
    #include <osgViewer/ViewerEventHandlers>
     
    #include "fg_os.hxx"
     
    namespace flightgear
    {
    class FGEventHandler : public osgGA::GUIEventHandler {
    public:
        FGEventHandler();
     
        virtual ~FGEventHandler() {}
     
        virtual const char* className() const {return "FGEventHandler"; }
    #if 0
        virtual void init(const osgGA::GUIEventAdapter& ea,
    		      osgGA::GUIActionAdapter& us);
    #endif
        virtual bool handle(const osgGA::GUIEventAdapter& ea,
    			osgGA::GUIActionAdapter& us);
     
        void setIdleHandler(fgIdleHandler idleHandler)
    	{
    	    this->idleHandler = idleHandler;
    	}
     
        fgIdleHandler getIdleHandler() const
    	{
    	    return idleHandler;
    	}
     
        void setDrawHandler(fgDrawHandler drawHandler)
    	{
    	    this->drawHandler = drawHandler;
    	}
     
        fgDrawHandler getDrawHandler() const
    	{
    	    return drawHandler;
    	}
     
        void setWindowResizeHandler(fgWindowResizeHandler windowResizeHandler)
    	{
    	    this->windowResizeHandler = windowResizeHandler;
    	}
     
        fgWindowResizeHandler getWindowResizeHandler() const
    	{
    	    return windowResizeHandler;
    	}
     
        void setKeyHandler(fgKeyHandler keyHandler)
    	{
    	    this->keyHandler = keyHandler;
    	}
     
        fgKeyHandler getKeyHandler() const
    	{
    	    return keyHandler;
    	}
     
        void setMouseClickHandler(fgMouseClickHandler mouseClickHandler)
    	{
    	    this->mouseClickHandler = mouseClickHandler;
    	}
     
        fgMouseClickHandler getMouseClickHandler()
    	{
    	    return mouseClickHandler;
    	}
     
        void setMouseMotionHandler(fgMouseMotionHandler mouseMotionHandler)
    	{
    	    this->mouseMotionHandler = mouseMotionHandler;
    	}
     
        fgMouseMotionHandler getMouseMotionHandler()
    	{
    	    return mouseMotionHandler;
    	}
     
        int getCurrentModifiers() const
    	{
    	    return currentModifiers;
    	}
     
        void setMouseWarped()
    	{
    	    mouseWarped = true;
    	}
     
        /** Whether or not resizing is supported. It might not be when
         * using multiple displays.
         */
        bool getResizable() { return resizable; }
        void setResizable(bool _resizable) { resizable = _resizable; }
     
    protected:
        osg::ref_ptr<osg::Node> _node;
        fgIdleHandler idleHandler;
        fgDrawHandler drawHandler;
        fgWindowResizeHandler windowResizeHandler;
        fgKeyHandler keyHandler;
        fgMouseClickHandler mouseClickHandler;
        fgMouseMotionHandler mouseMotionHandler;
        osg::ref_ptr<osgViewer::StatsHandler> statsHandler;
        osg::ref_ptr<osgGA::GUIEventAdapter> statsEvent;
        int statsType;
        int currentModifiers;
        std::map<int, int> numlockKeyMap;
        void handleKey(const osgGA::GUIEventAdapter& ea, int& key, int& modifiers);
        bool resizable;
        bool mouseWarped;
        // workaround for osgViewer double scroll events
        bool scrollButtonPressed;
        int release_keys[128];
        void handleStats(osgGA::GUIActionAdapter& us);
    };
     
    void eventToWindowCoords(const osgGA::GUIEventAdapter* ea, double& x, double& y);
    void eventToWindowCoordsYDown(const osgGA::GUIEventAdapter* ea,
                                  double& x, double& y);
    }
    #endif

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    protected:
        osg::ref_ptr<osg::Node> _node;
        fgIdleHandler idleHandler;
        fgDrawHandler drawHandler;


    la classe FGEVENHANDLER.H donc cette classe inclus le fichier "fg_os.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
    #ifndef _FG_OS_HXX
    #define _FG_OS_HXX
     
    #ifdef HAVE_CONFIG_H
    #  include <config.h>
    #endif
     
    #include <string>
    #include <vector>
     
    #include <osg/ref_ptr>
    #include <osg/Camera>
    #include <osg/GraphicsContext>
     
     
    enum { MOUSE_BUTTON_LEFT,
           MOUSE_BUTTON_MIDDLE,
           MOUSE_BUTTON_RIGHT };
     
    enum { MOUSE_BUTTON_DOWN,
           MOUSE_BUTTON_UP };
     
    enum { MOUSE_CURSOR_NONE,
           MOUSE_CURSOR_POINTER,
           MOUSE_CURSOR_WAIT,
           MOUSE_CURSOR_CROSSHAIR,
           MOUSE_CURSOR_LEFTRIGHT,
           MOUSE_CURSOR_TOPSIDE,
           MOUSE_CURSOR_BOTTOMSIDE,
           MOUSE_CURSOR_LEFTSIDE,
           MOUSE_CURSOR_RIGHTSIDE,
           MOUSE_CURSOR_TOPLEFT,
           MOUSE_CURSOR_TOPRIGHT,
           MOUSE_CURSOR_BOTTOMLEFT,
           MOUSE_CURSOR_BOTTOMRIGHT,
    };
     
    enum { KEYMOD_NONE     = 0,
           KEYMOD_RELEASED = 1, // Not a mod key, indicates "up" action
           KEYMOD_SHIFT    = 2,
           KEYMOD_CTRL     = 4,
           KEYMOD_ALT      = 8,
           KEYMOD_META     = 16,
           KEYMOD_SUPER    = 32,
           KEYMOD_HYPER    = 64,
           KEYMOD_MAX      = 128 };
     
    // A note on key codes: none are defined here.  FlightGear has no
    // hard-coded interpretations of codes other than modifier keys, so we
    // can get away with that.  The only firm requirement is that the
    // codes passed to the fgKeyHandler function be correctly interpreted
    // by the PUI library.  Users who need to hard-code key codes
    // (probably not a good idea in any case) can use the pu.hxx header
    // for definitions.
     
    //
    // OS integration functions
    //
     
    void fgOSInit(int* argc, char** argv);
    void fgOSOpenWindow(bool stencil);
    void fgOSFullScreen();
    void fgOSMainLoop();
    void fgOSExit(int code);
     
    void fgSetMouseCursor(int cursor);
    int  fgGetMouseCursor();
    void fgWarpMouse(int x, int y);
     
    int  fgGetKeyModifiers();
     
    void fgRequestRedraw();
     
    //
    // Callbacks and registration API
    //
     
    namespace osg { class Camera; class GraphicsContext; }
    namespace osgGA { class GUIEventAdapter; }
     
    typedef void (*fgIdleHandler)();
    typedef void (*fgDrawHandler)();
    typedef void (*fgWindowResizeHandler)(int w, int h);
     
    typedef void (*fgKeyHandler)(int key, int keymod, int mousex, int mousey);
    typedef void (*fgMouseClickHandler)(int button, int updown, int x, int y, bool mainWindow, const osgGA::GUIEventAdapter*);
    typedef void (*fgMouseMotionHandler)(int x, int y);
     
    void fgRegisterIdleHandler(fgIdleHandler func);
    void fgRegisterDrawHandler(fgDrawHandler func);
    void fgRegisterWindowResizeHandler(fgWindowResizeHandler func);
     
    void fgRegisterKeyHandler(fgKeyHandler func);
    void fgRegisterMouseClickHandler(fgMouseClickHandler func);
    void fgRegisterMouseMotionHandler(fgMouseMotionHandler func);
    #endif // _FG_OS_HXX
    le fichier "fg_os.h" ne decrit pas les classe fgIdleHandler et fgDrawHandler

    c'est pourquoi que je ne comprends pas comment est déclaré fgidlerHandler et fgDrawhandler

    j'espere que j'ai été un peu plus clair

    merci

  4. #4
    Membre confirmé
    Avatar de haraelendil
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2004
    Messages
    283
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Février 2004
    Messages : 283
    Points : 533
    Points
    533
    Par défaut
    Si ça compile, c'est forcément qu'elles sont déclarées quelque part.
    Si ce n'est pas directement dans fg_os.hxx, c'est surement dans un des fichiers qu'il inclut...

  5. #5
    Modérateur
    Avatar de bruno_pages
    Homme Profil pro
    ingénieur informaticien à la retraite
    Inscrit en
    Juin 2005
    Messages
    3 533
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 64
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : ingénieur informaticien à la retraite
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Juin 2005
    Messages : 3 533
    Points : 6 709
    Points
    6 709
    Par défaut
    j'ai téléchargé la chose pour les chercher dans les sources, ceux-ci sont bien définis src/Main/fg_os.hxx :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    typedef void (*fgIdleHandler)();
    typedef void (*fgDrawHandler)();
    il ne s'agit donc pas de classe, mais dans les deux cas d'un type pointeur sur une fonction sans argument ni valeur de retour (void)
    Bruno Pagès, auteur de Bouml (freeware), mes tutoriels sur DVP (vieux, non à jour )

    N'oubliez pas de consulter les FAQ UML et les cours et tutoriels UML

  6. #6
    Membre actif
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    502
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 502
    Points : 227
    Points
    227
    Par défaut
    merci de m'avoir répondu .

    pourriez vous me dire comment fonctionne un pointeur sur une fonction ?

    est ce normal de donner une variable a un pointeur de fonction ?

    merci encore !

  7. #7
    Expert éminent sénior
    Avatar de koala01
    Homme Profil pro
    aucun
    Inscrit en
    Octobre 2004
    Messages
    11 614
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : Belgique

    Informations professionnelles :
    Activité : aucun

    Informations forums :
    Inscription : Octobre 2004
    Messages : 11 614
    Points : 30 626
    Points
    30 626
    Par défaut
    Salut,

    Le pointeur de fonction permet, en gros, d'appeler n'importe quel fonction qui présente la signature adéquate.

    Mettons donc que tu aies un pointeur sur fonction ne renvoyant rien et ne prenant aucun argument ( void (*pointeurFonction)() ).

    Tu pourra lui passer toute fonction qui... ne renvoie rien et ne prend aucun argument

    Ainsi tu peux lui passer les fonctions
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    void doSomething();
    void doOtherthing();
    mais pas la fonction
    parce qu'elle... renvoie un int ni la fonction
    parce qu'elle... demande un int en paramètre

    Pour la suite de ta question, il faut "simplement" comprendre qu'un pointeur n'est jamais... qu'une variable un peu particulière en cela qu'elle représente... l'adresse mémoire à laquelle on trouvera effectivement la "chose attendue".

    Comme le début se trouve bel et bien à une adresse mémoire donnée (comme toute chose en informatique ) on peut donc bel et bien envisager d'utiliser un pointeur... de fonction comme s'il s'agissait d'une variable.

    Cette manière d'envisager les choses est généralement appelée un "callback" car cela permet de signaler dans la logique d'exécution qu'une fonction sera appelée tout en laissant le codeur préciser quelle fonction sera effectivement appelée en fonction du contexte

    Ceci dit, il existe, en C++ un système qui est presque encore mieux: le foncteur et son pendant le prédicat (entrée suivante dans la FAQ ). Il s'agit réellement d' "objet fonction"
    A méditer: La solution la plus simple est toujours la moins compliquée
    Ce qui se conçoit bien s'énonce clairement, et les mots pour le dire vous viennent aisément. Nicolas Boileau
    Compiler Gcc sous windows avec MinGW
    Coder efficacement en C++ : dans les bacs le 17 février 2014
    mon tout nouveau blog

  8. #8
    Membre actif
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    502
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 502
    Points : 227
    Points
    227
    Par défaut
    merci à vos tous pour vos réponses .

    je comprends mieux maintenant les pointeurs de fonctions.

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

Discussions similaires

  1. Probleme avec une class construite à partir d'un Tform
    Par Dereck07 dans le forum Débuter
    Réponses: 4
    Dernier message: 24/10/2010, 15h57
  2. Probleme avec une class qui traite la date
    Par tarikmahf dans le forum Collection et Stream
    Réponses: 3
    Dernier message: 10/11/2008, 22h12
  3. Probleme avec une classe d'association
    Par bassim dans le forum UML
    Réponses: 7
    Dernier message: 18/04/2007, 14h42
  4. [débutant] probleme avec une classe arbre
    Par go_all_in dans le forum C++
    Réponses: 17
    Dernier message: 08/06/2006, 10h33
  5. Probleme avec une class template
    Par lenectar dans le forum Langage
    Réponses: 2
    Dernier message: 01/03/2006, 10h49

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