BsScriptOSDropTarget.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsScriptEditorPrerequisites.h"
  5. #include "BsScriptObject.h"
  6. #include "BsRect2I.h"
  7. namespace BansheeEngine
  8. {
  9. /**
  10. * @brief Interop class between C++ & CLR for OSDropTarget. Managed drop target
  11. * is always associated with a managed EditorWindow.
  12. */
  13. class BS_SCR_BED_EXPORT ScriptOSDropTarget : public ScriptObject <ScriptOSDropTarget>
  14. {
  15. public:
  16. SCRIPT_OBJ(EDITOR_ASSEMBLY, "BansheeEditor", "OSDropTarget")
  17. private:
  18. ScriptOSDropTarget(MonoObject* instance, ScriptEditorWindow* parent);
  19. ~ScriptOSDropTarget();
  20. /**
  21. * @brief Destroys the internal native drop target.
  22. */
  23. void destroy();
  24. /**
  25. * @brief Creates an internal native drop target over the specified window. Any previous
  26. * drop target is overwritten.
  27. *
  28. * @param parentWindow Window the drop target is located on.
  29. * @param x X position of the drop target, relative to window, in pixels.
  30. * @param y Y position of the drop target, relative to window, in pixels.
  31. * @param width Width of the drop target in pixels.
  32. * @param height Height of the drop target in pixels.
  33. */
  34. void setDropTarget(const RenderWindowPtr& parentWindow, INT32 x, INT32 y, UINT32 width, UINT32 height);
  35. /**
  36. * @brief Updates bounds of an existing drop target.
  37. *
  38. * @param bounds Area of the drop target relative to
  39. * the editor widget (EditorWindow in managed terms).
  40. */
  41. void setBounds(const Rect2I& bounds);
  42. /**
  43. * @brief Triggered when editor widget (EditorWindow in managed terms) parent
  44. * changes. This might mean we need to re-create the drop target
  45. * as the parent render window might have changed.
  46. */
  47. void widgetParentChanged(EditorWidgetContainer* parent);
  48. /**
  49. * @brief Triggered when the parent editor widget (EditorWindow in managed terms) is resized.
  50. */
  51. void widgetResized(UINT32 width, UINT32 height);
  52. /**
  53. * @brief Triggered when the parent editor widget (EditorWindow in managed terms) is moved.
  54. */
  55. void widgetMoved(INT32 x, INT32 y);
  56. /**
  57. * @brief Returns the editor widget (EditorWindow in managed terms) this drop target belongs to.
  58. */
  59. EditorWidgetBase* getParentWidget() const;
  60. /**
  61. * @brief Returns the bounds of the drop target, relative to the parent window. This depends
  62. * of set bounds using ::setBounds and the current position and size of the editor widget.
  63. */
  64. Rect2I getDropTargetArea() const;
  65. /**
  66. * @brief Triggered when the drag and drop operation has entered the area over an OS drop target.
  67. *
  68. * @param thisPtr C++/CLR interop object that contains the native OSDropTarget
  69. * that triggered the event.
  70. * @param x X coordinate of the pointer, relative to parent window, in pixels.
  71. * @param y Y coordinate of the pointer, relative to parent window, in pixels.
  72. */
  73. static void dropTargetDragEnter(ScriptOSDropTarget* thisPtr, INT32 x, INT32 y);
  74. /**
  75. * @brief Triggered every frame that pointer moves while over the area over an OS drop target.
  76. *
  77. * @param thisPtr C++/CLR interop object that contains the native OSDropTarget
  78. * that triggered the event.
  79. * @param x X coordinate of the pointer, relative to parent window, in pixels.
  80. * @param y Y coordinate of the pointer, relative to parent window, in pixels.
  81. */
  82. static void dropTargetDragMove(ScriptOSDropTarget* thisPtr, INT32 x, INT32 y);
  83. /**
  84. * @brief Triggered when the drag and drop operation has left the area over an OS drop target.
  85. *
  86. * @param thisPtr C++/CLR interop object that contains the native OSDropTarget
  87. * that triggered the event.
  88. */
  89. static void dropTargetDragLeave(ScriptOSDropTarget* thisPtr);
  90. /**
  91. * @brief Triggered when the drag and drop operation has finished over an OS drop target.
  92. *
  93. * @param thisPtr C++/CLR interop object that contains the native OSDropTarget
  94. * that triggered the event.
  95. * @param x X coordinate of the pointer, relative to parent window, in pixels.
  96. * @param y Y coordinate of the pointer, relative to parent window, in pixels.
  97. */
  98. static void dropTargetDragDropped(ScriptOSDropTarget* thisPtr, INT32 x, INT32 y);
  99. ScriptEditorWindow* mParent;
  100. OSDropTarget* mDropTarget;
  101. Rect2I mParentArea;
  102. Rect2I mArea;
  103. bool mIsDestroyed;
  104. HEvent mDropTargetEnterConn;
  105. HEvent mDropTargetMoveConn;
  106. HEvent mDropTargetLeaveConn;
  107. HEvent mDropTargetDroppedConn;
  108. HEvent mWidgetParentChangedConn;
  109. HEvent mWidgetMovedConn;
  110. HEvent mWidgetResizedConn;
  111. /************************************************************************/
  112. /* CLR HOOKS */
  113. /************************************************************************/
  114. typedef void(__stdcall *OnEnterThunkDef) (MonoObject*, INT32, INT32, MonoException**);
  115. typedef void(__stdcall *OnMoveDef) (MonoObject*, INT32, INT32, MonoException**);
  116. typedef void(__stdcall *OnLeaveDef) (MonoObject*, MonoException**);
  117. typedef void(__stdcall *OnDropThunkDef) (MonoObject*, INT32, INT32, MonoException**);
  118. static OnEnterThunkDef onEnterThunk;
  119. static OnMoveDef onMoveThunk;
  120. static OnLeaveDef onLeaveThunk;
  121. static OnDropThunkDef onDropThunk;
  122. static void internal_CreateInstance(MonoObject* instance, ScriptEditorWindow* editorWindow);
  123. static void internal_Destroy(ScriptOSDropTarget* nativeInstance);
  124. static void internal_SetBounds(ScriptOSDropTarget* nativeInstance, Rect2I* bounds);
  125. static MonoArray* internal_GetFilePaths(ScriptOSDropTarget* nativeInstance);
  126. };
  127. }