[gthumb] added a color picker



commit 200eedf0c839db82ec9e9921d2d029189db021fe
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun Feb 26 11:31:05 2017 +0100

    added a color picker
    
    [new feature]

 data/icons/hicolor/16x16/actions/Makefile.am       |    1 +
 .../hicolor/16x16/actions/eyedropper-symbolic.svg  |  147 ++++++++++++
 extensions/file_tools/Makefile.am                  |    2 +
 extensions/file_tools/data/ui/Makefile.am          |    1 +
 .../file_tools/data/ui/color-picker-options.ui     |  253 ++++++++++++++++++++
 extensions/file_tools/gth-file-tool-color-picker.c |  251 +++++++++++++++++++
 extensions/file_tools/gth-file-tool-color-picker.h |   54 ++++
 extensions/file_tools/main.c                       |    3 +
 .../data/ui/red-eye-removal-options.ui             |    8 +-
 9 files changed, 716 insertions(+), 4 deletions(-)
---
diff --git a/data/icons/hicolor/16x16/actions/Makefile.am b/data/icons/hicolor/16x16/actions/Makefile.am
index eaa17ec..7ed801c 100644
--- a/data/icons/hicolor/16x16/actions/Makefile.am
+++ b/data/icons/hicolor/16x16/actions/Makefile.am
@@ -17,6 +17,7 @@ icons_DATA =                                  \
        emblem-flag-red.svg                     \
        emblem-flag-symbolic.svg                \
        export-symbolic.svg                     \
+       eyedropper-symbolic.svg                 \
        file-catalog-symbolic.svg               \
        file-library-symbolic.svg               \
        file-search-symbolic.svg                \
diff --git a/data/icons/hicolor/16x16/actions/eyedropper-symbolic.svg 
b/data/icons/hicolor/16x16/actions/eyedropper-symbolic.svg
new file mode 100644
index 0000000..4cde03b
--- /dev/null
+++ b/data/icons/hicolor/16x16/actions/eyedropper-symbolic.svg
@@ -0,0 +1,147 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/";
+   xmlns:cc="http://creativecommons.org/ns#";
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
+   xmlns:svg="http://www.w3.org/2000/svg";
+   xmlns="http://www.w3.org/2000/svg";
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd";
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape";
+   width="17.066668"
+   height="17.066668"
+   id="svg2"
+   version="1.1"
+   inkscape:version="0.92.1 r"
+   sodipodi:docname="eyedropper-symbolic.svg"
+   viewBox="0 0 16 16">
+  <defs
+     id="defs4">
+    <linearGradient
+       id="linearGradient3946">
+      <stop
+         id="stop3948"
+         offset="0"
+         style="stop-color:#000000;stop-opacity:0.74698794;" />
+      <stop
+         id="stop3950"
+         offset="1"
+         style="stop-color:#000000;stop-opacity:0.02409638;" />
+    </linearGradient>
+    <linearGradient
+       id="linearGradient3830-9">
+      <stop
+         style="stop-color:#000000;stop-opacity:0.74698794;"
+         offset="0"
+         id="stop3832-7" />
+      <stop
+         style="stop-color:#000000;stop-opacity:0.02409638;"
+         offset="1"
+         id="stop3834-5" />
+    </linearGradient>
+    <linearGradient
+       id="linearGradient3984">
+      <stop
+         style="stop-color:#f4deba;stop-opacity:1;"
+         offset="0"
+         id="stop3986" />
+      <stop
+         style="stop-color:#de9625;stop-opacity:0;"
+         offset="1"
+         id="stop3988" />
+    </linearGradient>
+  </defs>
+  <sodipodi:namedview
+     id="base"
+     pagecolor="#555753"
+     bordercolor="#666666"
+     borderopacity="1.0"
+     inkscape:pageopacity="1"
+     inkscape:pageshadow="2"
+     inkscape:zoom="32.000001"
+     inkscape:cx="3.9554796"
+     inkscape:cy="7.6137998"
+     inkscape:document-units="px"
+     inkscape:current-layer="layer1"
+     showgrid="true"
+     inkscape:snap-grids="true"
+     inkscape:window-width="1680"
+     inkscape:window-height="1023"
+     inkscape:window-x="0"
+     inkscape:window-y="27"
+     inkscape:window-maximized="1"
+     showborder="true"
+     fit-margin-top="0"
+     fit-margin-right="0"
+     fit-margin-left="0"
+     fit-margin-bottom="0"
+     showguides="true"
+     inkscape:snap-global="false">
+    <inkscape:grid
+       type="xygrid"
+       id="grid7044"
+       empspacing="8"
+       visible="true"
+       enabled="true"
+       snapvisiblegridlinesonly="true"
+       originx="-31.975588"
+       originy="-815.99998"
+       spacingx="0.99999995"
+       spacingy="0.99999995" />
+  </sodipodi:namedview>
+  <metadata
+     id="metadata7">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage"; />
+        <dc:title />
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <g
+     inkscape:label="Livello 1"
+     inkscape:groupmode="layer"
+     id="layer1"
+     transform="translate(-31.97559,-220.36218)">
+    <g
+       id="g4513"
+       transform="translate(-0.82373684,0.88446438)">
+      <path
+         inkscape:connector-curvature="0"
+         id="rect965"
+         d="m 42.723641,222.79258 2.849138,2.84914 c 0.386003,0.386 0.386003,1.00751 7e-6,1.3935 l 
-0.727817,0.72782 c -0.385996,0.386 -1.0075,0.386 -1.393503,-1e-5 l -2.849138,-2.84914 c -0.386003,-0.386 
-0.385996,-1.0075 0,-1.39349 l 0.727818,-0.72782 c 0.385995,-0.38599 1.007493,-0.386 1.393495,0 z"
+         
style="opacity:1;fill:#bebebe;fill-opacity:1;stroke:none;stroke-width:74.99999237;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
 />
