mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Snake: Spruce up the GUI a tiny bit
Give the game window a GUI::Frame appearance, and make sure the menus have Alt shortcuts. :^)
This commit is contained in:
parent
d136fafde7
commit
04c3cddb1e
Notes:
sideshowbarker
2024-07-18 18:43:15 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/04c3cddb1e4
3 changed files with 13 additions and 10 deletions
|
@ -75,13 +75,13 @@ void SnakeGame::spawn_fruit()
|
|||
Gfx::IntRect SnakeGame::score_rect() const
|
||||
{
|
||||
int score_width = font().width(m_score_text);
|
||||
return { width() - score_width - 2, height() - font().glyph_height() - 2, score_width, font().glyph_height() };
|
||||
return { frame_inner_rect().width() - score_width - 2, frame_inner_rect().height() - font().glyph_height() - 2, score_width, font().glyph_height() };
|
||||
}
|
||||
|
||||
Gfx::IntRect SnakeGame::high_score_rect() const
|
||||
{
|
||||
int high_score_width = font().width(m_high_score_text);
|
||||
return { 2, height() - font().glyph_height() - 2, high_score_width, font().glyph_height() };
|
||||
return { frame_thickness() + 2, frame_inner_rect().height() - font().glyph_height() - 2, high_score_width, font().glyph_height() };
|
||||
}
|
||||
|
||||
void SnakeGame::timer_event(Core::TimerEvent&)
|
||||
|
@ -179,11 +179,11 @@ void SnakeGame::keydown_event(GUI::KeyEvent& event)
|
|||
|
||||
Gfx::IntRect SnakeGame::cell_rect(const Coordinate& coord) const
|
||||
{
|
||||
auto game_rect = rect();
|
||||
auto game_rect = frame_inner_rect();
|
||||
auto cell_size = Gfx::IntSize(game_rect.width() / m_columns, game_rect.height() / m_rows);
|
||||
return {
|
||||
coord.column * cell_size.width(),
|
||||
coord.row * cell_size.height(),
|
||||
game_rect.x() + coord.column * cell_size.width(),
|
||||
game_rect.y() + coord.row * cell_size.height(),
|
||||
cell_size.width(),
|
||||
cell_size.height()
|
||||
};
|
||||
|
@ -191,7 +191,9 @@ Gfx::IntRect SnakeGame::cell_rect(const Coordinate& coord) const
|
|||
|
||||
void SnakeGame::paint_event(GUI::PaintEvent& event)
|
||||
{
|
||||
GUI::Frame::paint_event(event);
|
||||
GUI::Painter painter(*this);
|
||||
painter.add_clip_rect(frame_inner_rect());
|
||||
painter.add_clip_rect(event.rect());
|
||||
painter.fill_rect(event.rect(), Color::Black);
|
||||
|
||||
|
|
|
@ -8,10 +8,11 @@
|
|||
|
||||
#include <AK/CircularQueue.h>
|
||||
#include <AK/NonnullRefPtrVector.h>
|
||||
#include <LibGUI/Widget.h>
|
||||
#include <LibGUI/Frame.h>
|
||||
|
||||
class SnakeGame : public GUI::Frame {
|
||||
C_OBJECT(SnakeGame);
|
||||
|
||||
class SnakeGame : public GUI::Widget {
|
||||
C_OBJECT(SnakeGame)
|
||||
public:
|
||||
virtual ~SnakeGame() override;
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ int main(int argc, char** argv)
|
|||
|
||||
window->set_double_buffering_enabled(false);
|
||||
window->set_title("Snake");
|
||||
window->resize(320, 320);
|
||||
window->resize(324, 344);
|
||||
|
||||
auto& game = window->set_main_widget<SnakeGame>();
|
||||
|
||||
|
@ -70,7 +70,7 @@ int main(int argc, char** argv)
|
|||
GUI::Application::the()->quit();
|
||||
}));
|
||||
|
||||
auto& help_menu = menubar->add_menu("Help");
|
||||
auto& help_menu = menubar->add_menu("&Help");
|
||||
help_menu.add_action(GUI::CommonActions::make_about_action("Snake", app_icon, window));
|
||||
|
||||
window->set_menubar(move(menubar));
|
||||
|
|
Loading…
Reference in a new issue