ModalWindow.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 BansheeEngine;
  7. namespace BansheeEditor
  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. protected GUIPanel GUI;
  36. /// <summary>
  37. /// Constructor for internal use by the runtime.
  38. /// </summary>
  39. protected ModalWindow()
  40. {
  41. Internal_CreateInstance(this, false);
  42. }
  43. /// <summary>
  44. /// Creates a new modal window.
  45. /// </summary>
  46. /// <param name="allowCloseButton">Should the close button be displayed.</param>
  47. protected ModalWindow(bool allowCloseButton)
  48. {
  49. Internal_CreateInstance(this, allowCloseButton);
  50. }
  51. /// <summary>
  52. /// Converts coordinates in screen space to coordinates relative to the window.
  53. /// </summary>
  54. /// <param name="screenPos">Coordinates in screen space.</param>
  55. /// <returns>Coordinates relative to the window.</returns>
  56. protected Vector2I ScreenToWindowPos(Vector2I screenPos)
  57. {
  58. Vector2I windowPos;
  59. Internal_ScreenToWindowPos(mCachedPtr, ref screenPos, out windowPos);
  60. return windowPos;
  61. }
  62. /// <summary>
  63. /// Converts coordinates relative to the window to screen space to coordinates.
  64. /// </summary>
  65. /// <param name="windowPos">Coordinates relative to the window.</param>
  66. /// <returns>Coordinates in screen space.</returns>
  67. protected Vector2I WindowToScreenPos(Vector2I windowPos)
  68. {
  69. Vector2I screenPos;
  70. Internal_WindowToScreenPos(mCachedPtr, ref windowPos, out screenPos);
  71. return screenPos;
  72. }
  73. /// <summary>
  74. /// Triggered whenever the window size ranges.
  75. /// </summary>
  76. /// <param name="width">New width of the window in pixels.</param>
  77. /// <param name="height">New height of the window in pixels.</param>
  78. protected virtual void OnWindowResized(int width, int height)
  79. {
  80. }
  81. /// <summary>
  82. /// Closes the modal window.
  83. /// </summary>
  84. protected void Close()
  85. {
  86. Internal_Close(mCachedPtr);
  87. }
  88. /// <summary>
  89. /// Allows you to set the mame of the window to display in the title bar.
  90. /// </summary>
  91. public LocString Title
  92. {
  93. set { Internal_SetTitle(mCachedPtr, value); }
  94. }
  95. [MethodImpl(MethodImplOptions.InternalCall)]
  96. private static extern void Internal_CreateInstance(ModalWindow instance, bool allowCloseButton);
  97. [MethodImpl(MethodImplOptions.InternalCall)]
  98. private static extern void Internal_Close(IntPtr nativeInstance);
  99. [MethodImpl(MethodImplOptions.InternalCall)]
  100. private static extern void Internal_SetTitle(IntPtr nativeInstance, LocString title);
  101. [MethodImpl(MethodImplOptions.InternalCall)]
  102. private static extern int Internal_GetWidth(IntPtr nativeInstance);
  103. [MethodImpl(MethodImplOptions.InternalCall)]
  104. private static extern int Internal_SetWidth(IntPtr nativeInstance, int value);
  105. [MethodImpl(MethodImplOptions.InternalCall)]
  106. private static extern int Internal_GetHeight(IntPtr nativeInstance);
  107. [MethodImpl(MethodImplOptions.InternalCall)]
  108. private static extern int Internal_SetHeight(IntPtr nativeInstance, int value);
  109. [MethodImpl(MethodImplOptions.InternalCall)]
  110. private static extern void Internal_ScreenToWindowPos(IntPtr nativeInstance, ref Vector2I position, out Vector2I windowPos);
  111. [MethodImpl(MethodImplOptions.InternalCall)]
  112. private static extern void Internal_WindowToScreenPos(IntPtr nativeInstance, ref Vector2I position, out Vector2I screenPos);
  113. }
  114. /** @} */
  115. }