Commit 924acb2b authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

app/widgets/Makefile.am app/widgets/widgets-types.h added new widget

2004-02-19  Sven Neumann  <sven@gimp.org>

	* app/widgets/Makefile.am
	* app/widgets/widgets-types.h
	* app/widgets/gimpcolorbar.[ch]: added new widget GimpColorBar.

	* app/tools/gimpcurvestool.c
	* app/tools/gimplevelstool.c
	* app/widgets/gimphistogrambox.[ch]: use GimpColorBar widgets.

	* app/widgets/gimpcolorframe.[ch]: fixed typos.
parent c2b4867b
2004-02-19 Sven Neumann <sven@gimp.org>
* app/widgets/Makefile.am
* app/widgets/widgets-types.h
* app/widgets/gimpcolorbar.[ch]: added new widget GimpColorBar.
* app/tools/gimpcurvestool.c
* app/tools/gimplevelstool.c
* app/widgets/gimphistogrambox.[ch]: use GimpColorBar widgets.
* app/widgets/gimpcolorframe.[ch]: fixed typos.
2004-02-19 Michael Natterer <mitch@gimp.org>
* themes/Default/images/Makefile.am
......@@ -23,14 +23,8 @@
#include <string.h>
#include <errno.h>
#ifdef __GNUC__
#warning GTK_DISABLE_DEPRECATED
#endif
#undef GTK_DISABLE_DEPRECATED
#include <gtk/gtk.h>
#include "libgimpmath/gimpmath.h"
#include "libgimpbase/gimpbase.h"
#include "libgimpcolor/gimpcolor.h"
#include "libgimpwidgets/gimpwidgets.h"
......@@ -50,6 +44,7 @@
#include "core/gimpimagemap.h"
#include "core/gimptoolinfo.h"
#include "widgets/gimpcolorbar.h"
#include "widgets/gimpcursor.h"
#include "widgets/gimpenummenu.h"
#include "widgets/gimphelp-ids.h"
......@@ -64,10 +59,9 @@
#include "gimp-intl.h"
#define XRANGE_TOP (1 << 0)
#define XRANGE_BOTTOM (1 << 1)
#define YRANGE (1 << 2)
#define ALL (XRANGE_TOP | XRANGE_BOTTOM | YRANGE)
#define XRANGE (1 << 0)
#define YRANGE (1 << 1)
#define ALL (XRANGE | YRANGE)
/* NB: take care when changing these values: make sure the curve[] array in
* base/curves.h is large enough.
......@@ -482,6 +476,8 @@ gimp_curves_tool_dialog (GimpImageMapTool *image_map_tool)
GtkWidget *menu;
GtkWidget *table;
GtkWidget *button;
GtkWidget *vbox2;
GtkWidget *bar;
hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (image_map_tool->main_vbox), hbox,
......@@ -538,8 +534,8 @@ gimp_curves_tool_dialog (GimpImageMapTool *image_map_tool)
GTK_EXPAND, GTK_EXPAND, 0, 0);
gtk_widget_show (frame);
c_tool->yrange = gtk_preview_new (GTK_PREVIEW_COLOR);
gtk_preview_size (GTK_PREVIEW (c_tool->yrange), YRANGE_WIDTH, YRANGE_HEIGHT);
c_tool->yrange = gimp_color_bar_new (GTK_ORIENTATION_VERTICAL);
gtk_widget_set_size_request (c_tool->yrange, YRANGE_WIDTH, YRANGE_HEIGHT);
gtk_container_add (GTK_CONTAINER (frame), c_tool->yrange);
gtk_widget_show (c_tool->yrange);
......@@ -583,11 +579,20 @@ gimp_curves_tool_dialog (GimpImageMapTool *image_map_tool)
GTK_EXPAND, GTK_EXPAND, 0, 0);
gtk_widget_show (frame);
c_tool->xrange = gtk_preview_new (GTK_PREVIEW_COLOR);
gtk_preview_size (GTK_PREVIEW (c_tool->xrange), XRANGE_WIDTH, XRANGE_HEIGHT);
gtk_container_add (GTK_CONTAINER (frame), c_tool->xrange);
vbox2 = gtk_vbox_new (TRUE, 0);
gtk_container_add (GTK_CONTAINER (frame), vbox2);
gtk_widget_show (vbox2);
c_tool->xrange = gimp_color_bar_new (GTK_ORIENTATION_HORIZONTAL);
gtk_widget_set_size_request (c_tool->xrange,
XRANGE_WIDTH, XRANGE_HEIGHT / 2);
gtk_box_pack_start (GTK_BOX (vbox2), c_tool->xrange, TRUE, TRUE, 0);
gtk_widget_show (c_tool->xrange);
bar = gimp_color_bar_new (GTK_ORIENTATION_HORIZONTAL);
gtk_box_pack_start (GTK_BOX (vbox2), bar, TRUE, TRUE, 0);
gtk_widget_show (bar);
gtk_widget_show (table);
hbox = gtk_hbox_new (FALSE, 6);
......@@ -657,7 +662,7 @@ gimp_curves_tool_reset (GimpImageMapTool *image_map_tool)
channel++)
curves_channel_reset (c_tool->curves, channel);
curves_update (c_tool, XRANGE_TOP);
curves_update (c_tool, XRANGE);
gtk_widget_queue_draw (c_tool->graph);
}
......@@ -667,126 +672,46 @@ static void
curves_update (GimpCurvesTool *c_tool,
gint update)
{
GimpHistogramChannel sel_channel;
gint i, j;
GimpHistogramChannel channel;
if (c_tool->color)
{
sel_channel = c_tool->channel;
channel = c_tool->channel;
}
else
{
if (c_tool->channel == 2)
sel_channel = GIMP_HISTOGRAM_ALPHA;
channel = GIMP_HISTOGRAM_ALPHA;
else
sel_channel = GIMP_HISTOGRAM_VALUE;
channel = GIMP_HISTOGRAM_VALUE;
}
if (update & XRANGE_TOP)
if (update & XRANGE)
{
guchar buf[XRANGE_WIDTH * 3];
switch (sel_channel)
switch (channel)
{
case GIMP_HISTOGRAM_VALUE:
case GIMP_HISTOGRAM_ALPHA:
for (i = 0; i < XRANGE_HEIGHT / 2; i++)
{
for (j = 0; j < XRANGE_WIDTH ; j++)
{
buf[j * 3 + 0] = c_tool->curves->curve[sel_channel][j];
buf[j * 3 + 1] = c_tool->curves->curve[sel_channel][j];
buf[j * 3 + 2] = c_tool->curves->curve[sel_channel][j];
}
gtk_preview_draw_row (GTK_PREVIEW (c_tool->xrange),
buf, 0, i, XRANGE_WIDTH);
}
gimp_color_bar_set_buffers (GIMP_COLOR_BAR (c_tool->xrange),
c_tool->curves->curve[channel],
c_tool->curves->curve[channel],
c_tool->curves->curve[channel]);
break;
case GIMP_HISTOGRAM_RED:
case GIMP_HISTOGRAM_GREEN:
case GIMP_HISTOGRAM_BLUE:
{
for (i = 0; i < XRANGE_HEIGHT / 2; i++)
{
for (j = 0; j < XRANGE_WIDTH; j++)
{
buf[j * 3 + 0] = c_tool->curves->curve[GIMP_HISTOGRAM_RED][j];
buf[j * 3 + 1] = c_tool->curves->curve[GIMP_HISTOGRAM_GREEN][j];
buf[j * 3 + 2] = c_tool->curves->curve[GIMP_HISTOGRAM_BLUE][j];
}
gtk_preview_draw_row (GTK_PREVIEW (c_tool->xrange),
buf, 0, i, XRANGE_WIDTH);
}
break;
}
default:
g_warning ("unknown channel type %d, can't happen!?!?",
c_tool->channel);
gimp_color_bar_set_buffers (GIMP_COLOR_BAR (c_tool->xrange),
c_tool->curves->curve[GIMP_HISTOGRAM_RED],
c_tool->curves->curve[GIMP_HISTOGRAM_GREEN],
c_tool->curves->curve[GIMP_HISTOGRAM_BLUE]);
break;
}
gtk_widget_queue_draw_area (c_tool->xrange,
0, 0,
XRANGE_WIDTH, XRANGE_HEIGHT / 2);
}
if (update & XRANGE_BOTTOM)
{
guchar buf[XRANGE_WIDTH * 3];
for (i = 0; i < XRANGE_WIDTH; i++)
{
buf[i * 3 + 0] = i;
buf[i * 3 + 1] = i;
buf[i * 3 + 2] = i;
}
for (i = XRANGE_HEIGHT / 2; i < XRANGE_HEIGHT; i++)
gtk_preview_draw_row (GTK_PREVIEW (c_tool->xrange),
buf, 0, i, XRANGE_WIDTH);
gtk_widget_queue_draw_area (c_tool->xrange,
0, XRANGE_HEIGHT / 2,
XRANGE_WIDTH, XRANGE_HEIGHT / 2);
}
if (update & YRANGE)
{
guchar buf[YRANGE_WIDTH * 3];
guchar pix[3];
for (i = 0; i < YRANGE_HEIGHT; i++)
{
switch (sel_channel)
{
case GIMP_HISTOGRAM_VALUE:
case GIMP_HISTOGRAM_ALPHA:
pix[0] = pix[1] = pix[2] = (255 - i);
break;
case GIMP_HISTOGRAM_RED:
case GIMP_HISTOGRAM_GREEN:
case GIMP_HISTOGRAM_BLUE:
pix[0] = pix[1] = pix[2] = 0;
pix[sel_channel - 1] = (255 - i);
break;
default:
g_warning ("unknown channel type %d, can't happen!?!?",
c_tool->channel);
break;
}
for (j = 0; j < YRANGE_WIDTH * 3; j++)
buf[j] = pix[j%3];
gtk_preview_draw_row (GTK_PREVIEW (c_tool->yrange),
buf, 0, i, YRANGE_WIDTH);
}
gtk_widget_queue_draw (c_tool->yrange);
gimp_color_bar_set_channel (GIMP_COLOR_BAR (c_tool->yrange), channel);
}
}
......@@ -806,7 +731,7 @@ curves_channel_callback (GtkWidget *widget,
gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (c_tool->curve_type),
c_tool->curves->curve_type[c_tool->channel]);
curves_update (c_tool, XRANGE_TOP | YRANGE);
curves_update (c_tool, ALL);
}
static void
......@@ -817,7 +742,7 @@ curves_channel_reset_callback (GtkWidget *widget,
curves_channel_reset (c_tool->curves, c_tool->channel);
curves_update (c_tool, XRANGE_TOP);
curves_update (c_tool, XRANGE);
gtk_widget_queue_draw (c_tool->graph);
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (c_tool));
......@@ -874,7 +799,7 @@ curves_curve_type_callback (GtkWidget *widget,
curves_calculate_curve (c_tool->curves, c_tool->channel);
curves_update (c_tool, XRANGE_TOP);
curves_update (c_tool, XRANGE);
gtk_widget_queue_draw (c_tool->graph);
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (c_tool));
......@@ -959,7 +884,7 @@ curves_graph_events (GtkWidget *widget,
curves_calculate_curve (c_tool->curves, c_tool->channel);
curves_update (c_tool, XRANGE_TOP);
curves_update (c_tool, XRANGE);
gtk_widget_queue_draw (c_tool->graph);
return TRUE;
......@@ -1058,7 +983,7 @@ curves_graph_events (GtkWidget *widget,
GIMP_CURSOR_MODIFIER_NONE);
}
curves_update (c_tool, XRANGE_TOP);
curves_update (c_tool, XRANGE);
c_tool->cursor_x = tx - RADIUS;
c_tool->cursor_y = ty - RADIUS;
......
This diff is collapsed.
......@@ -31,6 +31,8 @@ libappwidgets_a_sources = \
gimpcellrendererviewable.h \
gimpchanneltreeview.c \
gimpchanneltreeview.h \
gimpcolorbar.c \
gimpcolorbar.h \
gimpcolordisplayeditor.c \
gimpcolordisplayeditor.h \
gimpcoloreditor.c \
......
/* The GIMP -- an image manipulation program
* 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 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#include "libgimpcolor/gimpcolor.h"
#include "widgets-types.h"
#include "config/gimpconfig-params.h"
#include "gimpcolorbar.h"
enum
{
PROP_0,
PROP_ORIENTATION,
PROP_INPUT,
PROP_COLOR,
PROP_CHANNEL
};
/* local function prototypes */
static void gimp_color_bar_class_init (GimpColorBarClass *klass);
static void gimp_color_bar_init (GimpColorBar *bar);
static void gimp_color_bar_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_color_bar_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static void gimp_color_bar_realize (GtkWidget *widget);
static void gimp_color_bar_unrealize (GtkWidget *widget);
static void gimp_color_bar_map (GtkWidget *widget);
static void gimp_color_bar_unmap (GtkWidget *widget);
static gboolean gimp_color_bar_expose (GtkWidget *widget,
GdkEventExpose *event);
static GtkMiscClass *parent_class = NULL;
GType
gimp_color_bar_get_type (void)
{
static GType type = 0;
if (! type)
{
static const GTypeInfo bar_info =
{
sizeof (GimpColorBarClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gimp_color_bar_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpColorBar),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_color_bar_init,
};
type = g_type_register_static (GTK_TYPE_MISC,
"GimpColorBar", &bar_info, 0);
}
return type;
}
static void
gimp_color_bar_class_init (GimpColorBarClass *klass)
{
GObjectClass *object_class;
GtkWidgetClass *widget_class;
GimpRGB white = { 1.0, 1.0, 1.0, 1.0 };
object_class = G_OBJECT_CLASS (klass);
widget_class = GTK_WIDGET_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->set_property = gimp_color_bar_set_property;
g_object_class_install_property (object_class, PROP_ORIENTATION,
g_param_spec_enum ("orientation",
NULL, NULL,
GTK_TYPE_ORIENTATION,
GTK_ORIENTATION_HORIZONTAL,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_INPUT,
g_param_spec_boolean ("input",
NULL, NULL,
FALSE,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_COLOR,
gimp_param_spec_color ("color",
NULL, NULL,
&white,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_ORIENTATION,
g_param_spec_enum ("channel",
NULL, NULL,
GIMP_TYPE_HISTOGRAM_CHANNEL,
GIMP_HISTOGRAM_VALUE,
G_PARAM_WRITABLE));
widget_class->size_allocate = gimp_color_bar_size_allocate;
widget_class->realize = gimp_color_bar_realize;
widget_class->unrealize = gimp_color_bar_unrealize;
widget_class->map = gimp_color_bar_map;
widget_class->unmap = gimp_color_bar_unmap;
widget_class->expose_event = gimp_color_bar_expose;
}
static void
gimp_color_bar_init (GimpColorBar *bar)
{
GTK_WIDGET_SET_FLAGS (bar, GTK_NO_WINDOW);
bar->orientation = GTK_ORIENTATION_HORIZONTAL;
bar->input = FALSE;
bar->input_window = NULL;
}
static void
gimp_color_bar_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpColorBar *bar = GIMP_COLOR_BAR (object);
switch (property_id)
{
case PROP_ORIENTATION:
bar->orientation = g_value_get_enum (value);
break;
case PROP_INPUT:
bar->input = g_value_get_boolean (value);
break;
case PROP_COLOR:
gimp_color_bar_set_color (bar, g_value_get_boxed (value));
break;
case PROP_CHANNEL:
gimp_color_bar_set_channel (bar, g_value_get_enum (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_color_bar_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
GimpColorBar *bar = GIMP_COLOR_BAR (widget);
GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation);
if (bar->input_window)
gdk_window_move_resize (bar->input_window,
widget->allocation.x,
widget->allocation.y,
widget->allocation.width,
widget->allocation.height);
}
static void
gimp_color_bar_realize (GtkWidget *widget)
{
GimpColorBar *bar = GIMP_COLOR_BAR (widget);
GTK_WIDGET_CLASS (parent_class)->realize (widget);
if (bar->input && ! bar->input_window)
{
GdkWindowAttr attributes;
attributes.x = widget->allocation.x;
attributes.y = widget->allocation.y;
attributes.width = widget->allocation.width;
attributes.height = widget->allocation.height;
attributes.window_type = GDK_WINDOW_TEMP;
attributes.wclass = GDK_INPUT_ONLY;
attributes.override_redirect = TRUE;
attributes.event_mask = (GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK |
GDK_BUTTON_MOTION_MASK |
gtk_widget_get_events (widget));
bar->input_window = gdk_window_new (widget->window,
&attributes,
(GDK_WA_X |
GDK_WA_Y |
GDK_WA_NOREDIR));
gdk_window_set_user_data (bar->input_window, widget);
}
}
static void
gimp_color_bar_unrealize (GtkWidget *widget)
{
GimpColorBar *bar = GIMP_COLOR_BAR (widget);
if (bar->input_window)
{
gdk_window_set_user_data (bar->input_window, NULL);
gdk_window_destroy (bar->input_window);
bar->input_window = NULL;
}
GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
}
static void
gimp_color_bar_map (GtkWidget *widget)
{
GimpColorBar *bar = GIMP_COLOR_BAR (widget);
GTK_WIDGET_CLASS (parent_class)->map (widget);
if (bar->input_window)
gdk_window_show (bar->input_window);
}
static void
gimp_color_bar_unmap (GtkWidget *widget)
{
GimpColorBar *bar = GIMP_COLOR_BAR (widget);
if (bar->input_window)
gdk_window_hide (bar->input_window);
GTK_WIDGET_CLASS (parent_class)->unmap (widget);
}
static gboolean
gimp_color_bar_expose (GtkWidget *widget,
GdkEventExpose *event)
{
GimpColorBar *bar = GIMP_COLOR_BAR (widget);
guchar *buf;
guchar *b;
gint x, y;
gint width, height;
gint i, j;
x = GTK_MISC (bar)->xpad;
y = GTK_MISC (bar)->ypad;
width = widget->allocation.width - 2 * x;
height = widget->allocation.height - 2 * y;
if (width < 1 || height < 1)
return TRUE;
buf = g_alloca (width * height * 3);
switch (bar->orientation)
{
case GTK_ORIENTATION_HORIZONTAL:
for (i = 0, b = buf; i < width; i++, b += 3)
{
guchar *src = bar->buf + 3 * ((i * 256) / width);
b[0] = src[0];
b[1] = src[1];
b[2] = src[2];
}
for (i = 0; i < height; i++)
memcpy (buf + i * width * 3, buf, width * 3);
break;
case GTK_ORIENTATION_VERTICAL:
for (i = 0, b = buf; i < height; i++, b += 3 * width)
{
guchar *src = bar->buf + 3 * (255 - ((i * 256) / height));
guchar *dest = b;
for (j = 0; j < width; j++, dest += 3)
{
dest[0] = src[0];
dest[1] = src[1];
dest[2] = src[2];
}
}
break;
}
gdk_draw_rgb_image (widget->window, widget->style->black_gc,
widget->allocation.x + x, widget->allocation.y + y,
width, height,
GDK_RGB_DITHER_NORMAL,
buf, 3 * width);
return TRUE;
}
/**
* gimp_color_bar_new:
*
* Creates a new #GimpColorBar widget.
*
* Return value: The new #GimpColorBar widget.
**/
GtkWidget *
gimp_color_bar_new (GtkOrientation orientation)
{
return g_object_new (GIMP_TYPE_COLOR_BAR,
"orientation", orientation,
NULL);
}
/**
* gimp_color_bar_set_color:
* @bar: a #GimpColorBar widget
* @color: a #GimpRGB color
*
* Makes the @bar display a gradient from black (on the left or the
* bottom), to the given @color (on the right or at the top).
**/
void
gimp_color_bar_set_color (GimpColorBar *bar,
const GimpRGB *color)
{
guchar *buf;
gint i;
g_return_if_fail (GIMP_IS_COLOR_BAR (bar));
g_return_if_fail (color != NULL);
for (i = 0, buf = bar->buf; i < 256; i++, buf += 3)
{
buf[0] = ROUND (color->r * (gdouble) i);
buf[1] = ROUND (color->g * (gdouble) i);
buf[2] = ROUND (color->b * (gdouble) i);
}
gtk_widget_queue_draw (GTK_WIDGET (bar));
}
/**
* gimp_color_bar_set_color:
* @bar: a #GimpColorBar widget
* @channel: a #GimpHistogramChannel
*
* Convenience function that calls gimp_color_bar_set_color() with the
* color that matches the @channel.
**/
void
gimp_color_bar_set_channel (GimpColorBar *bar,
GimpHistogramChannel channel)
{
GimpRGB color = { 1.0, 1.0, 1.0, 1.0 };
g_return_if_fail (GIMP_IS_COLOR_BAR (bar));
switch (channel)
{
case GIMP_HISTOGRAM_VALUE:
case GIMP_HISTOGRAM_ALPHA:
gimp_rgb_set (&color, 1.0, 1.0, 1.0);
break;
case GIMP_HISTOGRAM_RED:
gimp_rgb_set (&color, 1.0, 0.0, 0.0);
break;
case GIMP_HISTOGRAM_GREEN:
gimp_rgb_set (&color, 0.0, 1.0, 0.0);
break;
case GIMP_HISTOGRAM_BLUE:
gimp_rgb_set (&color, 0.0, 0.0, 1.0);
break;
}
gimp_color_bar_set_color (bar, &color);
}
/**
* gimp_color_bar_set_buffers:
* @bar: a #GimpColorBar widget
* @red: an array of 256 values
* @green: an array of 256 values
* @blue: an array of 256 values
*
* This function gives full control over the colors displayed by the
* @bar widget. The 3 arrays can for example be taken from a #Levels
* or a #Curves struct.
**/
void
gimp_color_bar_set_buffers (GimpColorBar *bar,
const guchar *red,
const guchar *green,
const guchar *blue)
{
guchar *buf;
gint i;
g_return_if_fail (GIMP_IS_COLOR_BAR (bar));
g_return_if_fail (red != NULL);
g_return_if_fail (green != NULL);
g_return_if_fail (blue != NULL);
for (i = 0, buf = bar->buf; i < 256; i++, buf += 3)
{
buf[0] = red[i];
buf[1] = green[i];
buf[2] = blue[i];
}