2002-10-29 23:18:23 +00:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
|
|
*
|
|
|
|
* gimpcolorscale.c
|
|
|
|
* Copyright (C) 2002 Sven Neumann <sven@gimp.org>
|
|
|
|
* Michael Natterer <mitch@gimp.org>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Library 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
|
|
|
|
#include "gimpwidgetstypes.h"
|
|
|
|
|
|
|
|
#include "gimpcolorscale.h"
|
|
|
|
|
|
|
|
|
|
|
|
static void gimp_color_scale_class_init (GimpColorScaleClass *klass);
|
2002-10-29 23:54:02 +00:00
|
|
|
static void gimp_color_scale_init (GimpColorScale *scale);
|
2002-10-29 23:18:23 +00:00
|
|
|
|
2002-10-29 23:54:02 +00:00
|
|
|
static void gimp_color_scale_destroy (GtkObject *object);
|
2002-10-29 23:18:23 +00:00
|
|
|
static void gimp_color_scale_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation);
|
|
|
|
static gboolean gimp_color_scale_expose (GtkWidget *widget,
|
|
|
|
GdkEventExpose *event);
|
|
|
|
|
2002-10-29 23:54:02 +00:00
|
|
|
static void gimp_color_scale_render (GimpColorScale *scale);
|
|
|
|
|
|
|
|
|
2002-10-29 23:18:23 +00:00
|
|
|
static GtkDrawingAreaClass * parent_class = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
GType
|
|
|
|
gimp_color_scale_get_type (void)
|
|
|
|
{
|
2002-10-29 23:54:02 +00:00
|
|
|
static GType scale_type = 0;
|
2002-10-29 23:18:23 +00:00
|
|
|
|
2002-10-29 23:54:02 +00:00
|
|
|
if (! scale_type)
|
2002-10-29 23:18:23 +00:00
|
|
|
{
|
2002-10-29 23:54:02 +00:00
|
|
|
static const GTypeInfo scale_info =
|
2002-10-29 23:18:23 +00:00
|
|
|
{
|
|
|
|
sizeof (GimpColorScaleClass),
|
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_color_scale_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpColorScale),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_color_scale_init,
|
|
|
|
};
|
|
|
|
|
2002-10-29 23:54:02 +00:00
|
|
|
scale_type = g_type_register_static (GTK_TYPE_DRAWING_AREA,
|
|
|
|
"GimpColorScale",
|
|
|
|
&scale_info, 0);
|
2002-10-29 23:18:23 +00:00
|
|
|
}
|
|
|
|
|
2002-10-29 23:54:02 +00:00
|
|
|
return scale_type;
|
2002-10-29 23:18:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_color_scale_class_init (GimpColorScaleClass *klass)
|
|
|
|
{
|
|
|
|
GtkObjectClass *object_class;
|
|
|
|
GtkWidgetClass *widget_class;
|
|
|
|
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
|
|
|
object_class = GTK_OBJECT_CLASS (klass);
|
|
|
|
widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->destroy = gimp_color_scale_destroy;
|
|
|
|
|
|
|
|
widget_class->size_allocate = gimp_color_scale_size_allocate;
|
|
|
|
widget_class->expose_event = gimp_color_scale_expose;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-10-29 23:54:02 +00:00
|
|
|
gimp_color_scale_init (GimpColorScale *scale)
|
2002-10-29 23:18:23 +00:00
|
|
|
{
|
2002-10-29 23:54:02 +00:00
|
|
|
scale->orientation = GTK_ORIENTATION_HORIZONTAL;
|
|
|
|
scale->channel = GIMP_COLOR_SELECTOR_HUE;
|
|
|
|
|
|
|
|
gimp_rgba_set (&scale->rgb, 0.0, 0.0, 0.0, 1.0);
|
|
|
|
gimp_rgb_to_hsv (&scale->rgb, &scale->hsv);
|
2002-10-29 23:18:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_color_scale_destroy (GtkObject *object)
|
|
|
|
{
|
2002-10-29 23:54:02 +00:00
|
|
|
GimpColorScale *scale;
|
2002-10-29 23:18:23 +00:00
|
|
|
|
2002-10-29 23:54:02 +00:00
|
|
|
scale = GIMP_COLOR_SCALE (object);
|
2002-10-29 23:18:23 +00:00
|
|
|
|
2002-10-29 23:54:02 +00:00
|
|
|
if (scale->adj)
|
|
|
|
gimp_color_scale_set_adjustment (scale, NULL);
|
|
|
|
|
|
|
|
if (scale->buf)
|
2002-10-29 23:18:23 +00:00
|
|
|
{
|
2002-10-29 23:54:02 +00:00
|
|
|
g_free (scale->buf);
|
|
|
|
scale->buf = NULL;
|
|
|
|
scale->width = 0;
|
|
|
|
scale->height = 0;
|
|
|
|
scale->rowstride = 0;
|
2002-10-29 23:18:23 +00:00
|
|
|
}
|
|
|
|
|
2002-10-29 23:54:02 +00:00
|
|
|
GTK_OBJECT_CLASS (parent_class)->destroy (object);
|
2002-10-29 23:18:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_color_scale_size_allocate (GtkWidget *widget,
|
2002-10-29 23:54:02 +00:00
|
|
|
GtkAllocation *allocation)
|
2002-10-29 23:18:23 +00:00
|
|
|
{
|
2002-10-29 23:54:02 +00:00
|
|
|
GimpColorScale *scale;
|
2002-10-29 23:18:23 +00:00
|
|
|
|
2002-10-29 23:54:02 +00:00
|
|
|
scale = GIMP_COLOR_SCALE (widget);
|
2002-10-29 23:18:23 +00:00
|
|
|
|
|
|
|
if (GTK_WIDGET_CLASS (parent_class)->size_allocate)
|
|
|
|
GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation);
|
|
|
|
|
2002-10-29 23:54:02 +00:00
|
|
|
if (widget->allocation.width != scale->width ||
|
|
|
|
widget->allocation.height != scale->height)
|
2002-10-29 23:18:23 +00:00
|
|
|
{
|
2002-10-29 23:54:02 +00:00
|
|
|
scale->width = widget->allocation.width;
|
|
|
|
scale->height = widget->allocation.height;
|
|
|
|
|
|
|
|
scale->rowstride = (scale->width * 3 + 3) & ~0x3;
|
2002-10-29 23:18:23 +00:00
|
|
|
|
2002-10-29 23:54:02 +00:00
|
|
|
g_free (scale->buf);
|
|
|
|
scale->buf = g_new (guchar, scale->rowstride * scale->height);
|
2002-10-29 23:18:23 +00:00
|
|
|
|
2002-10-29 23:54:02 +00:00
|
|
|
gimp_color_scale_render (scale);
|
|
|
|
}
|
2002-10-29 23:18:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_color_scale_expose (GtkWidget *widget,
|
2002-10-29 23:54:02 +00:00
|
|
|
GdkEventExpose *event)
|
2002-10-29 23:18:23 +00:00
|
|
|
{
|
2002-10-29 23:54:02 +00:00
|
|
|
GimpColorScale *scale;
|
|
|
|
guchar *buf;
|
2002-10-29 23:18:23 +00:00
|
|
|
|
2002-10-29 23:54:02 +00:00
|
|
|
scale = GIMP_COLOR_SCALE (widget);
|
2002-10-29 23:18:23 +00:00
|
|
|
|
2002-10-29 23:54:02 +00:00
|
|
|
if (! scale->buf || ! GTK_WIDGET_DRAWABLE (widget))
|
2002-10-29 23:18:23 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2002-10-29 23:54:02 +00:00
|
|
|
buf = scale->buf + event->area.y * scale->rowstride + event->area.x * 3;
|
2002-10-29 23:18:23 +00:00
|
|
|
|
|
|
|
gdk_draw_rgb_image_dithalign (widget->window,
|
|
|
|
widget->style->black_gc,
|
|
|
|
event->area.x,
|
|
|
|
event->area.y,
|
|
|
|
event->area.width,
|
|
|
|
event->area.height,
|
|
|
|
GDK_RGB_DITHER_MAX,
|
|
|
|
buf,
|
2002-10-29 23:54:02 +00:00
|
|
|
scale->rowstride,
|
2002-10-29 23:18:23 +00:00
|
|
|
event->area.x,
|
|
|
|
event->area.y);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_color_scale_new:
|
|
|
|
*
|
|
|
|
* Creates a new #GimpColorScale widget.
|
|
|
|
*
|
|
|
|
* Returns: Pointer to the new #GimpColorScale widget.
|
|
|
|
**/
|
|
|
|
GtkWidget *
|
2002-10-29 23:54:02 +00:00
|
|
|
gimp_color_scale_new (GtkOrientation orientation,
|
|
|
|
GimpColorSelectorChannel channel,
|
|
|
|
const GimpRGB *rgb,
|
|
|
|
const GimpHSV *hsv)
|
|
|
|
{
|
|
|
|
GimpColorScale *scale;
|
|
|
|
|
|
|
|
scale = g_object_new (GIMP_TYPE_COLOR_SCALE, NULL);
|
|
|
|
|
|
|
|
scale->orientation = orientation;
|
|
|
|
scale->channel = channel;
|
|
|
|
scale->rgb = *rgb;
|
|
|
|
scale->hsv = *hsv;
|
|
|
|
|
|
|
|
return GTK_WIDGET (scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_color_scale_set_orientation (GimpColorScale *scale,
|
|
|
|
GtkOrientation orientation)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_COLOR_SCALE (scale));
|
|
|
|
|
|
|
|
if (orientation != scale->orientation)
|
|
|
|
{
|
|
|
|
scale->orientation = orientation;
|
|
|
|
|
|
|
|
gimp_color_scale_render (scale);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_color_scale_set_channel (GimpColorScale *scale,
|
|
|
|
GimpColorSelectorChannel channel)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_COLOR_SCALE (scale));
|
|
|
|
|
|
|
|
if (channel != scale->channel)
|
|
|
|
{
|
|
|
|
scale->channel = channel;
|
|
|
|
|
|
|
|
gimp_color_scale_render (scale);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_color_scale_set_color (GimpColorScale *scale,
|
|
|
|
const GimpRGB *rgb,
|
|
|
|
const GimpHSV *hsv)
|
2002-10-29 23:18:23 +00:00
|
|
|
{
|
2002-10-29 23:54:02 +00:00
|
|
|
g_return_if_fail (GIMP_IS_COLOR_SCALE (scale));
|
|
|
|
g_return_if_fail (rgb != NULL);
|
|
|
|
g_return_if_fail (hsv != NULL);
|
2002-10-29 23:18:23 +00:00
|
|
|
|
2002-10-29 23:54:02 +00:00
|
|
|
scale->rgb = *rgb;
|
|
|
|
scale->hsv = *hsv;
|
2002-10-29 23:18:23 +00:00
|
|
|
|
2002-10-29 23:54:02 +00:00
|
|
|
gimp_color_scale_render (scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_color_scale_set_adjustment (GimpColorScale *scale,
|
|
|
|
GtkAdjustment *adj)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_COLOR_SCALE (scale));
|
|
|
|
g_return_if_fail (adj == NULL || GTK_IS_ADJUSTMENT (adj));
|
|
|
|
|
|
|
|
if (adj == scale->adj)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (scale->adj)
|
|
|
|
{
|
|
|
|
g_object_unref (scale->adj);
|
|
|
|
scale->adj = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
scale->adj = adj;
|
|
|
|
|
|
|
|
if (scale->adj)
|
|
|
|
{
|
|
|
|
g_object_ref (scale->adj);
|
|
|
|
gtk_object_sink (GTK_OBJECT (scale->adj));
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_color_scale_render (scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_color_scale_render (GimpColorScale *scale)
|
|
|
|
{
|
2002-10-29 23:18:23 +00:00
|
|
|
}
|