PolyEvent.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. // In order to prevent "namespace" collisions between events of different types, all event integers must be unique.
  53. // This is managed by arbitrarily assigning each class a "base" constant, and adding it to all its event type constants.
  54. // Bases for all Polycode classes are documented below, third party event types should be EVENTBASE_NONPOLYCODE or over.
  55. // Note that collisions are usually safe as long as collisions do not occur between a class and its subclass.
  56. // Event 0x100
  57. // Core 0x200
  58. // PlatformCore 0x300 (e.g. CocoaCore, WinCore etc)
  59. // InputEvent 0x400
  60. // SocketEvent 0x500
  61. // ClientEvent 0x600
  62. // ServerEvent 0x700
  63. // PhysicsScreenEvent 0x800
  64. // PhysicsSceneEvent 0x900
  65. // UIEvent 0xA00
  66. // UITreeEvent 0xB00
  67. static const int EVENTBASE_EVENT = 0x100;
  68. static const int COMPLETE_EVENT = EVENTBASE_EVENT+0;
  69. static const int CHANGE_EVENT = EVENTBASE_EVENT+1;
  70. static const int CANCEL_EVENT = EVENTBASE_EVENT+2;
  71. static const int EVENTBASE_NONPOLYCODE = 0x10000;
  72. bool deleteOnDispatch;
  73. protected:
  74. String eventType;
  75. EventDispatcher *dispatcher;
  76. int eventCode;
  77. };
  78. }