From 3bb36dbd3f97a94adaf442643983e6111c82ae4d Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 4 Apr 2021 23:51:00 +0200 Subject: [PATCH] 2048: Give the board view a nice GUI::Frame look :^) --- Userland/Games/2048/BoardView.cpp | 7 ++++++- Userland/Games/2048/BoardView.h | 10 +++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Userland/Games/2048/BoardView.cpp b/Userland/Games/2048/BoardView.cpp index 5730c494d6..a2196605ce 100644 --- a/Userland/Games/2048/BoardView.cpp +++ b/Userland/Games/2048/BoardView.cpp @@ -177,11 +177,16 @@ Gfx::Color BoardView::text_color_for_cell(u32 value) return Color::from_rgb(0xf9f6f2); } -void BoardView::paint_event(GUI::PaintEvent&) +void BoardView::paint_event(GUI::PaintEvent& event) { + Frame::paint_event(event); + Color background_color = Color::from_rgb(0xbbada0); GUI::Painter painter(*this); + painter.add_clip_rect(event.rect()); + painter.add_clip_rect(frame_inner_rect()); + painter.translate(frame_thickness(), frame_thickness()); if (!m_board) { painter.fill_rect(rect(), background_color); diff --git a/Userland/Games/2048/BoardView.h b/Userland/Games/2048/BoardView.h index d5a0679d1a..7ea1f95328 100644 --- a/Userland/Games/2048/BoardView.h +++ b/Userland/Games/2048/BoardView.h @@ -27,20 +27,20 @@ #pragma once #include "Game.h" -#include +#include -class BoardView final : public GUI::Widget { - C_OBJECT(BoardView) +class BoardView final : public GUI::Frame { + C_OBJECT(BoardView); public: - BoardView(const Game::Board*); virtual ~BoardView() override; - void set_board(const Game::Board* board); Function on_move; private: + explicit BoardView(const Game::Board*); + virtual void resize_event(GUI::ResizeEvent&) override; virtual void paint_event(GUI::PaintEvent&) override; virtual void keydown_event(GUI::KeyEvent&) override;