]> git.cworth.org Git - grrobot/blobdiff - src/grr_icon.c
Update to 2020
[grrobot] / src / grr_icon.c
index bf9a29a850f8342f3c8ce63e47c8d34680fc45c2..c273bd712ef450a69672453f766d7252a1c8df54 100644 (file)
@@ -1,6 +1,6 @@
 /* grrobot - Ricochet Robot using GTK+ and Xr
  *
- * Copyright © 2003 Carl Worth
+ * Copyright Â© 2003 Carl Worth
  *
  * Permission to use, copy, modify, distribute, and sell this software
  * and its documentation for any purpose is hereby granted without
@@ -91,8 +91,10 @@ struct {
     { RR_WALL_ABOVE, "wall",
       GRR_ICON_SVG_WALL, sizeof (GRR_ICON_SVG_WALL) },
 
-    { RR_WALL_NONE, "cell",
-      GRR_ICON_SVG_CELL, sizeof (GRR_ICON_SVG_CELL) }
+    { 0, "cell1",
+      GRR_ICON_SVG_CELL1, sizeof (GRR_ICON_SVG_CELL1) },
+    { 0, "cell2",
+      GRR_ICON_SVG_CELL2, sizeof (GRR_ICON_SVG_CELL2) }
 };
 #define NUM_BUILTINS (sizeof (builtins) / sizeof (builtins[0]))
 
@@ -125,35 +127,28 @@ grr_icon_create (char *name)
 static rr_status_t
 _grr_icon_init (grr_icon_t *icon, char *name)
 {
-    xsvg_status_t status;
     char *file, *buf;
     int buflen;
+    GError *error = NULL;
 
     icon->surface = NULL;
     icon->surface_width = 0;
     icon->surface_height = 0;
 
-    status = xsvg_create (&icon->xsvg);
-    if (status)
-       return RR_STATUS_NO_MEMORY;
-
     file = _grr_icon_find_file (name);
-
     if (file) {
-       status = xsvg_parse_file (icon->xsvg, file);
-       if (status == XSVG_STATUS_SUCCESS) {
-           free (file);
-           return RR_STATUS_SUCCESS;
-       }
-       fprintf (stderr, "Error parsing SVG icon: %s\n", file);
-       free (file);
-    }
-
-    _grr_icon_find_buffer (name, &buf, &buflen);
-    status = xsvg_parse_buffer (icon->xsvg, buf, buflen);
-    if (status) {
-       fprintf (stderr, "Error parsing built-in SVG icon for: %s\n", name);
-       return RR_STATUS_PARSE_ERROR;
+           icon->rsvg = rsvg_handle_new_from_file(file, &error);
+           if (!icon->rsvg) {
+                   fprintf (stderr, "Error parsing SVG icon: %s\n", file);
+                   return RR_STATUS_PARSE_ERROR;
+           }
+    } else {
+           _grr_icon_find_buffer (name, &buf, &buflen);
+           icon->rsvg = rsvg_handle_new_from_data(buf, buflen, &error);
+           if (!icon->rsvg) {
+                   fprintf (stderr, "Error parsing built-in SVG icon for: %s\n", name);
+                   return RR_STATUS_PARSE_ERROR;
+           }
     }
     return RR_STATUS_SUCCESS;
 }
@@ -223,37 +218,44 @@ grr_icon_target_name (rr_target_t target)
 void
 grr_icon_draw (grr_icon_t *icon, cairo_t *xrs)
 {
-    xsvg_status_t status;
-
-    status =  xsvg_render (icon->xsvg, xrs);
+    rsvg_handle_render_cairo(icon->rsvg, xrs);
+#if 0
     if (status) {
-       fprintf (stderr, "xsvg_render error\n");
+       fprintf (stderr, "svg_cairo_render error\n");
        return;
     }
+#endif
 }
 
 void
 grr_icon_predraw (grr_icon_t *icon, cairo_t *xrs, int width, int height)
 {
+    cairo_t *xrs2;
+    cairo_matrix_t ctm;
+
     if (icon->surface_width != width || icon->surface_height != height) {
        if (icon->surface)
            cairo_surface_destroy (icon->surface);
        icon->surface_width = width;
        icon->surface_height = height;
-       icon->surface = cairo_surface_create_similar (cairo_get_target_surface (xrs),
-                                                     CAIRO_FORMAT_ARGB32,
+       icon->surface = cairo_surface_create_similar (cairo_get_target (xrs),
+                                                     CAIRO_CONTENT_COLOR_ALPHA,
                                                      width, height);
     }
 
-    cairo_save (xrs);
-    cairo_set_target_surface (xrs, icon->surface);
-    grr_icon_draw (icon, xrs);
-    cairo_restore (xrs);
+    /* Need to copy the CTM from the original cairo_t to the new one */
+    xrs2 = cairo_create (icon->surface);
+    cairo_get_matrix (xrs, &ctm);
+    cairo_set_matrix (xrs2, &ctm);
+    grr_icon_draw (icon, xrs2);
+    cairo_destroy (xrs2);
 }
 
 void
-grr_icon_draw_predrawn (grr_icon_t *icon, cairo_t *xrs)
+grr_icon_draw_predrawn (grr_icon_t *icon, cairo_t *xrs, double alpha)
 {
-    if (icon->surface)
-       cairo_show_surface (xrs, icon->surface, icon->surface_width, icon->surface_height);
+    if (icon->surface) {
+       cairo_set_source_surface (xrs, icon->surface, 0.0, 0.0);
+       cairo_paint_with_alpha (xrs, alpha);
+    }
 }