[four-in-a-row/arnaudb/new-ui: 10/12] Disallow clicking outside the board.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [four-in-a-row/arnaudb/new-ui: 10/12] Disallow clicking outside the board.
- Date: Thu, 19 Dec 2019 19:50:45 +0000 (UTC)
commit 6e056e8866e01e21a65edeb436b8e730690ba14c
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Thu Dec 19 04:00:39 2019 +0100
Disallow clicking outside the board.
That is clearly more often a
bad click than a wanted one.
src/game-board-view.vala | 32 +++++++++++++++++++-------------
1 file changed, 19 insertions(+), 13 deletions(-)
---
diff --git a/src/game-board-view.vala b/src/game-board-view.vala
index 59d80e1..ff4c543 100644
--- a/src/game-board-view.vala
+++ b/src/game-board-view.vala
@@ -42,17 +42,6 @@ private class GameBoardView : Gtk.DrawingArea {
this.game_board = game_board;
}
- private inline int get_column(int xpos) {
- /* Derive column from pixel position */
- int c = (xpos - board_x) / tile_size;
- if (c > 6)
- c = 6;
- if (c < 0)
- c = 0;
-
- return c;
- }
-
internal inline void draw_tile(int r, int c) {
queue_draw_area(c*tile_size + board_x, r*tile_size + board_y, tile_size, tile_size);
}
@@ -278,10 +267,27 @@ private class GameBoardView : Gtk.DrawingArea {
protected override bool button_press_event(Gdk.EventButton e) {
int x;
+ int y;
Gdk.Window? window = get_window();
if (window == null)
assert_not_reached ();
- ((!) window).get_device_position(e.device, out x, null, null);
- return column_clicked(get_column(x));
+ ((!) window).get_device_position(e.device, out x, out y, null);
+
+ int col;
+ if (get_column(x, y, out col))
+ return column_clicked(col);
+ else
+ return false;
+ }
+ private inline bool get_column(int x, int y, out int col) {
+ col = (x - board_x) / tile_size;
+ if (x < board_x || y < board_y || col < 0 || col > 6)
+ return false;
+
+ int row = (y - board_y) / tile_size;
+ if (row < 0 || row > 6)
+ return false;
+
+ return true;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]