00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef OSDL_EVENTS_H_
00028 #define OSDL_EVENTS_H_
00029
00030
00031 #include "OSDLEventsCommon.h"
00032 #include "OSDLTypes.h"
00033 #include "OSDLException.h"
00034
00035 #include "Ceylan.h"
00036
00037
00038 #include <string>
00039
00040
00041
00042
00043 namespace OSDL
00044 {
00045
00046
00047
00048
00049 class CommonModule ;
00050
00051
00052
00053 namespace Engine
00054 {
00055
00056
00057 class Scheduler ;
00058
00059 }
00060
00061
00062
00063
00065 namespace Events
00066 {
00067
00068
00069
00070
00071 class KeyboardHandler ;
00072
00073
00074
00075
00076 class JoystickHandler ;
00077
00078
00079
00080
00081 class MouseHandler ;
00082
00083
00084
00092 typedef Ceylan::Uint32 Tick ;
00093
00094
00095
00102 typedef Tick EngineTick ;
00103
00104
00105
00114 typedef Tick SimulationTick ;
00115
00116
00117
00126 typedef Tick RenderingTick ;
00127
00128
00129
00138 typedef Tick InputTick ;
00139
00140
00141
00150 typedef EngineTick Period ;
00151
00152
00153
00160 typedef Ceylan::Uint8 BasicEventType ;
00161
00162
00163
00170 typedef Ceylan::Uint8 UserEventType ;
00171
00172
00173
00174
00236 class OSDL_DLL EventsModule : public Ceylan::Module
00237 {
00238
00239
00240
00241
00242 friend class OSDL::CommonModule ;
00243
00244
00245
00246 public:
00247
00248
00269 virtual void waitForAnyKey( bool displayWaitingMessage = true )
00270 const ;
00271
00272
00273
00292 virtual void waitForAnyUserInput() const ;
00293
00294
00295
00303 virtual bool hasPendingUserInput() const ;
00304
00305
00306
00314 virtual bool getGrabInputMode() const ;
00315
00316
00317
00327 virtual void setGrabInputMode( bool newMode ) ;
00328
00329
00330
00355 virtual bool sleepFor( Ceylan::System::Second seconds,
00356 Ceylan::System::Microsecond micros ) const ;
00357
00358
00359
00375 virtual void useScheduler( bool on = true ) ;
00376
00377
00378
00379
00385 virtual bool isGUIEnabled() const ;
00386
00387
00388
00396 virtual void setGUIEnableStatus( bool newStatus ) ;
00397
00398
00399
00400
00435 virtual void setIdleCallback(
00436 Ceylan::System::Callback idleCallback,
00437 void * callbackData = 0,
00438 Ceylan::System::Microsecond
00439 callbackExpectedMaxDuration = 0 ) ;
00440
00441
00442
00451 virtual void setEventLoopTargetFrequency(
00452 Ceylan::Maths::Hertz targetFrequency ) ;
00453
00454
00455
00471 virtual void enterMainLoop() ;
00472
00473
00474
00483 virtual void requestQuit() ;
00484
00485
00486
00487
00488
00489
00490
00491
00492
00497 virtual bool hasKeyboardHandler() const ;
00498
00499
00500
00507 virtual KeyboardHandler & getKeyboardHandler() const ;
00508
00509
00510
00520 virtual void setKeyboardHandler(
00521 KeyboardHandler & newHandler ) ;
00522
00523
00524
00525
00530 virtual bool hasJoystickHandler() const ;
00531
00532
00533
00540 virtual JoystickHandler & getJoystickHandler() const ;
00541
00542
00543
00553 virtual void setJoystickHandler(
00554 JoystickHandler & newHandler ) ;
00555
00556
00557
00558
00563 virtual bool hasMouseHandler() const ;
00564
00565
00566
00573 virtual MouseHandler & getMouseHandler() const ;
00574
00575
00576
00586 virtual void setMouseHandler( MouseHandler & newHandler ) ;
00587
00588
00589
00590
00602 virtual void updateInputState() ;
00603
00604
00605
00617 virtual const std::string toString(
00618 Ceylan::VerbosityLevels level = Ceylan::high ) const ;
00619
00620
00621
00622
00623
00624
00625
00626
00635 static std::string DescribeEnvironmentVariables() ;
00636
00637
00638
00650 static bool IsEventsInitialized() ;
00651
00652
00653
00665 static Ceylan::System::Millisecond
00666 GetMillisecondsSinceStartup() ;
00667
00668
00669
00671 static std::string DescribeEvent(
00672 const FocusEvent & focusEvent ) ;
00673
00674
00675
00677 static std::string DescribeEvent(
00678 const KeyboardEvent & keyboardEvent ) ;
00679
00680
00681
00683 static std::string DescribeEvent(
00684 const MouseMotionEvent & mouseMotionEvent ) ;
00685
00686
00687
00689 static std::string DescribeEvent(
00690 const MouseButtonEvent & mouseButtonEvent ) ;
00691
00692
00693
00695 static std::string DescribeEvent(
00696 const JoystickAxisEvent & axisEvent ) ;
00697
00698
00699
00701 static std::string DescribeEvent(
00702 const JoystickTrackballEvent & ballEvent ) ;
00703
00704
00706 static std::string DescribeEvent(
00707 const JoystickHatEvent & hatEvent ) ;
00708
00709
00710
00712 static std::string DescribeEvent(
00713 const JoystickButtonEvent & buttonEvent ) ;
00714
00715
00716
00718 static std::string DescribeEvent(
00719 const UserRequestedQuitEvent & quitEvent ) ;
00720
00721
00722
00724 static std::string DescribeEvent(
00725 const SystemSpecificWindowManagerEvent &
00726 windowManagerEvent ) ;
00727
00728
00729
00731 static std::string DescribeEvent(
00732 const WindowResizedEvent & resizeEvent ) ;
00733
00734
00735
00737 static std::string DescribeEvent(
00738 const ScreenExposedEvent & redrawEvent ) ;
00739
00740
00741
00743 static std::string DescribeEvent(
00744 const UserEvent & userEvent ) ;
00745
00746
00747
00765 static Ceylan::System::Microsecond EvaluateCallbackduration(
00766 Ceylan::System::Callback callback,
00767 void * callbackData ) ;
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00779 static std::string DescribeEvent( BasicEvent anEvent ) ;
00780
00781
00782
00788 static const BasicEventType ApplicationFocusChanged ;
00789
00790
00791
00793 static const BasicEventType KeyPressed ;
00794
00795
00796
00798 static const BasicEventType KeyReleased ;
00799
00800
00801
00803 static const BasicEventType MouseMoved ;
00804
00805
00806
00808 static const BasicEventType MouseButtonPressed ;
00809
00810
00811
00816 static const BasicEventType MouseButtonReleased ;
00817
00818
00819
00821 static const BasicEventType JoystickAxisChanged ;
00822
00823
00824
00830 static const BasicEventType JoystickTrackballChanged ;
00831
00832
00833
00839 static const BasicEventType JoystickHatPositionChanged ;
00840
00841
00842
00848 static const BasicEventType JoystickButtonPressed ;
00849
00850
00851
00857 static const BasicEventType JoystickButtonReleased ;
00858
00859
00860
00866 static const BasicEventType UserRequestedQuit ;
00867
00868
00869
00875 static const BasicEventType SystemSpecificTriggered ;
00876
00877
00878
00884 static const BasicEventType UserResizedVideoMode ;
00885
00886
00887
00893 static const BasicEventType ScreenNeedsRedraw ;
00894
00895
00896
00898 static const BasicEventType FirstUserEventTriggered ;
00899
00900
00901
00903 static const BasicEventType LastUserEventTriggered ;
00904
00905
00906
00907
00908
00909
00910
00916 static const UserEventType NoEvent ;
00917
00918
00919
00921 static const UserEventType QuitRequested ;
00922
00923
00924
00926 static const Ceylan::Maths::Hertz
00927 DefaultEventLoopTargetedFrequency = 100 ;
00928
00929
00930
00931
00932
00933 protected:
00934
00935
00936
00950 virtual void enterBasicMainLoop() ;
00951
00952
00953
00954
00955
00956
00957
00958
00968 virtual void onKeyboardFocusGained(
00969 const FocusEvent & keyboardFocusEvent ) ;
00970
00971
00972
00984 virtual void onKeyboardFocusLost(
00985 const FocusEvent & keyboardFocusEvent ) ;
00986
00987
00994 virtual void onKeyPressed(
00995 const KeyboardEvent & keyboardEvent ) ;
00996
00997
00998
01005 virtual void onKeyReleased(
01006 const KeyboardEvent & keyboardEvent ) ;
01007
01008
01009
01010
01011
01012
01013
01014
01015
01025 virtual void onMouseFocusGained(
01026 const FocusEvent & mouseFocus ) ;
01027
01028
01029
01039 virtual void onMouseFocusLost(
01040 const FocusEvent & mouseFocus ) ;
01041
01042
01043
01050 virtual void onMouseMotion(
01051 const MouseMotionEvent & mouseEvent ) ;
01052
01053
01054
01061 virtual void onMouseButtonPressed(
01062 const MouseButtonEvent & mouseEvent ) ;
01063
01064
01065
01072 virtual void onMouseButtonReleased(
01073 const MouseButtonEvent & mouseEvent ) ;
01074
01075
01076
01077
01078
01079
01080
01081
01082
01091 virtual void onJoystickAxisChanged(
01092 const JoystickAxisEvent & joystickEvent ) ;
01093
01094
01095
01104 virtual void onJoystickTrackballChanged(
01105 const JoystickTrackballEvent & joystickEvent ) ;
01106
01107
01108
01117 virtual void onJoystickHatChanged(
01118 const JoystickHatEvent & joystickEvent ) ;
01119
01120
01121
01130 virtual void onJoystickButtonPressed(
01131 const JoystickButtonEvent & joystickEvent ) ;
01132
01133
01134
01143 virtual void onJoystickButtonReleased(
01144 const JoystickButtonEvent & joystickEvent ) ;
01145
01146
01147
01148
01149
01150
01151
01152
01153
01164 virtual void onIdle() ;
01165
01166
01167
01176 virtual void onApplicationFocusChanged(
01177 const FocusEvent & focusEvent ) ;
01178
01179
01180
01188 virtual void onApplicationIconified(
01189 const FocusEvent & focusEvent ) ;
01190
01191
01192
01200 virtual void onApplicationRestored(
01201 const FocusEvent & focusEvent ) ;
01202
01203
01204
01209 virtual void onQuitRequested() ;
01210
01211
01212
01222 virtual void onSystemSpecificWindowManagerEvent(
01223 const SystemSpecificWindowManagerEvent & wmEvent ) ;
01224
01225
01226
01237 virtual void onResizedWindow(
01238 const WindowResizedEvent & resizeEvent ) ;
01239
01240
01241
01248 virtual void onScreenNeedsRedraw() ;
01249
01250
01251
01258 virtual void onUserEvent( const UserEvent & userEvent ) ;
01259
01260
01261
01267 virtual void onUnknownEventType(
01268 const BasicEvent & unknownEvent ) ;
01269
01270
01271
01272
01273
01274
01275
01276
01277
01285 bool _useScheduler ;
01286
01287
01292 bool _isGuiEnabled ;
01293
01294
01299 KeyboardHandler * _keyboardHandler ;
01300
01301
01302
01307 JoystickHandler * _joystickHandler ;
01308
01309
01310
01315 MouseHandler * _mouseHandler ;
01316
01317
01318
01324 static const std::string _SDLEnvironmentVariables[] ;
01325
01326
01327
01329 bool _quitRequested ;
01330
01331
01332
01350 Ceylan::Maths::Hertz _loopTargetedFrequency ;
01351
01352
01353
01359 Ceylan::Uint32 _idleCallsCount ;
01360
01361
01362
01368 Ceylan::System::Callback _loopIdleCallback ;
01369
01370
01371
01377 void * _loopIdleCallbackData ;
01378
01379
01380
01388 Ceylan::System::Microsecond _loopIdleCallbackMaxDuration ;
01389
01390
01391
01392
01393
01394
01395
01396
01398 static bool _EventsInitialized ;
01399
01400
01401
01403 static const Ceylan::Uint32 _FrameTimingSlotsCount ;
01404
01405
01406
01408 static const Ceylan::Sint16 _MouseFocus ;
01409
01410
01411
01413 static const Ceylan::Sint16 _KeyboardFocus ;
01414
01415
01416
01418 static const Ceylan::Sint16 _ApplicationFocus ;
01419
01420
01421
01427 static const std::string _MessageHeader ;
01428
01429
01430
01435 static const Ceylan::Uint32 _MouseButtonCount ;
01436
01437
01438
01439
01440
01441 private:
01442
01443
01444
01460 explicit EventsModule( Ceylan::Flags eventsFlag ) ;
01461
01462
01463
01465 virtual ~EventsModule() throw() ;
01466
01467
01468
01477 explicit EventsModule( const EventsModule & source ) ;
01478
01479
01480
01489 EventsModule & operator = ( const EventsModule & source ) ;
01490
01491
01492 } ;
01493
01494
01495 }
01496
01497 }
01498
01499
01500
01501 #endif // OSDL_EVENTS_H_