ModalWindow.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.CompilerServices;
  4. using BansheeEngine;
  5. namespace BansheeEditor
  6. {
  7. /// <summary>
  8. /// Base implementation of a window that when open doesn't allow you to interact with other windows. Modal windows
  9. /// are similar to editor windows but cannot be docked, and are meant to be used for temporary operations like dialog
  10. /// boxes and progress bars.
  11. /// </summary>
  12. public class ModalWindow : ScriptObject
  13. {
  14. /// <summary>
  15. /// Width of the window in pixels.
  16. /// </summary>
  17. public int Width
  18. {
  19. get { return Internal_GetWidth(mCachedPtr); }
  20. set { Internal_SetWidth(mCachedPtr, value); }
  21. }
  22. /// <summary>
  23. /// Height of the window in pixels.
  24. /// </summary>
  25. public int Height
  26. {
  27. get { return Internal_GetHeight(mCachedPtr); }
  28. set { Internal_SetHeight(mCachedPtr, value); }
  29. }
  30. protected GUIPanel GUI;
  31. /// <summary>
  32. /// Constructor for internal use by the runtime.
  33. /// </summary>
  34. protected ModalWindow()
  35. {
  36. Internal_CreateInstance(this, false);
  37. }
  38. /// <summary>
  39. /// Creates a new modal window.
  40. /// </summary>
  41. /// <param name="allowCloseButton">Should the close button be displayed.</param>
  42. protected ModalWindow(bool allowCloseButton)
  43. {
  44. Internal_CreateInstance(this, allowCloseButton);
  45. }
  46. /// <summary>
  47. /// Converts coordinates in screen space to coordinates relative to the window.
  48. /// </summary>
  49. /// <param name="screenPos">Coordinates in screen space.</param>
  50. /// <returns>Coordinates relative to the window.</returns>
  51. protected Vector2I ScreenToWindowPos(Vector2I screenPos)
  52. {
  53. Vector2I windowPos;
  54. Internal_ScreenToWindowPos(mCachedPtr, screenPos, out windowPos);
  55. return windowPos;
  56. }
  57. /// <summary>
  58. /// Converts coordinates relative to the window to screen space to coordinates.
  59. /// </summary>
  60. /// <param name="windowPos">Coordinates relative to the window.</param>
  61. /// <returns>Coordinates in screen space.</returns>
  62. protected Vector2I WindowToScreenPos(Vector2I windowPos)
  63. {
  64. Vector2I screenPos;
  65. Internal_WindowToScreenPos(mCachedPtr, windowPos, out screenPos);
  66. return screenPos;
  67. }
  68. /// <summary>
  69. /// Triggered whenever the window size ranges.
  70. /// </summary>
  71. /// <param name="width">New width of the window in pixels.</param>
  72. /// <param name="height">New height of the window in pixels.</param>
  73. protected virtual void OnWindowResized(int width, int height)
  74. {
  75. }
  76. /// <summary>
  77. /// Closes the modal window.
  78. /// </summary>
  79. protected void Close()
  80. {
  81. Internal_Close(mCachedPtr);
  82. }
  83. /// <summary>
  84. /// Allows you to set the mame of the window to display in the title bar.
  85. /// </summary>
  86. public LocString Title
  87. {
  88. set { Internal_SetTitle(mCachedPtr, value); }
  89. }
  90. [MethodImpl(MethodImplOptions.InternalCall)]
  91. private static extern void Internal_CreateInstance(ModalWindow instance, bool allowCloseButton);
  92. [MethodImpl(MethodImplOptions.InternalCall)]
  93. private static extern void Internal_Close(IntPtr nativeInstance);
  94. [MethodImpl(MethodImplOptions.InternalCall)]
  95. private static extern void Internal_SetTitle(IntPtr nativeInstance, LocString title);
  96. [MethodImpl(MethodImplOptions.InternalCall)]
  97. private static extern int Internal_GetWidth(IntPtr nativeInstance);
  98. [MethodImpl(MethodImplOptions.InternalCall)]
  99. private static extern int Internal_SetWidth(IntPtr nativeInstance, int value);
  100. [MethodImpl(MethodImplOptions.InternalCall)]
  101. private static extern int Internal_GetHeight(IntPtr nativeInstance);
  102. [MethodImpl(MethodImplOptions.InternalCall)]
  103. private static extern int Internal_SetHeight(IntPtr nativeInstance, int value);
  104. [MethodImpl(MethodImplOptions.InternalCall)]
  105. private static extern void Internal_ScreenToWindowPos(IntPtr nativeInstance, Vector2I position, out Vector2I windowPos);
  106. [MethodImpl(MethodImplOptions.InternalCall)]
  107. private static extern void Internal_WindowToScreenPos(IntPtr nativeInstance, Vector2I position, out Vector2I screenPos);
  108. }
  109. }