paragui-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[paragui-dev] Patch: SDL Event source customization


From: Martin Bickel
Subject: [paragui-dev] Patch: SDL Event source customization
Date: Sat, 14 May 2005 20:09:58 +0200

Hi,

I've written a mechanism for Paragui 1.2 development branch which
allows the user to customize the way Paragui obtains SDL_Events.
There's an interface class SDL_EventSupplier defining abstract virtual
methods for gettings events. 
Paragui now uses by default the PG_SDLEventSupplier and behaves just
like before. With PG_Application::SetEventSupplier a different event
source can be registered.
The default EventSupplier also fixes a bug: skipped SDL_MouseMotion
events caused wrong relative mouse pointer motion information.



Bye,
  Martin

Attachment: eventsupplier.patch
Description: Binary data

/*
    ParaGUI - crossplatform widgetset
    Copyright (C) 2000,2001,2002  Alexander Pipelka
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.
 
    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.
 
    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
    Alexander Pipelka
    address@hidden
 
    Last Update:      $Author: braindead $
    Update Date:      $Date: 2004/12/30 07:10:21 $
    Source File:      $Source: 
/cvsroot/paragui/paragui/include/pgapplication.h,v $
    CVS/RCS Revision: $Revision: 1.3.6.9.2.21 $
    Status:           $State: Exp $
*/

/** \file pgsdleventsupplier.h
 Header file for the PG_EventSupplier class.
 This include file defines the abstract PG_EventSupplier class 
*/

#ifndef PG_EVENTSUPPLIER_H
#define PG_EVENTSUPPLIER_H


#include "SDL.h"

/**
 @author Martin Bickel
 
 @short Interface for classes that supply SDL_Events to Paragui
 
        Paragui works with SDL_Events to obtain input and operating system 
events. Instead of getting them directly 
        from SDL it uses this interface, allowing the application to preprocess 
SDL_events or obtain them from an 
        application specific event source.
*/
class DECLSPEC PG_EventSupplier {
public:


        /**
        Polls for currently pending events, and returns true if there are any 
pending events, or false if there are none available. 
        If event is not NULL, the next event is removed from the queue and 
stored in that area.

        @param event pointer to an event structure
        @return  true - events are available
        */
        virtual bool PollEvent(SDL_Event* event) = 0;

        /**
        Checks if an event is in the queue. If there is, it will be copied into 
the event structure, 
        WITHOUT being removed from the event queue. 

        @param event pointer to an event structure
        @return  true - events are available
        */
        virtual bool PeepEvent(SDL_Event* event) = 0;


        /**
        Waits indefinitely for the next available event.

        @param event  pointer to an event structure
        @return  return 0 if there was an error while waiting for events        
        */
        virtual int WaitEvent(SDL_Event* event) = 0;

};

#endif // PG_EVENTSUPPLIER_H
/*
    ParaGUI - crossplatform widgetset
    Copyright (C) 2000,2001,2002  Alexander Pipelka
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.
 
    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.
 
    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
    Alexander Pipelka
    address@hidden
 
    Last Update:      $Author: braindead $
    Update Date:      $Date: 2004/12/01 11:28:22 $
    Source File:      $Source: 
/cvsroot/paragui/paragui/src/core/pgapplication.cpp,v $
    CVS/RCS Revision: $Revision: 1.2.4.22.2.21 $
    Status:           $State: Exp $
*/

#include "SDL.h"

#include "pgsdleventsupplier.h"

void PG_SDLEventSupplier::CombineMouseMotionEvents(SDL_Event* event) {
        if ( event->type == SDL_MOUSEMOTION ) {
                SDL_Event nextEvent;
                if ( PeepEvent ( &nextEvent ) )
                        if ( nextEvent.type == SDL_MOUSEMOTION ) {
                                int motionxrel = event->motion.xrel;
                                int motionyrel = event->motion.yrel;

                                // get the event from the queue
                                WaitEvent( event );

                                // add the motion distances of the last event
                                event->motion.xrel += motionxrel;
                                event->motion.yrel += motionyrel;
                        }
        }
}

bool PG_SDLEventSupplier::PeepEvent(SDL_Event* event) {
        return SDL_PeepEvents( event, 1, SDL_PEEKEVENT, 0xffffffff );
}


bool PG_SDLEventSupplier::PollEvent(SDL_Event* event) {
        bool eventAvail = SDL_PollEvent( event );
        if ( eventAvail )
                CombineMouseMotionEvents( event );
        return eventAvail;
}


int PG_SDLEventSupplier::WaitEvent(SDL_Event* event) {
        int res = SDL_WaitEvent( event );
        CombineMouseMotionEvents( event );
        return res;
}


/*
    ParaGUI - crossplatform widgetset
    Copyright (C) 2000,2001,2002  Alexander Pipelka
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.
 
    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.
 
    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
    Alexander Pipelka
    address@hidden
 
    Last Update:      $Author: braindead $
    Update Date:      $Date: 2004/12/30 07:10:21 $
    Source File:      $Source: 
/cvsroot/paragui/paragui/include/pgapplication.h,v $
    CVS/RCS Revision: $Revision: 1.3.6.9.2.21 $
    Status:           $State: Exp $
*/

/** \file pgsdleventsupplier.h
 Header file for the PG_EventSupplier class.
 This include file defines the abstract PG_EventSupplier class 
*/

#ifndef PG_SDLEVENTSUPPLIER_H
#define PG_SDLEVENTSUPPLIER_H

#include "pgeventsupplier.h"

/**
 @author Martin Bickel
 
 @short Classes which passes SDL_Events directly from SDL to Paragui
 
        No preprocessing or filtering takes place. 
*/

class DECLSPEC PG_SDLEventSupplier : public PG_EventSupplier {

protected:
        /**
        Mouse motion events can fill the event queue and should also be 
processed without much delay.
               This function is passed a newly received Event. It checks if it 
is a mouse motion event and, 
               if this is the case, checks the event queue for more mouse 
motion events, which are then incorporated
               into the current event and removed from the queue.

        @param event pointer to an event structure with a freshly received event
        */
        void CombineMouseMotionEvents(SDL_Event* event);

public:


        /**
        Polls for currently pending events, and returns true if there are any 
pending events, or false if there are none available. 
        If event is not NULL, the next event is removed from the queue and 
stored in that area.

        @param event pointer to an event structure
        @return  true - events are available
        */
        bool PollEvent(SDL_Event* event);

        /**
        Checks if an event is in the queue. If there is, it will be copied into 
the event structure, 
        WITHOUT being removed from the event queue. 

        @param event pointer to an event structure
        @return  true - events are available
        */
        bool PeepEvent(SDL_Event* event);


        /**
        Waits indefinitely for the next available event.

        @param event  pointer to an event structure
        @return  return 0 if there was an error while waiting for events        
        */
        int WaitEvent(SDL_Event* event);

};

#endif // PG_SDLEVENTSUPPLIER_H

reply via email to

[Prev in Thread] Current Thread [Next in Thread]