EditorWindow.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using BansheeEngine;
  4. namespace BansheeEditor
  5. {
  6. public class EditorWindow : ScriptObject
  7. {
  8. public int Width { get { return Internal_GetWidth(mCachedPtr); } }
  9. public int Height { get { return Internal_GetHeight(mCachedPtr); } }
  10. public bool HasFocus { get { return Internal_HasFocus(mCachedPtr); } }
  11. protected GUIPanel GUI;
  12. public static T OpenWindow<T>() where T : EditorWindow
  13. {
  14. return (T)Internal_CreateOrGetInstance(typeof(T).Namespace, typeof(T).Name);
  15. }
  16. public Vector2I ScreenToWindowPos(Vector2I screenPos)
  17. {
  18. return Internal_ScreenToWindowPos(mCachedPtr, screenPos);
  19. }
  20. public Vector2I WindowToScreenPos(Vector2I screenPos)
  21. {
  22. return Internal_WindowToScreenPos(mCachedPtr, screenPos);
  23. }
  24. protected EditorWindow()
  25. {
  26. GUI = CreatePanel(0, 0, Width, Height);
  27. }
  28. protected virtual void WindowResized(int width, int height)
  29. {
  30. GUI.SetArea(0, 0, width, height);
  31. }
  32. internal GUIPanel CreatePanel(int x, int y, int width, int height)
  33. {
  34. GUIPanel newPanel = new GUIPanel();
  35. Internal_InitializeGUIPanel(mCachedPtr, newPanel);
  36. newPanel.Initialize();
  37. newPanel.SetArea(x, y, width, height);
  38. return newPanel;
  39. }
  40. [MethodImpl(MethodImplOptions.InternalCall)]
  41. private static extern EditorWindow Internal_CreateOrGetInstance(string ns, string typeName);
  42. [MethodImpl(MethodImplOptions.InternalCall)]
  43. private static extern void Internal_InitializeGUIPanel(IntPtr nativeInstance, GUIPanel panel);
  44. [MethodImpl(MethodImplOptions.InternalCall)]
  45. private static extern int Internal_GetWidth(IntPtr nativeInstance);
  46. [MethodImpl(MethodImplOptions.InternalCall)]
  47. private static extern int Internal_GetHeight(IntPtr nativeInstance);
  48. [MethodImpl(MethodImplOptions.InternalCall)]
  49. private static extern bool Internal_HasFocus(IntPtr nativeInstance);
  50. [MethodImpl(MethodImplOptions.InternalCall)]
  51. private static extern Vector2I Internal_ScreenToWindowPos(IntPtr nativeInstance, Vector2I position);
  52. [MethodImpl(MethodImplOptions.InternalCall)]
  53. private static extern Vector2I Internal_WindowToScreenPos(IntPtr nativeInstance, Vector2I position);
  54. }
  55. }