Make ui::TitleView use ui::Transition for scrolling.

This commit is contained in:
J-D-K
2025-10-04 20:57:27 -04:00
parent c29d874d5a
commit fd655de1d0
6 changed files with 41 additions and 24 deletions

View File

@@ -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); }

View File

@@ -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);
}
}

View File

@@ -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);