EditorWindow.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. Vector2I windowPos;
  19. Internal_ScreenToWindowPos(mCachedPtr, screenPos, out windowPos);
  20. return windowPos;
  21. }
  22. public Vector2I WindowToScreenPos(Vector2I windowPos)
  23. {
  24. Vector2I screenPos;
  25. Internal_WindowToScreenPos(mCachedPtr, windowPos, out screenPos);
  26. return screenPos;
  27. }
  28. private void OnInitializeInternal()
  29. {
  30. GUI = CreatePanel(0, 0, Width, Height);
  31. }
  32. protected virtual void WindowResized(int width, int height)
  33. {
  34. GUI.SetArea(0, 0, width, height);
  35. }
  36. protected virtual void FocusChanged(bool inFocus)
  37. {
  38. }
  39. internal GUIPanel CreatePanel(int x, int y, int width, int height)
  40. {
  41. GUIPanel newPanel = new GUIPanel();
  42. Internal_InitializeGUIPanel(mCachedPtr, newPanel);
  43. newPanel.Initialize();
  44. newPanel.SetArea(x, y, width, height);
  45. return newPanel;
  46. }
  47. [MethodImpl(MethodImplOptions.InternalCall)]
  48. private static extern EditorWindow Internal_CreateOrGetInstance(string ns, string typeName);
  49. [MethodImpl(MethodImplOptions.InternalCall)]
  50. private static extern void Internal_InitializeGUIPanel(IntPtr nativeInstance, GUIPanel panel);
  51. [MethodImpl(MethodImplOptions.InternalCall)]
  52. private static extern int Internal_GetWidth(IntPtr nativeInstance);
  53. [MethodImpl(MethodImplOptions.InternalCall)]
  54. private static extern int Internal_GetHeight(IntPtr nativeInstance);
  55. [MethodImpl(MethodImplOptions.InternalCall)]
  56. private static extern bool Internal_HasFocus(IntPtr nativeInstance);
  57. [MethodImpl(MethodImplOptions.InternalCall)]
  58. private static extern void Internal_ScreenToWindowPos(IntPtr nativeInstance, Vector2I position, out Vector2I windowPos);
  59. [MethodImpl(MethodImplOptions.InternalCall)]
  60. private static extern void Internal_WindowToScreenPos(IntPtr nativeInstance, Vector2I position, out Vector2I screenPos);
  61. }
  62. }