BsScriptDropDownWindow.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 "BsDropDownWindow.h"
  7. #include "BsVector2I.h"
  8. namespace BansheeEngine
  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 void internal_CreateInstance(MonoObject* instance, ScriptEditorWindow* parentWindow, Vector2I* position, int width, int height);
  34. static void internal_Close(ScriptDropDownWindow* nativeInstance);
  35. static void internal_SetWidth(ScriptDropDownWindow* nativeInstance, UINT32 value);
  36. static void internal_SetHeight(ScriptDropDownWindow* nativeInstance, UINT32 value);
  37. static void internal_ScreenToWindowPos(ScriptDropDownWindow* nativeInstance, Vector2I* position, Vector2I* windowPos);
  38. static void internal_WindowToScreenPos(ScriptDropDownWindow* nativeInstance, Vector2I* position, Vector2I* screenPos);
  39. };
  40. /**
  41. * Managed implementation of a DropDownWindow. All managed drop down windows are implemented using this class, and the
  42. * managed instance contains the specifics of each implementation.
  43. */
  44. class BS_SCR_BED_EXPORT ManagedDropDownWindow : public DropDownWindow
  45. {
  46. public:
  47. ManagedDropDownWindow(const SPtr<RenderWindow>& parent, const SPtr<Camera>& camera,
  48. const Vector2I& position, MonoObject* managedInstance, UINT32 width, UINT32 height);
  49. ~ManagedDropDownWindow();
  50. /** Initializes the drop down window with the interop object that owns the managed instance of this window. */
  51. void initialize(ScriptDropDownWindow* parent);
  52. /** Called every frame. Triggers OnEditorUpdate method on the managed object. */
  53. void update() override;
  54. /** Trigger the OnInitialize method on the managed object. */
  55. void triggerOnInitialize();
  56. /** Trigger the OnDestroy method on the managed object. */
  57. void triggerOnDestroy();
  58. /** Returns the managed instance of the drop down window implementation. */
  59. MonoObject* getManagedInstance() const { return mManagedInstance; }
  60. /**
  61. * Reloads all the managed types and methods. Usually called right after construction or after assembly reload.
  62. *
  63. * @param[in] windowClass Managed class of the drop down window to retrieve the data for.
  64. */
  65. void reloadMonoTypes(MonoClass* windowClass);
  66. private:
  67. friend class ScriptModalWindow;
  68. typedef void(__stdcall *OnInitializeThunkDef) (MonoObject*, MonoException**);
  69. typedef void(__stdcall *OnDestroyThunkDef) (MonoObject*, MonoException**);
  70. typedef void(__stdcall *UpdateThunkDef) (MonoObject*, MonoException**);
  71. String mNamespace;
  72. String mTypename;
  73. OnInitializeThunkDef mOnInitializeThunk;
  74. OnDestroyThunkDef mOnDestroyThunk;
  75. UpdateThunkDef mUpdateThunk;
  76. bool mIsInitialized;
  77. MonoObject* mManagedInstance;
  78. uint32_t mGCHandle;
  79. ScriptDropDownWindow* mScriptParent;
  80. ScriptGUILayout* mContentsPanel;
  81. };
  82. /** @} */
  83. }