app/widgets/Makefile.am app/widgets/widgets-types.h new GimpHistogramView

2007-11-04  Michael Natterer  <mitch@gimp.org>

	* app/widgets/Makefile.am
	* app/widgets/widgets-types.h
	* app/widgets/gimpcurveview.[ch]: new GimpHistogramView subclass
	which does all the curve stuff.

	* app/widgets/gimphistorgramview.[ch]: removed all curve code again.

	* app/tools/gimpcurvestool.c: changed accordingly.


svn path=/trunk/; revision=24051
This commit is contained in:
Michael Natterer 2007-11-04 13:09:10 +00:00 committed by Michael Natterer
parent aabb94ec92
commit ae1f2eb2bc
8 changed files with 609 additions and 326 deletions

View File

@ -1,3 +1,14 @@
2007-11-04 Michael Natterer <mitch@gimp.org>
* app/widgets/Makefile.am
* app/widgets/widgets-types.h
* app/widgets/gimpcurveview.[ch]: new GimpHistogramView subclass
which does all the curve stuff.
* app/widgets/gimphistorgramview.[ch]: removed all curve code again.
* app/tools/gimpcurvestool.c: changed accordingly.
2007-11-04 Sven Neumann <sven@gimp.org>
* libgimpwidgets/gimpcolorselect.c

View File

