DropDownWindow.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Runtime.CompilerServices;
  6. using bs;
  7. namespace bs.Editor
  8. {
  9. /** @addtogroup Window
  10. * @{
  11. */
  12. /// <summary>
  13. /// Base class for all drop down window implementations. Drop down windows are temporary windows that open above all
  14. /// other GUI, and close as soon user clicks outside of them.
  15. /// </summary>
  16. public class DropDownWindow : ScriptObject
  17. {
  18. /// <summary>
  19. /// Width of the window in pixels.
  20. /// </summary>
  21. public int Width
  22. {
  23. get { return Internal_GetWidth(mCachedPtr); }
  24. set { Internal_SetWidth(mCachedPtr, value); }
  25. }
  26. /// <summary>
  27. /// Height of the window in pixels.
  28. /// </summary>
  29. public int Height
  30. {
  31. get { return Internal_GetHeight(mCachedPtr); }
  32. set { Internal_SetHeight(mCachedPtr, value); }
  33. }
  34. protected GUIPanel GUI;
  35. /// <summary>
  36. /// Opens a new drop down window at the specified location.
  37. /// </summary>
  38. /// <typeparam name="T">Type of the drop down window to open.</typeparam>
  39. /// <param name="parent">Parent GUI element relative to which to open the drop down window.</param>
  40. /// <param name="position">Position relative to the parent editor window at which to open the drop down window.
  41. /// </param>
  42. /// <returns>Instance of the opened drop down window.</returns>
  43. public static T Open<T>(GUIElement parent, Vector2I position) where T : DropDownWindow, new()
  44. {
  45. IntPtr parentPtr = IntPtr.Zero;
  46. if (parent != null)
  47. parentPtr = parent.GetCachedPtr();
  48. T window = (T)Internal_CreateInstance(typeof(T).Namespace, typeof(T).Name, parentPtr, ref position);
  49. return window;
  50. }
  51. /// <summary>
  52. /// Constructs a new drop down window.
  53. /// </summary>
  54. protected DropDownWindow()
  55. { }
  56. /// <summary>
  57. /// Converts coordinates in screen space to coordinates relative to the drop down window.
  58. /// </summary>
  59. /// <param name="screenPos">Coordinates in screen space.</param>
  60. /// <returns>Coordinates relative to the drop down window.</returns>
  61. protected Vector2I ScreenToWindowPos(Vector2I screenPos)
  62. {
  63. Vector2I windowPos;
  64. Internal_ScreenToWindowPos(mCachedPtr, ref screenPos, out windowPos);
  65. return windowPos;
  66. }
  67. /// <summary>
  68. /// Converts coordinates relative to the drop down window to screen space to coordinates.
  69. /// </summary>
  70. /// <param name="windowPos">Coordinates relative to the drop down window.</param>
  71. /// <returns>Coordinates in screen space.</returns>
  72. protected Vector2I WindowToScreenPos(Vector2I windowPos)
  73. {
  74. Vector2I screenPos;
  75. Internal_WindowToScreenPos(mCachedPtr, ref windowPos, out screenPos);
  76. return screenPos;
  77. }
  78. /// <summary>
  79. /// Closes the drop down window.
  80. /// </summary>
  81. protected void Close()
  82. {
  83. Internal_Close(mCachedPtr);
  84. }
  85. [MethodImpl(MethodImplOptions.InternalCall)]
  86. private static extern DropDownWindow Internal_CreateInstance(string ns, string typeName, IntPtr parentWindow, ref Vector2I position);
  87. [MethodImpl(MethodImplOptions.InternalCall)]
  88. private static extern void Internal_Close(IntPtr nativeInstance);
  89. [MethodImpl(MethodImplOptions.InternalCall)]
  90. private static extern int Internal_GetWidth(IntPtr nativeInstance);
  91. [MethodImpl(MethodImplOptions.InternalCall)]
  92. private static extern void Internal_SetWidth(IntPtr nativeInstance, int value);
  93. [MethodImpl(MethodImplOptions.InternalCall)]
  94. private static extern int Internal_GetHeight(IntPtr nativeInstance);
  95. [MethodImpl(MethodImplOptions.InternalCall)]
  96. private static extern void Internal_SetHeight(IntPtr nativeInstance, int value);
  97. [MethodImpl(MethodImplOptions.InternalCall)]
  98. private static extern void Internal_ScreenToWindowPos(IntPtr nativeInstance, ref Vector2I position, out Vector2I windowPos);
  99. [MethodImpl(MethodImplOptions.InternalCall)]
  100. private static extern void Internal_WindowToScreenPos(IntPtr nativeInstance, ref Vector2I position, out Vector2I screenPos);
  101. }
  102. /** @} */
  103. }