}
void
-Menu::set_pos(float x, float y)
+Menu::set_center_pos(float x, float y)
{
pos.x = x;
pos.y = y;
return items.size() * 24;
}
-/* Draw the current menu. */
+void
+Menu::on_window_resize()
+{
+ pos.x = SCREEN_WIDTH / 2;
+ pos.y = SCREEN_HEIGHT / 2;
+}
+
void
Menu::draw(DrawingContext& context)
{
void set_active_item(int id);
void draw(DrawingContext& context);
- Vector get_pos() const { return pos; }
- void set_pos(float x, float y);
+ Vector get_center_pos() const { return pos; }
+ void set_center_pos(float x, float y);
void event(const SDL_Event& event);
float get_width() const;
float get_height() const;
+ virtual void on_window_resize();
+
protected:
/** Return the index of the menu item that was 'hit' (ie. the user
clicked on it) in the last event() call */
Rectf menu2rect(const Menu& menu)
{
- return Rectf(menu.get_pos().x - menu.get_width() / 2,
- menu.get_pos().y - menu.get_height() / 2,
- menu.get_pos().x + menu.get_width() / 2,
- menu.get_pos().y + menu.get_height() / 2);
+ return Rectf(menu.get_center_pos().x - menu.get_width() / 2,
+ menu.get_center_pos().y - menu.get_height() / 2,
+ menu.get_center_pos().x + menu.get_width() / 2,
+ menu.get_center_pos().y + menu.get_height() / 2);
}
} // namespace
m_is_active = true;
}
+ void set(const Rectf& rect)
+ {
+ m_to_rect = m_from_rect = rect;
+ }
+
void update()
{
if (m_is_active)
void
MenuManager::draw(DrawingContext& context)
{
- if (m_transition->is_active() || current())
+ if (m_transition->is_active())
{
m_transition->update();
m_transition->draw(context);
}
-
- if (current())
+ else
{
- if (!m_transition->is_active())
+ if (current())
{
+ // brute force the transition into the right shape in case the
+ // menu has changed sizes
+ m_transition->set(menu2rect(*current()));
+ m_transition->draw(context);
+
current()->draw(context);
}
+ }
- if (MouseCursor::current())
- {
- MouseCursor::current()->draw(context);
- }
+ if (current() && MouseCursor::current())
+ {
+ MouseCursor::current()->draw(context);
}
}
{
for(auto i = m_menu_stack.begin(); i != m_menu_stack.end(); ++i)
{
- // FIXME: This is of course not quite right, since it ignores any
- // previous set_pos() calls, it also doesn't update the
- // transition-effect/background rectangle
- (*i)->set_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
+ (*i)->on_window_resize();
}
}
}
else
{
- from_rect = Rectf(to->get_pos(), Sizef(0, 0));
+ from_rect = Rectf(to->get_center_pos(), Sizef(0, 0));
}
Rectf to_rect;
}
else
{
- to_rect = Rectf(from->get_pos(), Sizef(0, 0));
+ to_rect = Rectf(from->get_center_pos(), Sizef(0, 0));
}
m_transition->start(from_rect, to_rect);
MainMenu::MainMenu()
{
- set_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2 + 35);
+ set_center_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2 + 35);
+
add_entry(MNID_STARTGAME, _("Start Game"));
add_entry(MNID_LEVELS_CONTRIB, _("Contrib Levels"));
add_entry(MNID_ADDONS, _("Add-ons"));
}
void
+MainMenu::on_window_resize()
+{
+ set_center_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2 + 35);
+}
+
+void
MainMenu::check_menu()
{
switch (check())