[gnome-games] gnotravex: Make it possible to both click to move and drag pieces
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] gnotravex: Make it possible to both click to move and drag pieces
- Date: Tue, 20 Dec 2011 23:37:36 +0000 (UTC)
commit a8469e53959457b065959facd80af76cef1e870e
Author: Robert Ancell <robert ancell canonical com>
Date: Wed Dec 21 10:37:30 2011 +1100
gnotravex: Make it possible to both click to move and drag pieces
gnotravex/data/org.gnome.gnotravex.gschema.xml.in | 5 ----
gnotravex/help/C/move.page | 16 +-------------
gnotravex/src/gnotravex.vala | 21 -------------------
gnotravex/src/puzzle-view.vala | 23 +++++++++++++++++---
4 files changed, 20 insertions(+), 45 deletions(-)
---
diff --git a/gnotravex/data/org.gnome.gnotravex.gschema.xml.in b/gnotravex/data/org.gnome.gnotravex.gschema.xml.in
index 8ac6c7a..b3d46aa 100644
--- a/gnotravex/data/org.gnome.gnotravex.gschema.xml.in
+++ b/gnotravex/data/org.gnome.gnotravex.gschema.xml.in
@@ -6,10 +6,5 @@
<_summary>The size of the playing grid</_summary>
<_description>The value of this key is used to decide the size of the playing grid.</_description>
</key>
- <key name="click-to-move" type="b">
- <default>false</default>
- <_summary>Select the style of control</_summary>
- <_description>Select whether to drag the tiles or to click on the source then the destination.</_description>
- </key>
</schema>
</schemalist>
diff --git a/gnotravex/help/C/move.page b/gnotravex/help/C/move.page
index 03a3502..2f72223 100644
--- a/gnotravex/help/C/move.page
+++ b/gnotravex/help/C/move.page
@@ -21,9 +21,7 @@
<section id="move-piece">
<title>Move a piece</title>
<p>
- To move a piece, you need to click-and-hold on it, drag it from its current
- position to its new position, either on the right box or on the
- left box, and release the mouse button.
+ To move a piece, you can either click on it to select it, and click on the square to place it or drag it to the new square.
</p>
<p>
These moves are not permanent and can be reversed.
@@ -35,16 +33,4 @@
</p>
</note>
</section>
- <section id="move-avoid">
- <title>Avoid the click-and-hold</title>
- <p>
- If you do not feel comfortable with the click-and-hold action to move the
- pieces, it is possible to change that behavior so that you only have to
- click on a piece to move it, and click again to release it in its new position.
- </p>
- <p>
- To do that, from the main menu bar, choose <gui style="menu">Move</gui>,
- and select <gui style="checkbox">Click to Move</gui>.
- </p>
- </section>
</page>
diff --git a/gnotravex/src/gnotravex.vala b/gnotravex/src/gnotravex.vala
index 391b3fa..156d59f 100644
--- a/gnotravex/src/gnotravex.vala
+++ b/gnotravex/src/gnotravex.vala
@@ -5,7 +5,6 @@ public class Gnotravex : Gtk.Application
private const int DELAY = 10;
private const string KEY_GRID_SIZE = "grid-size";
- private const string KEY_CLICK_MOVE = "click-to-move";
private Settings settings;
@@ -63,7 +62,6 @@ public class Gnotravex : Gtk.Application
" </menu>" +
" <menu action='SettingsMenu'>" +
" <menuitem action='Fullscreen'/>" +
- " <menuitem action='ClickToMove'/>" +
" <separator/>" +
" <menuitem action='Size2x2'/>" +
" <menuitem action='Size3x3'/>" +
@@ -101,7 +99,6 @@ public class Gnotravex : Gtk.Application
action_group.set_translation_domain (GETTEXT_PACKAGE);
action_group.add_actions (action_entry, this);
action_group.add_radio_actions (size_action_entry, -1, size_cb);
- action_group.add_toggle_actions (toggles, this);
ui_manager.insert_action_group (action_group, 0);
window.add_accel_group (ui_manager.get_accel_group ());
@@ -129,8 +126,6 @@ public class Gnotravex : Gtk.Application
action_group.add_action_with_accel (fullscreen_action, null);
var leave_fullscreen_action = new GnomeGamesSupport.FullscreenAction ("LeaveFullscreen", window);
action_group.add_action_with_accel (leave_fullscreen_action, null);
- var action = (Gtk.ToggleAction) action_group.get_action ("ClickToMove");
- action.active = settings.get_boolean (KEY_CLICK_MOVE);
var size = settings.get_int (KEY_GRID_SIZE);
if (size < 2 || size > 6)
size = 3;
@@ -153,7 +148,6 @@ public class Gnotravex : Gtk.Application
view = new PuzzleView ();
view.hexpand = true;
view.vexpand = true;
- view.click_to_move = settings.get_boolean (KEY_CLICK_MOVE);
view.button_press_event.connect (view_button_press_event);
view.show ();
grid.attach (view, 0, 2, 1, 1);
@@ -327,17 +321,6 @@ public class Gnotravex : Gtk.Application
new_game ();
}
- private void clickmove_toggle_cb (Gtk.Action action)
- {
- var click_to_move = ((Gtk.ToggleAction) action).active;
-
- if (click_to_move == settings.get_boolean (KEY_CLICK_MOVE))
- return;
-
- settings.set_boolean (KEY_CLICK_MOVE, click_to_move);
- view.click_to_move = click_to_move;
- }
-
private void move_up_cb (Gtk.Action action)
{
puzzle.move_up ();
@@ -376,10 +359,6 @@ public class Gnotravex : Gtk.Application
{"Contents", GnomeGamesSupport.STOCK_CONTENTS, null, null, null, help_cb},
{"About", Gtk.Stock.ABOUT, null, null, null, about_cb}
};
- private const Gtk.ToggleActionEntry toggles[] =
- {
- {"ClickToMove", null, N_("_Click to Move"), null, "Pick up and drop tiles by clicking", clickmove_toggle_cb}
- };
public static int main (string[] args)
{
diff --git a/gnotravex/src/puzzle-view.vala b/gnotravex/src/puzzle-view.vala
index 4633180..ab4389c 100644
--- a/gnotravex/src/puzzle-view.vala
+++ b/gnotravex/src/puzzle-view.vala
@@ -64,11 +64,12 @@ public class PuzzleView : Gtk.DrawingArea
/* Theme */
private Theme theme;
- public bool click_to_move = false;
-
/* Tile being controlled by the mouse */
private TileImage? selected_tile = null;
+ /* Timeout to detect if a click is a selection or a drag */
+ private uint selection_timeout = 0;
+
/* The position inside the tile where the cursor is */
private double selected_x_offset;
private double selected_y_offset;
@@ -367,9 +368,19 @@ public class PuzzleView : Gtk.DrawingArea
selected_tile = image;
selected_x_offset = x - image.x;
selected_y_offset = y - image.y;
+
+ if (selection_timeout != 0)
+ Source.remove (selection_timeout);
+ selection_timeout = Timeout.add (200, selection_timeout_cb);
}
}
}
+
+ private bool selection_timeout_cb ()
+ {
+ selection_timeout = 0;
+ return false;
+ }
private void drop_tile (double x, double y)
{
@@ -425,7 +436,7 @@ public class PuzzleView : Gtk.DrawingArea
{
if (selected_tile == null)
pick_tile (event.x, event.y);
- else if (click_to_move)
+ else if (selected_tile != null)
drop_tile (event.x, event.y);
}
@@ -434,9 +445,13 @@ public class PuzzleView : Gtk.DrawingArea
public override bool button_release_event (Gdk.EventButton event)
{
- if (event.button == 1 && selected_tile != null && !click_to_move)
+ if (event.button == 1 && selected_tile != null && selection_timeout == 0)
drop_tile (event.x, event.y);
+ if (selection_timeout != 0)
+ Source.remove (selection_timeout);
+ selection_timeout = 0;
+
return false;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]