[gnome-robots] Migrate cursors to Vala



commit 562aa9533afcbeb4c0cfb087aa83754d527e3ccc
Author: Andrey Kutejko <andy128k gmail com>
Date:   Tue Aug 25 19:34:43 2020 +0200

    Migrate cursors to Vala

 src/cursor-down-left.h  |  31 -----
 src/cursor-down-right.h |  30 -----
 src/cursor-down.h       |  30 -----
 src/cursor-hold.h       |  30 -----
 src/cursor-left.h       |  30 -----
 src/cursor-right.h      |  30 -----
 src/cursor-up-left.h    |  30 -----
 src/cursor-up-right.h   |  30 -----
 src/cursor-up.h         |  30 -----
 src/cursors.c           | 104 ---------------
 src/cursors.h           |  29 -----
 src/cursors.vala        | 327 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/game.c              |  12 +-
 src/gnome-robots.c      |   1 -
 src/meson.build         |   2 +-
 15 files changed, 336 insertions(+), 410 deletions(-)
---
diff --git a/src/cursors.vala b/src/cursors.vala
new file mode 100644
index 0000000..dd55170
--- /dev/null
+++ b/src/cursors.vala
@@ -0,0 +1,327 @@
+/*
+ * Gnome Robots II - Cursor definitions.
+ *
+ * Copyright 2004 by Callum McKenzie.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * For more details see the file COPYING.
+ */
+
+using Gdk;
+
+Cursor make_cursor (Display display, string[] xpm, int hsx, int hsy) {
+    var pixbuf = new Pixbuf.from_xpm_data (xpm);
+    return new Cursor.from_pixbuf (display, pixbuf, hsx, hsy);
+}
+
+Cursor default_cursor;
+Cursor cursors[9];
+
+public void make_cursors () {
+    var display = Display.get_default ();
+
+    default_cursor = new Cursor.for_display (display, CursorType.LEFT_PTR);
+
+    cursors[0] = make_cursor (display, cursor_up_left, 3, 3);
+    cursors[1] = make_cursor (display, cursor_up, 10, 3);
+    cursors[2] = make_cursor (display, cursor_up_right, 17, 3);
+    cursors[3] = make_cursor (display, cursor_left, 3, 10);
+    cursors[4] = make_cursor (display, cursor_hold, 10, 10);
+    cursors[5] = make_cursor (display, cursor_right, 17, 10);
+    cursors[6] = make_cursor (display, cursor_down_left, 3, 17);
+    cursors[7] = make_cursor (display, cursor_down, 10, 17);
+    cursors[8] = make_cursor (display, cursor_down_right, 17, 17);
+}
+
+public void set_cursor_default (Window window) {
+    window.set_cursor (default_cursor);
+}
+
+public void set_cursor_by_direction (Window window, int dx, int dy) {
+    int index = 3 * dy + dx + 4;
+    window.set_cursor (cursors[index]);
+}
+
+const string cursor_up[] = {
+  /* width height num_colors chars_per_pixel */
+  " 20 20 3 2",
+  /* colors */
+  ".. c none",
+  "## c #ffffff",
+  "** c #000000",
+  /* pixels */
+  "........................................",
+  "....................##..................",
+  "..................##**##................",
+  "................##******##..............",
+  "..............##**********##............",
+  "............##**************##..........",
+  "..........##******************##........",
+  "........##**********************##......",
+  "......########**************########....",
+  "..............##**********##............",
+  "..............##**********##............",
+  "..............##**********##............",
+  "..............##**********##............",
+  "..............##**********##............",
+  "..............##**********##............",
+  "..............##**********##............",
+  "..............##############............",
+  "........................................",
+  "........................................",
+  "........................................"
+};
+
+const string cursor_up_right[] = {
+  /* width height num_colors chars_per_pixel */
+  " 20 20 3 2",
+  /* colors */
+  ".. c none",
+  "## c #ffffff",
+  "** c #000000",
+  /* pixels */
+  "........................................",
+  "................######################..",
+  "..................##****************##..",
+  "....................##**************##..",
+  "......................##************##..",
+  "....................##**************##..",
+  "..................##****************##..",
+  "................##******************##..",
+  "..............##**************##****##..",
+  "............##**************##..##**##..",
+  "..............##**********##......####..",
+  "................##******##..........##..",
+  "..................##**##................",
+  "....................##..................",
+  "........................................",
+  "........................................",
+  "........................................",
+  "........................................",
+  "........................................",
+  "........................................"
+};
+
+const string cursor_right[] = {
+  /* width height num_colors chars_per_pixel */
+  " 20 20 3 2",
+  /* colors */
+  ".. c none",
+  "## c #ffffff",
+  "** c #000000",
+  /* pixels */
+  "........................................",
+  "........................................",
+  "......................##................",
+  "......................####..............",
+  "......................##**##............",
+  "......................##****##..........",
+  "......################********##........",
+  "......##************************##......",
+  "......##**************************##....",
+  "......##****************************##..",
+  "......##**************************##....",
+  "......##************************##......",
+  "......################********##........",
+  "......................##****##..........",
+  "......................##**##............",
+  "......................####..............",
+  "......................##................",
+  "........................................",
+  "........................................",
+  "........................................"
+};
+
+const string cursor_down_right[] = {
+  /* width height num_colors chars_per_pixel */
+  " 20 20 3 2",
+  /* colors */
+  ".. c none",
+  "## c #ffffff",
+  "** c #000000",
+  /* pixels */
+  "........................................",
+  "........................................",
+  "........................................",
+  "........................................",
+  "........................................",
+  "........................................",
+  "....................##..................",
+  "..................##**##................",
+  "................##******##..........##..",
+  "..............##**********##......####..",
+  "............##**************##..##**##..",
+  "..............##**************##****##..",
+  "................##******************##..",
+  "..................##****************##..",
+  "....................##**************##..",
+  "......................##************##..",
+  "....................##**************##..",
+  "..................##****************##..",
+  "................######################..",
+  "........................................"
+};
+
+const string cursor_down[] = {
+  /* width height num_colors chars_per_pixel */
+  " 20 20 3 2",
+  /* colors */
+  ".. c none",
+  "## c #ffffff",
+  "** c #000000",
+  /* pixels */
+  "........................................",
+  "........................................",
+  "........................................",
+  "..............##############............",
+  "..............##**********##............",
+  "..............##**********##............",
+  "..............##**********##............",
+  "..............##**********##............",
+  "..............##**********##............",
+  "..............##**********##............",
+  "..............##**********##............",
+  "......########**************########....",
+  "........##**********************##......",
+  "..........##******************##........",
+  "............##**************##..........",
+  "..............##**********##............",
+  "................##******##..............",
+  "..................##**##................",
+  "....................##..................",
+  "........................................"
+};
+
+const string cursor_down_left[] =
+{
+  /* width height num_colors chars_per_pixel */
+  " 20 20 3 2",
+  /* colors */
+  ".. c none",
+  "## c #ffffff",
+  "** c #000000",
+  /* pixels */
+  "........................................",
+  "........................................",
+  "........................................",
+  "........................................",
+  "........................................",
+  "........................................",
+  "..................##....................",
+  "................##**##..................",
+  "..##..........##******##................",
+  "..####......##**********##..............",
+  "..##**##..##**************##............",
+  "..##****##**************##..............",
+  "..##******************##................",
+  "..##****************##..................",
+  "..##**************##....................",
+  "..##************##......................",
+  "..##**************##....................",
+  "..##****************##..................",
+  "..######################................",
+  "........................................"
+};
+
+const string cursor_left[] = {
+  /* width height num_colors chars_per_pixel */
+  " 20 20 3 2",
+  /* colors */
+  ".. c none",
+  "## c #ffffff",
+  "** c #000000",
+  /* pixels */
+  "........................................",
+  "........................................",
+  "................##......................",
+  "..............####......................",
+  "............##**##......................",
+  "..........##****##......................",
+  "........##********################......",
+  "......##************************##......",
+  "....##**************************##......",
+  "..##****************************##......",
+  "....##**************************##......",
+  "......##************************##......",
+  "........##********################......",
+  "..........##****##......................",
+  "............##**##......................",
+  "..............####......................",
+  "................##......................",
+  "........................................",
+  "........................................",
+  "........................................"
+};
+
+const string cursor_up_left[] = {
+  /* width height num_colors chars_per_pixel */
+  " 20 20 3 2",
+  /* colors */
+  ".. c none",
+  "## c #ffffff",
+  "** c #000000",
+  /* pixels */
+  "........................................",
+  "..######################................",
+  "..##****************##..................",
+  "..##**************##....................",
+  "..##************##......................",
+  "..##**************##....................",
+  "..##****************##..................",
+  "..##******************##................",
+  "..##****##**************##..............",
+  "..##**##..##**************##............",
+  "..####......##**********##..............",
+  "..##..........##******##................",
+  "................##**##..................",
+  "..................##....................",
+  "........................................",
+  "........................................",
+  "........................................",
+  "........................................",
+  "........................................",
+  "........................................"
+};
+
+const string cursor_hold[] = {
+  /* width height num_colors chars_per_pixel */
+  " 20 20 3 2",
+  /* colors */
+  ".. c none",
+  "## c #ffffff",
+  "** c #000000",
+  /* pixels */
+  "........................................",
+  "........................................",
+  "........................................",
+  "........................................",
+  "..............##########................",
+  "..........####**********####............",
+  "..........##**************##............",
+  "........##******************##..........",
+  "........##******************##..........",
+  "........##******************##..........",
+  "........##******************##..........",
+  "........##******************##..........",
+  "..........##**************##............",
+  "..........####**********####............",
+  "..............##########................",
+  "........................................",
+  "........................................",
+  "........................................",
+  "........................................",
+  "........................................"
+};
+
diff --git a/src/game.c b/src/game.c
index 0d967df..0f06a85 100644
--- a/src/game.c
+++ b/src/game.c
@@ -34,7 +34,6 @@
 #include "gnome-robots.h"
 #include "properties.h"
 #include "graphics.h"
