diff options
author | BrandonKi <kirincichb@gmail.com> | 2021-05-31 14:19:56 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-02 11:18:40 +0200 |
commit | ee38f5241d285943939d259a9732ac318d3070c6 (patch) | |
tree | 89d30084f873676c5d7b91cc3640da06f5413950 /Userland/Games | |
parent | cdb070cdfbf5a8eb09ae9d6e42943894ceea4c2a (diff) | |
download | serenity-ee38f5241d285943939d259a9732ac318d3070c6.zip |
LibChess: Change cursor style when hovering or dragging valid piece
Diffstat (limited to 'Userland/Games')
-rw-r--r-- | Userland/Games/Chess/ChessWidget.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/Userland/Games/Chess/ChessWidget.cpp b/Userland/Games/Chess/ChessWidget.cpp index db1e05fb56..9f873fe71d 100644 --- a/Userland/Games/Chess/ChessWidget.cpp +++ b/Userland/Games/Chess/ChessWidget.cpp @@ -169,6 +169,7 @@ void ChessWidget::mousedown_event(GUI::MouseEvent& event) if (event.button() == GUI::MouseButton::Right) { if (m_dragging_piece) { m_dragging_piece = false; + set_override_cursor(Gfx::StandardCursor::None); m_available_moves.clear(); } else { m_current_marking.from = mouse_to_square(event); @@ -181,6 +182,7 @@ void ChessWidget::mousedown_event(GUI::MouseEvent& event) auto piece = board().get_piece(square); if (drag_enabled() && piece.color == board().turn() && !m_playback) { m_dragging_piece = true; + set_override_cursor(Gfx::StandardCursor::Drag); m_drag_point = event.position(); m_moving_square = square; @@ -219,6 +221,7 @@ void ChessWidget::mouseup_event(GUI::MouseEvent& event) return; m_dragging_piece = false; + set_override_cursor(Gfx::StandardCursor::Hand); m_available_moves.clear(); auto target_square = mouse_to_square(event); @@ -282,6 +285,7 @@ void ChessWidget::mouseup_event(GUI::MouseEvent& event) VERIFY_NOT_REACHED(); } if (over) { + set_override_cursor(Gfx::StandardCursor::None); set_drag_enabled(false); update(); GUI::MessageBox::show(window(), msg, "Game Over", GUI::MessageBox::Type::Information); @@ -299,15 +303,28 @@ void ChessWidget::mousemove_event(GUI::MouseEvent& event) if (!frame_inner_rect().contains(event.position())) return; - if (!m_dragging_piece) + if (m_engine && board().turn() != side()) return; + if (!m_dragging_piece) { + auto square = mouse_to_square(event); + if (!square.in_bounds()) + return; + auto piece = board().get_piece(square); + if (piece.color == board().turn()) + set_override_cursor(Gfx::StandardCursor::Hand); + else + set_override_cursor(Gfx::StandardCursor::None); + return; + } + m_drag_point = event.position(); update(); } void ChessWidget::keydown_event(GUI::KeyEvent& event) { + set_override_cursor(Gfx::StandardCursor::None); switch (event.key()) { case KeyCode::Key_Left: playback_move(PlaybackDirection::Backward); |