+      <path
+         inkscape:connector-curvature="0"
+         id="rect967"
+         d="m 45.972733,221.21311 1.179511,1.17951 c 0.391737,0.39174 0.391737,1.02248 -7e-6,1.41422 l 
-1.707154,1.70715 c -0.391737,0.39174 -1.022476,0.39174 -1.414214,0 l -1.17951,-1.17951 c -0.391737,-0.39173 
-0.391737,-1.02247 0,-1.41421 l 1.707154,-1.70715 c 0.391744,-0.39175 1.022483,-0.39175 1.41422,-1e-5 z"
+         
style="opacity:1;fill:#bebebe;fill-opacity:1;stroke:none;stroke-width:74.99999237;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
 />
+      <g
+         transform="rotate(45,40.744507,227.85234)"
+         style="opacity:0.65799997"
+         id="g1014">
+        <path
+           sodipodi:nodetypes="ccccc"
+           inkscape:connector-curvature="0"
+           id="rect969"
+           d="m 39.32657,226.74786 2.3972,2e-5 -0.28795,8.82117 -1.93785,-0.0207 z"
+           
style="opacity:1;fill:#bebebe;fill-opacity:1;stroke:none;stroke-width:74.99999237;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
 />
+        <circle
+           r="0.97447306"
+           cy="235.5069"
+           cx="40.456532"
+           id="circle971"
+           
style="opacity:1;fill:#bebebe;fill-opacity:1;stroke:none;stroke-width:74.99999237;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
 />
+      </g>
+      <path
+         inkscape:connector-curvature="0"
+         id="path1016"
+         d="m 35.77869,231.00061 -1.226806,1.27624 a 0.97447307,0.97447307 0 0 0 -0.113526,0.0952 
0.97447307,0.97447307 0 0 0 0,1.37878 0.97447307,0.97447307 0 0 0 1.333008,0.0421 l 0.0055,0.005 
2.98645,-2.79785 z"
+         
style="opacity:1;fill:#bebebe;fill-opacity:1;stroke:none;stroke-width:74.99999237;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
 />
