[gtk+/wip/colorchooser] Deprecate old color selection widgets
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/colorchooser] Deprecate old color selection widgets
- Date: Sat, 4 Feb 2012 06:47:45 +0000 (UTC)
commit 3efa138609fa3c3959286af2ac8f380e846c8fef
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Feb 3 20:38:21 2012 -0500
Deprecate old color selection widgets
GtkColorSelectionDialog, GtkColorSelection and GtkHSV have
been superseded by the GtkColorChooser* family of widgets.
gtk/Makefile.am | 20 ++-
gtk/{ => deprecated}/gtkcolorsel.c | 4 +-
gtk/{ => deprecated}/gtkcolorsel.h | 24 +++-
gtk/{ => deprecated}/gtkcolorseldialog.c | 6 +-
gtk/{ => deprecated}/gtkcolorseldialog.h | 4 +-
gtk/{ => deprecated}/gtkhsv.c | 83 +---------
gtk/{ => deprecated}/gtkhsv.h | 20 +--
gtk/gtk.h | 7 +-
gtk/gtkcolorchooserwidget.c | 2 +-
gtk/gtkcoloreditor.c | 2 +-
gtk/gtkcolorplane.c | 2 +-
gtk/gtkcolorscale.c | 2 +-
gtk/gtkcolorutils.c | 260 ++++++++++++++++++++++++++++++
gtk/gtkcolorutils.h | 48 ++++++
14 files changed, 369 insertions(+), 115 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 35bf2c1..6b91485 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -145,6 +145,8 @@ endif
# by configure)
deprecated_h_sources = \
+ deprecated/gtkcolorsel.h \
+ deprecated/gtkcolorseldialog.h \
deprecated/gtkfontsel.h \
deprecated/gtkhandlebox.h \
deprecated/gtkhbbox.h \
@@ -153,6 +155,7 @@ deprecated_h_sources = \
deprecated/gtkhscale.h \
deprecated/gtkhscrollbar.h \
deprecated/gtkhseparator.h \
+ deprecated/gtkhsv.h \
deprecated/gtkstyle.h \
deprecated/gtkrc.h \
deprecated/gtktable.h \
@@ -215,11 +218,10 @@ gtk_public_h_sources = \
gtkcheckmenuitem.h \
gtkclipboard.h \
gtkcolorbutton.h \
- gtkcolorsel.h \
- gtkcolorseldialog.h \
gtkcolorchooser.h \
gtkcolorchooserwidget.h \
gtkcolorchooserdialog.h \
+ gtkcolorutils.h \
gtkcombobox.h \
gtkcomboboxtext.h \
gtkcontainer.h \
@@ -249,7 +251,6 @@ gtk_public_h_sources = \
gtkframe.h \
gtkgradient.h \
gtkgrid.h \
- gtkhsv.h \
gtkiconfactory.h \
gtkicontheme.h \
gtkiconview.h \
@@ -513,6 +514,8 @@ gtk_private_h_sources = \
# GTK+ C sources to build the library from
deprecated_c_sources = \
+ deprecated/gtkcolorsel.c \
+ deprecated/gtkcolorseldialog.c \
deprecated/gtkfontsel.c \
deprecated/gtkhandlebox.c \
deprecated/gtkhbbox.c \
@@ -521,6 +524,7 @@ deprecated_c_sources = \
deprecated/gtkhscale.c \
deprecated/gtkhscrollbar.c \
deprecated/gtkhseparator.c \
+ deprecated/gtkhsv.c \
deprecated/gtkrc.c \
deprecated/gtkstyle.c \
deprecated/gtktable.c \
@@ -597,15 +601,14 @@ gtk_base_c_sources = \
gtkcheckbutton.c \
gtkcheckmenuitem.c \
gtkcolorbutton.c \
- gtkcolorsel.c \
- gtkcolorseldialog.c \
+ gtkcolorchooser.c \
+ gtkcolorchooserwidget.c \
+ gtkcolorchooserdialog.c \
gtkcoloreditor.c \
gtkcolorplane.c \
gtkcolorscale.c \
gtkcolorswatch.c \
- gtkcolorchooser.c \
- gtkcolorchooserwidget.c \
- gtkcolorchooserdialog.c \
+ gtkcolorutils.c \
gtkcombobox.c \
gtkcomboboxtext.c \
gtkcontainer.c \
@@ -654,7 +657,6 @@ gtk_base_c_sources = \
gtkframe.c \
gtkgradient.c \
gtkgrid.c \
- gtkhsv.c \
gtkiconcache.c \
gtkiconcachevalidator.c \
gtkiconfactory.c \
diff --git a/gtk/gtkcolorsel.c b/gtk/deprecated/gtkcolorsel.c
similarity index 99%
rename from gtk/gtkcolorsel.c
rename to gtk/deprecated/gtkcolorsel.c
index 2f36d3e..813d24c 100644
--- a/gtk/gtkcolorsel.c
+++ b/gtk/deprecated/gtkcolorsel.c
@@ -27,6 +27,8 @@
#include "config.h"
+#define GDK_DISABLE_DEPRECATION_WARNINGS
+
#include "gtkcolorsel.h"
#include <math.h>
@@ -62,7 +64,7 @@
/**
* SECTION:gtkcolorsel
- * @Short_description: A widget used to select a color
+ * @Short_description: Deprecated widget used to select a color
* @Title: GtkColorSelection
*
* The #GtkColorSelection is a widget that is used to select
diff --git a/gtk/gtkcolorsel.h b/gtk/deprecated/gtkcolorsel.h
similarity index 90%
rename from gtk/gtkcolorsel.h
rename to gtk/deprecated/gtkcolorsel.h
index d8b7877..9acf9c3 100644
--- a/gtk/gtkcolorsel.h
+++ b/gtk/deprecated/gtkcolorsel.h
@@ -89,51 +89,67 @@ struct _GtkColorSelectionClass
/* ColorSelection */
GType gtk_color_selection_get_type (void) G_GNUC_CONST;
+GDK_DEPRECATED_FOR(gtk_color_chooser_widget_new)
GtkWidget *gtk_color_selection_new (void);
+GDK_DEPRECATED_FOR(gtk_color_chooser_get_use_alpha)
gboolean gtk_color_selection_get_has_opacity_control (GtkColorSelection *colorsel);
+GDK_DEPRECATED_FOR(gtk_color_chooser_set_use_alpha)
void gtk_color_selection_set_has_opacity_control (GtkColorSelection *colorsel,
gboolean has_opacity);
+GDK_DEPRECATED
gboolean gtk_color_selection_get_has_palette (GtkColorSelection *colorsel);
+GDK_DEPRECATED
void gtk_color_selection_set_has_palette (GtkColorSelection *colorsel,
gboolean has_palette);
+GDK_DEPRECATED_FOR(gtk_color_chooser_set_rgba)
void gtk_color_selection_set_current_alpha (GtkColorSelection *colorsel,
guint16 alpha);
+GDK_DEPRECATED_FOR(gtk_color_chooser_get_rgba)
guint16 gtk_color_selection_get_current_alpha (GtkColorSelection *colorsel);
+GDK_DEPRECATED
void gtk_color_selection_set_previous_alpha (GtkColorSelection *colorsel,
guint16 alpha);
+GDK_DEPRECATED
guint16 gtk_color_selection_get_previous_alpha (GtkColorSelection *colorsel);
+GDK_DEPRECATED_FOR(gtk_color_chooser_set_rgba)
void gtk_color_selection_set_current_rgba (GtkColorSelection *colorsel,
const GdkRGBA *rgba);
+GDK_DEPRECATED_FOR(gtk_color_chooser_get_rgba)
void gtk_color_selection_get_current_rgba (GtkColorSelection *colorsel,
GdkRGBA *rgba);
+GDK_DEPRECATED
void gtk_color_selection_set_previous_rgba (GtkColorSelection *colorsel,
const GdkRGBA *rgba);
+GDK_DEPRECATED
void gtk_color_selection_get_previous_rgba (GtkColorSelection *colorsel,
GdkRGBA *rgba);
+GDK_DEPRECATED
gboolean gtk_color_selection_is_adjusting (GtkColorSelection *colorsel);
+GDK_DEPRECATED
gboolean gtk_color_selection_palette_from_string (const gchar *str,
GdkColor **colors,
gint *n_colors);
+GDK_DEPRECATED
gchar* gtk_color_selection_palette_to_string (const GdkColor *colors,
gint n_colors);
GtkColorSelectionChangePaletteWithScreenFunc gtk_color_selection_set_change_palette_with_screen_hook (GtkColorSelectionChangePaletteWithScreenFunc func);
-GDK_DEPRECATED_FOR(gtk_color_selection_set_current_rgba)
+GDK_DEPRECATED_FOR(gtk_color_chooser_set_rgba)
void gtk_color_selection_set_current_color (GtkColorSelection *colorsel,
const GdkColor *color);
-GDK_DEPRECATED_FOR(gtk_color_selection_get_current_rgba)
+GDK_DEPRECATED_FOR(gtk_color_chooser_get_rgba)
void gtk_color_selection_get_current_color (GtkColorSelection *colorsel,
GdkColor *color);
-GDK_DEPRECATED_FOR(gtk_color_selection_set_previous_rgba)
+GDK_DEPRECATED
void gtk_color_selection_set_previous_color (GtkColorSelection *colorsel,
const GdkColor *color);
-GDK_DEPRECATED_FOR(gtk_color_selection_get_previous_rgba)
+GDK_DEPRECATED
void gtk_color_selection_get_previous_color (GtkColorSelection *colorsel,
GdkColor *color);
diff --git a/gtk/gtkcolorseldialog.c b/gtk/deprecated/gtkcolorseldialog.c
similarity index 98%
rename from gtk/gtkcolorseldialog.c
rename to gtk/deprecated/gtkcolorseldialog.c
index a8a77e7..772a8cb 100644
--- a/gtk/gtkcolorseldialog.c
+++ b/gtk/deprecated/gtkcolorseldialog.c
@@ -24,6 +24,10 @@
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "config.h"
+
+#define GDK_DISABLE_DEPRECATION_WARNINGS
+
+
#include <string.h>
#include <glib.h>
#include "gtkcolorseldialog.h"
@@ -36,7 +40,7 @@
/**
* SECTION:gtkcolorseldlg
- * @Short_description: A standard dialog box for selecting a color
+ * @Short_description: Deprecated dialog box for selecting a color
* @Title: GtkColorSelectionDialog
*
* The #GtkColorSelectionDialog provides a standard dialog which
diff --git a/gtk/gtkcolorseldialog.h b/gtk/deprecated/gtkcolorseldialog.h
similarity index 96%
rename from gtk/gtkcolorseldialog.h
rename to gtk/deprecated/gtkcolorseldialog.h
index aeaa507..a989fc2 100644
--- a/gtk/gtkcolorseldialog.h
+++ b/gtk/deprecated/gtkcolorseldialog.h
@@ -32,7 +32,7 @@
#define __GTK_COLOR_SELECTION_DIALOG_H__
#include <gtk/gtkdialog.h>
-#include <gtk/gtkcolorsel.h>
+#include <gtk/deprecated/gtkcolorsel.h>
G_BEGIN_DECLS
@@ -71,7 +71,9 @@ struct _GtkColorSelectionDialogClass
/* ColorSelectionDialog */
GType gtk_color_selection_dialog_get_type (void) G_GNUC_CONST;
+GDK_DEPRECATED_FOR(gtk_color_chooser_dialog_new)
GtkWidget* gtk_color_selection_dialog_new (const gchar *title);
+GDK_DEPRECATED_FOR(GtkColorChooser)
GtkWidget* gtk_color_selection_dialog_get_color_selection (GtkColorSelectionDialog *colorsel);
diff --git a/gtk/gtkhsv.c b/gtk/deprecated/gtkhsv.c
similarity index 96%
rename from gtk/gtkhsv.c
rename to gtk/deprecated/gtkhsv.c
index e375667..3fac2e1 100644
--- a/gtk/gtkhsv.c
+++ b/gtk/deprecated/gtkhsv.c
@@ -31,6 +31,8 @@
#include "config.h"
+#define GDK_DISABLE_DEPRECATION_WARNINGS
+
#include <math.h>
#include <string.h>
@@ -52,6 +54,9 @@
* intuitive way. Moving the selection around the outer ring changes the hue,
* and moving the selection point inside the inner triangle changes value and
* saturation.
+ *
+ * #GtkHSV has been deprecated together with #GtkColorSelection, where
+ * it was used.
*/
@@ -1454,84 +1459,6 @@ gtk_hsv_is_adjusting (GtkHSV *hsv)
return priv->mode != DRAG_NONE;
}
-/**
- * gtk_hsv_to_rgb:
- * @h: Hue
- * @s: Saturation
- * @v: Value
- * @r: (out): Return value for the red component
- * @g: (out): Return value for the green component
- * @b: (out): Return value for the blue component
- *
- * Converts a color from HSV space to RGB.
- * Input values must be in the [0.0, 1.0] range;
- * output values will be in the same range.
- *
- * Since: 2.14
- */
-void
-gtk_hsv_to_rgb (gdouble h,
- gdouble s,
- gdouble v,
- gdouble *r,
- gdouble *g,
- gdouble *b)
-{
- g_return_if_fail (h >= 0.0 && h <= 1.0);
- g_return_if_fail (s >= 0.0 && s <= 1.0);
- g_return_if_fail (v >= 0.0 && v <= 1.0);
-
- hsv_to_rgb (&h, &s, &v);
-
- if (r)
- *r = h;
-
- if (g)
- *g = s;
-
- if (b)
- *b = v;
-}
-
-/**
- * gtk_rgb_to_hsv:
- * @r: Red
- * @g: Green
- * @b: Blue
- * @h: (out): Return value for the hue component
- * @s: (out): Return value for the saturation component
- * @v: (out): Return value for the value component
- *
- * Converts a color from RGB space to HSV.
- * Input values must be in the [0.0, 1.0] range;
- * output values will be in the same range.
- *
- * Since: 2.14
- */
-void
-gtk_rgb_to_hsv (gdouble r,
- gdouble g,
- gdouble b,
- gdouble *h,
- gdouble *s,
- gdouble *v)
-{
- g_return_if_fail (r >= 0.0 && r <= 1.0);
- g_return_if_fail (g >= 0.0 && g <= 1.0);
- g_return_if_fail (b >= 0.0 && b <= 1.0);
-
- rgb_to_hsv (&r, &g, &b);
-
- if (h)
- *h = r;
-
- if (s)
- *s = g;
-
- if (v)
- *v = b;
-}
-
static void
gtk_hsv_move (GtkHSV *hsv,
GtkDirectionType dir)
diff --git a/gtk/gtkhsv.h b/gtk/deprecated/gtkhsv.h
similarity index 90%
rename from gtk/gtkhsv.h
rename to gtk/deprecated/gtkhsv.h
index ae6bdb3..bdf2694 100644
--- a/gtk/gtkhsv.h
+++ b/gtk/deprecated/gtkhsv.h
@@ -80,37 +80,29 @@ struct _GtkHSVClass
GType gtk_hsv_get_type (void) G_GNUC_CONST;
+GDK_DEPRECATED
GtkWidget* gtk_hsv_new (void);
+GDK_DEPRECATED
void gtk_hsv_set_color (GtkHSV *hsv,
double h,
double s,
double v);
+GDK_DEPRECATED
void gtk_hsv_get_color (GtkHSV *hsv,
gdouble *h,
gdouble *s,
gdouble *v);
+GDK_DEPRECATED
void gtk_hsv_set_metrics (GtkHSV *hsv,
gint size,
gint ring_width);
+GDK_DEPRECATED
void gtk_hsv_get_metrics (GtkHSV *hsv,
gint *size,
gint *ring_width);
+GDK_DEPRECATED
gboolean gtk_hsv_is_adjusting (GtkHSV *hsv);
-/* Convert colors between the RGB and HSV color spaces */
-void gtk_hsv_to_rgb (gdouble h,
- gdouble s,
- gdouble v,
- gdouble *r,
- gdouble *g,
- gdouble *b);
-void gtk_rgb_to_hsv (gdouble r,
- gdouble g,
- gdouble b,
- gdouble *h,
- gdouble *s,
- gdouble *v);
-
G_END_DECLS
#endif /* __GTK_HSV_H__ */
diff --git a/gtk/gtk.h b/gtk/gtk.h
index 130d2fa..6aa44d2 100644
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
@@ -81,8 +81,7 @@
#include <gtk/gtkcolorchooser.h>
#include <gtk/gtkcolorchooserdialog.h>
#include <gtk/gtkcolorchooserwidget.h>
-#include <gtk/gtkcolorsel.h>
-#include <gtk/gtkcolorseldialog.h>
+#include <gtk/gtkcolorutils.h>
#include <gtk/gtkcombobox.h>
#include <gtk/gtkcomboboxtext.h>
#include <gtk/gtkcontainer.h>
@@ -112,7 +111,6 @@
#include <gtk/gtkframe.h>
#include <gtk/gtkgradient.h>
#include <gtk/gtkgrid.h>
-#include <gtk/gtkhsv.h>
#include <gtk/gtkiconfactory.h>
#include <gtk/gtkicontheme.h>
#include <gtk/gtkiconview.h>
@@ -226,11 +224,14 @@
#include <gtk/gtkwidgetpath.h>
#include <gtk/gtkwindow.h>
+#include <gtk/deprecated/gtkcolorsel.h>
+#include <gtk/deprecated/gtkcolorseldialog.h>
#include <gtk/deprecated/gtkfontsel.h>
#include <gtk/deprecated/gtkhandlebox.h>
#include <gtk/deprecated/gtkhbbox.h>
#include <gtk/deprecated/gtkhbox.h>
#include <gtk/deprecated/gtkhpaned.h>
+#include <gtk/deprecated/gtkhsv.h>
#include <gtk/deprecated/gtkhscale.h>
#include <gtk/deprecated/gtkhscrollbar.h>
#include <gtk/deprecated/gtkhseparator.h>
diff --git a/gtk/gtkcolorchooserwidget.c b/gtk/gtkcolorchooserwidget.c
index f71060f..b35d938 100644
--- a/gtk/gtkcolorchooserwidget.c
+++ b/gtk/gtkcolorchooserwidget.c
@@ -24,9 +24,9 @@
#include "gtkcolorchooserwidget.h"
#include "gtkcoloreditor.h"
#include "gtkcolorswatch.h"
+#include "gtkcolorutils.h"
#include "gtkbox.h"
#include "gtkgrid.h"
-#include "gtkhsv.h"
#include "gtklabel.h"
#include "gtkorientable.h"
#include "gtkprivate.h"
diff --git a/gtk/gtkcoloreditor.c b/gtk/gtkcoloreditor.c
index 80a91c4..a34ee36 100644
--- a/gtk/gtkcoloreditor.c
+++ b/gtk/gtkcoloreditor.c
@@ -35,13 +35,13 @@
#include "gtkcolorplane.h"
#include "gtkcolorscale.h"
#include "gtkcolorswatch.h"
+#include "gtkcolorutils.h"
#include "gtkgrid.h"
#include "gtkorientable.h"
#include "gtkaspectframe.h"
#include "gtkdrawingarea.h"
#include "gtkentry.h"
#include "gtkoverlay.h"
-#include "gtkhsv.h"
#include "gtkadjustment.h"
#include "gtklabel.h"
#include "gtkspinbutton.h"
diff --git a/gtk/gtkcolorplane.c b/gtk/gtkcolorplane.c
index efc205c..2e7b2a0 100644
--- a/gtk/gtkcolorplane.c
+++ b/gtk/gtkcolorplane.c
@@ -19,8 +19,8 @@
#include "config.h"
-#include "gtkhsv.h"
#include "gtkcolorplane.h"
+#include "gtkcolorutils.h"
#include "gtkcontainer.h"
#include "gtkaccessible.h"
#include "gtkwindow.h"
diff --git a/gtk/gtkcolorscale.c b/gtk/gtkcolorscale.c
index fb0f5db..e7ca4bf 100644
--- a/gtk/gtkcolorscale.c
+++ b/gtk/gtkcolorscale.c
@@ -20,7 +20,7 @@
#include "config.h"
#include "gtkcolorscale.h"
-#include "gtkhsv.h"
+#include "gtkcolorutils.h"
#include "gtkorientable.h"
#include "gtkstylecontext.h"
#include "gtkaccessible.h"
diff --git a/gtk/gtkcolorutils.c b/gtk/gtkcolorutils.c
new file mode 100644
index 0000000..ef63712
--- /dev/null
+++ b/gtk/gtkcolorutils.c
@@ -0,0 +1,260 @@
+/* Color utilities
+ *
+ * Copyright (C) 1999 The Free Software Foundation
+ *
+ * Authors: Simon Budig <Simon Budig unix-ag org> (original code)
+ * Federico Mena-Quintero <federico gimp org> (cleanup for GTK+)
+ * Jonathan Blandford <jrb redhat com> (cleanup for GTK+)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
+ * file for a list of people on the GTK+ Team. See the ChangeLog
+ * files for a list of changes. These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+#include "config.h"
+
+#include <math.h>
+#include <string.h>
+
+#include "gtkcolorutils.h"
+
+
+#define INTENSITY(r, g, b) ((r) * 0.30 + (g) * 0.59 + (b) * 0.11)
+
+/* Converts from HSV to RGB */
+static void
+hsv_to_rgb (gdouble *h,
+ gdouble *s,
+ gdouble *v)
+{
+ gdouble hue, saturation, value;
+ gdouble f, p, q, t;
+
+ if (*s == 0.0)
+ {
+ *h = *v;
+ *s = *v;
+ *v = *v; /* heh */
+ }
+ else
+ {
+ hue = *h * 6.0;
+ saturation = *s;
+ value = *v;
+
+ if (hue == 6.0)
+ hue = 0.0;
+
+ f = hue - (int) hue;
+ p = value * (1.0 - saturation);
+ q = value * (1.0 - saturation * f);
+ t = value * (1.0 - saturation * (1.0 - f));
+
+ switch ((int) hue)
+ {
+ case 0:
+ *h = value;
+ *s = t;
+ *v = p;
+ break;
+
+ case 1:
+ *h = q;
+ *s = value;
+ *v = p;
+ break;
+
+ case 2:
+ *h = p;
+ *s = value;
+ *v = t;
+ break;
+
+ case 3:
+ *h = p;
+ *s = q;
+ *v = value;
+ break;
+
+ case 4:
+ *h = t;
+ *s = p;
+ *v = value;
+ break;
+
+ case 5:
+ *h = value;
+ *s = p;
+ *v = q;
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+ }
+}
+
+/* Converts from RGB to HSV */
+static void
+rgb_to_hsv (gdouble *r,
+ gdouble *g,
+ gdouble *b)
+{
+ gdouble red, green, blue;
+ gdouble h, s, v;
+ gdouble min, max;
+ gdouble delta;
+
+ red = *r;
+ green = *g;
+ blue = *b;
+
+ h = 0.0;
+
+ if (red > green)
+ {
+ if (red > blue)
+ max = red;
+ else
+ max = blue;
+
+ if (green < blue)
+ min = green;
+ else
+ min = blue;
+ }
+ else
+ {
+ if (green > blue)
+ max = green;
+ else
+ max = blue;
+
+ if (red < blue)
+ min = red;
+ else
+ min = blue;
+ }
+
+ v = max;
+
+ if (max != 0.0)
+ s = (max - min) / max;
+ else
+ s = 0.0;
+
+ if (s == 0.0)
+ h = 0.0;
+ else
+ {
+ delta = max - min;
+
+ if (red == max)
+ h = (green - blue) / delta;
+ else if (green == max)
+ h = 2 + (blue - red) / delta;
+ else if (blue == max)
+ h = 4 + (red - green) / delta;
+
+ h /= 6.0;
+
+ if (h < 0.0)
+ h += 1.0;
+ else if (h > 1.0)
+ h -= 1.0;
+ }
+
+ *r = h;
+ *g = s;
+ *b = v;
+}
+
+/**
+ * gtk_hsv_to_rgb:
+ * @h: Hue
+ * @s: Saturation
+ * @v: Value
+ * @r: (out): Return value for the red component
+ * @g: (out): Return value for the green component
+ * @b: (out): Return value for the blue component
+ *
+ * Converts a color from HSV space to RGB.
+ *
+ * Input values must be in the [0.0, 1.0] range;
+ * output values will be in the same range.
+ *
+ * Since: 2.14
+ */
+void
+gtk_hsv_to_rgb (gdouble h, gdouble s, gdouble v,
+ gdouble *r, gdouble *g, gdouble *b)
+{
+ g_return_if_fail (h >= 0.0 && h <= 1.0);
+ g_return_if_fail (s >= 0.0 && s <= 1.0);
+ g_return_if_fail (v >= 0.0 && v <= 1.0);
+
+ hsv_to_rgb (&h, &s, &v);
+
+ if (r)
+ *r = h;
+
+ if (g)
+ *g = s;
+
+ if (b)
+ *b = v;
+}
+
+/**
+ * gtk_rgb_to_hsv:
+ * @r: Red
+ * @g: Green
+ * @b: Blue
+ * @h: (out): Return value for the hue component
+ * @s: (out): Return value for the saturation component
+ * @v: (out): Return value for the value component
+ *
+ * Converts a color from RGB space to HSV.
+ *
+ * Input values must be in the [0.0, 1.0] range;
+ * output values will be in the same range.
+ *
+ * Since: 2.14
+ */
+void
+gtk_rgb_to_hsv (gdouble r, gdouble g, gdouble b,
+ gdouble *h, gdouble *s, gdouble *v)
+{
+ g_return_if_fail (r >= 0.0 && r <= 1.0);
+ g_return_if_fail (g >= 0.0 && g <= 1.0);
+ g_return_if_fail (b >= 0.0 && b <= 1.0);
+
+ rgb_to_hsv (&r, &g, &b);
+
+ if (h)
+ *h = r;
+
+ if (s)
+ *s = g;
+
+ if (v)
+ *v = b;
+}
diff --git a/gtk/gtkcolorutils.h b/gtk/gtkcolorutils.h
new file mode 100644
index 0000000..cef16b9
--- /dev/null
+++ b/gtk/gtkcolorutils.h
@@ -0,0 +1,48 @@
+/* Color utilties
+ *
+ * Copyright (C) 1999 The Free Software Foundation
+ *
+ * Authors: Simon Budig <Simon Budig unix-ag org> (original code)
+ * Federico Mena-Quintero <federico gimp org> (cleanup for GTK+)
+ * Jonathan Blandford <jrb redhat com> (cleanup for GTK+)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
+ * file for a list of people on the GTK+ Team. See the ChangeLog
+ * files for a list of changes. These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#ifndef __GTK_COLOR_UTILS_H__
+#define __GTK_COLOR_UTILS_H__
+
+#include <glib.h>
+
+void gtk_hsv_to_rgb (gdouble h, gdouble s, gdouble v,
+ gdouble *r, gdouble *g, gdouble *b);
+void gtk_rgb_to_hsv (gdouble r, gdouble g, gdouble b,
+ gdouble *h, gdouble *s, gdouble *v);
+
+G_END_DECLS
+
+#endif /* __GTK_COLOR_UTILS_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]