[gnome-mines] Add a flag without a keyboard, on a touch screen.
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-mines] Add a flag without a keyboard, on a touch screen.
- Date: Fri, 4 Oct 2019 07:56:13 +0000 (UTC)
commit de9cde5ecaaf10f5053b269e278bc380bf092518
Author: Ordissimo <thierry ordissimo com>
Date: Fri Oct 4 07:56:03 2019 +0000
Add a flag without a keyboard, on a touch screen.
src/minefield-view.vala | 19 +++++++++++++++----
src/tile.vala | 7 +++++++
2 files changed, 22 insertions(+), 4 deletions(-)
---
diff --git a/src/minefield-view.vala b/src/minefield-view.vala
index 2e7a47b..cc5ab63 100644
--- a/src/minefield-view.vala
+++ b/src/minefield-view.vala
@@ -93,6 +93,7 @@ private class Position : Object
public class MinefieldView : Gtk.Grid
{
private Settings settings;
+ private bool force_nolongpress;
/* true if allowed to mark locations with question marks */
private bool use_question_marks
@@ -151,6 +152,7 @@ public class MinefieldView : Gtk.Grid
public MinefieldView (Settings settings)
{
this.settings = settings;
+ this.force_nolongpress = false;
row_homogeneous = true;
row_spacing = 0;
column_homogeneous = true;
@@ -193,6 +195,7 @@ public class MinefieldView : Gtk.Grid
mines[i,j].show ();
mines[i,j].tile_pressed.connect ((x, y, event) => { tile_pressed_cb (x, y, event); });
mines[i,j].tile_released.connect ((x, y, event) => { tile_released_cb (x, y, event); });
+ mines[i,j].tile_long_pressed.connect ((x, y) => { tile_long_pressed_cb (x, y); });
add (mines[i,j], i, j);
}
}
@@ -239,9 +242,9 @@ public class MinefieldView : Gtk.Grid
if (event.button == 3 || (event.button == 1 && (event.state & Gdk.ModifierType.CONTROL_MASK) != 0))
{
toggle_mark (selected.x, selected.y);
+ this.force_nolongpress = true;
}
- /* Left button to clear */
- else if (event.button == 1)
+ else
{
selected.is_set = true;
}
@@ -253,9 +256,10 @@ public class MinefieldView : Gtk.Grid
public void tile_released_cb (int x, int y, Gdk.EventButton event)
{
- if (event.button != 1)
- return;
+ if (event.button != 1) return;
+ this.force_nolongpress = false;
+
/* Check for end cases and paused game */
if (minefield.exploded || minefield.is_complete || minefield.paused)
return;
@@ -281,6 +285,13 @@ public class MinefieldView : Gtk.Grid
selected.is_set = false;
}
+ public void tile_long_pressed_cb (int x, int y)
+ {
+ if (this.force_nolongpress == true) return;
+ selected.is_set = false;
+ toggle_mark (selected.x, selected.y);
+ }
+
private void explode_cb (Minefield minefield)
{
get_style_context ().add_class ("explodedField");
diff --git a/src/tile.vala b/src/tile.vala
index 51f0d83..b2c0be7 100644
--- a/src/tile.vala
+++ b/src/tile.vala
@@ -2,9 +2,11 @@ public class Tile : Gtk.Button
{
private int _row;
private int _column;
+ private Gtk.GestureLongPress _gesture;
public signal void tile_mouse_over (int x, int y);
public signal void tile_pressed (int x, int y, Gdk.EventButton event);
public signal void tile_released (int x, int y, Gdk.EventButton event);
+ public signal void tile_long_pressed (int x, int y);
public int row
{
@@ -21,6 +23,11 @@ public class Tile : Gtk.Button
_column = pcol;
can_focus = false;
add_class ("tile");
+ _gesture = new Gtk.GestureLongPress (this);
+ _gesture.pressed.connect((x, y) =>
+ {
+ tile_long_pressed (prow, pcol);
+ });
button_press_event.connect ((event) =>
{
/* By default windows with both button press and button release
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]