+    </g>
+  </g>
+</svg>
diff --git a/extensions/file_tools/Makefile.am b/extensions/file_tools/Makefile.am
index c81bbaf..5319484 100644
--- a/extensions/file_tools/Makefile.am
+++ b/extensions/file_tools/Makefile.am
@@ -17,6 +17,7 @@ HEADER_FILES =                                        \
        gth-curve-preset-editor-dialog.h        \
        gth-file-tool-adjust-colors.h           \
        gth-file-tool-adjust-contrast.h         \
+       gth-file-tool-color-picker.h            \
        gth-file-tool-crop.h                    \
        gth-file-tool-curves.h                  \
        gth-file-tool-effects.h                 \
@@ -74,6 +75,7 @@ libfile_tools_la_SOURCES =                    \
        gth-curve-preset-editor-dialog.c        \
        gth-file-tool-adjust-colors.c           \
        gth-file-tool-adjust-contrast.c         \
+       gth-file-tool-color-picker.c            \
        gth-file-tool-crop.c                    \
        gth-file-tool-curves.c                  \
        gth-file-tool-effects.c                 \
diff --git a/extensions/file_tools/data/ui/Makefile.am b/extensions/file_tools/data/ui/Makefile.am
index 455af2d..a6348aa 100644
--- a/extensions/file_tools/data/ui/Makefile.am
+++ b/extensions/file_tools/data/ui/Makefile.am
@@ -2,6 +2,7 @@ uidir = $(pkgdatadir)/ui
 ui_DATA =                              \
        adjust-colors-options.ui        \
        adjust-contrast-options.ui      \
+       color-picker-options.ui         \
        crop-options.ui                 \
        curve-preset-editor.ui          \
        curves-options.ui               \
