BsScriptDropDownWindow.h 4.1 KB

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