BsPlatform.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. namespace BansheeEngine
  4. {
  5. /**
  6. * @brief Contains values representing default
  7. * mouse cursor types.
  8. */
  9. enum class PlatformCursorType
  10. {
  11. Arrow,
  12. Wait,
  13. IBeam,
  14. Help,
  15. Hand,
  16. SizeAll,
  17. SizeNESW,
  18. SizeNS,
  19. SizeNWSE,
  20. SizeWE
  21. };
  22. /**
  23. * @brief Contains values reprenting window non client areas.
  24. *
  25. * @note These are used for things like resize/move and tell the OS
  26. * where each of those areas are on our window.
  27. */
  28. enum class NonClientAreaBorderType
  29. {
  30. TopLeft,
  31. Top,
  32. TopRight,
  33. Left,
  34. Right,
  35. BottomLeft,
  36. Bottom,
  37. BottomRight
  38. };
  39. /**
  40. * @brief Types of mouse buttons provided by the OS.
  41. */
  42. enum class OSMouseButton
  43. {
  44. Left, Middle, Right, Count
  45. };
  46. /**
  47. * @brief Describes pointer (mouse, touch) states as reported
  48. * by the OS.
  49. */
  50. struct BS_CORE_EXPORT OSPointerButtonStates
  51. {
  52. OSPointerButtonStates()
  53. {
  54. mouseButtons[0] = false;
  55. mouseButtons[1] = false;
  56. mouseButtons[2] = false;
  57. shift = false;
  58. ctrl = false;
  59. }
  60. bool mouseButtons[OSMouseButton::Count];
  61. bool shift, ctrl;
  62. };
  63. /**
  64. * @brief Type of drop event type. This is used
  65. * when dragging items over drop targets.
  66. */
  67. enum class OSDropType
  68. {
  69. FileList,
  70. None
  71. };
  72. /**
  73. * @brief Drop targets allow you to register a certain portion of a window as a drop target that
  74. * accepts certain drop types. Accepted drop types are provided by the OS and include things
  75. * like file and item dragging.
  76. *
  77. * You will receive events with the specified drop area as long as it is active.
  78. */
  79. class BS_CORE_EXPORT OSDropTarget
  80. {
  81. public:
  82. /**
  83. * @brief Triggered when a pointer is being dragged over the drop area.
  84. * Provides window coordinates of the pointer position.
  85. */
  86. Event<void(INT32 x, INT32 y)> onDragOver;
  87. /**
  88. * @brief Triggered when the user completes a drop while pointer is over
  89. * the drop area.
  90. * Provides window coordinates of the pointer position.
  91. */
  92. Event<void(INT32 x, INT32 y)> onDrop;
  93. /**
  94. * @brief Triggered when a pointer enters the drop area.
  95. * Provides window coordinates of the pointer position.
  96. */
  97. Event<void(INT32 x, INT32 y)> onEnter;
  98. /**
  99. * @brief Triggered when a pointer leaves the drop area.
  100. */
  101. Event<void()> onLeave;
  102. /**
  103. * @brief Sets the drop target area, in local window coordinates.
  104. */
  105. void setArea(INT32 x, INT32 y, UINT32 width, UINT32 height);
  106. /**
  107. * @brief Gets the type of drop that this drop target is looking for. Only
  108. * valid after a drop has been triggered.
  109. */
  110. OSDropType getDropType() const { return mDropType; }
  111. /**
  112. * @brief Returns a list of files received by the drop target. Only valid
  113. * after a drop of FileList type has been triggered.
  114. */
  115. const Vector<WString>& getFileList() const { return *mFileList; }
  116. /**
  117. * @brief Internal method. Clears all internal values.
  118. */
  119. void _clear();
  120. /**
  121. * @brief Internal method. Sets the file list and marks the drop event as FileList.
  122. */
  123. void _setFileList(const Vector<WString>& fileList);
  124. /**
  125. * @brief Marks the drop area as inactive or active.
  126. */
  127. void _setActive(bool active) { mActive = active; }
  128. /**
  129. * @brief Checks is the specified position within the current drop area.
  130. * Position should be in window local coordinates.
  131. */
  132. bool _isInside(const Vector2I& pos) const;
  133. /**
  134. * @brief Returns true if the drop target is active.
  135. */
  136. bool _isActive() const { return mActive; }
  137. private:
  138. friend class Platform;
  139. OSDropTarget(const RenderWindow* ownerWindow, INT32 x, INT32 y, UINT32 width, UINT32 height);
  140. ~OSDropTarget();
  141. /**
  142. * @brief Returns a render window this drop target is attached to.
  143. */
  144. const RenderWindow* getOwnerWindow() const { return mOwnerWindow; }
  145. private:
  146. INT32 mX, mY;
  147. UINT32 mWidth, mHeight;
  148. bool mActive;
  149. const RenderWindow* mOwnerWindow;
  150. OSDropType mDropType;
  151. union
  152. {
  153. Vector<WString>* mFileList;
  154. };
  155. };
  156. }
  157. // Bring in the specific platform's header file
  158. #if BS_PLATFORM == BS_PLATFORM_WIN32
  159. # include "Win32/BsPlatformImpl.h"
  160. #elif (BS_PLATFORM == BS_PLATFORM_LINUX)
  161. # include "GLX/BsPlatformImpl.h"
  162. #elif BS_PLATFORM == BS_PLATFORM_APPLE
  163. # include "OSX/BsPlatformImpl.h"
  164. #endif