Skip to content

Commit

Permalink
Improve game view
Browse files Browse the repository at this point in the history
Draw square at tentative position instead.
Clear cursor when a pointer leaves or the view is pinched.
  • Loading branch information
yescallop committed Nov 16, 2024
1 parent 6757c85 commit d0f6fc6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 26 deletions.
53 changes: 30 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions client/src/game_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,13 @@ pub fn GameView(
draw_circle(p, stone_radius);

ctx.set_fill_style_str("grey");
draw_circle(p, dot_radius);
let (x, y) = calc.view_to_canvas_pos(p);
ctx.fill_rect(
x - dot_radius,
y - dot_radius,
dot_radius * 2.0,
dot_radius * 2.0,
);
}
}

Expand Down Expand Up @@ -759,6 +765,9 @@ pub fn GameView(
if state.down_pointers.len() == 2 {
state.prev_view_size = view_size.get();
state.pointer_state = PointerState::Pinched;
if cursor_pos.get().is_some() {
cursor_pos.set(None);
}
}
};

Expand Down Expand Up @@ -880,6 +889,9 @@ pub fn GameView(
if state.last_hover_before_enabled.and_then(|po| po.id) == po.id {
state.last_hover_before_enabled = None;
}
if cursor_pos.get().is_some() {
cursor_pos.set(None);
}
};

// Handles `contextmenu` events.
Expand Down Expand Up @@ -919,8 +931,7 @@ pub fn GameView(

Effect::new(move || {
if !disabled.get() {
let mut state = state.write_value();
if let Some(po) = state.last_hover_before_enabled.take() {
if let Some(po) = state.write_value().last_hover_before_enabled.take() {
update_cursor(po);
}
}
Expand Down

0 comments on commit d0f6fc6

Please sign in to comment.