AnimationWindow.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using BansheeEngine;
  4. namespace BansheeEditor
  5. {
  6. /** @addtogroup Windows
  7. * @{
  8. */
  9. /// <summary>
  10. /// Displays animation curve editor window.
  11. /// </summary>
  12. internal class AnimationWindow : EditorWindow
  13. {
  14. private GUITimeline timeline;
  15. private GUICurveDrawing curveDrawing;
  16. private GUIFloatField lengthField;
  17. private GUIIntField fpsField;
  18. /// <summary>
  19. /// Opens the animation window.
  20. /// </summary>
  21. [MenuItem("Windows/Animation", ButtonModifier.CtrlAlt, ButtonCode.A, 6000)]
  22. private static void OpenGameWindow()
  23. {
  24. OpenWindow<AnimationWindow>();
  25. }
  26. /// <inheritdoc/>
  27. protected override LocString GetDisplayName()
  28. {
  29. return new LocEdString("Animation");
  30. }
  31. private void OnInitialize()
  32. {
  33. lengthField = new GUIFloatField(new LocEdString("Length"), 50);
  34. fpsField = new GUIIntField(new LocEdString("FPS"), 50);
  35. lengthField.Value = 60.0f;
  36. fpsField.Value = 1;
  37. lengthField.OnChanged += x => timeline.SetRange(lengthField.Value);
  38. fpsField.OnChanged += x => timeline.SetFPS(x);
  39. GUILayout buttonLayout = GUI.AddLayoutX();
  40. buttonLayout.AddElement(lengthField);
  41. buttonLayout.AddElement(fpsField);
  42. timeline = new GUITimeline(GUI, Width, 20);
  43. EdAnimationCurve[] curves = CreateDummyCurves();
  44. curveDrawing = new GUICurveDrawing(GUI, Width, Height - 20, curves);
  45. // TODO - Calculate min/max Y and range to set as default
  46. // - Also recalculate whenever curves change and increase as needed
  47. }
  48. private EdAnimationCurve[] CreateDummyCurves()
  49. {
  50. EdAnimationCurve[] curves = new EdAnimationCurve[1];
  51. curves[0].AddKeyframe(0.0f, 1.0f);
  52. KeyFrame[] keyFrames = new KeyFrame[3];
  53. keyFrames[0].time = 0.0f;
  54. keyFrames[0].value = 1.0f;
  55. keyFrames[1].time = 10.0f;
  56. keyFrames[1].value = 5.0f;
  57. keyFrames[2].time = 15.0f;
  58. keyFrames[2].value = -2.0f;
  59. // TODO - Set up tangents
  60. return curves;
  61. }
  62. protected override void WindowResized(int width, int height)
  63. {
  64. timeline.SetSize(width, 20);
  65. curveDrawing.SetSize(width, height - 20);
  66. }
  67. private void OnEditorUpdate()
  68. {
  69. //int position = (int)(MathEx.Sin(Time.RealElapsed)*50.0f + 50.0f);
  70. //canvas.SetPosition(position, 0);
  71. }
  72. }
  73. /** @} */
  74. }