mirror of
https://github.com/J-D-K/JKSV.git
synced 2026-03-21 17:24:37 -05:00
Make ui::TitleView use ui::Transition for scrolling.
This commit is contained in:
parent
c29d874d5a
commit
fd655de1d0
|
|
@ -5,6 +5,7 @@
|
|||
#include "ui/ColorMod.hpp"
|
||||
#include "ui/Element.hpp"
|
||||
#include "ui/TitleTile.hpp"
|
||||
#include "ui/Transition.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
|
@ -49,8 +50,8 @@ namespace ui
|
|||
/// @brief Pointer to user passed.
|
||||
data::User *m_user{};
|
||||
|
||||
/// @brief Y coordinate.
|
||||
double m_y = 32.0f;
|
||||
/// @brief Transition used for animating the scrolling.
|
||||
ui::Transition m_transition{};
|
||||
|
||||
/// @brief Currently highlighted/selected title.
|
||||
int m_selected{};
|
||||
|
|
|
|||
|
|
@ -99,7 +99,10 @@ namespace ui
|
|||
/// @brief Sets the threshold before snapping occurs.
|
||||
void set_threshold(int threshold) noexcept;
|
||||
|
||||
static inline int DEFAULT_THRESHOLD = 2;
|
||||
/// @brief Updates the scaling for all transitions.
|
||||
static void update_scaling() noexcept;
|
||||
|
||||
static inline int DEFAULT_THRESHOLD = 1;
|
||||
|
||||
private:
|
||||
/// @brief Current X.
|
||||
|
|
@ -130,7 +133,7 @@ namespace ui
|
|||
double m_threshold{};
|
||||
|
||||
/// @brief Scaling from config.
|
||||
double m_scaling{};
|
||||
static inline double sm_scaling{};
|
||||
|
||||
void update_x_coord() noexcept;
|
||||
|
||||
|
|
|
|||
|
|
@ -283,6 +283,7 @@ void SettingsState::cycle_anim_scaling()
|
|||
if ((scaling += 0.25f) > 4.0f) { scaling = 1.0f; }
|
||||
|
||||
config::set_animation_scaling(scaling);
|
||||
ui::Transition::update_scaling();
|
||||
}
|
||||
|
||||
const char *SettingsState::get_status_text(uint8_t value)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ ui::IconMenu::IconMenu(int x, int y, int renderTargetHeight)
|
|||
// This needs to be overriden from the base state.
|
||||
m_boundingBox->set_width(152);
|
||||
m_boundingBox->set_height(146);
|
||||
m_optionHeight = 144;
|
||||
}
|
||||
|
||||
void ui::IconMenu::update(bool hasFocus) { Menu::update(hasFocus); }
|
||||
|
|
|
|||
|
|
@ -10,11 +10,14 @@
|
|||
|
||||
namespace
|
||||
{
|
||||
constexpr int ICON_ROW_SIZE = 7;
|
||||
constexpr double UPPER_THRESHOLD = 32.0f;
|
||||
constexpr double LOWER_THRESHOLD = 388.0f;
|
||||
constexpr int ICON_ROW_SIZE = 7;
|
||||
}
|
||||
|
||||
ui::TitleView::TitleView(data::User *user)
|
||||
: m_user(user)
|
||||
, m_transition(0, UPPER_THRESHOLD, 0, 0, 0, UPPER_THRESHOLD, 0, 0, m_transition.DEFAULT_THRESHOLD)
|
||||
, m_bounding(ui::BoundingBox::create(0, 0, 188, 188))
|
||||
{
|
||||
TitleView::refresh();
|
||||
|
|
@ -28,6 +31,7 @@ void ui::TitleView::update(bool hasFocus)
|
|||
TitleView::handle_input();
|
||||
TitleView::handle_scrolling();
|
||||
TitleView::update_tiles();
|
||||
m_transition.update();
|
||||
}
|
||||
|
||||
void ui::TitleView::render(sdl::SharedTexture &target, bool hasFocus)
|
||||
|
|
@ -38,7 +42,8 @@ void ui::TitleView::render(sdl::SharedTexture &target, bool hasFocus)
|
|||
if (m_titleTiles.empty()) { return; }
|
||||
|
||||
const int tileCount = m_titleTiles.size();
|
||||
for (int i = 0, tempY = m_y; i < tileCount; i += ICON_ROW_SIZE, tempY += TILE_SPACE_VERT)
|
||||
const int y = m_transition.get_y();
|
||||
for (int i = 0, tempY = y; i < tileCount; i += ICON_ROW_SIZE, tempY += TILE_SPACE_VERT)
|
||||
{
|
||||
const int endRow = i + ICON_ROW_SIZE;
|
||||
for (int j = i, tempX = 32; j < endRow && j < tileCount; j++, tempX += TILE_SPACE_HOR)
|
||||
|
|
@ -127,20 +132,23 @@ void ui::TitleView::handle_input()
|
|||
|
||||
void ui::TitleView::handle_scrolling()
|
||||
{
|
||||
static constexpr double UPPER_THRESHOLD = 32.0f;
|
||||
static constexpr double LOWER_THRESHOLD = 388.0f;
|
||||
|
||||
const double scaling = config::get_animation_scaling();
|
||||
|
||||
if (m_selectedY < UPPER_THRESHOLD)
|
||||
double shift{};
|
||||
bool changed{};
|
||||
if (m_selectedY < static_cast<int>(UPPER_THRESHOLD))
|
||||
{
|
||||
const double shiftDown = (UPPER_THRESHOLD - m_selectedY) / scaling;
|
||||
m_y += std::round(shiftDown);
|
||||
shift = (UPPER_THRESHOLD - m_selectedY);
|
||||
changed = true;
|
||||
}
|
||||
else if (m_selectedY > LOWER_THRESHOLD)
|
||||
else if (m_selectedY > static_cast<int>(LOWER_THRESHOLD))
|
||||
{
|
||||
const double shiftUp = (LOWER_THRESHOLD - m_selectedY) / scaling;
|
||||
m_y += std::round(shiftUp);
|
||||
shift = (LOWER_THRESHOLD - m_selectedY);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
const int shiftedY = m_transition.get_y() + std::round(shift);
|
||||
m_transition.set_target_y(shiftedY);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@
|
|||
|
||||
#include <cmath>
|
||||
|
||||
ui::Transition::Transition()
|
||||
: m_scaling(config::get_animation_scaling()) {};
|
||||
ui::Transition::Transition() { Transition::update_scaling(); }
|
||||
|
||||
ui::Transition::Transition(int x,
|
||||
int y,
|
||||
|
|
@ -27,7 +26,9 @@ ui::Transition::Transition(int x,
|
|||
, m_targetWidth(targetWidth)
|
||||
, m_targetHeight(targetHeight)
|
||||
, m_threshold(threshold)
|
||||
, m_scaling(config::get_animation_scaling()) {};
|
||||
{
|
||||
Transition::update_scaling();
|
||||
}
|
||||
|
||||
void ui::Transition::update() noexcept
|
||||
{
|
||||
|
|
@ -96,11 +97,13 @@ void ui::Transition::set_target_height(int targetHeight) noexcept { m_targetHeig
|
|||
|
||||
void ui::Transition::set_threshold(int threshold) noexcept { m_threshold = static_cast<double>(threshold); }
|
||||
|
||||
void ui::Transition::update_scaling() noexcept { sm_scaling = config::get_animation_scaling(); }
|
||||
|
||||
void ui::Transition::update_x_coord() noexcept
|
||||
{
|
||||
if (m_x == m_targetX) { return; }
|
||||
|
||||
const double add = (m_targetX - m_x) / m_scaling;
|
||||
const double add = (m_targetX - m_x) / sm_scaling;
|
||||
m_x += std::round(add);
|
||||
|
||||
const double distance = math::Util<double>::absolute_distance(m_x, m_targetX);
|
||||
|
|
@ -111,7 +114,7 @@ void ui::Transition::update_y_coord() noexcept
|
|||
{
|
||||
if (m_y == m_targetY) { return; }
|
||||
|
||||
const double add = (m_targetY - m_y) / m_scaling;
|
||||
const double add = (m_targetY - m_y) / sm_scaling;
|
||||
m_y += std::round(add);
|
||||
|
||||
const double distance = math::Util<double>::absolute_distance(m_y, m_targetY);
|
||||
|
|
@ -122,7 +125,7 @@ void ui::Transition::update_width() noexcept
|
|||
{
|
||||
if (m_width == m_targetWidth) { return; }
|
||||
|
||||
const double add = (m_targetWidth - m_width) / m_scaling;
|
||||
const double add = (m_targetWidth - m_width) / sm_scaling;
|
||||
m_width += std::round(add);
|
||||
|
||||
const double distance = math::Util<double>::absolute_distance(m_width, m_targetWidth);
|
||||
|
|
@ -133,7 +136,7 @@ void ui::Transition::update_height() noexcept
|
|||
{
|
||||
if (m_height == m_targetHeight) { return; }
|
||||
|
||||
const double add = (m_targetHeight - m_height) / m_scaling;
|
||||
const double add = (m_targetHeight - m_height) / sm_scaling;
|
||||
m_height += add;
|
||||
|
||||
const double distance = math::Util<double>::absolute_distance(m_height, m_targetHeight);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user