DropDownWindow.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.CompilerServices;
  4. using BansheeEngine;
  5. namespace BansheeEditor
  6. {
  7. public class DropDownWindow : ScriptObject
  8. {
  9. private int width;
  10. private int height;
  11. public int Width
  12. {
  13. get { return width; }
  14. set { Internal_SetWidth(mCachedPtr, value); width = value; }
  15. }
  16. public int Height
  17. {
  18. get { return height; }
  19. set { Internal_SetHeight(mCachedPtr, value); height = value; }
  20. }
  21. protected GUIPanel GUI;
  22. public static T Open<T>(EditorWindow parent, Vector2I position) where T : DropDownWindow, new()
  23. {
  24. T window = new T();
  25. window.Initialize(parent, position);
  26. return window;
  27. }
  28. protected DropDownWindow(int width = 200, int height = 200)
  29. {
  30. this.width = width;
  31. this.height = height;
  32. }
  33. private void Initialize(EditorWindow parent, Vector2I position)
  34. {
  35. IntPtr parentPtr = IntPtr.Zero;
  36. if (parent != null)
  37. parentPtr = parent.GetCachedPtr();
  38. Internal_CreateInstance(this, parentPtr, position, width, height);
  39. }
  40. protected Vector2I ScreenToWindowPos(Vector2I screenPos)
  41. {
  42. Vector2I windowPos;
  43. Internal_ScreenToWindowPos(mCachedPtr, screenPos, out windowPos);
  44. return windowPos;
  45. }
  46. protected Vector2I WindowToScreenPos(Vector2I windowPos)
  47. {
  48. Vector2I screenPos;
  49. Internal_WindowToScreenPos(mCachedPtr, windowPos, out screenPos);
  50. return screenPos;
  51. }
  52. protected void Close()
  53. {
  54. Internal_Close(mCachedPtr);
  55. }
  56. [MethodImpl(MethodImplOptions.InternalCall)]
  57. private static extern void Internal_CreateInstance(DropDownWindow instance, IntPtr parentWindow, Vector2I position, int width, int height);
  58. [MethodImpl(MethodImplOptions.InternalCall)]
  59. private static extern void Internal_Close(IntPtr nativeInstance);
  60. [MethodImpl(MethodImplOptions.InternalCall)]
  61. private static extern void Internal_SetWidth(IntPtr nativeInstance, int value);
  62. [MethodImpl(MethodImplOptions.InternalCall)]
  63. private static extern void Internal_SetHeight(IntPtr nativeInstance, int value);
  64. [MethodImpl(MethodImplOptions.InternalCall)]
  65. private static extern void Internal_ScreenToWindowPos(IntPtr nativeInstance, Vector2I position, out Vector2I windowPos);
  66. [MethodImpl(MethodImplOptions.InternalCall)]
  67. private static extern void Internal_WindowToScreenPos(IntPtr nativeInstance, Vector2I position, out Vector2I screenPos);
  68. }
  69. }