@ -49,7 +49,7 @@
#include "widgets/gimpcolorbar.h"
#include "widgets/gimpcursor.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimphistogramview.h"
#include "widgets/gimpcurveview.h"
#include "display/gimpdisplay.h"
@ -273,8 +273,8 @@ gimp_curves_tool_initialize (GimpTool *tool,
gimp_drawable_calculate_histogram (drawable, c_tool->hist);
gimp_histogram_view_set_histogram (GIMP_HISTOGRAM_VIEW (c_tool->graph),
c_tool->hist);
gimp_histogram_view_set_curve (GIMP_HISTOGRAM_VIEW (c_tool->graph),
c_tool->curve[c_tool->channel]);
gimp_curve_view_set_curve (GIMP_CURVE_VIEW (c_tool->graph),
c_tool->curve[c_tool->channel]);
return TRUE;
}
@ -297,8 +297,8 @@ gimp_curves_tool_button_release (GimpTool *tool,
gimp_curve_get_closest_point (curve,
c_tool->col_value[c_tool->channel]);
gimp_histogram_view_set_selected (GIMP_HISTOGRAM_VIEW (c_tool->graph),
c_tool->selected);
gimp_curve_view_set_selected (GIMP_CURVE_VIEW (c_tool->graph),
c_tool->selected);
gimp_curve_set_point (curve,
c_tool->selected,
@ -317,8 +317,8 @@ gimp_curves_tool_button_release (GimpTool *tool,
gimp_curve_get_closest_point (curve,
c_tool->col_value[i]);
gimp_histogram_view_set_selected (GIMP_HISTOGRAM_VIEW (c_tool->graph),
c_tool->selected);
gimp_curve_view_set_selected (GIMP_CURVE_VIEW (c_tool->graph),
c_tool->selected);
gimp_curve_set_point (curve,
c_tool->selected,
@ -405,8 +405,8 @@ gimp_curves_tool_color_picked (GimpColorTool *color_tool,
else
channel = (tool->channel == 1) ? GIMP_HISTOGRAM_ALPHA : GIMP_HISTOGRAM_VALUE;
gimp_histogram_view_set_xpos (GIMP_HISTOGRAM_VIEW (tool->graph),
tool->col_value[channel]);
gimp_curve_view_set_xpos (GIMP_CURVE_VIEW (tool->graph),
tool->col_value[channel]);
}
static gboolean
@ -429,8 +429,7 @@ curves_key_press (GimpCurvesTool *tool,
{
tool->selected = i;
gimp_histogram_view_set_selected (GIMP_HISTOGRAM_VIEW (tool->graph),
i);
gimp_curve_view_set_selected (GIMP_CURVE_VIEW (tool->graph), i);
return TRUE;
}
@ -444,8 +443,7 @@ curves_key_press (GimpCurvesTool *tool,
{
tool->selected = i;
gimp_histogram_view_set_selected (GIMP_HISTOGRAM_VIEW (tool->graph),
i);
gimp_curve_view_set_selected (GIMP_CURVE_VIEW (tool->graph), i);
return TRUE;
}
@ -601,16 +599,10 @@ gimp_curves_tool_dialog (GimpImageMapTool *image_map_tool)
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_widget_show (frame);
tool->graph = gimp_histogram_view_new (FALSE);
tool->graph = gimp_curve_view_new ();
gtk_widget_set_size_request (tool->graph,
GRAPH_SIZE + RADIUS * 2,
GRAPH_SIZE + RADIUS * 2);
GTK_WIDGET_SET_FLAGS (tool->graph, GTK_CAN_FOCUS);
gtk_widget_add_events (tool->graph, (GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK |
GDK_POINTER_MOTION_MASK |
GDK_KEY_PRESS_MASK |
GDK_LEAVE_NOTIFY_MASK));
g_object_set (tool->graph,
"border-width", RADIUS,
"subdivisions", 1,
@ -858,8 +850,8 @@ curves_channel_callback (GtkWidget *widget,
tool->channel = value;
gimp_histogram_view_set_channel (GIMP_HISTOGRAM_VIEW (tool->graph),
tool->channel);
gimp_histogram_view_set_xpos (GIMP_HISTOGRAM_VIEW (tool->graph),
tool->col_value[tool->channel]);
gimp_curve_view_set_xpos (GIMP_CURVE_VIEW (tool->graph),
tool->col_value[tool->channel]);
gimp_color_bar_set_channel (GIMP_COLOR_BAR (tool->yrange), tool->channel);
@ -867,8 +859,8 @@ curves_channel_callback (GtkWidget *widget,
if (! tool->color)
tool->channel = (tool->channel == GIMP_HISTOGRAM_ALPHA) ? 1 : 0;
gimp_histogram_view_set_curve (GIMP_HISTOGRAM_VIEW (tool->graph),
tool->curve[tool->channel]);
gimp_curve_view_set_curve (GIMP_CURVE_VIEW (tool->graph),
tool->curve[tool->channel]);
gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (tool->curve_type),
tool->curve[tool->channel]->curve_type);
@ -1014,8 +1006,8 @@ curves_graph_events (GtkWidget *widget,
tool->selected = closest_point;
gimp_histogram_view_set_selected (GIMP_HISTOGRAM_VIEW (tool->graph),
closest_point);
gimp_curve_view_set_selected (GIMP_CURVE_VIEW (tool->graph),
closest_point);
gimp_curve_set_point (curve, tool->selected, x, 255 - y);
@ -1027,8 +1019,7 @@ curves_graph_events (GtkWidget *widget,
tool->selected = x;
tool->last = y;
gimp_histogram_view_set_selected (GIMP_HISTOGRAM_VIEW (tool->graph),
x);
gimp_curve_view_set_selected (GIMP_CURVE_VIEW (tool->graph), x);
break;
}
@ -1081,8 +1072,8 @@ curves_graph_events (GtkWidget *widget,
{
tool->selected = closest_point;
gimp_histogram_view_set_selected (GIMP_HISTOGRAM_VIEW (tool->graph),
closest_point);
gimp_curve_view_set_selected (GIMP_CURVE_VIEW (tool->graph),
closest_point);
}
gimp_curve_set_point (curve, tool->selected, x, 255 - y);
@ -1122,8 +1113,7 @@ curves_graph_events (GtkWidget *widget,
tool->selected = x;
tool->last = y;
gimp_histogram_view_set_selected (GIMP_HISTOGRAM_VIEW (tool->graph),
x);
gimp_curve_view_set_selected (GIMP_CURVE_VIEW (tool->graph), x);
}
if (mevent->state & GDK_BUTTON1_MASK)
@ -1136,8 +1126,7 @@ curves_graph_events (GtkWidget *widget,
curves_set_cursor (tool, new_cursor);
gimp_histogram_view_set_cusor (GIMP_HISTOGRAM_VIEW (tool->graph),
x, y);
gimp_curve_view_set_cusor (GIMP_CURVE_VIEW (tool->graph), x, y);
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (tool));
}
@ -1152,8 +1141,7 @@ curves_graph_events (GtkWidget *widget,
break;
case GDK_LEAVE_NOTIFY:
gimp_histogram_view_set_cusor (GIMP_HISTOGRAM_VIEW (tool->graph),
-1, -1);
gimp_curve_view_set_cusor (GIMP_CURVE_VIEW (tool->graph), -1, -1);
return TRUE;
default:

View File

@ -100,6 +100,8 @@ libappwidgets_a_sources = \
gimpcursor.h \
gimpcursorview.c \
gimpcursorview.h \
gimpcurveview.c \
gimpcurveview.h \
gimpdasheditor.c \
gimpdasheditor.h \
gimpdataeditor.c \

484
app/widgets/gimpcurveview.c Normal file
View File

@ -0,0 +1,484 @@
/* GIMP - The GNU 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 "libgimpmath/gimpmath.h"
#include "widgets-types.h"
#include "core/gimpcurve.h"
#include "core/gimpmarshal.h"
#include "gimpcurveview.h"
enum
{
PROP_0,
PROP_CHANNEL,
PROP_SCALE,
PROP_BORDER_WIDTH,
PROP_SUBDIVISIONS
};
static void gimp_curve_view_finalize (GObject *object);
static void gimp_curve_view_dispose (GObject *object);
static void gimp_curve_view_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_curve_view_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static gboolean gimp_curve_view_expose (GtkWidget *widget,
GdkEventExpose *event);
static gboolean gimp_curve_view_button_press (GtkWidget *widget,
GdkEventButton *bevent);
static gboolean gimp_curve_view_button_release (GtkWidget *widget,
GdkEventButton *bevent);
static gboolean gimp_curve_view_motion_notify (GtkWidget *widget,
GdkEventMotion *bevent);
G_DEFINE_TYPE (GimpCurveView, gimp_curve_view,
GIMP_TYPE_HISTOGRAM_VIEW)
#define parent_class gimp_curve_view_parent_class
static void
gimp_curve_view_class_init (GimpCurveViewClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GimpHistogramViewClass *hist_class = GIMP_HISTOGRAM_VIEW_CLASS (klass);
object_class->finalize = gimp_curve_view_finalize;
object_class->dispose = gimp_curve_view_dispose;
object_class->get_property = gimp_curve_view_get_property;
object_class->set_property = gimp_curve_view_set_property;
widget_class->expose_event = gimp_curve_view_expose;
widget_class->button_press_event = gimp_curve_view_button_press;
widget_class->button_release_event = gimp_curve_view_button_release;
widget_class->motion_notify_event = gimp_curve_view_motion_notify;
hist_class->light_histogram = TRUE;
#if 0
g_object_class_install_property (object_class, PROP_CHANNEL,
g_param_spec_enum ("curve-channel",
NULL, NULL,
GIMP_TYPE_CURVE_CHANNEL,
GIMP_CURVE_VALUE,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_SCALE,
g_param_spec_enum ("curve-scale",
NULL, NULL,
GIMP_TYPE_CURVE_SCALE,
GIMP_CURVE_SCALE_LINEAR,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_BORDER_WIDTH,
g_param_spec_int ("border-width", NULL, NULL,
0, 32, 1,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_SUBDIVISIONS,
g_param_spec_int ("subdivisions",
NULL, NULL,
1, 64, 5,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
#endif
}
static void
gimp_curve_view_init (GimpCurveView *view)
{
view->curve = NULL;
view->selected = 0;
view->xpos = -1;
view->cursor_x = -1;
view->cursor_y = -1;
GTK_WIDGET_SET_FLAGS (view, GTK_CAN_FOCUS);
gtk_widget_add_events (GTK_WIDGET (view),
GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK |
GDK_POINTER_MOTION_MASK |
GDK_KEY_PRESS_MASK |
GDK_LEAVE_NOTIFY_MASK);
}
static void
gimp_curve_view_finalize (GObject *object)
{
GimpCurveView *view = GIMP_CURVE_VIEW (object);
if (view->xpos_layout)
{
g_object_unref (view->xpos_layout);
view->xpos_layout = NULL;
}
if (view->cursor_layout)
{
g_object_unref (view->cursor_layout);
view->cursor_layout = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_curve_view_dispose (GObject *object)
{
GimpCurveView *view = GIMP_CURVE_VIEW (object);
gimp_curve_view_set_curve (view, NULL);
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
gimp_curve_view_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpCurveView *view = GIMP_CURVE_VIEW (object);
switch (property_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_curve_view_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpCurveView *view = GIMP_CURVE_VIEW (object);
switch (property_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static gboolean
gimp_curve_view_expose (GtkWidget *widget,
GdkEventExpose *event)
{
GimpCurveView *view = GIMP_CURVE_VIEW (widget);
gint x, y, i;
gint border;
gint width, height;
GdkPoint points[256];
GdkGC *graph_gc;
GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
if (! view->curve)
return FALSE;
border = GIMP_HISTOGRAM_VIEW (view)->border_width;
width = widget->allocation.width - 2 * border;
height = widget->allocation.height - 2 * border;
/* Draw the grid lines */
for (i = 1; i < 4; i++)
{
gdk_draw_line (widget->window,
widget->style->dark_gc[GTK_STATE_NORMAL],
border,
border + i * (height / 4),
border + width - 1,
border + i * (height / 4));
gdk_draw_line (widget->window,
widget->style->dark_gc[GTK_STATE_NORMAL],
border + i * (width / 4),
border,
border + i * (width / 4),
border + height - 1);
}
/* Draw the curve */
graph_gc = widget->style->text_gc[GTK_STATE_NORMAL];
for (i = 0; i < 256; i++)
{
x = i;
y = 255 - view->curve->curve[x];
points[i].x = border + ROUND ((gdouble) width * x / 256.0);
points[i].y = border + ROUND ((gdouble) height * y / 256.0);
}
gdk_draw_lines (widget->window, graph_gc, points, 256);
if (view->curve->curve_type == GIMP_CURVE_SMOOTH)
{
/* Draw the points */
for (i = 0; i < GIMP_CURVE_NUM_POINTS; i++)
{
x = view->curve->points[i][0];
if (x < 0)
continue;
y = 255 - view->curve->points[i][1];
gdk_draw_arc (widget->window, graph_gc,
TRUE,
ROUND ((gdouble) width * x / 256.0),
ROUND ((gdouble) height * y / 256.0),
border * 2, border * 2, 0, 23040);
if (i == view->selected)
gdk_draw_arc (widget->window,
widget->style->base_gc[GTK_STATE_NORMAL],
TRUE,
ROUND ((gdouble) width * x / 256.0) + 2,
ROUND ((gdouble) height * y / 256.0) + 2,
(border - 2) * 2, (border - 2) * 2, 0, 23040);
}
}
if (view->xpos >= 0)
{
gchar buf[32];
/* draw the color line */
gdk_draw_line (widget->window,
widget->style->text_gc[GTK_STATE_NORMAL],
border +
ROUND ((gdouble) width * view->xpos / 256.0),
border,
border +
ROUND ((gdouble) width * view->xpos / 256.0),
height + border - 1);
/* and xpos indicator */
g_snprintf (buf, sizeof (buf), "x:%d", view->xpos);
if (! view->xpos_layout)
view->xpos_layout = gtk_widget_create_pango_layout (widget, buf);
else
pango_layout_set_text (view->xpos_layout, buf, -1);
pango_layout_get_pixel_size (view->xpos_layout, &x, &y);
if ((view->xpos + border) < 127)
x = border + 4;
else
x = -(x + 2);
gdk_draw_layout (widget->window,
widget->style->text_gc[GTK_STATE_NORMAL],
border +
ROUND ((gdouble) width * view->xpos / 256.0 + x),
height - y - 2,
view->xpos_layout);
}
if (view->cursor_x >= 0 && view->cursor_x <= 255 &&
view->cursor_y >= 0 && view->cursor_y <= 255)
{
gchar buf[32];
gint x, y;
gint w, h;
if (! view->cursor_layout)
{
view->cursor_layout = gtk_widget_create_pango_layout (widget,
"x:888 y:888");
pango_layout_get_pixel_extents (view->cursor_layout,
NULL, &view->cursor_rect);
}
x = border * 2 + 2;
y = border * 2 + 2;
w = view->cursor_rect.width + 4;
h = view->cursor_rect.height + 4;
gdk_draw_rectangle (widget->window,
widget->style->base_gc[GTK_STATE_ACTIVE],
TRUE,
x, y, w + 1, h + 1);
gdk_draw_rectangle (widget->window,
widget->style->text_gc[GTK_STATE_NORMAL],
FALSE,
x, y, w, h);
g_snprintf (buf, sizeof (buf), "x:%3d y:%3d",
view->cursor_x, 255 - view->cursor_y);
pango_layout_set_text (view->cursor_layout, buf, 11);
gdk_draw_layout (widget->window,
widget->style->text_gc[GTK_STATE_ACTIVE],
x + 2, y + 2,
view->cursor_layout);
}
return FALSE;
}
static gboolean
gimp_curve_view_button_press (GtkWidget *widget,
GdkEventButton *bevent)
{
GimpCurveView *view = GIMP_CURVE_VIEW (widget);
return GTK_WIDGET_CLASS (parent_class)->button_press_event (widget, bevent);
}
static gboolean
gimp_curve_view_button_release (GtkWidget *widget,
GdkEventButton *bevent)
{
GimpCurveView *view = GIMP_CURVE_VIEW (widget);
return GTK_WIDGET_CLASS (parent_class)->button_release_event (widget, bevent);
}
static gboolean
gimp_curve_view_motion_notify (GtkWidget *widget,
GdkEventMotion *mevent)
{
GimpCurveView *view = GIMP_CURVE_VIEW (widget);
return GTK_WIDGET_CLASS (parent_class)->motion_notify_event (widget, mevent);
}
GtkWidget *
gimp_curve_view_new (void)
{
GtkWidget *view = g_object_new (GIMP_TYPE_CURVE_VIEW, NULL);
gtk_widget_add_events (view,
GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK |
GDK_BUTTON1_MOTION_MASK);
return view;
}
static void
gimp_curve_view_curve_notify (GimpCurve *curve,
const GParamSpec *pspec,
GimpCurveView *view)
{
if (! strcmp (pspec->name, "curve-type") ||
! strcmp (pspec->name, "points") ||
! strcmp (pspec->name, "curve"))
{
gtk_widget_queue_draw (GTK_WIDGET (view));
}
}
void
gimp_curve_view_set_curve (GimpCurveView *view,
GimpCurve *curve)
{
g_return_if_fail (GIMP_IS_CURVE_VIEW (view));
g_return_if_fail (curve == NULL || GIMP_IS_CURVE (curve));
if (view->curve == curve)
return;
if (view->curve)
{
g_signal_handlers_disconnect_by_func (view->curve,
gimp_curve_view_curve_notify,
view);
g_object_unref (view->curve);
}
view->curve = curve;
if (view->curve)
{
g_object_ref (view->curve);
g_signal_connect (view->curve, "notify",
G_CALLBACK (gimp_curve_view_curve_notify),
view);
}
}
GimpCurve *
gimp_curve_view_get_curve (GimpCurveView *view)
{
g_return_val_if_fail (GIMP_IS_CURVE_VIEW (view), NULL);
return view->curve;
}
void
gimp_curve_view_set_selected (GimpCurveView *view,
gint selected)
{
g_return_if_fail (GIMP_IS_CURVE_VIEW (view));
view->selected = selected;
gtk_widget_queue_draw (GTK_WIDGET (view));
}
void
gimp_curve_view_set_xpos (GimpCurveView *view,
gint x)
{
g_return_if_fail (GIMP_IS_CURVE_VIEW (view));
view->xpos = x;
gtk_widget_queue_draw (GTK_WIDGET (view));
}
void
gimp_curve_view_set_cusor (GimpCurveView *view,
gint x,
gint y)
{
g_return_if_fail (GIMP_IS_CURVE_VIEW (view));
view->cursor_x = x;
view->cursor_y = y;
gtk_widget_queue_draw (GTK_WIDGET (view));
}

View File

@ -0,0 +1,75 @@
/* GIMP - The GNU 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.
*/
#ifndef __GIMP_CURVE_VIEW_H__
#define __GIMP_CURVE_VIEW_H__
#include "gimphistogramview.h"
#define GIMP_TYPE_CURVE_VIEW (gimp_curve_view_get_type ())
#define GIMP_CURVE_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_CURVE_VIEW, GimpCurveView))
#define GIMP_CURVE_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_CURVE_VIEW, GimpCurveViewClass))
#define GIMP_IS_CURVE_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_CURVE_VIEW))
#define GIMP_IS_CURVE_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_CURVE_VIEW))
#define GIMP_CURVE_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_CURVE_VIEW, GimpCurveViewClass))
typedef struct _GimpCurveViewClass GimpCurveViewClass;
struct _GimpCurveView
{
GimpHistogramView parent_instance;
GimpCurve *curve;
gint selected;
gint xpos;
PangoLayout *xpos_layout;
gint cursor_x;
gint cursor_y;
PangoLayout *cursor_layout;
PangoRectangle cursor_rect;
};
struct _GimpCurveViewClass
{
GimpHistogramViewClass parent_class;
};
GType gimp_curve_view_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_curve_view_new (void);
void gimp_curve_view_set_curve (GimpCurveView *view,
GimpCurve *curve);
GimpCurve * gimp_curve_view_get_curve (GimpCurveView *view);
void gimp_curve_view_set_selected (GimpCurveView *view,
gint selected);
void gimp_curve_view_set_xpos (GimpCurveView *view,
gint x);
void gimp_curve_view_set_cusor (GimpCurveView *view,
gint x,
gint y);
#endif /* __GIMP_CURVE_VIEW_H__ */

View File

@ -18,8 +18,6 @@
#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#include "libgimpmath/gimpmath.h"
@ -28,7 +26,6 @@
#include "base/gimphistogram.h"
#include "core/gimpcurve.h"
#include "core/gimpmarshal.h"
#include "gimphistogramview.h"
@ -53,7 +50,6 @@ enum
};
static void gimp_histogram_view_dispose (GObject *object);
static void gimp_histogram_view_set_property (GObject *object,
guint property_id,
const GValue *value,
@ -110,7 +106,6 @@ gimp_histogram_view_class_init (GimpHistogramViewClass *klass)
G_TYPE_INT,
G_TYPE_INT);
object_class->dispose = gimp_histogram_view_dispose;
object_class->get_property = gimp_histogram_view_get_property;
object_class->set_property = gimp_histogram_view_set_property;
@ -158,34 +153,6 @@ gimp_histogram_view_init (GimpHistogramView *view)
view->histogram = NULL;
view->start = 0;
view->end = 255;
view->curve = NULL;
view->selected = 0;
view->xpos = -1;
view->cursor_x = -1;
view->cursor_y = -1;
}
static void
gimp_histogram_view_dispose (GObject *object)
{
GimpHistogramView *view = GIMP_HISTOGRAM_VIEW (object);
gimp_histogram_view_set_curve (view, NULL);
if (view->xpos_layout)
{
g_object_unref (view->xpos_layout);
view->xpos_layout = NULL;
}
if (view->cursor_layout)
{
g_object_unref (view->cursor_layout);
view->cursor_layout = NULL;
}
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
@ -319,13 +286,16 @@ gimp_histogram_view_expose (GtkWidget *widget,
max = gimp_histogram_view_get_maximum (view, view->channel);
gc_in = (view->curve ?
widget->style->mid_gc[GTK_STATE_SELECTED] :
widget->style->text_gc[GTK_STATE_SELECTED]);
gc_out = (view->curve ?
widget->style->mid_gc[GTK_STATE_NORMAL] :
widget->style->text_gc[GTK_STATE_NORMAL]);
if (GIMP_HISTOGRAM_VIEW_GET_CLASS (view)->light_histogram)
{
gc_in = widget->style->mid_gc[GTK_STATE_SELECTED];
gc_out = widget->style->mid_gc[GTK_STATE_NORMAL];
}
else
{
gc_in = widget->style->text_gc[GTK_STATE_SELECTED];
gc_out = widget->style->text_gc[GTK_STATE_NORMAL];
}
if (view->channel == GIMP_HISTOGRAM_RGB)
{
@ -406,147 +376,6 @@ gimp_histogram_view_expose (GtkWidget *widget,
g_object_unref (rgb_gc[x]);
}
if (view->curve)
{
gint x, y, i;
GdkPoint points[256];
GdkGC *graph_gc;
/* Draw the grid lines */
for (i = 1; i < 4; i++)
{
gdk_draw_line (widget->window,
widget->style->dark_gc[GTK_STATE_NORMAL],
border,
border + i * (height / 4),
border + width - 1,
border + i * (height / 4));
gdk_draw_line (widget->window,
widget->style->dark_gc[GTK_STATE_NORMAL],
border + i * (width / 4),
border,
border + i * (width / 4),
border + height - 1);
}
/* Draw the curve */
graph_gc = widget->style->text_gc[GTK_STATE_NORMAL];
for (i = 0; i < 256; i++)
{
x = i;
y = 255 - view->curve->curve[x];
points[i].x = border + ROUND ((gdouble) width * x / 256.0);
points[i].y = border + ROUND ((gdouble) height * y / 256.0);
}
gdk_draw_lines (widget->window, graph_gc, points, 256);
if (view->curve->curve_type == GIMP_CURVE_SMOOTH)
{
/* Draw the points */
for (i = 0; i < GIMP_CURVE_NUM_POINTS; i++)
{
x = view->curve->points[i][0];
if (x < 0)
continue;
y = 255 - view->curve->points[i][1];
gdk_draw_arc (widget->window, graph_gc,
TRUE,
ROUND ((gdouble) width * x / 256.0),
ROUND ((gdouble) height * y / 256.0),
border * 2, border * 2, 0, 23040);
if (i == view->selected)
gdk_draw_arc (widget->window,
widget->style->base_gc[GTK_STATE_NORMAL],
TRUE,
ROUND ((gdouble) width * x / 256.0) + 2,
ROUND ((gdouble) height * y / 256.0) + 2,
(border - 2) * 2, (border - 2) * 2, 0, 23040);
}
}
if (view->xpos >= 0)
{
gchar buf[32];
/* draw the color line */
gdk_draw_line (widget->window,
widget->style->text_gc[GTK_STATE_NORMAL],
border +
ROUND ((gdouble) width * view->xpos / 256.0),
border,
border +
ROUND ((gdouble) width * view->xpos / 256.0),
height + border - 1);
/* and xpos indicator */
g_snprintf (buf, sizeof (buf), "x:%d", view->xpos);
if (! view->xpos_layout)
view->xpos_layout = gtk_widget_create_pango_layout (widget, buf);
else
pango_layout_set_text (view->xpos_layout, buf, -1);
pango_layout_get_pixel_size (view->xpos_layout, &x, &y);
if ((view->xpos + border) < 127)
x = border + 4;
else
x = -(x + 2);
gdk_draw_layout (widget->window,
widget->style->text_gc[GTK_STATE_NORMAL],
border +
ROUND ((gdouble) width * view->xpos / 256.0 + x),
height - y - 2,
view->xpos_layout);
}
if (view->cursor_x >= 0 && view->cursor_x <= 255 &&
view->cursor_y >= 0 && view->cursor_y <= 255)
{
gchar buf[32];
gint x, y;
gint w, h;
if (! view->cursor_layout)
{
view->cursor_layout = gtk_widget_create_pango_layout (widget,
"x:888 y:888");
pango_layout_get_pixel_extents (view->cursor_layout,
NULL, &view->cursor_rect);
}
x = border * 2 + 2;
y = border * 2 + 2;
w = view->cursor_rect.width + 4;
h = view->cursor_rect.height + 4;
gdk_draw_rectangle (widget->window,
widget->style->base_gc[GTK_STATE_ACTIVE],
TRUE,
x, y, w + 1, h + 1);
gdk_draw_rectangle (widget->window,
widget->style->text_gc[GTK_STATE_NORMAL],
FALSE,
x, y, w, h);
g_snprintf (buf, sizeof (buf), "x:%3d y:%3d",
view->cursor_x, 255 - view->cursor_y);
pango_layout_set_text (view->cursor_layout, buf, 11);
gdk_draw_layout (widget->window,
widget->style->text_gc[GTK_STATE_ACTIVE],
x + 2, y + 2,
view->cursor_layout);
}
}
return FALSE;
}
@ -764,88 +593,3 @@ gimp_histogram_view_get_range (GimpHistogramView *view,
if (start) *start = view->start;
if (end) *end = view->end;
}
static void
gimp_histogram_view_curve_notify (GimpCurve *curve,
const GParamSpec *pspec,
GimpHistogramView *view)
{
if (! strcmp (pspec->name, "curve-type") ||
! strcmp (pspec->name, "points") ||
! strcmp (pspec->name, "curve"))
{
gtk_widget_queue_draw (GTK_WIDGET (view));
}
}
void
gimp_histogram_view_set_curve (GimpHistogramView *view,
GimpCurve *curve)
{
g_return_if_fail (GIMP_IS_HISTOGRAM_VIEW (view));
g_return_if_fail (curve == NULL || GIMP_IS_CURVE (curve));
if (view->curve == curve)
return;
if (view->curve)
{
g_signal_handlers_disconnect_by_func (view->curve,
gimp_histogram_view_curve_notify,
view);
g_object_unref (view->curve);
}
view->curve = curve;
if (view->curve)
{
g_object_ref (view->curve);
g_signal_connect (view->curve, "notify",
G_CALLBACK (gimp_histogram_view_curve_notify),
view);
}
}
GimpCurve *
gimp_histogram_view_get_curve (GimpHistogramView *view)
{
g_return_val_if_fail (GIMP_IS_HISTOGRAM_VIEW (view), NULL);
return view->curve;
}
void
gimp_histogram_view_set_selected (GimpHistogramView *view,
gint selected)
{
g_return_if_fail (GIMP_IS_HISTOGRAM_VIEW (view));
view->selected = selected;
gtk_widget_queue_draw (GTK_WIDGET (view));
}
void
gimp_histogram_view_set_xpos (GimpHistogramView *view,
gint x)
{
g_return_if_fail (GIMP_IS_HISTOGRAM_VIEW (view));
view->xpos = x;
gtk_widget_queue_draw (GTK_WIDGET (view));
}
void
gimp_histogram_view_set_cusor (GimpHistogramView *view,
gint x,
gint y)
{
g_return_if_fail (GIMP_IS_HISTOGRAM_VIEW (view));
view->cursor_x = x;
view->cursor_y = y;
gtk_widget_queue_draw (GTK_WIDGET (view));
}

View File

@ -45,24 +45,14 @@ struct _GimpHistogramView
gint border_width;
gint subdivisions;
/* to be moved to a GimpCursorView subclass */
GimpCurve *curve;
gint selected;
gint xpos;
PangoLayout *xpos_layout;
gint cursor_x;
gint cursor_y;
PangoLayout *cursor_layout;
PangoRectangle cursor_rect;
};
struct _GimpHistogramViewClass
{
GtkDrawingAreaClass parent_class;
gboolean light_histogram;
void (* range_changed) (GimpHistogramView *view,
gint start,
gint end);
@ -92,17 +82,5 @@ void gimp_histogram_view_get_range (GimpHistogramView *view,
gint *start,
gint *end);
void gimp_histogram_view_set_curve (GimpHistogramView *view,
GimpCurve *curve);
GimpCurve * gimp_histogram_view_get_curve (GimpHistogramView *view);
void gimp_histogram_view_set_selected (GimpHistogramView *view,
gint selected);
void gimp_histogram_view_set_xpos (GimpHistogramView *view,
gint x);
void gimp_histogram_view_set_cusor (GimpHistogramView *view,
gint x,
gint y);
#endif /* __GIMP_HISTOGRAM_VIEW_H__ */

View File

@ -157,6 +157,7 @@ typedef struct _GimpColorFrame GimpColorFrame;
typedef struct _GimpColorPanel GimpColorPanel;
typedef struct _GimpControllerEditor GimpControllerEditor;
typedef struct _GimpControllerList GimpControllerList;
typedef struct _GimpCurveView GimpCurveView;
typedef struct _GimpDashEditor GimpDashEditor;
typedef struct _GimpFgBgEditor GimpFgBgEditor;
typedef struct _GimpFgBgView GimpFgBgView;