BsGUITimeline.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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(m:GUIEditor,api:bed) 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. /** Style type name for the internal background image. */
  20. static constexpr const char* BACKGROUND_STYLE_TYPE = "Background";
  21. /** Determines the range of values to display on the timeline, in seconds. */
  22. BS_SCRIPT_EXPORT(pr:setter,n:Range)
  23. void setRange(float range);
  24. /** @copydoc setRange */
  25. BS_SCRIPT_EXPORT(pr:getter,n:Range)
  26. float getRange() const;
  27. /** Determines the offset at which the displayed timeline values start at, in seconds. */
  28. BS_SCRIPT_EXPORT(pr:setter,n:Offset)
  29. void setOffset(float offset);
  30. /** @copydoc setOffset */
  31. BS_SCRIPT_EXPORT(pr:getter,n:Offset)
  32. float getOffset() const { return mOffset; }
  33. /** Number of frames per second, used for frame selection and marking. */
  34. BS_SCRIPT_EXPORT(pr:setter,n:FPS)
  35. void setFPS(UINT32 FPS);
  36. /** @copydoc setFPS */
  37. BS_SCRIPT_EXPORT(pr:getter,n:FPS)
  38. UINT32 getFPS() const { return mFPS; }
  39. /** Frame to display the frame marker on. Set to -1 to clear the frame marker. */
  40. BS_SCRIPT_EXPORT(pr:setter,n:MarkedFrame)
  41. void setMarkedFrame(UINT32 index);
  42. /** @copydoc setFPS */
  43. BS_SCRIPT_EXPORT(pr:getter,n:MarkedFrame)
  44. UINT32 setMarkedFrame() const { return mFPS; }
  45. /**
  46. * Uses the assigned FPS, range and physical size to calculate the frame that is under the provided coordinates.
  47. *
  48. * @param[in] pixelCoords Coordinates relative to this GUI element.
  49. * @return Frame that was clicked on, or -1 if the coordinates are outside of valid bounds.
  50. */
  51. BS_SCRIPT_EXPORT()
  52. UINT32 getFrame(const Vector2I& pixelCoords) const;
  53. /**
  54. * Returns the time at the specified pixel value along the timeline.
  55. *
  56. * @param[in] pixel X coordinate to sample at, relative to this GUI element in pixels.
  57. * @return Time along the curve at the specified coordinate.
  58. */
  59. BS_SCRIPT_EXPORT()
  60. float getTime(INT32 pixel) const;
  61. /**
  62. * Finds the pixel offset relative to the GUI element's origin for the specified time.
  63. *
  64. * @param[in] time Time value to return the offset for.
  65. * @return Offset in pixels relative to GUI element's origin
  66. */
  67. BS_SCRIPT_EXPORT()
  68. INT32 getOffset(float time) const;
  69. /**
  70. * Returns time for a frame with the specified index. Depends on set range and FPS.
  71. *
  72. * @param[in] index Index of the frame (not a key-frame) to get the time for.
  73. * @return Time of the frame with the provided index.
  74. */
  75. BS_SCRIPT_EXPORT()
  76. float getTimeForFrame(INT32 index) const;
  77. /** Sets the size of padding to apply to the left and right sides of the curve drawing, in pixels. */
  78. BS_SCRIPT_EXPORT(pr:setter,n:Padding)
  79. void setPadding(UINT32 padding);
  80. /** @copydoc setPadding */
  81. BS_SCRIPT_EXPORT(pr:getter,n:Padding)
  82. UINT32 getPadding() const { return mPadding; };
  83. /**
  84. * @name Internal
  85. * @{
  86. */
  87. /** @copydoc GUIElement::_getOptimalSize */
  88. Vector2I _getOptimalSize() const override;
  89. /** @} */
  90. protected:
  91. GUITimeline(const String& styleName, const GUIDimensions& dimensions);
  92. ~GUITimeline() override = default;
  93. /** Returns the width of the GUI element that can be drawn to (width minus padding). */
  94. UINT32 getDrawableWidth() const;
  95. /** Similar to getRange() but expands the range so it's expanded to encompas the right-most padding area. */
  96. float getRangeWithPadding() const;
  97. /** Draws a vertical frame marker at the specified time. */
  98. void drawFrameMarker(float t);
  99. /** Draws a frame marker at the currently selected frame. */
  100. void drawFrameMarker();
  101. /** @copydoc GUIElement::_updateLayoutInternal */
  102. void _updateLayoutInternal(const GUILayoutData& data) override;
  103. /** @copydoc GUIElement::styleUpdated */
  104. void styleUpdated() override;
  105. GUICanvas* mCanvas = nullptr;
  106. GUITexture* mBackground = nullptr;
  107. float mRange = 20.0f;
  108. float mOffset = 0.0f;
  109. UINT32 mFPS = 1;
  110. UINT32 mMarkedFrame = (UINT32)-1;
  111. UINT32 mPadding = 30;
  112. };
  113. /** @} */
  114. }