Skip to content

Commit

Permalink
Menu item image preview size is now relative to screen size
Browse files Browse the repository at this point in the history
  • Loading branch information
Vankata453 committed Jul 15, 2024
1 parent d8a7c73 commit 9612857
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/gui/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
#include "video/video_system.hpp"
#include "video/viewport.hpp"

const Sizef Menu::s_preview_size(426.f, 240.f);
const float Menu::s_preview_fade_time = 0.1f;

Menu::Menu() :
Expand Down Expand Up @@ -692,14 +691,15 @@ Menu::draw_preview(DrawingContext& context)
if (valid_last_index)
{
// Draw progress preview of current item.
const Sizef preview_size(static_cast<float>(SCREEN_WIDTH) / 2.5f, static_cast<float>(SCREEN_HEIGHT) / 2.5f);
SurfacePtr preview = m_items[m_last_preview_item]->get_preview();
const float width_diff = s_preview_size.width - static_cast<float>(preview->get_width());
const float height_diff = s_preview_size.height - static_cast<float>(preview->get_height());
const float width_diff = preview_size.width - static_cast<float>(preview->get_width());
const float height_diff = preview_size.height - static_cast<float>(preview->get_height());
// If the preview is smaller than the maximal size, make sure to draw it with its original size and adjust position to center.
Rectf preview_rect(Vector(static_cast<float>(context.get_width()) * 0.73f - s_preview_size.width / 2 + (width_diff > 0 ? width_diff / 2 : 0),
static_cast<float>(context.get_height()) / 2 - s_preview_size.height / 2 + (height_diff > 0 ? height_diff / 2 : 0)),
Sizef(width_diff > 0 ? static_cast<float>(preview->get_width()) : s_preview_size.width,
height_diff > 0 ? static_cast<float>(preview->get_height()) : s_preview_size.height));
Rectf preview_rect(Vector(static_cast<float>(context.get_width()) * 0.73f - preview_size.width / 2 + (width_diff > 0 ? width_diff / 2 : 0),
static_cast<float>(context.get_height()) / 2 - preview_size.height / 2 + (height_diff > 0 ? height_diff / 2 : 0)),
Sizef(width_diff > 0 ? static_cast<float>(preview->get_width()) : preview_size.width,
height_diff > 0 ? static_cast<float>(preview->get_height()) : preview_size.height));

// If the preview starts overlapping the menu, due to a smaller screen resolution, do not draw it.
// Instead, set the Y position to half the height, so preview data, if available, can still be drawn.
Expand Down
2 changes: 0 additions & 2 deletions src/gui/menu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

#include "gui/menu_action.hpp"
#include "math/rectf.hpp"
#include "math/sizef.hpp"
#include "math/vector.hpp"
#include "supertux/timer.hpp"
#include "video/color.hpp"
Expand Down Expand Up @@ -58,7 +57,6 @@ class PathObject;
class Menu
{
protected:
static const Sizef s_preview_size;
static const float s_preview_fade_time;

public:
Expand Down
2 changes: 1 addition & 1 deletion src/supertux/menu/world_preview_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ WorldPreviewMenu::draw_preview_data(DrawingContext& context, const Rectf& previe
// Draw world progress.
if (!m_world_entries[index].progress_text.empty())
context.color().draw_text(Resources::normal_font, m_world_entries[index].progress_text,
Vector(preview_rect.get_left() + s_preview_size.width / 2, preview_rect.get_bottom() * 1.05f),
Vector(preview_rect.get_left() + static_cast<float>(SCREEN_WIDTH) / 5, preview_rect.get_bottom() * 1.03f),
ALIGN_CENTER, LAYER_GUI, Color(1, 1, 1, alpha));
}

Expand Down

0 comments on commit 9612857

Please sign in to comment.