BsScriptOSDropTarget.h 5.6 KB

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