BsScriptDropDownWindow.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 "EditorWindow/BsDropDownWindow.h"
  7. #include "Math/BsVector2I.h"
  8. namespace bs
  9. {
  10. /** @addtogroup ScriptInteropEditor
  11. * @{
  12. */
  13. class ManagedDropDownWindow;
  14. /** Interop class between C++ & CLR for types deriving from DropDownWindow. */
  15. class BS_SCR_BED_EXPORT ScriptDropDownWindow : public ScriptObject <ScriptDropDownWindow>
  16. {
  17. public:
  18. SCRIPT_OBJ(EDITOR_ASSEMBLY, "BansheeEditor", "DropDownWindow")
  19. ~ScriptDropDownWindow();
  20. private:
  21. friend class ManagedDropDownWindow;
  22. ScriptDropDownWindow(ManagedDropDownWindow* window);
  23. /** Triggered when the assembly refresh starts. */
  24. void onAssemblyRefreshStarted();
  25. /** Triggered when the native DropDownWindow wrapped by this object gets closed. */
  26. void notifyWindowClosed();
  27. ManagedDropDownWindow* mDropDownWindow;
  28. HEvent mOnAssemblyRefreshStartedConn;
  29. static MonoField* guiPanelField;
  30. /************************************************************************/
  31. /* CLR HOOKS */
  32. /************************************************************************/
  33. static MonoObject* internal_CreateInstance(MonoString* ns, MonoString* typeName, ScriptEditorWindow* parentWindow, Vector2I* position);
  34. static void internal_Close(ScriptDropDownWindow* nativeInstance);
  35. static UINT32 internal_GetWidth(ScriptDropDownWindow* nativeInstance);
  36. static void internal_SetWidth(ScriptDropDownWindow* nativeInstance, UINT32 value);
  37. static UINT32 internal_GetHeight(ScriptDropDownWindow* nativeInstance);
  38. static void internal_SetHeight(ScriptDropDownWindow* nativeInstance, UINT32 value);
  39. static void internal_ScreenToWindowPos(ScriptDropDownWindow* nativeInstance, Vector2I* position, Vector2I* windowPos);
  40. static void internal_WindowToScreenPos(ScriptDropDownWindow* nativeInstance, Vector2I* position, Vector2I* screenPos);
  41. };
  42. /**
  43. * Managed implementation of a DropDownWindow. All managed drop down windows are implemented using this class, and the
  44. * managed instance contains the specifics of each implementation.
  45. */
  46. class BS_SCR_BED_EXPORT ManagedDropDownWindow : public DropDownWindow
  47. {
  48. public:
  49. ManagedDropDownWindow(const SPtr<RenderWindow>& parent, const SPtr<Camera>& camera,
  50. const Vector2I& position, MonoObject* managedInstance, UINT32 width, UINT32 height);
  51. ~ManagedDropDownWindow();
  52. /** Initializes the drop down window with the interop object that owns the managed instance of this window. */
  53. void initialize(ScriptDropDownWindow* parent);
  54. /** Called every frame. Triggers OnEditorUpdate method on the managed object. */
  55. void update() override;
  56. /** Trigger the OnInitialize method on the managed object. */
  57. void triggerOnInitialize();
  58. /** Trigger the OnDestroy method on the managed object. */
  59. void triggerOnDestroy();
  60. /** Returns the managed instance of the drop down window implementation. */
  61. MonoObject* getManagedInstance() const { return mManagedInstance; }
  62. /**
  63. * Reloads all the managed types and methods. Usually called right after construction or after assembly reload.
  64. *
  65. * @param[in] windowClass Managed class of the drop down window to retrieve the data for.
  66. */
  67. void reloadMonoTypes(MonoClass* windowClass);
  68. private:
  69. friend class ScriptModalWindow;
  70. typedef void(BS_THUNKCALL *OnInitializeThunkDef) (MonoObject*, MonoException**);
  71. typedef void(BS_THUNKCALL *OnDestroyThunkDef) (MonoObject*, MonoException**);
  72. typedef void(BS_THUNKCALL *UpdateThunkDef) (MonoObject*, MonoException**);
  73. String mNamespace;
  74. String mTypename;
  75. OnInitializeThunkDef mOnInitializeThunk;
  76. OnDestroyThunkDef mOnDestroyThunk;
  77. UpdateThunkDef mUpdateThunk;
  78. bool mIsInitialized;
  79. MonoObject* mManagedInstance;
  80. uint32_t mGCHandle;
  81. ScriptDropDownWindow* mScriptParent;
  82. ScriptGUILayout* mContentsPanel;
  83. };
  84. /** @} */
  85. }