ModalWindow.cs 4.8 KB

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