diff --git a/extensions/file_tools/data/ui/color-picker-options.ui 
b/extensions/file_tools/data/ui/color-picker-options.ui
new file mode 100644
index 0000000..5c7e4b5
--- /dev/null
+++ b/extensions/file_tools/data/ui/color-picker-options.ui
@@ -0,0 +1,253 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.20.0 -->
+<interface>
+  <requires lib="gtk+" version="3.12"/>
+  <object class="GtkAdjustment" id="x_adjustment">
+    <property name="upper">10000</property>
+    <property name="step_increment">1</property>
+  </object>
+  <object class="GtkAdjustment" id="y_adjustment">
+    <property name="upper">10000</property>
+    <property name="step_increment">1</property>
+  </object>
+  <object class="GtkAlignment" id="options">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="border_width">12</property>
+    <child>
+      <object class="GtkBox" id="vbox2">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">12</property>
+        <child>
+          <object class="GtkBox" id="vbox1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="orientation">vertical</property>
+            <property name="spacing">12</property>
+            <child>
+              <object class="GtkBox" id="box1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="orientation">vertical</property>
+                <property name="spacing">12</property>
+                <child>
+                  <object class="GtkLabel" id="label1">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="halign">start</property>
+                    <property name="label" translatable="yes">Position</property>
+                    <attributes>
+                      <attribute name="weight" value="bold"/>
+                    </attributes>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkTable" id="table2">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="n_rows">2</property>
+                    <property name="n_columns">2</property>
+                    <property name="column_spacing">6</property>
+                    <property name="row_spacing">6</property>
+                    <child>
+                      <object class="GtkLabel" id="x_label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="label" translatable="yes">_X:</property>
+                        <property name="use_underline">True</property>
+                        <property name="mnemonic_widget">x_spinbutton</property>
+                        <property name="xalign">0</property>
+                      </object>
+                      <packing>
+                        <property name="x_options">GTK_FILL</property>
+                        <property name="y_options"/>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="y_label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="label" translatable="yes">_Y:</property>
+                        <property name="use_underline">True</property>
+                        <property name="mnemonic_widget">y_spinbutton</property>
+                        <property name="xalign">0</property>
+                      </object>
+                      <packing>
+                        <property name="top_attach">1</property>
+                        <property name="bottom_attach">2</property>
+                        <property name="x_options">GTK_FILL</property>
+                        <property name="y_options"/>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkBox" id="hbox5">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <child>
+                          <object class="GtkSpinButton" id="x_spinbutton">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="invisible_char">●</property>
+                            <property name="adjustment">x_adjustment</property>
+                            <property name="climb_rate">1</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">True</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="right_attach">2</property>
+                        <property name="x_options">GTK_FILL</property>
+                        <property name="y_options">GTK_FILL</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkBox" id="hbox6">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <child>
+                          <object class="GtkSpinButton" id="y_spinbutton">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="invisible_char">●</property>
+                            <property name="adjustment">y_adjustment</property>
+                            <property name="climb_rate">1</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">True</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="right_attach">2</property>
+                        <property name="top_attach">1</property>
+                        <property name="bottom_attach">2</property>
+                        <property name="x_options">GTK_FILL</property>
+                        <property name="y_options">GTK_FILL</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkBox" id="color_section">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="orientation">vertical</property>
+            <property name="spacing">12</property>
+            <child>
+              <object class="GtkLabel">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">start</property>
+                <property name="label" translatable="yes">Color</property>
+                <attributes>
+                  <attribute name="weight" value="bold"/>
+                </attributes>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkColorButton" id="color_chooser">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_alpha">True</property>
+                <property name="title" translatable="yes"/>
+                <property name="show_editor">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" id="hex_color">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="secondary_icon_name">edit-copy-symbolic</property>
+                <property name="secondary_icon_tooltip_text" translatable="yes">Copy</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" id="rgb_color">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="secondary_icon_name">edit-copy-symbolic</property>
+                <property name="secondary_icon_tooltip_text" translatable="yes">Copy</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">3</property>
+              </packing>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <object class="GtkLabel" id="alpha_color">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">start</property>
+                <property name="selectable">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">6</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/extensions/file_tools/gth-file-tool-color-picker.c 
b/extensions/file_tools/gth-file-tool-color-picker.c
new file mode 100644
index 0000000..eba138e
--- /dev/null
+++ b/extensions/file_tools/gth-file-tool-color-picker.c
@@ -0,0 +1,251 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2017 Free Software Foundation, Inc.
+ *
+ *  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 2 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/>.
+ */
+
+#include <config.h>
+#include <math.h>
+#include <gthumb.h>
+#include <extensions/image_viewer/gth-image-viewer-page.h>
+#include "gth-file-tool-color-picker.h"
+
+
+#define GET_WIDGET(x) (_gtk_builder_get_widget (self->priv->builder, (x)))
+
+
+struct _GthFileToolColorPickerPrivate {
+       GtkBuilder       *builder;
+       GthImageSelector *selector;
+};
+
+
+G_DEFINE_TYPE (GthFileToolColorPicker, gth_file_tool_color_picker, GTH_TYPE_IMAGE_VIEWER_PAGE_TOOL)
+
+
+static void
+_gth_file_tool_color_picker_show_color (GthFileToolColorPicker *self,
+                                       int                     x,
+                                       int                     y)
+{
+       cairo_surface_t *source;
+       unsigned char   *p_source;
+       int              temp;
+       guchar           r, g, b, a;
+       GdkRGBA          color;
+       char            *description;
+
+       source = gth_image_viewer_page_tool_get_source (GTH_IMAGE_VIEWER_PAGE_TOOL (self));
+       if ((source == NULL) || (x < 0) || (y < 0) || (x >= cairo_image_surface_get_width (source)) || (y >= 
cairo_image_surface_get_height (source))) {
+               gtk_widget_set_sensitive (GET_WIDGET ("color_section"), FALSE);
+               return;
+       }
+
+       gtk_widget_set_sensitive (GET_WIDGET ("color_section"), TRUE);
+
+       p_source = _cairo_image_surface_flush_and_get_data (source) + (y * cairo_image_surface_get_stride 
(source)) + (x * 4);
+       CAIRO_GET_RGBA (p_source, r, g, b, a);
+
+       color.red   = (double ) r / 255.0;
+       color.green = (double ) g / 255.0;
+       color.blue  = (double ) b / 255.0;
+       color.alpha = (double ) a / 255.0;
+
+       gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (GET_WIDGET ("color_chooser")), &color);
+
+       description = g_strdup_printf ("#%02X%02X%02X", r, g, b);
+       gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("hex_color")), description);
+       g_free (description);
+
+       description = g_strdup_printf ("rgb(%u, %u, %u)", r, g, b);
+       gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("rgb_color")), description);
+       g_free (description);
+
+       if (color.alpha < 1.0) {
+               description = g_strdup_printf ("alpha: %0.2f", color.alpha);
+               gtk_label_set_text (GTK_LABEL (GET_WIDGET ("alpha_color")), description);
+               g_free (description);
+       }
+       else
+               gtk_widget_hide (GET_WIDGET ("alpha_color"));
+}
+
+
+static void
+selector_selected_cb (GthImageSelector  *selector,
+                     int                x,
+                     int                y,
+                     gpointer           user_data)
+{
+       GthFileToolColorPicker *self = user_data;
+
+       _gth_file_tool_color_picker_show_color (self, x, y);
+}
+
+
+static void
+selector_motion_notify_cb (GthImageSelector *selector,
+                          int               x,
+                          int               y,
+                          gpointer          user_data)
+{
+       GthFileToolColorPicker *self = user_data;
+
+       gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("x_spinbutton")), (double) x);
+       gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("y_spinbutton")), (double) y);
+}
+
+
+static void
+color_text_icon_press_cb (GtkEntry             *entry,
+                         GtkEntryIconPosition  icon_pos,
+                         GdkEvent             *event,
+                         gpointer              user_data)
+{
+       GthFileToolColorPicker *self = user_data;
+
+       if (icon_pos == GTK_ENTRY_ICON_SECONDARY) {
+               gtk_clipboard_set_text (gtk_clipboard_get_default (gtk_widget_get_display (GTK_WIDGET 
(entry))),
+                                       gtk_entry_get_text (GTK_ENTRY (entry)),
+                                       -1);
+       }
+}
+
+
+static GtkWidget *
+gth_file_tool_color_picker_get_options (GthFileTool *base)
+{
+       GthFileToolColorPicker *self;
+       GtkWidget              *window;
+       GthViewerPage          *viewer_page;
+       GtkWidget              *viewer;
+       GtkWidget              *options;
+
+       self = (GthFileToolColorPicker *) base;
+
+       window = gth_file_tool_get_window (base);
+       viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window));
+       if (! GTH_IS_IMAGE_VIEWER_PAGE (viewer_page))
+               return NULL;
+
+       self->priv->builder = _gtk_builder_new_from_file ("color-picker-options.ui", "file_tools");
+       options = _gtk_builder_get_widget (self->priv->builder, "options");
+       gtk_widget_show (options);
+
+       _gth_file_tool_color_picker_show_color (self, -1, -1);
+
+       viewer = gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (viewer_page));
+       self->priv->selector = (GthImageSelector *) gth_image_selector_new (GTH_SELECTOR_TYPE_POINT);
+       gth_image_selector_set_mask_visible (self->priv->selector, FALSE);
+       g_signal_connect (self->priv->selector,
+                         "selected",
+                         G_CALLBACK (selector_selected_cb),
+                         self);
+       g_signal_connect (self->priv->selector,
+                         "motion_notify",
+                         G_CALLBACK (selector_motion_notify_cb),
+                         self);
+       gth_image_viewer_set_tool (GTH_IMAGE_VIEWER (viewer), (GthImageViewerTool *) self->priv->selector);
+
+       g_signal_connect (GET_WIDGET ("hex_color"),
+                         "icon-press",
+                         G_CALLBACK (color_text_icon_press_cb),
+                         self);
+       g_signal_connect (GET_WIDGET ("rgb_color"),
+                         "icon-press",
+                         G_CALLBACK (color_text_icon_press_cb),
+                         self);
+
+       return options;
+}
+
+
+static void
+gth_file_tool_color_picker_destroy_options (GthFileTool *base)
+{
+       GthFileToolColorPicker *self;
+       GtkWidget              *window;
+       GthViewerPage          *viewer_page;
+
+       self = (GthFileToolColorPicker *) base;
+
+       window = gth_file_tool_get_window (GTH_FILE_TOOL (self));
+       viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window));
+       gth_image_viewer_page_reset_viewer_tool (GTH_IMAGE_VIEWER_PAGE (viewer_page));
+
+       _g_object_unref (self->priv->builder);
+       _g_object_unref (self->priv->selector);
+       self->priv->builder = NULL;
+       self->priv->selector = NULL;
+}
+
+
+static void
+gth_file_tool_color_picker_apply_options (GthFileTool *base)
+{
+       gth_file_tool_hide_options (GTH_FILE_TOOL (base));
+}
+
+
+static void
+gth_file_tool_color_picker_finalize (GObject *object)
+{
+       GthFileToolColorPicker *self;
+
+       g_return_if_fail (object != NULL);
+       g_return_if_fail (GTH_IS_FILE_TOOL_COLOR_PICKER (object));
+
+       self = (GthFileToolColorPicker *) object;
+
+       _g_object_unref (self->priv->selector);
+       _g_object_unref (self->priv->builder);
+
+       /* Chain up */
+       G_OBJECT_CLASS (gth_file_tool_color_picker_parent_class)->finalize (object);
+}
+
+
+static void
+gth_file_tool_color_picker_class_init (GthFileToolColorPickerClass *klass)
+{
+       GObjectClass     *gobject_class;
+       GthFileToolClass *file_tool_class;
+
+       g_type_class_add_private (klass, sizeof (GthFileToolColorPickerPrivate));
+
+       gobject_class = (GObjectClass*) klass;
+       gobject_class->finalize = gth_file_tool_color_picker_finalize;
+
+       file_tool_class = (GthFileToolClass *) klass;
+       file_tool_class->get_options = gth_file_tool_color_picker_get_options;
+       file_tool_class->destroy_options = gth_file_tool_color_picker_destroy_options;
+       file_tool_class->apply_options = gth_file_tool_color_picker_apply_options;
+}
+
+
+static void
+gth_file_tool_color_picker_init (GthFileToolColorPicker *self)
+{
+       self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTH_TYPE_FILE_TOOL_COLOR_PICKER, 
GthFileToolColorPickerPrivate);
+       self->priv->builder = NULL;
+       self->priv->selector = NULL;
+       gth_file_tool_construct (GTH_FILE_TOOL (self), "eyedropper-symbolic", _("Color Picker"), 
GTH_TOOLBOX_SECTION_COLORS);
+       gth_file_tool_set_zoomable (GTH_FILE_TOOL (self), TRUE);
+       gth_file_tool_set_changes_image (GTH_FILE_TOOL (self), FALSE);
+       gtk_widget_set_tooltip_text (GTK_WIDGET (self), _("Pick a color from the image"));
+}
diff --git a/extensions/file_tools/gth-file-tool-color-picker.h 
b/extensions/file_tools/gth-file-tool-color-picker.h
new file mode 100644
index 0000000..9b644a7
--- /dev/null
+++ b/extensions/file_tools/gth-file-tool-color-picker.h
@@ -0,0 +1,54 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2017 Free Software Foundation, Inc.
+ *
+ *  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 2 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/>.
+ */
+
+#ifndef GTH_FILE_TOOL_COLOR_PICKER_H
+#define GTH_FILE_TOOL_COLOR_PICKER_H
+
+#include <gthumb.h>
+#include <extensions/image_viewer/image-viewer.h>
+
+G_BEGIN_DECLS
+
+#define GTH_TYPE_FILE_TOOL_COLOR_PICKER (gth_file_tool_color_picker_get_type ())
+#define GTH_FILE_TOOL_COLOR_PICKER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTH_TYPE_FILE_TOOL_COLOR_PICKER, 
GthFileToolColorPicker))
+#define GTH_FILE_TOOL_COLOR_PICKER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), 
GTH_TYPE_FILE_TOOL_COLOR_PICKER, GthFileToolColorPickerClass))
+#define GTH_IS_FILE_TOOL_COLOR_PICKER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GTH_TYPE_FILE_TOOL_COLOR_PICKER))
+#define GTH_IS_FILE_TOOL_COLOR_PICKER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GTH_TYPE_FILE_TOOL_COLOR_PICKER))
+#define GTH_FILE_TOOL_COLOR_PICKER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GTH_TYPE_FILE_TOOL_COLOR_PICKER, GthFileToolColorPickerClass))
+
+typedef struct _GthFileToolColorPicker GthFileToolColorPicker;
+typedef struct _GthFileToolColorPickerClass GthFileToolColorPickerClass;
+typedef struct _GthFileToolColorPickerPrivate GthFileToolColorPickerPrivate;
+
+struct _GthFileToolColorPicker {
+       GthImageViewerPageTool parent_instance;
+       GthFileToolColorPickerPrivate *priv;
+};
+
+struct _GthFileToolColorPickerClass {
+       GthImageViewerPageToolClass parent_class;
+};
+
+GType  gth_file_tool_color_picker_get_type  (void);
+
+G_END_DECLS
+
+#endif /* GTH_FILE_TOOL_COLOR_PICKER_H */
diff --git a/extensions/file_tools/main.c b/extensions/file_tools/main.c
index 25f85dc..525988b 100644
--- a/extensions/file_tools/main.c
+++ b/extensions/file_tools/main.c
@@ -21,11 +21,13 @@
 
 
 #include <config.h>
