Bug 547270 – Make GtkHSV public

2008-08-11  Michael Natterer  <mitch@imendio.com>

	Bug 547270 – Make GtkHSV public

	* gtk/Makefile.am
	* gtk/gtk.h: install gtkhsv.h as public header (its symbols were
	always public anyway).

	* gtk/gtkhsv.h: add single-include guards, add class struct padding,
	seal the instance member, cleanup.

	* gtk/gtkhsv.c: center the widget in its allocation,
	add "Since: 2.14", cleanup.


svn path=/trunk/; revision=21078
This commit is contained in:
Michael Natterer
2008-08-11 19:57:38 +00:00
committed by Michael Natterer
parent 7dbf580797
commit ac32796399
5 changed files with 132 additions and 74 deletions

View File

@ -1,3 +1,17 @@
2008-08-11 Michael Natterer <mitch@imendio.com>
Bug 547270 Make GtkHSV public
* gtk/Makefile.am
* gtk/gtk.h: install gtkhsv.h as public header (its symbols were
always public anyway).
* gtk/gtkhsv.h: add single-include guards, add class struct padding,
seal the instance member, cleanup.
* gtk/gtkhsv.c: center the widget in its allocation,
add "Since: 2.14", cleanup.
2008-08-11 Torsten Schoenfeld <kaffeetisch@gmx.de> 2008-08-11 Torsten Schoenfeld <kaffeetisch@gmx.de>
* gtk/gtkcalendar.h: Fix the Since: tag of GtkCalendarDetailFunc * gtk/gtkcalendar.h: Fix the Since: tag of GtkCalendarDetailFunc

View File

@ -212,6 +212,7 @@ gtk_public_h_sources = \
gtkhscale.h \ gtkhscale.h \
gtkhscrollbar.h \ gtkhscrollbar.h \
gtkhseparator.h \ gtkhseparator.h \
gtkhsv.h \
gtkiconfactory.h \ gtkiconfactory.h \
gtkicontheme.h \ gtkicontheme.h \
gtkiconview.h \ gtkiconview.h \
@ -354,7 +355,6 @@ gtk_private_h_sources = \
gtkfilechooserutils.h \ gtkfilechooserutils.h \
gtkfilesystem.h \ gtkfilesystem.h \
gtkfilesystemmodel.h \ gtkfilesystemmodel.h \
gtkhsv.h \
gtkiconcache.h \ gtkiconcache.h \
gtkintl.h \ gtkintl.h \
gtkkeyhash.h \ gtkkeyhash.h \

View File

@ -100,6 +100,7 @@
#include <gtk/gtkhscale.h> #include <gtk/gtkhscale.h>
#include <gtk/gtkhscrollbar.h> #include <gtk/gtkhscrollbar.h>
#include <gtk/gtkhseparator.h> #include <gtk/gtkhseparator.h>
#include <gtk/gtkhsv.h>
#include <gtk/gtkiconfactory.h> #include <gtk/gtkiconfactory.h>
#include <gtk/gtkicontheme.h> #include <gtk/gtkicontheme.h>
#include <gtk/gtkiconview.h> #include <gtk/gtkiconview.h>

View File

