(no subject)

New Message Reply Date view Thread view Subject view Author view

From: sean spicer (spicer_sean++at++hotmail.com)
Date: 10/31/2001 07:25:11


Hi Erik,

I'm not sure this helps, but I've recently written some event handling code
in performer that works fine on Linux. Below are the critical methods
(somewhat simplified):

//--------------------------------------------------------------------
//
// Description:
// Initialize the application
//
// Use: public
//
int PerformerApplication::pr_init() {

    //----------------------------------------------------------------
    // Initialize Performer
    //
    pfInit();

    //----------------------------------------------------------------
    // Set the Multipipe mode
    //
    pfMultipipe(_numPipes);

    //----------------------------------------------------------------
    // Set the multiprocess mode
    //
    pfMultiprocess(_multiProcessMode);

    //----------------------------------------------------------------
    // Configure Performer, and fork processes.
    //
    pfConfig();

    //----------------------------------------------------------------
    // Initialize Performer utils
    //
    pfuInit();

    //----------------------------------------------------------------
    // Create window decorations if desired. This is not the best
    // way to do this...I know.
    //
    if(_useWindowDecorations == true) {

        int xOrigin, yOrigin, winWidth, winHeight;

        getWindowOriginSize(xOrigin, yOrigin, winWidth, winHeight);

        register int i;
        for(i=0; i<_numPipes; ++i) {

            pfPipe *p = pfGetPipe(i);
            pfPipeWindow *pw = new pfPipeWindow(p);
            pw->setName(getAppName().c_str());
            pw->setOriginSize(xOrigin, yOrigin,
                              winWidth, winHeight);

            pw->open();

        }

    }

    pfPipe *p = pfGetPipe(0);
    pfPipeWindow *pw = p->getPWin(0);
    pfuInitInput(pw, PFUINPUT_X);

    //----------------------------------------------------------------
    // Initialize pipes.
    //
    pr_initPipes();

    //----------------------------------------------------------------
    // Initialize channels. Default is one-per-pipe, this must be
    // done after the windows are open.
    //
    pr_initChannels();

}

//--------------------------------------------------------------------
//
// Description:
// Process events from inside the application
//
// Use: protected
//
void PerformerApplication::processEvents() {

    pfuGetEvents(&_events);
    pfuGetMouse(&_mouse);
    pr_processEvents(_events, _mouse);

}

//--------------------------------------------------------------------
//
// Description:
// process application events
//
// Use: private
//
void PerformerApplication::pr_processEvents(pfuEventStream &events,
                                            pfuMouse &mouse) {

    int numDevs = events.numDevs;

    register int i=0, j=0;
    int key;
    int dev;

    //---------------------------------------------------------------
    // Handle Key events and others.
    //
    for(i=0;i<numDevs;++i) {

        dev = events.devQ[i];

        if(events.devCount[dev] > 0) {

            switch(dev) {

            case PFUDEV_REDRAW:
                events.devCount[dev] = 0; // Mark done
                break;

            case PFUDEV_WINQUIT:
                setQuitFlag(true);
                break;

            case PFUDEV_KEYBD:
                for(j=0;j<events.numKeys; ++j) {

                    key = events.keyQ[j];
                    if(events.keyCount[key]) {

                        notifyKeyListeners(key);

                    }
                    events.keyCount[key] = 0; // Reset the key
                }
                break;
            }
        }
    }
    events.numDevs = 0;

    //----------------------------------------------------------------
    // Handle Left Mouse button events.
    //
    if( (mouse.click & PFUDEV_MOUSE_LEFT_DOWN) && _leftMouseDown == false) {
        _leftMouseDown = true;
        notifyMouseListeners(EventDrivenApplication::LEFT_MOUSE_DOWN,
                             mouse.xpos, mouse.ypos);
    } else if (mouse.release & PFUDEV_MOUSE_LEFT_DOWN
               && _leftMouseDown == true) {
        _leftMouseDown = false;
        notifyMouseListeners(EventDrivenApplication::LEFT_MOUSE_UP,
                             mouse.xpos, mouse.ypos);
    } else if (_leftMouseDown == true) {
        notifyMouseListeners(EventDrivenApplication::LEFT_MOUSE_MOVING,
                             mouse.xpos, mouse.ypos);
    }

    //----------------------------------------------------------------
    // Handle Midddle Mouse button events.
    //
    if( (mouse.click & PFUDEV_MOUSE_MIDDLE_DOWN) &&
        _middleMouseDown == false) {
        notifyMouseListeners(EventDrivenApplication::MIDDLE_MOUSE_DOWN,
                             mouse.xpos, mouse.ypos);
        _middleMouseDown = true;
    } else if (mouse.release & PFUDEV_MOUSE_MIDDLE_DOWN
               && _middleMouseDown == true) {
        notifyMouseListeners(EventDrivenApplication::MIDDLE_MOUSE_UP,
                             mouse.xpos, mouse.ypos);

        _middleMouseDown = false;
    } else if (_middleMouseDown == true) {
        notifyMouseListeners(EventDrivenApplication::MIDDLE_MOUSE_MOVING,
                             mouse.xpos, mouse.ypos);
    }

    //----------------------------------------------------------------
    // Handle Right Mouse button events.
    //
    if( (mouse.click & PFUDEV_MOUSE_RIGHT_DOWN) && _rightMouseDown == false)
{
        notifyMouseListeners(EventDrivenApplication::RIGHT_MOUSE_DOWN,
                             mouse.xpos, mouse.ypos);
        _rightMouseDown = true;
    } else if (mouse.release & PFUDEV_MOUSE_RIGHT_DOWN
               && _rightMouseDown == true) {
        notifyMouseListeners(EventDrivenApplication::RIGHT_MOUSE_UP,
                             mouse.xpos, mouse.ypos);
        _rightMouseDown = false;
    } else if (_rightMouseDown == true) {
        notifyMouseListeners(EventDrivenApplication::RIGHT_MOUSE_MOVING,
                             mouse.xpos, mouse.ypos);
    }

}

//--------------------------------------------------------------------
//
// Description:
// process application keyboard events
//
// Use: protected
//
void PerformerApplication::handleKeyboardEvent(short key) {

    switch (key) {

    case 27: // Esc key
    case 'q':
    case 'Q':
        setQuitFlag(true);
        break;

    default: // Unsupported input.
        break;
    }

}

Hopefully that'll get you started !

cheers,

sean

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Wed Oct 31 2001 - 07:23:13 PST

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.