ServiceMenu: arreglos de colorets
This commit is contained in:
@@ -4,13 +4,33 @@
|
||||
#include "screen.h" // Para param
|
||||
#include <array>
|
||||
|
||||
MenuRenderer::MenuRenderer(std::shared_ptr<Text> element_text, std::shared_ptr<Text> title_text)
|
||||
: element_text_(std::move(element_text)), title_text_(std::move(title_text)) {}
|
||||
MenuRenderer::MenuRenderer(const ServiceMenu *menu_state, std::shared_ptr<Text> element_text, std::shared_ptr<Text> title_text)
|
||||
: element_text_(std::move(element_text)), title_text_(std::move(title_text)) { init(menu_state); }
|
||||
|
||||
void MenuRenderer::init(const ServiceMenu *menu_state)
|
||||
{
|
||||
aspect_ = menu_state->getAspect();
|
||||
switch (aspect_)
|
||||
{
|
||||
case ServiceMenu::Aspect::SHADOW:
|
||||
bg_color_ = SERV_MENU_BG_COLOR_SHADOW;
|
||||
bg_alpha_ = 255;
|
||||
break;
|
||||
|
||||
case ServiceMenu::Aspect::ALPHA:
|
||||
bg_color_ = SERV_MENU_BG_COLOR_ALPHA;
|
||||
bg_alpha_ = 240;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MenuRenderer::render(const ServiceMenu *menu_state)
|
||||
{
|
||||
// Dibuja la sombra
|
||||
if (menu_state->getAspect() == ServiceMenu::Aspect::ASPECT1)
|
||||
if (aspect_ == ServiceMenu::Aspect::SHADOW)
|
||||
{
|
||||
SDL_FRect shadowRect = {rect_.x + 5, rect_.y + 5, rect_.w, rect_.h};
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 64);
|
||||
@@ -18,13 +38,14 @@ void MenuRenderer::render(const ServiceMenu *menu_state)
|
||||
}
|
||||
|
||||
// Dibuja el fondo
|
||||
const Uint8 ALPHA = menu_state->getAspect() == ServiceMenu::Aspect::ASPECT1 ? 255 : 255;
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), bg_color_.r, bg_color_.g, bg_color_.b, ALPHA);
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), bg_color_.r, bg_color_.g, bg_color_.b, bg_alpha_);
|
||||
SDL_RenderFillRect(Screen::get()->getRenderer(), &rect_);
|
||||
|
||||
// Dibuja el borde
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), title_color_.r, title_color_.g, title_color_.b, 255);
|
||||
const Color BORDER_COLOR = title_color_.darken();
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), BORDER_COLOR.r, BORDER_COLOR.g, BORDER_COLOR.b, 255);
|
||||
SDL_RenderRect(Screen::get()->getRenderer(), &rect_);
|
||||
SDL_RenderRect(Screen::get()->getRenderer(), &border_rect_);
|
||||
|
||||
// Dibuja el título
|
||||
float y = rect_.y + title_padding_;
|
||||
@@ -32,7 +53,7 @@ void MenuRenderer::render(const ServiceMenu *menu_state)
|
||||
|
||||
// Dibuja la línea separadora
|
||||
y = rect_.y + upper_height_;
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), title_color_.r, title_color_.g, title_color_.b, 255);
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), BORDER_COLOR.r, BORDER_COLOR.g, BORDER_COLOR.b, 255);
|
||||
SDL_RenderLine(Screen::get()->getRenderer(), rect_.x + ServiceMenu::OPTIONS_HORIZONTAL_PADDING_, y, rect_.x + rect_.w - ServiceMenu::OPTIONS_HORIZONTAL_PADDING_, y);
|
||||
|
||||
// Dibuja las opciones
|
||||
@@ -113,7 +134,7 @@ SDL_FRect MenuRenderer::calculateNewRect(const ServiceMenu *menu_state)
|
||||
const auto &display_options = menu_state->getDisplayOptions();
|
||||
lower_height_ = ((display_options.size() > 0 ? display_options.size() - 1 : 0) * (options_height_ + options_padding_)) + options_height_ + (lower_padding_ * 2);
|
||||
height_ = upper_height_ + lower_height_;
|
||||
|
||||
|
||||
return {(param.game.width - width_) / 2.0f, (param.game.height - height_) / 2.0f, (float)width_, (float)height_};
|
||||
}
|
||||
|
||||
@@ -130,7 +151,7 @@ void MenuRenderer::resize(const ServiceMenu *menu_state)
|
||||
}
|
||||
else
|
||||
{
|
||||
rect_ = new_rect;
|
||||
rect_ = setRect(new_rect);
|
||||
resizing_ = false;
|
||||
}
|
||||
options_y_ = new_rect.y + upper_height_ + lower_padding_;
|
||||
@@ -138,8 +159,7 @@ void MenuRenderer::resize(const ServiceMenu *menu_state)
|
||||
|
||||
void MenuRenderer::setSize(const ServiceMenu *menu_state)
|
||||
{
|
||||
SDL_FRect new_rect = calculateNewRect(menu_state);
|
||||
rect_ = new_rect;
|
||||
rect_ = setRect(calculateNewRect(menu_state));
|
||||
resizing_ = false;
|
||||
options_y_ = rect_.y + upper_height_ + lower_padding_;
|
||||
}
|
||||
@@ -152,15 +172,17 @@ void MenuRenderer::updateResizeAnimation()
|
||||
float t = static_cast<float>(resize_anim_step_) / resize_anim_steps_;
|
||||
if (t >= 1.0f)
|
||||
{
|
||||
rect_ = rect_anim_to_;
|
||||
rect_ = setRect(rect_anim_to_);
|
||||
resizing_ = false;
|
||||
return;
|
||||
}
|
||||
float ease = 1 - (1 - t) * (1 - t);
|
||||
rect_.x = rect_anim_from_.x + (rect_anim_to_.x - rect_anim_from_.x) * ease;
|
||||
rect_.y = rect_anim_from_.y + (rect_anim_to_.y - rect_anim_from_.y) * ease;
|
||||
rect_.w = rect_anim_from_.w + (rect_anim_to_.w - rect_anim_from_.w) * ease;
|
||||
rect_.h = rect_anim_from_.h + (rect_anim_to_.h - rect_anim_from_.h) * ease;
|
||||
SDL_FRect rect =
|
||||
{rect_anim_from_.x + (rect_anim_to_.x - rect_anim_from_.x) * ease,
|
||||
rect_anim_from_.y + (rect_anim_to_.y - rect_anim_from_.y) * ease,
|
||||
rect_anim_from_.w + (rect_anim_to_.w - rect_anim_from_.w) * ease,
|
||||
rect_anim_from_.h + (rect_anim_to_.h - rect_anim_from_.h) * ease};
|
||||
rect_ = setRect(rect);
|
||||
}
|
||||
|
||||
void MenuRenderer::precalculateMenuWidths(const std::vector<std::unique_ptr<MenuOption>> &all_options, const ServiceMenu *menu_state)
|
||||
@@ -209,10 +231,12 @@ void MenuRenderer::updateColorCounter()
|
||||
|
||||
Color MenuRenderer::getAnimatedSelectedColor()
|
||||
{
|
||||
static const std::array<Color, 12> colors = {
|
||||
Color(0xFF, 0xFB, 0x8A), Color(0xFF, 0xE4, 0x5D), Color(0xFF, 0xD1, 0x3C),
|
||||
Color(0xFF, 0xBF, 0x23), Color(0xFF, 0xAA, 0x12), Color(0xE6, 0x9A, 0x08),
|
||||
Color(0xE6, 0x9A, 0x08), Color(0xFF, 0xAA, 0x12), Color(0xFF, 0xBF, 0x23),
|
||||
Color(0xFF, 0xD1, 0x3C), Color(0xFF, 0xE4, 0x5D), Color(0xFF, 0xFB, 0x8A)};
|
||||
return colors.at(color_counter_ % colors.size());
|
||||
static auto colorCycle = generateMirroredCycle(SERV_MENU_SELECTED_COLOR, ColorCycleStyle::HueWave);
|
||||
return colorCycle.at(color_counter_ % colorCycle.size());
|
||||
}
|
||||
|
||||
SDL_FRect MenuRenderer::setRect(SDL_FRect rect)
|
||||
{
|
||||
border_rect_ = {rect.x - 1, rect.y + 1, rect.w + 2, rect.h - 2};
|
||||
return rect;
|
||||
}
|
||||
Reference in New Issue
Block a user