@ -22,17 +22,6 @@
* Boston, MA 02111-1307, USA. * Boston, MA 02111-1307, USA.
*/ */
#include "config.h"
#include <math.h>
#include <string.h>
#include "gtkhsv.h"
#include "gdk/gdkkeysyms.h"
#include "gtkbindings.h"
#include "gtkcontainer.h"
#include "gtkmarshalers.h"
#include "gtkintl.h"
#include "gtkalias.h"
/* /*
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS * 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 * file for a list of people on the GTK+ Team. See the ChangeLog
@ -40,6 +29,19 @@
* GTK+ at ftp://ftp.gtk.org/pub/gtk/. * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/ */
#include "config.h"
#include <math.h>
#include <string.h>
#include "gdk/gdkkeysyms.h"
#include "gtkhsv.h"
#include "gtkbindings.h"
#include "gtkmarshalers.h"
#include "gtkintl.h"
#include "gtkalias.h"
/* Default width/height */ /* Default width/height */
#define DEFAULT_SIZE 100 #define DEFAULT_SIZE 100
@ -537,23 +539,25 @@ compute_triangle (GtkHSV *hsv,
gint *vy) gint *vy)
{ {
HSVPrivate *priv; HSVPrivate *priv;
gdouble center; gdouble center_x;
gdouble center_y;
gdouble inner, outer; gdouble inner, outer;
gdouble angle; gdouble angle;
priv = hsv->priv; priv = hsv->priv;
center = GTK_WIDGET (hsv)->requisition.width / 2.0; center_x = GTK_WIDGET (hsv)->allocation.width / 2.0;
center_y = GTK_WIDGET (hsv)->allocation.height / 2.0;
outer = priv->size / 2.0; outer = priv->size / 2.0;
inner = outer - priv->ring_width; inner = outer - priv->ring_width;
angle = priv->h * 2.0 * G_PI; angle = priv->h * 2.0 * G_PI;
*hx = floor (center + cos (angle) * inner + 0.5); *hx = floor (center_x + cos (angle) * inner + 0.5);
*hy = floor (center - sin (angle) * inner + 0.5); *hy = floor (center_y - sin (angle) * inner + 0.5);
*sx = floor (center + cos (angle + 2.0 * G_PI / 3.0) * inner + 0.5); *sx = floor (center_x + cos (angle + 2.0 * G_PI / 3.0) * inner + 0.5);
*sy = floor (center - sin (angle + 2.0 * G_PI / 3.0) * inner + 0.5); *sy = floor (center_y - sin (angle + 2.0 * G_PI / 3.0) * inner + 0.5);
*vx = floor (center + cos (angle + 4.0 * G_PI / 3.0) * inner + 0.5); *vx = floor (center_x + cos (angle + 4.0 * G_PI / 3.0) * inner + 0.5);
*vy = floor (center - sin (angle + 4.0 * G_PI / 3.0) * inner + 0.5); *vy = floor (center_y - sin (angle + 4.0 * G_PI / 3.0) * inner + 0.5);
} }
/* Computes whether a point is inside the hue ring */ /* Computes whether a point is inside the hue ring */
@ -564,16 +568,19 @@ is_in_ring (GtkHSV *hsv,
{ {
HSVPrivate *priv; HSVPrivate *priv;
gdouble dx, dy, dist; gdouble dx, dy, dist;
gdouble center, inner, outer; gdouble center_x;
gdouble center_y;
gdouble inner, outer;
priv = hsv->priv; priv = hsv->priv;
center = priv->size / 2.0; center_x = GTK_WIDGET (hsv)->allocation.width / 2.0;
center_y = GTK_WIDGET (hsv)->allocation.height / 2.0;
outer = priv->size / 2.0; outer = priv->size / 2.0;
inner = outer - priv->ring_width; inner = outer - priv->ring_width;
dx = x - center; dx = x - center_x;
dy = center - y; dy = center_y - y;
dist = dx * dx + dy * dy; dist = dx * dx + dy * dy;
return (dist >= inner * inner && dist <= outer * outer); return (dist >= inner * inner && dist <= outer * outer);
@ -589,18 +596,20 @@ compute_sv (GtkHSV *hsv,
{ {
int ihx, ihy, isx, isy, ivx, ivy; int ihx, ihy, isx, isy, ivx, ivy;
double hx, hy, sx, sy, vx, vy; double hx, hy, sx, sy, vx, vy;
double center; double center_x;
double center_y;
compute_triangle (hsv, &ihx, &ihy, &isx, &isy, &ivx, &ivy); compute_triangle (hsv, &ihx, &ihy, &isx, &isy, &ivx, &ivy);
center = GTK_WIDGET (hsv)->requisition.width / 2.0; center_x = GTK_WIDGET (hsv)->allocation.width / 2.0;
hx = ihx - center; center_y = GTK_WIDGET (hsv)->allocation.height / 2.0;
hy = center - ihy; hx = ihx - center_x;
sx = isx - center; hy = center_y - ihy;
sy = center - isy; sx = isx - center_x;
vx = ivx - center; sy = center_y - isy;
vy = center - ivy; vx = ivx - center_x;
x -= center; vy = center_y - ivy;
y = center - y; x -= center_x;
y = center_y - y;
if (vx * (x - sx) + vy * (y - sy) < 0.0) if (vx * (x - sx) + vy * (y - sy) < 0.0)
{ {
@ -688,13 +697,15 @@ compute_v (GtkHSV *hsv,
gdouble x, gdouble x,
gdouble y) gdouble y)
{ {
double center; double center_x;
double center_y;
double dx, dy; double dx, dy;
double angle; double angle;
center = GTK_WIDGET (hsv)->requisition.width / 2.0; center_x = GTK_WIDGET (hsv)->allocation.width / 2.0;
dx = x - center; center_y = GTK_WIDGET (hsv)->allocation.height / 2.0;
dy = center - y; dx = x - center_x;
dy = center_y - y;
angle = atan2 (dy, dx); angle = atan2 (dy, dx);
if (angle < 0.0) if (angle < 0.0)
@ -889,7 +900,8 @@ paint_ring (GtkHSV *hsv,
HSVPrivate *priv; HSVPrivate *priv;
int xx, yy; int xx, yy;
gdouble dx, dy, dist; gdouble dx, dy, dist;
gdouble center; gdouble center_x;
gdouble center_y;
gdouble inner, outer; gdouble inner, outer;
guint32 *buf, *p; guint32 *buf, *p;
gdouble angle; gdouble angle;
@ -908,7 +920,8 @@ paint_ring (GtkHSV *hsv,
priv = hsv->priv; priv = hsv->priv;
center = widget->requisition.width / 2.0; center_x = widget->allocation.width / 2.0;
center_y = widget->allocation.height / 2.0;
outer = priv->size / 2.0; outer = priv->size / 2.0;
inner = outer - priv->ring_width; inner = outer - priv->ring_width;
@ -922,11 +935,11 @@ paint_ring (GtkHSV *hsv,
{ {
p = buf + yy * width; p = buf + yy * width;
dy = -(yy + y - center); dy = -(yy + y - center_y);
for (xx = 0; xx < width; xx++) for (xx = 0; xx < width; xx++)
{ {
dx = xx + x - center; dx = xx + x - center_x;
dist = dx * dx + dy * dy; dist = dx * dx + dy * dy;
if (dist < ((inner-1) * (inner-1)) || dist > ((outer+1) * (outer+1))) if (dist < ((inner-1) * (inner-1)) || dist > ((outer+1) * (outer+1)))
@ -971,10 +984,10 @@ paint_ring (GtkHSV *hsv,
else else
cairo_set_source_rgb (source_cr, 1., 1., 1.); cairo_set_source_rgb (source_cr, 1., 1., 1.);
cairo_move_to (source_cr, -x + center, - y + center); cairo_move_to (source_cr, -x + center_x, - y + center_y);
cairo_line_to (source_cr, cairo_line_to (source_cr,
-x + center + cos (priv->h * 2.0 * G_PI) * center, -x + center_x + cos (priv->h * 2.0 * G_PI) * priv->size / 2,
-y + center - sin (priv->h * 2.0 * G_PI) * center); -y + center_y - sin (priv->h * 2.0 * G_PI) * priv->size / 2);
cairo_stroke (source_cr); cairo_stroke (source_cr);
cairo_destroy (source_cr); cairo_destroy (source_cr);
@ -988,7 +1001,7 @@ paint_ring (GtkHSV *hsv,
cairo_set_line_width (cr, priv->ring_width); cairo_set_line_width (cr, priv->ring_width);
cairo_new_path (cr); cairo_new_path (cr);
cairo_arc (cr, cairo_arc (cr,
center, center, center_x, center_y,
priv->size / 2. - priv->ring_width / 2., priv->size / 2. - priv->ring_width / 2.,
0, 2 * G_PI); 0, 2 * G_PI);
cairo_stroke (cr); cairo_stroke (cr);
@ -1357,6 +1370,8 @@ gtk_hsv_focus (GtkWidget *widget,
* Creates a new HSV color selector. * Creates a new HSV color selector.
* *
* Return value: A newly-created HSV color selector. * Return value: A newly-created HSV color selector.
*
* Since: 2.14
**/ **/
GtkWidget* GtkWidget*
gtk_hsv_new (void) gtk_hsv_new (void)
@ -1373,6 +1388,8 @@ gtk_hsv_new (void)
* *
* Sets the current color in an HSV color selector. Color component values must * Sets the current color in an HSV color selector. Color component values must
* be in the [0.0, 1.0] range. * be in the [0.0, 1.0] range.
*
* Since: 2.14
**/ **/
void void
gtk_hsv_set_color (GtkHSV *hsv, gtk_hsv_set_color (GtkHSV *hsv,
@ -1407,9 +1424,14 @@ gtk_hsv_set_color (GtkHSV *hsv,
* *
* Queries the current color in an HSV color selector. Returned values will be * Queries the current color in an HSV color selector. Returned values will be
* in the [0.0, 1.0] range. * in the [0.0, 1.0] range.
*
* Since: 2.14
**/ **/
void void
gtk_hsv_get_color (GtkHSV *hsv, double *h, double *s, double *v) gtk_hsv_get_color (GtkHSV *hsv,
double *h,
double *s,
double *v)
{ {
HSVPrivate *priv; HSVPrivate *priv;
@ -1434,6 +1456,8 @@ gtk_hsv_get_color (GtkHSV *hsv, double *h, double *s, double *v)
* @ring_width: Width of the hue ring. * @ring_width: Width of the hue ring.
* *
* Sets the size and ring width of an HSV color selector. * Sets the size and ring width of an HSV color selector.
*
* Since: 2.14
**/ **/
void void
gtk_hsv_set_metrics (GtkHSV *hsv, gtk_hsv_set_metrics (GtkHSV *hsv,
@ -1468,6 +1492,8 @@ gtk_hsv_set_metrics (GtkHSV *hsv,
* @ring_width: Return value for the width of the hue ring. * @ring_width: Return value for the width of the hue ring.
* *
* Queries the size and ring width of an HSV color selector. * Queries the size and ring width of an HSV color selector.
*
* Since: 2.14
**/ **/
void void
gtk_hsv_get_metrics (GtkHSV *hsv, gtk_hsv_get_metrics (GtkHSV *hsv,
@ -1499,6 +1525,8 @@ gtk_hsv_get_metrics (GtkHSV *hsv,
* Return value: TRUE if clients can ignore changes to the color value, since * Return value: TRUE if clients can ignore changes to the color value, since
* they may be transitory, or FALSE if they should consider the color value * they may be transitory, or FALSE if they should consider the color value
* status to be final. * status to be final.
*
* Since: 2.14
**/ **/
gboolean gboolean
gtk_hsv_is_adjusting (GtkHSV *hsv) gtk_hsv_is_adjusting (GtkHSV *hsv)
@ -1523,6 +1551,8 @@ gtk_hsv_is_adjusting (GtkHSV *hsv)
* *
* Converts a color from HSV space to RGB. Input values must be in the * 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. * [0.0, 1.0] range; output values will be in the same range.
*
* Since: 2.14
**/ **/
void void
gtk_hsv_to_rgb (gdouble h, gtk_hsv_to_rgb (gdouble h,
@ -1559,6 +1589,8 @@ gtk_hsv_to_rgb (gdouble h,
* *
* Converts a color from RGB space to HSV. Input values must be in the * 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. * [0.0, 1.0] range; output values will be in the same range.
*
* Since: 2.14
**/ **/
void void
gtk_rgb_to_hsv (gdouble r, gtk_rgb_to_hsv (gdouble r,

View File

@ -21,8 +21,6 @@
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA. * Boston, MA 02111-1307, USA.
*/ */
#ifndef __GTK_HSV_H__
#define __GTK_HSV_H__
/* /*
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
@ -31,7 +29,14 @@
* GTK+ at ftp://ftp.gtk.org/pub/gtk/. * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/ */
#include <gtk/gtkcontainer.h> #if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#ifndef __GTK_HSV_H__
#define __GTK_HSV_H__
#include <gtk/gtkwidget.h>
G_BEGIN_DECLS G_BEGIN_DECLS
@ -51,7 +56,7 @@ struct _GtkHSV
GtkWidget parent_instance; GtkWidget parent_instance;
/* Private data */ /* Private data */
gpointer priv; gpointer GSEAL (priv);
}; };
struct _GtkHSVClass struct _GtkHSVClass
@ -59,12 +64,17 @@ struct _GtkHSVClass
GtkWidgetClass parent_class; GtkWidgetClass parent_class;
/* Notification signals */ /* Notification signals */
void (* changed) (GtkHSV *hsv);
void (*changed) (GtkHSV *hsv);
/* Keybindings */ /* Keybindings */
void (* move) (GtkHSV *hsv, void (* move) (GtkHSV *hsv,
GtkDirectionType type); GtkDirectionType type);
/* Padding for future expansion */
void (*_gtk_reserved1) (void);
void (*_gtk_reserved2) (void);
void (*_gtk_reserved3) (void);
void (*_gtk_reserved4) (void);
}; };
@ -85,6 +95,8 @@ void gtk_hsv_get_metrics (GtkHSV *hsv,
gint *size, gint *size,
gint *ring_width); gint *ring_width);
gboolean gtk_hsv_is_adjusting (GtkHSV *hsv); gboolean gtk_hsv_is_adjusting (GtkHSV *hsv);
/* Convert colors between the RGB and HSV color spaces */
void gtk_hsv_to_rgb (gdouble h, void gtk_hsv_to_rgb (gdouble h,
gdouble s, gdouble s,
gdouble v, gdouble v,
@ -98,7 +110,6 @@ void gtk_rgb_to_hsv (gdouble r,
gdouble *s, gdouble *s,
gdouble *v); gdouble *v);
G_END_DECLS G_END_DECLS
#endif /* __GTK_HSV_H__ */ #endif /* __GTK_HSV_H__ */