PolyEvent.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. Copyright (C) 2011 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #pragma once
  20. #include "PolyGlobals.h"
  21. #include "PolyString.h"
  22. namespace Polycode {
  23. class EventDispatcher;
  24. /**
  25. * Event base class. Subclass this class to pass complex data through events.
  26. */
  27. class _PolyExport Event : public PolyBase {
  28. public:
  29. /**
  30. * Default constructor.
  31. */
  32. Event();
  33. /**
  34. * Initializes the event with an eventCode
  35. * @param eventCode Event code to initalize with.
  36. */
  37. Event(int eventCode);
  38. virtual ~Event();
  39. /**
  40. * Returns the event code for this event.
  41. * @return Event code for the event.
  42. */
  43. int getEventCode() const;
  44. /**
  45. * Returns the event dispatcher which originated the event.
  46. * @return Event dispatcher which originated the event.
  47. */
  48. EventDispatcher *getDispatcher() const;
  49. void setEventCode(int eventCode);
  50. void setDispatcher(EventDispatcher *dispatcher);
  51. const String& getEventType() const;
  52. void cancelEvent();
  53. // In order to prevent "namespace" collisions between events of different types, all event integers must be unique.
  54. // This is managed by arbitrarily assigning each class a "base" constant, and adding it to all its event type constants.
  55. // Bases for all Polycode classes are documented below, third party event types should be EVENTBASE_NONPOLYCODE or over.
  56. // Note that collisions are usually safe as long as collisions do not occur between a class and its subclass.
  57. // Event 0x100
  58. // Core 0x200
  59. // PlatformCore 0x300 (e.g. CocoaCore, WinCore etc)
  60. // InputEvent 0x400
  61. // SocketEvent 0x500
  62. // ClientEvent 0x600
  63. // ServerEvent 0x700
  64. // PhysicsScreenEvent 0x800
  65. // PhysicsSceneEvent 0x900
  66. // UIEvent 0xA00
  67. // UITreeEvent 0xB00
  68. static const int EVENTBASE_EVENT = 0x100;
  69. static const int COMPLETE_EVENT = EVENTBASE_EVENT+0;
  70. static const int CHANGE_EVENT = EVENTBASE_EVENT+1;
  71. static const int CANCEL_EVENT = EVENTBASE_EVENT+2;
  72. static const int NOTIFY_EVENT = EVENTBASE_EVENT+3;
  73. static const int FIRE_EVENT = EVENTBASE_EVENT+4;
  74. static const int RESOURCE_RELOAD_EVENT = EVENTBASE_EVENT+5;
  75. static const int SELECT_EVENT = EVENTBASE_EVENT+6;
  76. static const int REMOVE_EVENT = EVENTBASE_EVENT+7;
  77. static const int RESOURCE_CHANGE_EVENT = EVENTBASE_EVENT+8;
  78. static const int EVENTBASE_NONPOLYCODE = 0x10000;
  79. bool deleteOnDispatch;
  80. bool cancelEventFlag;
  81. protected:
  82. String eventType;
  83. EventDispatcher *dispatcher;
  84. int eventCode;
  85. };
  86. }