22 #include <engine/config.hpp>
31 [&ctx](
const auto&
event)
33 --(*ctx.menu_item_index);
34 if (*ctx.menu_item_index < 0)
35 *ctx.menu_item_index = static_cast<int>(ctx.menu_item_texts.size()) - 1;
37 ::menu::update_text_color(ctx);
45 [&ctx](
const auto&
event)
47 ++(*ctx.menu_item_index);
48 if (*ctx.menu_item_index >= ctx.menu_item_texts.size())
49 *ctx.menu_item_index = 0;
51 ::menu::update_text_color(ctx);
59 [&ctx](
const auto&
event)
61 auto callback = ctx.menu_left_callbacks[*ctx.menu_item_index];
62 if (callback != nullptr)
71 [&ctx](
const auto&
event)
73 auto callback = ctx.menu_right_callbacks[*ctx.menu_item_index];
74 if (callback != nullptr)
83 [&ctx](
const auto&
event)
85 const auto& callback = ctx.menu_select_callbacks[*ctx.menu_item_index];
86 if (callback != nullptr)
95 [&ctx](
const auto&
event)
97 if (ctx.menu_back_callback != nullptr)
98 ctx.menu_back_callback();
104 auto menu_action_threshold = [](
float x) ->
bool
119 auto select_menu_item = [&ctx](
const math::fvec2& mouse_position) ->
bool
127 const auto& name_bounds = name->get_bounds();
128 float min_x = name_bounds.min.x();
129 float min_y = name_bounds.min.y();
130 float max_x = name_bounds.max.x();
131 float max_y = name_bounds.max.y();
135 const auto& value_bounds = value->get_bounds();
136 min_x = std::min<float>(min_x, value_bounds.min.x());
137 min_y = std::min<float>(min_y, value_bounds.min.y());
138 max_x = std::max<float>(max_x, value_bounds.max.x());
139 max_y = std::max<float>(max_y, value_bounds.max.y());
147 const auto& viewport = ctx.
window->get_viewport_size();
148 const float x = mouse_position.x();
149 const float y =
static_cast<float>((viewport[1] - mouse_position.y() + 1));
151 if (x >= min_x && x <= max_x)
153 if (y >= min_y && y <= max_y)
171 [&ctx, select_menu_item](
const auto&
event)
174 select_menu_item(math::fvec2(event.position));
182 [&ctx, select_menu_item](
const auto&
event)
185 if (select_menu_item(math::fvec2(event.position)))
188 auto callback = ctx.menu_select_callbacks[*ctx.menu_item_index];
189 if (event.button == input::mouse_button::left)
191 if (ctx.menu_left_callbacks[*ctx.menu_item_index])
193 callback = ctx.menu_left_callbacks[*ctx.menu_item_index];
196 else if (event.button == input::mouse_button::right)
198 if (ctx.menu_right_callbacks[*ctx.menu_item_index])
200 callback = ctx.menu_right_callbacks[*ctx.menu_item_index];
std::vector< std::shared_ptr<::event::subscription > > menu_mouse_subscriptions
input::action menu_modifier_action
input::action menu_left_action
input::action menu_up_action
type::bitmap_font menu_font
input::action menu_back_action
input::action menu_select_action
std::vector< std::shared_ptr<::event::subscription > > menu_action_subscriptions
std::vector< std::tuple< scene::text *, scene::text * > > menu_item_texts
std::shared_ptr< app::window > window
input::action_map menu_action_map
input::action menu_down_action
input::action menu_right_action
std::unique_ptr< app::input_manager > input_manager
const font_metrics & get_font_metrics() const
Returns metrics describing the font.
Publish-subscribe messaging.
float size
Vertical size of the font.