EditorWindow.cs 2.6 KB

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