OSDLEvents.h

Go to the documentation of this file.
00001 #ifndef OSDL_EVENTS_H_
00002 #define OSDL_EVENTS_H_
00003 
00004 
00005 #include "OSDLEventsCommon.h"    // for typedefs
00006 #include "OSDLTypes.h"           // for Flag
00007 #include "OSDLException.h"       // for OSDL::Exception
00008 
00009 #include "Ceylan.h"              // for Uint32, Flags, etc.
00010 
00011 #include "SDL.h"                 // for SDL_Event
00012 
00013 #include <string>
00014 
00015 
00016 
00017 namespace OSDL
00018 {
00019 
00020 
00021     // The event module is managed by the common module;
00022     class CommonModule ;
00023     
00024     
00025     namespace Engine
00026     {
00027     
00028         // The event module can use the scheduler.
00029         class Scheduler ;
00030     
00031     }
00032     
00033     
00034     
00036     namespace Events
00037     {
00038     
00039     
00040         // The event module can manage the keyboard.
00041         class KeyboardHandler ;
00042         
00043             
00044         // The event module can manage the joysticks.
00045         class JoystickHandler ;
00046         
00047         
00048         // The event module can manage a mouse.
00049         class MouseHandler ;
00050         
00051         
00052         
00060         typedef Ceylan::Uint32 Tick ;
00061         
00062         
00069         typedef Tick EngineTick ;
00070         
00071         
00080         typedef Tick SimulationTick ;
00081         
00082         
00091         typedef Tick RenderingTick ;
00092     
00093     
00102         typedef Tick InputTick ;
00103         
00104 
00114         typedef Ceylan::Uint32 Hertz ;
00115 
00116 
00125         typedef EngineTick Period ;
00126 
00127         
00134         typedef Ceylan::Uint8 BasicEventType  ;
00135         
00136         
00143         typedef Ceylan::Uint8 UserEventType ;
00144                         
00145 
00146             
00204         class OSDL_DLL EventsModule : public Ceylan::Module
00205         {
00206         
00207         
00208             // The common module has to create the event module.
00209             friend class OSDL::CommonModule ;
00210                     
00211             
00212             
00213             public:
00214 
00215                             
00229                 virtual void waitForAnyKey( bool displayWaitingMessage = true ) 
00230                     const throw() ; 
00231 
00232 
00257                 virtual bool sleepFor( Ceylan::System::Second seconds, 
00258                         Ceylan::System::Microsecond micros ) 
00259                     const throw( EventsException ) ; 
00260 
00261                 
00277                  virtual void useScheduler( bool on = true ) throw() ;
00278                                   
00279 
00280                 
00315                 virtual void setIdleCallback( 
00316                     Ceylan::System::Callback idleCallback, 
00317                     void * callbackData = 0, 
00318                     Ceylan::System::Microsecond 
00319                         callbackExpectedMaxDuration = 0 ) throw() ;
00320                             
00321                 
00330                 virtual void setEventLoopTargetFrequency( 
00331                     Hertz targetFrequency ) throw() ;
00332                 
00333                                                         
00348                 virtual void enterMainLoop() throw( EventsException ) ;
00349 
00350 
00361                 virtual void requestQuit() throw() ;
00362                 
00363 
00364 
00365 
00366                 // Handler subsection.
00367                 
00368                 
00373                 virtual bool hasKeyboardHandler() const throw() ;
00374                  
00375                 
00382                 virtual KeyboardHandler & getKeyboardHandler() const 
00383                     throw( EventsException ) ;
00384                                                             
00385 
00395                 virtual void setKeyboardHandler( 
00396                     KeyboardHandler & newHandler ) throw() ;
00397                     
00398                                     
00399                  
00400                  
00405                 virtual bool hasJoystickHandler() const throw() ;
00406                  
00407                 
00414                 virtual JoystickHandler & getJoystickHandler() 
00415                     const throw( EventsException ) ;
00416                                                             
00417 
00427                 virtual void setJoystickHandler( 
00428                     JoystickHandler & newHandler ) throw() ;
00429                     
00430 
00431 
00436                 virtual bool hasMouseHandler() const throw() ;
00437                  
00438                 
00445                 virtual MouseHandler & getMouseHandler() const 
00446                     throw( EventsException ) ;
00447                                                             
00448 
00458                 virtual void setMouseHandler( 
00459                     MouseHandler & newHandler ) throw() ;
00460                     
00461                     
00462                     
00463                                     
00475                 virtual void updateInputState() throw() ;
00476                 
00477                     
00489                 virtual const std::string toString( 
00490                         Ceylan::VerbosityLevels level = Ceylan::high ) 
00491                     const throw() ;
00492 
00493 
00494                 
00495                 // Static section.
00496                 
00497                     
00506                 static std::string DescribeEnvironmentVariables() throw() ; 
00507 
00508 
00509 
00521                 static bool IsEventsInitialized() throw() ;
00522         
00523     
00535                 static Ceylan::System::Millisecond GetMillisecondsSinceStartup()
00536                     throw( EventsException ) ; 
00537 
00538 
00540                 static std::string DescribeEvent( 
00541                     const FocusEvent & focusEvent ) ;
00542                 
00543                 
00545                 static std::string DescribeEvent( 
00546                     const KeyboardEvent & keyboardEvent ) ;
00547                                 
00548                 
00550                 static std::string DescribeEvent( 
00551                     const MouseMotionEvent & mouseMotionEvent ) ;
00552                 
00553                 
00555                 static std::string DescribeEvent( 
00556                     const MouseButtonEvent & mouseButtonEvent ) ;
00557                 
00558                 
00560                 static std::string DescribeEvent( 
00561                     const JoystickAxisEvent & axisEvent ) ;
00562                 
00563                 
00565                 static std::string DescribeEvent( 
00566                     const JoystickTrackballEvent & ballEvent ) ;
00567                 
00568                 
00570                 static std::string DescribeEvent( 
00571                     const JoystickHatEvent & hatEvent ) ;
00572                 
00573                 
00575                 static std::string DescribeEvent( 
00576                     const JoystickButtonEvent & buttonEvent ) ;
00577                 
00578                 
00580                 static std::string DescribeEvent( 
00581                     const UserRequestedQuitEvent & quitEvent ) ;
00582                 
00583                 
00585                 static std::string DescribeEvent( 
00586                     const SystemSpecificWindowManagerEvent & 
00587                         windowManagerEvent ) ;
00588                 
00589                 
00591                 static std::string DescribeEvent( 
00592                     const WindowResizedEvent & resizeEvent ) ;
00593                 
00595                 static std::string DescribeEvent( 
00596                     const ScreenExposedEvent & redrawEvent ) ;
00597                 
00599                 static std::string DescribeEvent( 
00600                     const UserEvent & userEvent ) ;
00601                 
00602                 
00620                 static Ceylan::System::Microsecond EvaluateCallbackduration(
00621                     Ceylan::System::Callback callback,
00622                     void * callbackData ) throw() ;
00623     
00624     
00625     
00626                 /*
00627                  * Basic event types, used to discriminate in the generic
00628                  * event structure which is the actual type.
00629                  *
00630                  */
00631                                                 
00632                 
00634                 static std::string DescribeEvent( BasicEvent anEvent ) throw() ;
00635                   
00636     
00642                 static const BasicEventType ApplicationFocusChanged ;
00643                                 
00645                 static const BasicEventType KeyPressed ;
00646                 
00648                 static const BasicEventType KeyReleased ;
00649                 
00651                 static const BasicEventType MouseMoved ;
00652                 
00654                 static const BasicEventType MouseButtonPressed ;
00655                 
00656                 
00662                 static const BasicEventType MouseButtonReleased ;
00663                 
00664                 
00666                 static const BasicEventType JoystickAxisChanged ;
00667                 
00668                 
00674                 static const BasicEventType JoystickTrackballChanged ;
00675                 
00676                 
00682                 static const BasicEventType JoystickHatPositionChanged ;
00683                 
00684                 
00690                 static const BasicEventType JoystickButtonPressed ;
00691                 
00692                 
00698                 static const BasicEventType JoystickButtonReleased ;
00699                 
00700                 
00706                 static const BasicEventType UserRequestedQuit ;
00707                 
00708                 
00714                 static const BasicEventType SystemSpecificTriggered ;
00715                 
00716                 
00722                 static const BasicEventType UserResizedVideoMode ;
00723                 
00724                 
00730                 static const BasicEventType ScreenNeedsRedraw ;
00731                 
00732                 
00734                 static const BasicEventType FirstUserEventTriggered ;
00735                 
00737                 static const BasicEventType LastUserEventTriggered ;
00738                 
00739                                 
00740                 // User event types :
00741                 
00747                 static const UserEventType NoEvent ;
00748                 
00749                 
00751                 static const UserEventType QuitRequested ;
00752                 
00753                                             
00755                 static const Hertz DefaultEventLoopTargetedFrequency = 100 ;
00756                 
00757                 
00758                 
00759                 
00760         protected :
00761         
00762         
00763 
00777                 virtual void enterBasicMainLoop() throw( EventsException ) ;
00778                         
00779         
00780                 
00781                 
00782                 // Keyboard section.
00783                 
00784             
00794                 virtual void onKeyboardFocusGained( 
00795                     const FocusEvent & keyboardFocusEvent ) throw() ;   
00796 
00797                 
00808                 virtual void onKeyboardFocusLost(
00809                     const FocusEvent & keyboardFocusEvent ) throw() ;   
00810                 
00811                 
00818                 virtual void onKeyPressed( 
00819                     const KeyboardEvent & keyboardEvent ) throw() ;
00820         
00821         
00828                 virtual void onKeyReleased( 
00829                     const KeyboardEvent & keyboardEvent ) throw() ;
00830         
00831     
00832     
00833     
00834                 // Mouse section.
00835                 
00836                             
00846                 virtual void onMouseFocusGained( 
00847                     const FocusEvent & mouseFocus ) throw() ;   
00848 
00849                 
00859                 virtual void onMouseFocusLost( 
00860                     const FocusEvent & mouseFocus ) throw() ;   
00861                 
00862         
00863         
00870                 virtual void onMouseMotion( 
00871                     const MouseMotionEvent & mouseEvent ) throw() ; 
00872                 
00873         
00880                 virtual void onMouseButtonPressed( 
00881                     const MouseButtonEvent & mouseEvent ) throw() ; 
00882                 
00883                 
00890                 virtual void onMouseButtonReleased( 
00891                     const MouseButtonEvent & mouseEvent ) throw() ; 
00892                 
00893                 
00894                 
00895 
00896                 // Joystick section.
00897                 
00898                 
00907                 virtual void onJoystickAxisChanged( 
00908                     const JoystickAxisEvent & joystickEvent ) throw() ; 
00909                 
00910                 
00919                 virtual void onJoystickTrackballChanged( 
00920                     const JoystickTrackballEvent & joystickEvent ) throw() ; 
00921                 
00922                 
00931                 virtual void onJoystickHatChanged( 
00932                     const JoystickHatEvent & joystickEvent ) throw() ; 
00933                 
00934                 
00943                 virtual void onJoystickButtonPressed( 
00944                     const JoystickButtonEvent & joystickEvent ) throw() ; 
00945                 
00946                 
00955                 virtual void onJoystickButtonReleased( 
00956                         const JoystickButtonEvent & joystickEvent ) 
00957                     throw() ; 
00958                 
00959                 
00960             
00961                 
00962                 // Application-generic section.
00963                 
00964                  
00974                 virtual void onIdle() throw() ;
00975                  
00976         
00985                 virtual void onApplicationFocusChanged( 
00986                     const FocusEvent & focusEvent ) throw() ;
00987                 
00988                 
00996                 virtual void onApplicationIconified(
00997                      const FocusEvent & focusEvent ) throw() ;  
00998 
00999                 
01007                 virtual void onApplicationRestored( 
01008                     const FocusEvent & focusEvent ) throw() ;   
01009 
01010 
01015                 virtual void onQuitRequested() throw() ;
01016                 
01017                                 
01026                 virtual void onSystemSpecificWindowManagerEvent( 
01027                     const SystemSpecificWindowManagerEvent & wmEvent ) throw() ;
01028                     
01029                 
01040                 virtual void onResizedWindow( 
01041                     const WindowResizedEvent & resizeEvent ) throw() ;
01042                 
01043                 
01050                 virtual void onScreenNeedsRedraw() throw() ;
01051                 
01052                 
01059                 virtual void onUserEvent( const UserEvent & userEvent ) 
01060                     throw() ;
01061     
01062 
01068                 virtual void onUnknownEventType( 
01069                     const BasicEvent & unknownEvent ) throw() ;
01070                 
01071                                     
01072                     
01073                  
01074                 // Section for protected attributes.
01075                                 
01076                                         
01084                 bool _useScheduler ;                
01085 
01086 
01091                 KeyboardHandler * _keyboardHandler ;
01092 
01093                  
01098                 JoystickHandler * _joystickHandler ;    
01099                                 
01100                                 
01105                 MouseHandler * _mouseHandler ;  
01106                                 
01107         
01108         
01114                 static std::string _SDLEnvironmentVariables[] ;
01115 
01116 
01118                 bool _quitRequested ;
01119                 
01120                 
01137                 Hertz _loopTargetedFrequency ;              
01138                 
01139                 
01145                 Ceylan::Uint32 _idleCallsCount ;
01146 
01147 
01153                 Ceylan::System::Callback _loopIdleCallback ;
01154                         
01155                                 
01161                 void * _loopIdleCallbackData ;              
01162                 
01163                 
01171                 Ceylan::System::Microsecond _loopIdleCallbackMaxDuration ;
01172                 
01173                 
01174                 
01175                 // Static section.
01176                 
01177                 
01179                 static bool _EventsInitialized ;
01180             
01181 
01183                 static const Ceylan::Uint32 _FrameTimingSlotsCount ;
01184                 
01185                 
01187                 static const Ceylan::Sint16 _MouseFocus ;
01188                 
01190                 static const Ceylan::Sint16 _KeyboardFocus ;
01191                 
01193                 static const Ceylan::Sint16 _ApplicationFocus ;
01194             
01195                 
01201                 static const std::string _MessageHeader ;
01202                 
01203                 
01208                 static const Ceylan::Uint32 _MouseButtonCount ;
01209             
01210                 
01211                 
01212                 
01213         private:
01214         
01215         
01231                 explicit EventsModule( Ceylan::Flags eventsFlag ) 
01232                     throw( EventsException ) ;
01233             
01234             
01236                 virtual ~EventsModule() throw() ;
01237                     
01238 
01247                 explicit EventsModule( const EventsModule & source ) throw() ;
01248             
01249             
01258                 EventsModule & operator = ( const EventsModule & source )
01259                     throw() ;
01260                 
01261         } ;
01262     
01263     }   
01264     
01265 }
01266 
01267 
01268 
01269 #endif // OSDL_EVENTS_H_
01270 

Generated on Fri Mar 30 14:46:59 2007 for OSDL by  doxygen 1.5.1