mirror of
https://github.com/J-D-K/JKSV.git
synced 2026-03-21 17:24:37 -05:00
116 lines
4.2 KiB
C++
116 lines
4.2 KiB
C++
#pragma once
|
|
#include "sdl.hpp"
|
|
#include "system/Timer.hpp"
|
|
#include "ui/Element.hpp"
|
|
|
|
#include <string>
|
|
|
|
namespace ui
|
|
{
|
|
/// @brief This is used in multiple places and rewriting it over and over is a waste of time.
|
|
class TextScroll : public ui::Element
|
|
{
|
|
public:
|
|
/// @brief This is only here so I can get around the backup menu having static members.
|
|
TextScroll() = default;
|
|
|
|
/// @brief Constructor for TextScroll.
|
|
/// @param text Text to create the textscroll with.
|
|
/// @param fontSize Size of the font in pixels to use.
|
|
/// @param width Maximum width to use for rendering text.
|
|
/// @param x X coordinate to render to.
|
|
/// @param y Y coordinate to render to.
|
|
/// @param center Whether or not text should be centered if it's not wide enough for scrolling.
|
|
/// @param color Color to use to render the text.
|
|
TextScroll(std::string_view text,
|
|
int x,
|
|
int y,
|
|
int width,
|
|
int height,
|
|
int fontSize,
|
|
sdl::Color textColor,
|
|
sdl::Color clearColor,
|
|
bool center = true);
|
|
|
|
/// @brief Required destructor.
|
|
~TextScroll() {};
|
|
|
|
/// @brief Creates/sets the text and parameters for TextScroll.
|
|
/// @param text Text to display/scroll.
|
|
/// @param fontSize Font size to use when rendering.
|
|
/// @param availableWidth Available width of the target buffer.
|
|
/// @param y Y coordinate used to render text.
|
|
/// @param center Whether or not text should be centered if it's not wide enough for scrolling.
|
|
/// @param color Color to use to render text.
|
|
void create(std::string_view text,
|
|
int x,
|
|
int y,
|
|
int width,
|
|
int height,
|
|
int fontSize,
|
|
sdl::Color textColor,
|
|
sdl::Color clearColor,
|
|
bool center = true);
|
|
|
|
/// @brief Sets and allows changing the text scrolled.
|
|
void set_text(std::string_view text, bool center);
|
|
|
|
/// @brief Allows setting of the X and Y render coordinates.
|
|
void set_xy(int x, int y);
|
|
|
|
/// @brief Runs the update routine.
|
|
/// @param hasFocus Whether or not the calling state has focus.
|
|
void update(bool hasFocus);
|
|
|
|
/// @brief Runs the render routine.
|
|
/// @param target Target to render to.
|
|
/// @param hasFocus Whether or not the calling state has focus.
|
|
void render(SDL_Texture *target, bool hasFocus);
|
|
|
|
private:
|
|
/// @brief Text to display.
|
|
std::string m_text{};
|
|
|
|
/// @brief X coordinate to render text at.
|
|
int m_textX{};
|
|
|
|
/// @brief Y coordinate to render text at. This is centered vertically.
|
|
int m_textY{};
|
|
|
|
/// @brief The X coordinate the render target is rendered to.
|
|
int m_renderX{};
|
|
|
|
/// @brief Y coordinate to render the target to.
|
|
int m_renderY{};
|
|
|
|
/// @brief Font size used to calculate and render text.
|
|
int m_fontSize{};
|
|
|
|
/// @brief Color used to render the text.
|
|
sdl::Color m_textColor{};
|
|
|
|
/// @brief Color used to clear the render target.
|
|
sdl::Color m_clearColor{};
|
|
|
|
/// @brief Width of text in pixels.
|
|
int m_textWidth{};
|
|
|
|
/// @brief Width of the render target.
|
|
int m_targetWidth{};
|
|
|
|
/// @brief Height of the render target.
|
|
int m_targetHeight{};
|
|
|
|
/// @brief Whether or not text is too wide to fit into the availableWidth passed to the constructor.
|
|
bool m_textScrolling{};
|
|
|
|
/// @brief Whether or not a scroll was triggered.
|
|
bool m_textScrollTriggered{};
|
|
|
|
sdl::SharedTexture m_renderTarget{};
|
|
|
|
/// @brief Timer for scrolling text.
|
|
sys::Timer m_scrollTimer;
|
|
};
|
|
} // namespace ui
|