mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-17 07:50:04 +00:00
Chess: Add chess application to Chess namespace
This is required to port the application to GML.
This commit is contained in:
parent
b6bbff5f3f
commit
10dbadced8
Notes:
sideshowbarker
2024-07-17 04:10:16 +09:00
Author: https://github.com/d-gaston
Commit: 10dbadced8
Pull-request: https://github.com/SerenityOS/serenity/pull/24329
Reviewed-by: https://github.com/AtkinsSJ
Reviewed-by: https://github.com/LucasChollet ✅
Reviewed-by: https://github.com/tcl3
5 changed files with 32 additions and 16 deletions
|
@ -24,6 +24,8 @@
|
|||
#include <LibGfx/Path.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace Chess {
|
||||
|
||||
ErrorOr<NonnullRefPtr<ChessWidget>> ChessWidget::try_create()
|
||||
{
|
||||
auto widget = TRY(AK::adopt_nonnull_ref_or_enomem(new (nothrow) ChessWidget));
|
||||
|
@ -43,7 +45,7 @@ void ChessWidget::paint_event(GUI::PaintEvent& event)
|
|||
GUI::Painter painter(*this);
|
||||
painter.add_clip_rect(event.rect());
|
||||
|
||||
painter.fill_rect(frame_inner_rect(), Color::Black);
|
||||
painter.fill_rect(frame_inner_rect(), Gfx::Color::Black);
|
||||
|
||||
painter.translate(frame_thickness() + widget_offset_x, frame_thickness() + widget_offset_y);
|
||||
|
||||
|
@ -74,8 +76,8 @@ void ChessWidget::paint_event(GUI::PaintEvent& event)
|
|||
auto const piece = active_board.get_piece(sq);
|
||||
if (m_highlight_checks && last_move.is_check && piece.type == Chess::Type::King && piece.color == active_board.turn()) {
|
||||
Array<Gfx::ColorStop, 2> colors = {
|
||||
Gfx::ColorStop { .color = Color::Red, .position = 0.16f },
|
||||
Gfx::ColorStop { .color = Color::Transparent, .position = .66f }
|
||||
Gfx::ColorStop { .color = Gfx::Color::Red, .position = 0.16f },
|
||||
Gfx::ColorStop { .color = Gfx::Color::Transparent, .position = .66f }
|
||||
};
|
||||
|
||||
painter.fill_rect_with_radial_gradient(tile_rect, colors, tile_rect.center() - tile_rect.top_left(), tile_rect.size());
|
||||
|
@ -445,11 +447,11 @@ void ChessWidget::set_board_theme(StringView name)
|
|||
// FIXME: Add some kind of themes.json
|
||||
// The following Colors have been taken from lichess.org, but i'm pretty sure they took them from chess.com.
|
||||
if (name == "Beige") {
|
||||
m_board_theme = { "Beige"sv, Color::from_rgb(0xb58863), Color::from_rgb(0xf0d9b5) };
|
||||
m_board_theme = { "Beige"sv, Gfx::Color::from_rgb(0xb58863), Gfx::Color::from_rgb(0xf0d9b5) };
|
||||
} else if (name == "Green") {
|
||||
m_board_theme = { "Green"sv, Color::from_rgb(0x86a666), Color::from_rgb(0xffffdd) };
|
||||
m_board_theme = { "Green"sv, Gfx::Color::from_rgb(0x86a666), Gfx::Color::from_rgb(0xffffdd) };
|
||||
} else if (name == "Blue") {
|
||||
m_board_theme = { "Blue"sv, Color::from_rgb(0x8ca2ad), Color::from_rgb(0xdee3e6) };
|
||||
m_board_theme = { "Blue"sv, Gfx::Color::from_rgb(0x8ca2ad), Gfx::Color::from_rgb(0xdee3e6) };
|
||||
} else {
|
||||
set_board_theme("Beige"sv);
|
||||
}
|
||||
|
@ -893,3 +895,5 @@ void ChessWidget::config_bool_did_change(StringView domain, StringView group, St
|
|||
update();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#include <LibGUI/Frame.h>
|
||||
#include <LibGfx/Bitmap.h>
|
||||
|
||||
namespace Chess {
|
||||
|
||||
class PGNParseError {
|
||||
public:
|
||||
PGNParseError() = default;
|
||||
|
@ -86,8 +88,8 @@ public:
|
|||
|
||||
struct BoardTheme {
|
||||
StringView name;
|
||||
Color dark_square_color;
|
||||
Color light_square_color;
|
||||
Gfx::Color dark_square_color;
|
||||
Gfx::Color light_square_color;
|
||||
};
|
||||
|
||||
BoardTheme const& board_theme() const { return m_board_theme; }
|
||||
|
@ -155,11 +157,11 @@ private:
|
|||
size_t m_playback_move_number { 0 };
|
||||
BoardMarking m_current_marking;
|
||||
Vector<BoardMarking> m_board_markings;
|
||||
BoardTheme m_board_theme { "Beige"sv, Color::from_rgb(0xb58863), Color::from_rgb(0xf0d9b5) };
|
||||
Color m_move_highlight_color { Color::from_argb(0x66ccee00) };
|
||||
Color m_marking_primary_color { Color::from_argb(0x66ff0000) };
|
||||
Color m_marking_alternate_color { Color::from_argb(0x66ffaa00) };
|
||||
Color m_marking_secondary_color { Color::from_argb(0x6655dd55) };
|
||||
BoardTheme m_board_theme { "Beige"sv, Gfx::Color::from_rgb(0xb58863), Gfx::Color::from_rgb(0xf0d9b5) };
|
||||
Gfx::Color m_move_highlight_color { Gfx::Color::from_argb(0x66ccee00) };
|
||||
Gfx::Color m_marking_primary_color { Gfx::Color::from_argb(0x66ff0000) };
|
||||
Gfx::Color m_marking_alternate_color { Gfx::Color::from_argb(0x66ffaa00) };
|
||||
Gfx::Color m_marking_secondary_color { Gfx::Color::from_argb(0x6655dd55) };
|
||||
Chess::Color m_side { Chess::Color::White };
|
||||
HashMap<Chess::Piece, RefPtr<Gfx::Bitmap const>> m_pieces;
|
||||
bool m_any_piece_images_are_missing { false };
|
||||
|
@ -173,3 +175,5 @@ private:
|
|||
bool m_coordinates { true };
|
||||
bool m_highlight_checks { true };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2020, the SerenityOS developers.
|
||||
* Copyright (c) 2020-2024, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -9,6 +9,8 @@
|
|||
#include <LibGUI/Button.h>
|
||||
#include <LibGUI/Frame.h>
|
||||
|
||||
namespace Chess {
|
||||
|
||||
PromotionDialog::PromotionDialog(ChessWidget& chess_widget)
|
||||
: Dialog(chess_widget.window())
|
||||
, m_selected_piece(Chess::Type::None)
|
||||
|
@ -37,3 +39,5 @@ void PromotionDialog::event(Core::Event& event)
|
|||
{
|
||||
Dialog::event(event);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2020, the SerenityOS developers.
|
||||
* Copyright (c) 2020-2024, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -9,6 +9,8 @@
|
|||
#include "ChessWidget.h"
|
||||
#include <LibGUI/Dialog.h>
|
||||
|
||||
namespace Chess {
|
||||
|
||||
class PromotionDialog final : public GUI::Dialog {
|
||||
C_OBJECT(PromotionDialog)
|
||||
public:
|
||||
|
@ -20,3 +22,5 @@ private:
|
|||
|
||||
Chess::Type m_selected_piece;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-chess"sv));
|
||||
|
||||
auto window = GUI::Window::construct();
|
||||
auto widget = TRY(ChessWidget::try_create());
|
||||
auto widget = TRY(Chess::ChessWidget::try_create());
|
||||
window->set_main_widget(widget);
|
||||
|
||||
auto engines = TRY(available_engines());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue