[gimp] plug-ins: port lighting from stock icons to using a resource



commit f6b60e08f23160dc67cfdd9b2a800056423f7066
Author: Michael Natterer <mitch gimp org>
Date:   Sat Jul 20 17:23:54 2019 +0200

    plug-ins: port lighting from stock icons to using a resource
    
    and icons names. Also fix two more warnings so it's now completely
    undeprecated.

 plug-ins/lighting/Makefile.am                      |   4 +-
 plug-ins/lighting/images/.gitignore                |   6 +-
 plug-ins/lighting/images/Makefile.am               |  48 ++++-----
 .../images/lighting-icon-images.gresource.xml      |  15 +++
 ...igh.png => lighting-intensity-ambient-high.png} | Bin
 ...-low.png => lighting-intensity-ambient-low.png} | Bin
 ...igh.png => lighting-intensity-diffuse-high.png} | Bin
 ...-low.png => lighting-intensity-diffuse-low.png} | Bin
 ....png => lighting-reflectivity-diffuse-high.png} | Bin
 ...w.png => lighting-reflectivity-diffuse-low.png} | Bin
 ...ng => lighting-reflectivity-highlight-high.png} | Bin
 ...png => lighting-reflectivity-highlight-low.png} | Bin
 ...png => lighting-reflectivity-specular-high.png} | Bin
 ....png => lighting-reflectivity-specular-low.png} | Bin
 plug-ins/lighting/lighting-icons.c                 |  43 ++++++++
 plug-ins/lighting/lighting-icons.h                 |  37 +++++++
 plug-ins/lighting/lighting-preview.c               |  18 ++--
 plug-ins/lighting/lighting-stock.c                 | 110 ---------------------
 plug-ins/lighting/lighting-stock.h                 |  37 -------
 plug-ins/lighting/lighting-ui.c                    |  36 +++----
 20 files changed, 151 insertions(+), 203 deletions(-)
---
diff --git a/plug-ins/lighting/Makefile.am b/plug-ins/lighting/Makefile.am
index 92c3ce3397..88db730c1f 100644
--- a/plug-ins/lighting/Makefile.am
+++ b/plug-ins/lighting/Makefile.am
@@ -30,6 +30,8 @@ libexec_PROGRAMS = lighting
 lighting_SOURCES = \
        lighting-apply.c        \
        lighting-apply.h        \
+       lighting-icons.c        \
+       lighting-icons.h        \
        lighting-image.c        \
        lighting-image.h        \
        lighting-main.c         \
@@ -38,8 +40,6 @@ lighting_SOURCES = \
        lighting-preview.h      \
        lighting-shade.c        \
        lighting-shade.h        \
-       lighting-stock.c        \
-       lighting-stock.h        \
        lighting-ui.c           \
        lighting-ui.h
 
diff --git a/plug-ins/lighting/images/.gitignore b/plug-ins/lighting/images/.gitignore
index 72a909e14e..b752947561 100644
--- a/plug-ins/lighting/images/.gitignore
+++ b/plug-ins/lighting/images/.gitignore
@@ -1,6 +1,4 @@
 /Makefile
 /Makefile.in
-/.xvpics
-/.thumbnails
-/stock-icons.list
-/stock-pixbufs.h
+/lighting-icon-images.c
+/lighting-icon-images.h
diff --git a/plug-ins/lighting/images/Makefile.am b/plug-ins/lighting/images/Makefile.am
index 55dfbde88a..c2fd813a3e 100644
--- a/plug-ins/lighting/images/Makefile.am
+++ b/plug-ins/lighting/images/Makefile.am
@@ -1,29 +1,33 @@
 ## Process this file with automake to produce Makefile.in
 
 STOCK_IMAGES = \
-       stock-intensity-ambient-high.png        \
-       stock-intensity-ambient-low.png         \
-       stock-intensity-diffuse-high.png        \
-       stock-intensity-diffuse-low.png         \
-       stock-reflectivity-diffuse-high.png     \
-       stock-reflectivity-diffuse-low.png      \
-       stock-reflectivity-specular-high.png    \
-       stock-reflectivity-specular-low.png     \
-       stock-reflectivity-highlight-high.png   \
-       stock-reflectivity-highlight-low.png
+       lighting-intensity-ambient-high.png             \
+       lighting-intensity-ambient-low.png              \
+       lighting-intensity-diffuse-high.png             \
+       lighting-intensity-diffuse-low.png              \
+       lighting-reflectivity-diffuse-high.png          \
+       lighting-reflectivity-diffuse-low.png           \
+       lighting-reflectivity-specular-high.png         \
+       lighting-reflectivity-specular-low.png          \
+       lighting-reflectivity-highlight-high.png        \
+       lighting-reflectivity-highlight-low.png
 
-EXTRA_DIST = $(STOCK_IMAGES)
+EXTRA_DIST =
+       $(STOCK_IMAGES)         \
+       lighting-icon-images.gresource.xml
 
-noinst_DATA = stock-pixbufs.h
-CLEANFILES = $(noinst_DATA) stock-icons.list
+noinst_DATA = \
+       lighting-icon-images.c  \
+       lighting-icon-images.h
 
-stock-icons.list: $(STOCK_IMAGES) Makefile.am
-       ( rm -f $@; \
-          for image in $(STOCK_IMAGES); do \
-            echo $$image | \
-              sed -e 's|.*/||' -e 's|-|_|g' -e 's|\.png$$||' >> $@; \
-           echo "  $(srcdir)/$$image" >> $@; \
-         done )
+CLEANFILES = $(noinst_DATA)
 
-$(srcdir)/stock-pixbufs.h: stock-icons.list
-       $(GDK_PIXBUF_CSOURCE) --raw --build-list `cat stock-icons.list` > $(@F)
+lighting-icon-images.h: lighting-icon-images.gresource.xml
+       $(AM_V_GEN) $(HOST_GLIB_COMPILE_RESOURCES) \
+         --sourcedir=$(srcdir) --generate-header \
+         --target=$@ lighting-icon-images.gresource.xml
+
+lighting-icon-images.c: lighting-icon-images.h
+       $(AM_V_GEN) $(HOST_GLIB_COMPILE_RESOURCES) \
+         --sourcedir=$(srcdir) --generate-source \
+         --target=$@ lighting-icon-images.gresource.xml
diff --git a/plug-ins/lighting/images/lighting-icon-images.gresource.xml 
b/plug-ins/lighting/images/lighting-icon-images.gresource.xml
new file mode 100644
index 0000000000..5295811345
--- /dev/null
+++ b/plug-ins/lighting/images/lighting-icon-images.gresource.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gimp/lighting/icons">
+    <file preprocess="to-pixdata">lighting-intensity-ambient-high.png</file>
+    <file preprocess="to-pixdata">lighting-intensity-ambient-low.png</file>
+    <file preprocess="to-pixdata">lighting-intensity-diffuse-high.png</file>
+    <file preprocess="to-pixdata">lighting-intensity-diffuse-low.png</file>
+    <file preprocess="to-pixdata">lighting-reflectivity-diffuse-high.png</file>
+    <file preprocess="to-pixdata">lighting-reflectivity-diffuse-low.png</file>
+    <file preprocess="to-pixdata">lighting-reflectivity-specular-high.png</file>
+    <file preprocess="to-pixdata">lighting-reflectivity-specular-low.png</file>
+    <file preprocess="to-pixdata">lighting-reflectivity-highlight-high.png</file>
+    <file preprocess="to-pixdata">lighting-reflectivity-highlight-low.png</file>
+  </gresource>
+</gresources>
diff --git a/plug-ins/lighting/images/stock-intensity-ambient-high.png 
b/plug-ins/lighting/images/lighting-intensity-ambient-high.png
similarity index 100%
rename from plug-ins/lighting/images/stock-intensity-ambient-high.png
rename to plug-ins/lighting/images/lighting-intensity-ambient-high.png
diff --git a/plug-ins/lighting/images/stock-intensity-ambient-low.png 
b/plug-ins/lighting/images/lighting-intensity-ambient-low.png
similarity index 100%
rename from plug-ins/lighting/images/stock-intensity-ambient-low.png
rename to plug-ins/lighting/images/lighting-intensity-ambient-low.png
diff --git a/plug-ins/lighting/images/stock-intensity-diffuse-high.png 
b/plug-ins/lighting/images/lighting-intensity-diffuse-high.png
similarity index 100%
rename from plug-ins/lighting/images/stock-intensity-diffuse-high.png
rename to plug-ins/lighting/images/lighting-intensity-diffuse-high.png
diff --git a/plug-ins/lighting/images/stock-intensity-diffuse-low.png 
b/plug-ins/lighting/images/lighting-intensity-diffuse-low.png
similarity index 100%
rename from plug-ins/lighting/images/stock-intensity-diffuse-low.png
rename to plug-ins/lighting/images/lighting-intensity-diffuse-low.png
diff --git a/plug-ins/lighting/images/stock-reflectivity-diffuse-high.png 
b/plug-ins/lighting/images/lighting-reflectivity-diffuse-high.png
similarity index 100%
rename from plug-ins/lighting/images/stock-reflectivity-diffuse-high.png
rename to plug-ins/lighting/images/lighting-reflectivity-diffuse-high.png
diff --git a/plug-ins/lighting/images/stock-reflectivity-diffuse-low.png 
b/plug-ins/lighting/images/lighting-reflectivity-diffuse-low.png
similarity index 100%
rename from plug-ins/lighting/images/stock-reflectivity-diffuse-low.png
rename to plug-ins/lighting/images/lighting-reflectivity-diffuse-low.png
diff --git a/plug-ins/lighting/images/stock-reflectivity-highlight-high.png 
b/plug-ins/lighting/images/lighting-reflectivity-highlight-high.png
similarity index 100%
rename from plug-ins/lighting/images/stock-reflectivity-highlight-high.png
rename to plug-ins/lighting/images/lighting-reflectivity-highlight-high.png
diff --git a/plug-ins/lighting/images/stock-reflectivity-highlight-low.png 
b/plug-ins/lighting/images/lighting-reflectivity-highlight-low.png
similarity index 100%
rename from plug-ins/lighting/images/stock-reflectivity-highlight-low.png
rename to plug-ins/lighting/images/lighting-reflectivity-highlight-low.png
diff --git a/plug-ins/lighting/images/stock-reflectivity-specular-high.png 
b/plug-ins/lighting/images/lighting-reflectivity-specular-high.png
similarity index 100%
rename from plug-ins/lighting/images/stock-reflectivity-specular-high.png
rename to plug-ins/lighting/images/lighting-reflectivity-specular-high.png
diff --git a/plug-ins/lighting/images/stock-reflectivity-specular-low.png 
b/plug-ins/lighting/images/lighting-reflectivity-specular-low.png
similarity index 100%
rename from plug-ins/lighting/images/stock-reflectivity-specular-low.png
rename to plug-ins/lighting/images/lighting-reflectivity-specular-low.png
diff --git a/plug-ins/lighting/lighting-icons.c b/plug-ins/lighting/lighting-icons.c
new file mode 100644
index 0000000000..0d46aace6e
--- /dev/null
+++ b/plug-ins/lighting/lighting-icons.c
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * 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 <https://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <gtk/gtk.h>
+
+#include "lighting-icons.h"
+
+#include "images/lighting-icon-images.h"
+#include "images/lighting-icon-images.c"
+
+
+void
+lighting_icons_init (void)
+{
+  static gboolean initialized = FALSE;
+
+  GtkIconTheme *icon_theme;
+
+  if (initialized)
+    return;
+
+  initialized = TRUE;
+
+  icon_theme = gtk_icon_theme_get_default ();
+
+  gtk_icon_theme_add_resource_path (icon_theme, "/org/gimp/lighting/icons");
+}
diff --git a/plug-ins/lighting/lighting-icons.h b/plug-ins/lighting/lighting-icons.h
new file mode 100644
index 0000000000..aa48c9e2d2
--- /dev/null
+++ b/plug-ins/lighting/lighting-icons.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * 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 <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef __LIGHTING_ICONS_H__
+#define __LIGHTING_ICONS_H__
+
+
+#define LIGHTING_INTENSITY_AMBIENT_LOW        "lighting-intensity-ambient-low"
+#define LIGHTING_INTENSITY_AMBIENT_HIGH       "lighting-intensity-ambient-high"
+#define LIGHTING_INTENSITY_DIFFUSE_LOW        "lighting-intensity-diffuse-low"
+#define LIGHTING_INTENSITY_DIFFUSE_HIGH       "lighting-intensity-diffuse-high"
+#define LIGHTING_REFLECTIVITY_DIFFUSE_LOW     "lighting-reflectivity-diffuse-low"
+#define LIGHTING_REFLECTIVITY_DIFFUSE_HIGH    "lighting-reflectivity-diffuse-high"
+#define LIGHTING_REFLECTIVITY_SPECULAR_LOW    "lighting-reflectivity-specular-low"
+#define LIGHTING_REFLECTIVITY_SPECULAR_HIGH   "lighting-reflectivity-specular-high"
+#define LIGHTING_REFLECTIVITY_HIGHLIGHT_LOW   "lighting-reflectivity-highlight-low"
+#define LIGHTING_REFLECTIVITY_HIGHLIGHT_HIGH  "lighting-reflectivity-highlight-high"
+
+
+void  lighting_icons_init (void);
+
+
+#endif /* __LIGHTING_ICONs_H__ */
diff --git a/plug-ins/lighting/lighting-preview.c b/plug-ins/lighting/lighting-preview.c
index 4a5f1b9977..fc2b641172 100644
--- a/plug-ins/lighting/lighting-preview.c
+++ b/plug-ins/lighting/lighting-preview.c
@@ -246,7 +246,7 @@ check_handle_hit (gint xpos, gint ypos)
 
 
 static void
-draw_handles (void)
+draw_handles (cairo_t *cr)
 {
   gdouble     dxpos, dypos;
   gint        startx, starty, pw, ph;
@@ -291,16 +291,15 @@ draw_handles (void)
 
   if (mapvals.lightsource[k].type != NO_LIGHT)
     {
-      GdkColor  color;
-      cairo_t *cr;
-      cr = gdk_cairo_create (gtk_widget_get_window (previewarea));
+      GdkRGBA  color;
 
       cairo_set_line_width (cr, 1.0);
 
-      color.red   = 0x0;
-      color.green = 0x4000;
-      color.blue  = 0xFFFF;
-      gdk_cairo_set_source_color (cr, &color);
+      color.red   = 0.0;
+      color.green = 0.2;
+      color.blue  = 1.0;
+      color.alpha = 1.0;
+      gdk_cairo_set_source_rgba (cr, &color);
 
       /* draw circle at light position */
       switch (mapvals.lightsource[k].type)
@@ -322,7 +321,6 @@ draw_handles (void)
         case NO_LIGHT:
           break;
         }
-      cairo_destroy (cr);
     }
 }
 
@@ -440,7 +438,7 @@ preview_draw (GtkWidget *area,
   /* draw symbols if enabled in UI */
   if (mapvals.interactive_preview)
     {
-      draw_handles ();
+      draw_handles (cr);
     }
 
   return FALSE;
diff --git a/plug-ins/lighting/lighting-ui.c b/plug-ins/lighting/lighting-ui.c
index fc600969a9..919bf2c7d2 100644
--- a/plug-ins/lighting/lighting-ui.c
+++ b/plug-ins/lighting/lighting-ui.c
@@ -28,10 +28,10 @@
 
 #include "lighting-ui.h"
 #include "lighting-main.h"
+#include "lighting-icons.h"
 #include "lighting-image.h"
 #include "lighting-apply.h"
 #include "lighting-preview.h"
-#include "lighting-stock.h"
 
 #include "libgimp/stdplugins-intl.h"
 
@@ -654,8 +654,8 @@ create_material_page (void)
 
   /* Ambient intensity */
 
-  image = gtk_image_new_from_stock (STOCK_INTENSITY_AMBIENT_LOW,
-                                    GTK_ICON_SIZE_BUTTON);
+  image = gtk_image_new_from_icon_name (LIGHTING_INTENSITY_AMBIENT_LOW,
+                                        GTK_ICON_SIZE_BUTTON);
   label = gimp_grid_attach_aligned (GTK_GRID (grid), 0, 0,
                                     _("_Glowing:"), 0.0, 0.5,
                                     image, 1);
@@ -678,15 +678,15 @@ create_material_page (void)
                            _("Amount of original color to show where no "
                              "direct light falls"), NULL);
 
-  image = gtk_image_new_from_stock (STOCK_INTENSITY_AMBIENT_HIGH,
-                                    GTK_ICON_SIZE_BUTTON);
+  image = gtk_image_new_from_icon_name (LIGHTING_INTENSITY_AMBIENT_HIGH,
+                                        GTK_ICON_SIZE_BUTTON);
   gtk_grid_attach (GTK_GRID (grid), image, 3, 0, 1, 1);
   gtk_widget_show (image);
 
   /* Diffuse intensity */
 
-  image = gtk_image_new_from_stock (STOCK_INTENSITY_DIFFUSE_LOW,
-                                    GTK_ICON_SIZE_BUTTON);
+  image = gtk_image_new_from_icon_name (LIGHTING_INTENSITY_DIFFUSE_LOW,
+                                        GTK_ICON_SIZE_BUTTON);
   label = gimp_grid_attach_aligned (GTK_GRID (grid), 0, 1,
                                     _("_Bright:"), 0.0, 0.5,
                                     image, 1);
@@ -709,15 +709,15 @@ create_material_page (void)
                            _("Intensity of original color when lit by a light "
                              "source"), NULL);
 
-  image = gtk_image_new_from_stock (STOCK_INTENSITY_DIFFUSE_HIGH,
-                                    GTK_ICON_SIZE_BUTTON);
+  image = gtk_image_new_from_icon_name (LIGHTING_INTENSITY_DIFFUSE_HIGH,
+                                        GTK_ICON_SIZE_BUTTON);
   gtk_grid_attach (GTK_GRID (grid), image, 3, 1, 1, 1);
   gtk_widget_show (image);
 
   /* Specular reflection */
 
