BsScriptOSDropTarget.h 5.4 KB

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