BsScriptOSDropTarget.h 5.7 KB

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