ModalWindow.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 implementation of a window that when open doesn't allow you to interact with other windows. Modal windows
  14. /// are similar to editor windows but cannot be docked, and are meant to be used for temporary operations like dialog
  15. /// boxes and progress bars.
  16. /// </summary>
  17. public class ModalWindow : ScriptObject
  18. {
  19. /// <summary>
  20. /// Width of the window in pixels.
  21. /// </summary>
  22. public int Width
  23. {
  24. get { return Internal_GetWidth(mCachedPtr); }
  25. set { Internal_SetWidth(mCachedPtr, value); }
  26. }
  27. /// <summary>
  28. /// Height of the window in pixels.
  29. /// </summary>
  30. public int Height
  31. {
  32. get { return Internal_GetHeight(mCachedPtr); }
  33. set { Internal_SetHeight(mCachedPtr, value); }
  34. }
  35. /// <summary>
  36. /// Width of the content area of the window, in pixels. The content area represents the area of the window not
  37. /// including the title bar and the border.
  38. /// </summary>
  39. public int ContentWidth
  40. {
  41. get { return Internal_GetContentWidth(mCachedPtr); }
  42. set { Internal_SetContentWidth(mCachedPtr, value); }
  43. }
  44. /// <summary>
  45. /// Height of the content area of the window, in pixels. The content area represents the area of the window not
  46. /// including the title bar and the border.
  47. /// </summary>
  48. public int ContentHeight
  49. {
  50. get { return Internal_GetContentHeight(mCachedPtr); }
  51. set { Internal_SetContentHeight(mCachedPtr, value); }
  52. }
  53. protected GUIPanel GUI;
  54. /// <summary>
  55. /// Constructor for internal use by the runtime.
  56. /// </summary>
  57. protected ModalWindow()
  58. {
  59. Internal_CreateInstance(this, false);
  60. }
  61. /// <summary>
  62. /// Creates a new modal window.
  63. /// </summary>
  64. /// <param name="allowCloseButton">Should the close button be displayed.</param>
  65. protected ModalWindow(bool allowCloseButton)
  66. {
  67. Internal_CreateInstance(this, allowCloseButton);
  68. }
  69. /// <summary>
  70. /// Converts coordinates in screen space to coordinates relative to the window.
  71. /// </summary>
  72. /// <param name="screenPos">Coordinates in screen space.</param>
  73. /// <returns>Coordinates relative to the window.</returns>
  74. protected Vector2I ScreenToWindowPos(Vector2I screenPos)
  75. {
  76. Vector2I windowPos;
  77. Internal_ScreenToWindowPos(mCachedPtr, ref screenPos, out windowPos);
  78. return windowPos;
  79. }
  80. /// <summary>
  81. /// Converts coordinates relative to the window to screen space to coordinates.
  82. /// </summary>
  83. /// <param name="windowPos">Coordinates relative to the window.</param>
  84. /// <returns>Coordinates in screen space.</returns>
  85. protected Vector2I WindowToScreenPos(Vector2I windowPos)
  86. {
  87. Vector2I screenPos;
  88. Internal_WindowToScreenPos(mCachedPtr, ref windowPos, out screenPos);
  89. return screenPos;
  90. }
  91. /// <summary>
  92. /// Triggered whenever the window size ranges.
  93. /// </summary>
  94. /// <param name="width">New width of the window in pixels.</param>
  95. /// <param name="height">New height of the window in pixels.</param>
  96. protected virtual void OnWindowResized(int width, int height)
  97. {
  98. }
  99. /// <summary>
  100. /// Closes the modal window.
  101. /// </summary>
  102. protected void Close()
  103. {
  104. Internal_Close(mCachedPtr);
  105. }
  106. /// <summary>
  107. /// Allows you to set the mame of the window to display in the title bar.
  108. /// </summary>
  109. public LocString Title
  110. {
  111. set { Internal_SetTitle(mCachedPtr, value); }
  112. }
  113. [MethodImpl(MethodImplOptions.InternalCall)]
  114. private static extern void Internal_CreateInstance(ModalWindow instance, bool allowCloseButton);
  115. [MethodImpl(MethodImplOptions.InternalCall)]
  116. private static extern void Internal_Close(IntPtr nativeInstance);
  117. [MethodImpl(MethodImplOptions.InternalCall)]
  118. private static extern void Internal_SetTitle(IntPtr nativeInstance, LocString title);
  119. [MethodImpl(MethodImplOptions.InternalCall)]
  120. private static extern int Internal_GetWidth(IntPtr nativeInstance);
  121. [MethodImpl(MethodImplOptions.InternalCall)]
  122. private static extern int Internal_SetWidth(IntPtr nativeInstance, int value);
  123. [MethodImpl(MethodImplOptions.InternalCall)]
  124. private static extern int Internal_GetHeight(IntPtr nativeInstance);
  125. [MethodImpl(MethodImplOptions.InternalCall)]
  126. private static extern int Internal_SetHeight(IntPtr nativeInstance, int value);
  127. [MethodImpl(MethodImplOptions.InternalCall)]
  128. private static extern int Internal_GetContentWidth(IntPtr nativeInstance);
  129. [MethodImpl(MethodImplOptions.InternalCall)]
  130. private static extern int Internal_SetContentWidth(IntPtr nativeInstance, int value);
  131. [MethodImpl(MethodImplOptions.InternalCall)]
  132. private static extern int Internal_GetContentHeight(IntPtr nativeInstance);
  133. [MethodImpl(MethodImplOptions.InternalCall)]
  134. private static extern int Internal_SetContentHeight(IntPtr nativeInstance, int value);
  135. [MethodImpl(MethodImplOptions.InternalCall)]
  136. private static extern void Internal_ScreenToWindowPos(IntPtr nativeInstance, ref Vector2I position, out Vector2I windowPos);
  137. [MethodImpl(MethodImplOptions.InternalCall)]
  138. private static extern void Internal_WindowToScreenPos(IntPtr nativeInstance, ref Vector2I position, out Vector2I screenPos);
  139. }
  140. /** @} */
  141. }