[gnome-robots/arnaudb/wip/gtk4: 13/36] Adapt to GdkCursor API.




commit 2add7815a8a8e2661005f47fd779f5e1cea68e9f
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Mon May 25 15:56:41 2020 +0200

    Adapt to GdkCursor API.

 data/cursors/cursor-down-left.png  | Bin 212 -> 648 bytes
 data/cursors/cursor-down-right.png | Bin 217 -> 658 bytes
 data/cursors/cursor-down.png       | Bin 220 -> 653 bytes
 data/cursors/cursor-hold.png       | Bin 204 -> 632 bytes
 data/cursors/cursor-left.png       | Bin 220 -> 651 bytes
 data/cursors/cursor-right.png      | Bin 224 -> 658 bytes
 data/cursors/cursor-up-left.png    | Bin 216 -> 655 bytes
 data/cursors/cursor-up-right.png   | Bin 211 -> 653 bytes
 data/cursors/cursor-up.png         | Bin 208 -> 635 bytes
 data/cursors/cursors.xcf           | Bin 0 -> 5995 bytes
 src/cursor-down-left.h             |  80 ------------------------------------
 src/cursor-down-right.h            |  80 ------------------------------------
 src/cursor-down.h                  |  81 -------------------------------------
 src/cursor-hold.h                  |  79 ------------------------------------
 src/cursor-left.h                  |  81 -------------------------------------
 src/cursor-right.h                 |  81 -------------------------------------
 src/cursor-up-left.h               |  80 ------------------------------------
 src/cursor-up-right.h              |  80 ------------------------------------
 src/cursor-up.h                    |  80 ------------------------------------
 src/cursors.c                      |  58 +++++++++++---------------
 src/gnome-robots.gresource.xml     |  11 +++++
 21 files changed, 34 insertions(+), 757 deletions(-)
---
diff --git a/data/cursors/cursor-down-left.png b/data/cursors/cursor-down-left.png
index 56b3183..d7a6fe4 100644
Binary files a/data/cursors/cursor-down-left.png and b/data/cursors/cursor-down-left.png differ
diff --git a/data/cursors/cursor-down-right.png b/data/cursors/cursor-down-right.png
index 1fa42e3..e7ea296 100644
Binary files a/data/cursors/cursor-down-right.png and b/data/cursors/cursor-down-right.png differ
diff --git a/data/cursors/cursor-down.png b/data/cursors/cursor-down.png
index ce563e0..5c0a3ce 100644
Binary files a/data/cursors/cursor-down.png and b/data/cursors/cursor-down.png differ
diff --git a/data/cursors/cursor-hold.png b/data/cursors/cursor-hold.png
index 74903fb..be33934 100644
Binary files a/data/cursors/cursor-hold.png and b/data/cursors/cursor-hold.png differ
diff --git a/data/cursors/cursor-left.png b/data/cursors/cursor-left.png
index f809be6..6ab0beb 100644
Binary files a/data/cursors/cursor-left.png and b/data/cursors/cursor-left.png differ
diff --git a/data/cursors/cursor-right.png b/data/cursors/cursor-right.png
index 19fc04f..1c72962 100644
Binary files a/data/cursors/cursor-right.png and b/data/cursors/cursor-right.png differ
diff --git a/data/cursors/cursor-up-left.png b/data/cursors/cursor-up-left.png
index e62dc16..ef0b9ff 100644
Binary files a/data/cursors/cursor-up-left.png and b/data/cursors/cursor-up-left.png differ
diff --git a/data/cursors/cursor-up-right.png b/data/cursors/cursor-up-right.png
index 8232db4..129d571 100644
Binary files a/data/cursors/cursor-up-right.png and b/data/cursors/cursor-up-right.png differ
diff --git a/data/cursors/cursor-up.png b/data/cursors/cursor-up.png
index a0a5a93..a62b54c 100644
Binary files a/data/cursors/cursor-up.png and b/data/cursors/cursor-up.png differ
diff --git a/data/cursors/cursors.xcf b/data/cursors/cursors.xcf
new file mode 100644
index 0000000..8e61a9d
Binary files /dev/null and b/data/cursors/cursors.xcf differ
diff --git a/src/cursors.c b/src/cursors.c
index cba97ef..541e1c4 100644
--- a/src/cursors.c
+++ b/src/cursors.c
@@ -26,37 +26,25 @@
 #include "game.h"
 #include "gbdefs.h"
 
-#include "cursor-down.h"
-#include "cursor-down-left.h"
-#include "cursor-down-right.h"
-#include "cursor-hold.h"
-#include "cursor-left.h"
-#include "cursor-right.h"
 #include "cursors.h"