+#include <gth-file-tool-color-picker.h>
 #include <gtk/gtk.h>
 #include <gthumb.h>
 #include "callbacks.h"
 #include "gth-file-tool-adjust-colors.h"
 #include "gth-file-tool-adjust-contrast.h"
+#include "gth-file-tool-color-picker.h"
 #include "gth-file-tool-crop.h"
 #include "gth-file-tool-curves.h"
 #include "gth-file-tool-effects.h"
@@ -61,6 +63,7 @@ gthumb_extension_activate (void)
        gth_main_register_type ("file-tools", GTH_TYPE_FILE_TOOL_GRAYSCALE);
        gth_main_register_type ("file-tools", GTH_TYPE_FILE_TOOL_CURVES);
        gth_main_register_type ("file-tools", GTH_TYPE_FILE_TOOL_EFFECTS);
+       gth_main_register_type ("file-tools", GTH_TYPE_FILE_TOOL_COLOR_PICKER);
 
        gth_main_register_type ("file-tools", GTH_TYPE_FILE_TOOL_ROTATE_LEFT);
        gth_main_register_type ("file-tools", GTH_TYPE_FILE_TOOL_ROTATE_RIGHT);
diff --git a/extensions/red_eye_removal/data/ui/red-eye-removal-options.ui 
b/extensions/red_eye_removal/data/ui/red-eye-removal-options.ui
index cefeaf8..3f689d1 100644
--- a/extensions/red_eye_removal/data/ui/red-eye-removal-options.ui
+++ b/extensions/red_eye_removal/data/ui/red-eye-removal-options.ui
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.18.3 -->
+<!-- Generated with glade 3.20.0 -->
 <interface>
   <requires lib="gtk+" version="3.0"/>
   <object class="GtkAdjustment" id="x_adjustment">
@@ -33,8 +33,8 @@
                   <object class="GtkLabel" id="label1">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
+                    <property name="label" translatable="yes">Position</property>
                     <property name="xalign">0</property>
-                    <property name="label" translatable="yes">Selection</property>
                     <attributes>
                       <attribute name="weight" value="bold"/>
                     </attributes>
@@ -57,10 +57,10 @@
                       <object class="GtkLabel" id="x_label">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="xalign">0</property>
                         <property name="label" translatable="yes">_X:</property>
                         <property name="use_underline">True</property>
                         <property name="mnemonic_widget">x_spinbutton</property>
+                        <property name="xalign">0</property>
                       </object>
                       <packing>
                         <property name="x_options">GTK_FILL</property>
@@ -71,10 +71,10 @@
                       <object class="GtkLabel" id="y_label">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="xalign">0</property>
                         <property name="label" translatable="yes">_Y:</property>
                         <property name="use_underline">True</property>
                         <property name="mnemonic_widget">y_spinbutton</property>
+                        <property name="xalign">0</property>
                       </object>
                       <packing>
                         <property name="top_attach">1</property>


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