-  image = gtk_image_new_from_stock (STOCK_REFLECTIVITY_SPECULAR_LOW,
-                                    GTK_ICON_SIZE_BUTTON);
+  image = gtk_image_new_from_icon_name (LIGHTING_REFLECTIVITY_SPECULAR_LOW,
+                                        GTK_ICON_SIZE_BUTTON);
   label = gimp_grid_attach_aligned (GTK_GRID (grid), 0, 2,
                                     _("_Shiny:"), 0.0, 0.5,
                                     image, 1);
@@ -740,14 +740,14 @@ create_material_page (void)
                            _("Controls how intense the highlights will be"),
                            NULL);
 
-  image = gtk_image_new_from_stock (STOCK_REFLECTIVITY_SPECULAR_HIGH,
-                                    GTK_ICON_SIZE_BUTTON);
+  image = gtk_image_new_from_icon_name (LIGHTING_REFLECTIVITY_SPECULAR_HIGH,
+                                        GTK_ICON_SIZE_BUTTON);
   gtk_grid_attach (GTK_GRID (grid), image, 3, 2, 1, 1);
   gtk_widget_show (image);
 
   /* Highlight */
-  image = gtk_image_new_from_stock (STOCK_REFLECTIVITY_HIGHLIGHT_LOW,
-                                    GTK_ICON_SIZE_BUTTON);
+  image = gtk_image_new_from_icon_name (LIGHTING_REFLECTIVITY_HIGHLIGHT_LOW,
+                                        GTK_ICON_SIZE_BUTTON);
   label = gimp_grid_attach_aligned (GTK_GRID (grid), 0, 3,
                                     _("_Polished:"), 0.0, 0.5,
                                     image, 1);
@@ -770,8 +770,8 @@ create_material_page (void)
                            _("Higher values makes the highlights more focused"),
                            NULL);
 
-  image = gtk_image_new_from_stock (STOCK_REFLECTIVITY_HIGHLIGHT_HIGH,
-                                    GTK_ICON_SIZE_BUTTON);
+  image = gtk_image_new_from_icon_name (LIGHTING_REFLECTIVITY_HIGHLIGHT_HIGH,
+                                        GTK_ICON_SIZE_BUTTON);
   gtk_grid_attach (GTK_GRID (grid), image, 3, 3, 1, 1);
   gtk_widget_show (image);
 
@@ -1029,7 +1029,7 @@ main_dialog (gint32 drawable_id)
       g_free (path);
     }
 
-  lighting_stock_init ();
+  lighting_icons_init ();
 
   appwin = gimp_dialog_new (_("Lighting Effects"), PLUG_IN_ROLE,
                             NULL, 0,


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