-#include "cursor-up.h"
-#include "cursor-up-left.h"
-#include "cursor-up-right.h"
 
 typedef struct {
-  const guint8 *data;
-  gsize data_len;
-  int hsx;
-  int hsy;
+  gchar *small_name;
+  int hotspot_x;
+  int hotspot_y;
   GdkCursor *cursor;
 } cursor_props;
 
-#define CURSOR_ENTRY(d,hx,hy) { cursor_##d, sizeof (cursor_##d), hx, hy, NULL }
-
-cursor_props cursor_list[] = {
-  CURSOR_ENTRY (up_left, 3, 3),
-  CURSOR_ENTRY (up, 10, 3),
-  CURSOR_ENTRY (up_right, 17, 3),
-  CURSOR_ENTRY (left, 3, 10),
-  CURSOR_ENTRY (hold, 10, 10),
-  CURSOR_ENTRY (right, 17, 10),
-  CURSOR_ENTRY (down_left, 3, 17),
-  CURSOR_ENTRY (down, 10, 17),
-  CURSOR_ENTRY (down_right, 17, 17)
+cursor_props cursor_list[] = { /* cursors are 17x17 */
+  { "up-left",     1,  1, NULL },
+  { "up",          8,  1, NULL },
+  { "up-right",   15,  1, NULL },
+  { "left",        1,  8, NULL },
+  { "hold",        8,  8, NULL },
+  { "right",      15,  8, NULL },
+  { "down-left",   1, 15, NULL },
+  { "down",        8, 15, NULL },
+  { "down-right", 15, 15, NULL }
 };
 
 GdkCursor *default_cursor;
@@ -64,22 +52,22 @@ GdkCursor *default_cursor;
 void
 make_cursors (void)
 {
-  GdkPixbuf *pixbuf;
+  GdkTexture *texture;
   int i;
+  gchar *resource;
   cursor_props *c;
 
-  default_cursor = gdk_cursor_new_for_display (gdk_display_get_default (),
-                                               GDK_LEFT_PTR);
+  default_cursor = gdk_cursor_new_from_name ("default", /* fallback */ NULL);
 
   c = cursor_list;
   for (i = 0; i < G_N_ELEMENTS (cursor_list); ++i) {
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-    pixbuf = gdk_pixbuf_new_from_inline (c->data_len, c->data, FALSE, NULL);
-G_GNUC_END_IGNORE_DEPRECATIONS
-    c->cursor = gdk_cursor_new_from_pixbuf (gdk_display_get_default (),
-                                            pixbuf,
-                                            c->hsx, c->hsy);
-    g_object_unref (pixbuf);
+    resource = g_strconcat ("/org/gnome/Robots/cursors/cursor-", c->small_name, ".png", NULL);
+    texture = gdk_texture_new_from_resource (resource);
+
+    c->cursor = gdk_cursor_new_from_texture (texture, c->hotspot_x, c->hotspot_y, /* fallback */ NULL);
+
+    g_object_unref (texture);
+    g_free (resource);
 
     c++;
   }
diff --git a/src/gnome-robots.gresource.xml b/src/gnome-robots.gresource.xml
index 32579e0..93b28dc 100644
--- a/src/gnome-robots.gresource.xml
+++ b/src/gnome-robots.gresource.xml
@@ -4,6 +4,17 @@
     <file preprocess="xml-stripblanks" alias="robots.ui">../data/robots.ui</file>
     <file alias="robots.css">../data/robots.css</file>
   </gresource> -->
+  <gresource prefix="/org/gnome/Robots/cursors">
+    <file preprocess="to-pixdata" alias="cursor-hold.png"       >../data/cursors/cursor-hold.png</file>
+    <file preprocess="to-pixdata" alias="cursor-up.png"         >../data/cursors/cursor-up.png</file>
+    <file preprocess="to-pixdata" alias="cursor-up-right.png"   >../data/cursors/cursor-up-right.png</file>
+    <file preprocess="to-pixdata" alias="cursor-right.png"      >../data/cursors/cursor-right.png</file>
+    <file preprocess="to-pixdata" alias="cursor-down-right.png" >../data/cursors/cursor-down-right.png</file>
+    <file preprocess="to-pixdata" alias="cursor-down.png"       >../data/cursors/cursor-down.png</file>
+    <file preprocess="to-pixdata" alias="cursor-down-left.png"  >../data/cursors/cursor-down-left.png</file>
+    <file preprocess="to-pixdata" alias="cursor-left.png"       >../data/cursors/cursor-left.png</file>
+    <file preprocess="to-pixdata" alias="cursor-up-left.png"    >../data/cursors/cursor-up-left.png</file>
+  </gresource>
   <gresource prefix="/org/gnome/Robots/gtk">
     <file preprocess="xml-stripblanks" alias="menus.ui">../data/app-menu.ui</file>
   </gresource>


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