ModalWindow.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.CompilerServices;
  4. using BansheeEngine;
  5. namespace BansheeEditor
  6. {
  7. public class ModalWindow : ScriptObject
  8. {
  9. public int Width
  10. {
  11. get { return Internal_GetWidth(mCachedPtr); }
  12. set { Internal_SetWidth(mCachedPtr, value); }
  13. }
  14. public int Height
  15. {
  16. get { return Internal_GetHeight(mCachedPtr); }
  17. set { Internal_SetHeight(mCachedPtr, value); }
  18. }
  19. protected GUIPanel GUI;
  20. protected ModalWindow()
  21. {
  22. Internal_CreateInstance(this, false);
  23. }
  24. protected ModalWindow(bool allowCloseButton)
  25. {
  26. Internal_CreateInstance(this, allowCloseButton);
  27. }
  28. protected Vector2I ScreenToWindowPos(Vector2I screenPos)
  29. {
  30. Vector2I windowPos;
  31. Internal_ScreenToWindowPos(mCachedPtr, screenPos, out windowPos);
  32. return windowPos;
  33. }
  34. protected Vector2I WindowToScreenPos(Vector2I windowPos)
  35. {
  36. Vector2I screenPos;
  37. Internal_WindowToScreenPos(mCachedPtr, windowPos, out screenPos);
  38. return screenPos;
  39. }
  40. private void OnInitializeInternal()
  41. {
  42. GUI = new GUIPanel();
  43. Internal_InitializeGUIPanel(mCachedPtr, GUI);
  44. GUI.Initialize();
  45. GUI.SetArea(0, 0, Width, Height);
  46. }
  47. private void OnDestroyInternal()
  48. {
  49. GUI.Destroy();
  50. Internal_DestroyGUIPanel(mCachedPtr, GUI);
  51. }
  52. protected virtual void OnWindowResized(int width, int height)
  53. {
  54. GUI.SetArea(0, 0, width, height);
  55. }
  56. protected void Close()
  57. {
  58. Internal_Close(mCachedPtr);
  59. }
  60. public LocString Title
  61. {
  62. set { Internal_SetTitle(mCachedPtr, value); }
  63. }
  64. [MethodImpl(MethodImplOptions.InternalCall)]
  65. private static extern void Internal_CreateInstance(ModalWindow instance, bool allowCloseButton);
  66. [MethodImpl(MethodImplOptions.InternalCall)]
  67. private static extern void Internal_Close(IntPtr nativeInstance);
  68. [MethodImpl(MethodImplOptions.InternalCall)]
  69. private static extern void Internal_SetTitle(IntPtr nativeInstance, LocString title);
  70. [MethodImpl(MethodImplOptions.InternalCall)]
  71. private static extern void Internal_InitializeGUIPanel(IntPtr nativeInstance, GUIPanel panel);
  72. [MethodImpl(MethodImplOptions.InternalCall)]
  73. private static extern void Internal_DestroyGUIPanel(IntPtr nativeInstance, GUIPanel panel);
  74. [MethodImpl(MethodImplOptions.InternalCall)]
  75. private static extern int Internal_GetWidth(IntPtr nativeInstance);
  76. [MethodImpl(MethodImplOptions.InternalCall)]
  77. private static extern int Internal_SetWidth(IntPtr nativeInstance, int value);
  78. [MethodImpl(MethodImplOptions.InternalCall)]
  79. private static extern int Internal_GetHeight(IntPtr nativeInstance);
  80. [MethodImpl(MethodImplOptions.InternalCall)]
  81. private static extern int Internal_SetHeight(IntPtr nativeInstance, int value);
  82. [MethodImpl(MethodImplOptions.InternalCall)]
  83. private static extern void Internal_ScreenToWindowPos(IntPtr nativeInstance, Vector2I position, out Vector2I windowPos);
  84. [MethodImpl(MethodImplOptions.InternalCall)]
  85. private static extern void Internal_WindowToScreenPos(IntPtr nativeInstance, Vector2I position, out Vector2I screenPos);
  86. }
  87. }