summaryrefslogtreecommitdiff
path: root/Games/Chess/ChessWidget.h
diff options
context:
space:
mode:
authorAnicJov <contact.andrija@gmail.com>2020-12-10 17:54:11 +0100
committerAndreas Kling <kling@serenityos.org>2020-12-10 20:40:51 +0100
commite119d7d6b905835bd52d5fc2b66ced0eaa41b9e1 (patch)
tree56b25028634623c3bedba6279aade526970c52c5 /Games/Chess/ChessWidget.h
parentf631e73519a7b6dabe75b6b60d3579d3afb342c7 (diff)
downloadserenity-e119d7d6b905835bd52d5fc2b66ced0eaa41b9e1.zip
Chess: Added ability to put markings on the board
With this patch you can use right-click to mark a square on the board. You can add modifier keys to the click to change to alternate color (with CTRL) or secondary color (with Shift). If you right-click and drag from one square to another you will create an arrow. The markings go away as soon as you left-click on the board or the board state changes. Note: The arrows sometimes look weird, and horizontal ones get cut off. They also don't account for alpha. This is not a bug in Chess code, rather, likely in the fill_path() function that's used to draw the arrows. If anyone might know what's up with that I urge you to take a look. :)
Diffstat (limited to 'Games/Chess/ChessWidget.h')
-rw-r--r--Games/Chess/ChessWidget.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/Games/Chess/ChessWidget.h b/Games/Chess/ChessWidget.h
index 7535ce8bdf..493c93d25b 100644
--- a/Games/Chess/ChessWidget.h
+++ b/Games/Chess/ChessWidget.h
@@ -100,13 +100,40 @@ public:
void set_coordinates(bool coordinates) { m_coordinates = coordinates; }
bool coordinates() const { return m_coordinates; }
+ struct BoardMarking {
+ Chess::Square from { 50, 50 };
+ Chess::Square to { 50, 50 };
+ bool alternate_color { false };
+ bool secondary_color { false };
+ enum class Type {
+ Square,
+ Arrow,
+ None
+ };
+ Type type() const
+ {
+ if (from.in_bounds() && to.in_bounds() && from != to)
+ return Type::Arrow;
+ else if ((from.in_bounds() && !to.in_bounds()) || (from.in_bounds() && to.in_bounds() && from == to))
+ return Type::Square;
+
+ return Type::None;
+ }
+ bool operator==(const BoardMarking& other) const { return from == other.from && to == other.to; }
+ };
+
private:
Chess::Board m_board;
Chess::Board m_board_playback;
bool m_playback { false };
size_t m_playback_move_number { 0 };
+ BoardMarking m_current_marking;
+ Vector<BoardMarking> m_board_markings;
BoardTheme m_board_theme { "Beige", Color::from_rgb(0xb58863), Color::from_rgb(0xf0d9b5) };
Color m_move_highlight_color { Color::from_rgba(0x66ccee00) };
+ Color m_marking_primary_color { Color::from_rgba(0x66ff0000) };
+ Color m_marking_alternate_color { Color::from_rgba(0x66ffaa00) };
+ Color m_marking_secondary_color { Color::from_rgba(0x6655dd55) };
Chess::Colour m_side { Chess::Colour::White };
HashMap<Chess::Piece, RefPtr<Gfx::Bitmap>> m_pieces;
String m_piece_set;