BsGUITimeline.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsEditorPrerequisites.h"
  5. #include "GUI/BsGUIElement.h"
  6. #include "2D/BsImageSprite.h"
  7. #include "GUI/BsGUIElementContainer.h"
  8. namespace bs
  9. {
  10. /** @addtogroup GUI-Editor
  11. * @{
  12. */
  13. /** Base class that can be implemented by GUI elements needing to elements along draw a horizontal timeline. */
  14. class BS_ED_EXPORT BS_SCRIPT_EXPORT(ed:true,m:GUIEditor) GUITimeline : public GUIElementContainer
  15. {
  16. public:
  17. /** Returns type name of the GUI element used for finding GUI element styles. */
  18. static const String& getGUITypeName();
  19. /** Determines the range of values to display on the timeline, in seconds. */
  20. BS_SCRIPT_EXPORT(pr:setter,n:Range)
  21. void setRange(float range);
  22. /** @copydoc setRange */
  23. BS_SCRIPT_EXPORT(pr:getter,n:Range)
  24. float getRange() const;
  25. /** Determines the offset at which the displayed timeline values start at, in seconds. */
  26. BS_SCRIPT_EXPORT(pr:setter,n:Offset)
  27. void setOffset(float offset);
  28. /** @copydoc setOffset */
  29. BS_SCRIPT_EXPORT(pr:getter,n:Offset)
  30. float getOffset() const { return mOffset; }
  31. /** Number of frames per second, used for frame selection and marking. */
  32. BS_SCRIPT_EXPORT(pr:setter,n:FPS)
  33. void setFPS(UINT32 FPS);
  34. /** @copydoc setFPS */
  35. BS_SCRIPT_EXPORT(pr:getter,n:FPS)
  36. UINT32 getFPS() const { return mFPS; }
  37. /** Frame to display the frame marker on. Set to -1 to clear the frame marker. */
  38. BS_SCRIPT_EXPORT(pr:setter,n:MarkedFrame)
  39. void setMarkedFrame(UINT32 index);
  40. /** @copydoc setFPS */
  41. BS_SCRIPT_EXPORT(pr:getter,n:MarkedFrame)
  42. UINT32 setMarkedFrame() const { return mFPS; }
  43. /**
  44. * Uses the assigned FPS, range and physical size to calculate the frame that is under the provided coordinates.
  45. *
  46. * @param[in] pixelCoords Coordinates relative to this GUI element.
  47. * @return Frame that was clicked on, or -1 if the coordinates are outside of valid bounds.
  48. */
  49. BS_SCRIPT_EXPORT()
  50. UINT32 getFrame(const Vector2I& pixelCoords) const;
  51. /**
  52. * Returns the time at the specified pixel value along the timeline.
  53. *
  54. * @param[in] pixel X coordinate to sample at, relative to this GUI element in pixels.
  55. * @return Time along the curve at the specified coordinate.
  56. */
  57. BS_SCRIPT_EXPORT()
  58. float getTime(INT32 pixel) const;
  59. /**
  60. * Finds the pixel offset relative to the GUI element's origin for the specified time.
  61. *
  62. * @param[in] time Time value to return the offset for.
  63. * @return Offset in pixels relative to GUI element's origin
  64. */
  65. BS_SCRIPT_EXPORT()
  66. INT32 getOffset(float time) const;
  67. /**
  68. * Returns time for a frame with the specified index. Depends on set range and FPS.
  69. *
  70. * @param[in] index Index of the frame (not a key-frame) to get the time for.
  71. * @return Time of the frame with the provided index.
  72. */
  73. BS_SCRIPT_EXPORT()
  74. float getTimeForFrame(INT32 index) const;
  75. /** Sets the size of padding to apply to the left and right sides of the curve drawing, in pixels. */
  76. BS_SCRIPT_EXPORT(pr:setter,n:Padding)
  77. void setPadding(UINT32 padding);
  78. /** @copydoc setPadding */
  79. BS_SCRIPT_EXPORT(pr:getter,n:Padding)
  80. UINT32 getPadding() const { return mPadding; };
  81. /**
  82. * @name Internal
  83. * @{
  84. */
  85. /** @copydoc GUIElement::_getOptimalSize */
  86. Vector2I _getOptimalSize() const override;
  87. /** @} */
  88. protected:
  89. GUITimeline(const String& styleName, const GUIDimensions& dimensions);
  90. ~GUITimeline() override = default;
  91. /** Returns the width of the GUI element that can be drawn to (width minus padding). */
  92. UINT32 getDrawableWidth() const;
  93. /** Similar to getRange() but expands the range so it's expanded to encompas the right-most padding area. */
  94. float getRangeWithPadding() const;
  95. /** Draws a vertical frame marker at the specified time. */
  96. void drawFrameMarker(float t);
  97. /** Draws a frame marker at the currently selected frame. */
  98. void drawFrameMarker();
  99. /** @copydoc GUIElement::_updateLayoutInternal */
  100. void _updateLayoutInternal(const GUILayoutData& data) override;
  101. /** @copydoc GUIElement::styleUpdated */
  102. void styleUpdated() override;
  103. GUICanvas* mCanvas = nullptr;
  104. float mRange = 20.0f;
  105. float mOffset = 0.0f;
  106. UINT32 mFPS = 1;
  107. UINT32 mMarkedFrame = (UINT32)-1;
  108. UINT32 mPadding = 30;
  109. };
  110. /** @} */
  111. }