-#include "cursors.h"
 
 /**********************************************************************/
 /* Exported Variables                                                 */
@@ -1357,10 +1356,15 @@ move_cb (GtkEventControllerMotion *controller,
          gpointer                  user_data)
 {
   int dx, dy;
+  GdkWindow *window;
 
-  get_dir ((int)x, (int)y, &dx, &dy);
-
-  set_cursor_by_direction (gtk_widget_get_window (game_area), dx, dy);
+  window = gtk_widget_get_window (game_area);
+  if (game_state != STATE_PLAYING) {
+    set_cursor_default (window);
+  } else {
+    get_dir ((int)x, (int)y, &dx, &dy);
+    set_cursor_by_direction (window, dx, dy);
+  }
 
   return;
 }
diff --git a/src/gnome-robots.c b/src/gnome-robots.c
index 493d326..3a716dd 100644
--- a/src/gnome-robots.c
+++ b/src/gnome-robots.c
@@ -38,7 +38,6 @@
 #include "graphics.h"
 #include "properties.h"
 #include "game.h"
-#include "cursors.h"
 
 /* Minimum sizes. */
 #define MINIMUM_TILE_WIDTH   8
diff --git a/src/meson.build b/src/meson.build
index 4716956..20c975d 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -17,6 +17,7 @@ vala_sources = files(
     'controls.vala',
     'game-config.vala',
     'sound.vala',
+    'cursors.vala',
 )
 
 vala_lib = static_library('riiv',
@@ -39,7 +40,6 @@ riiv_dependency = declare_dependency(
 )
 
 sources = files(
-    'cursors.c',
     'game.c',
     'gnome-robots.c',
     'graphics.c',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]