Commit e5927feb authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

added API to modify free-form curves and properties to listen to curve

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

	* app/core/gimpcurve.[ch]: added API to modify free-form curves
	and properties to listen to curve changes.

	* app/widgets/gimphistogramview.[ch]: added everything that's
	needed for rendering a curve with all its color and cursor
	indicators on top of a histogram. This code will move to a
	subclass soon.

	* app/tools/gimpcurvestool.[ch]: removed all curve rendering here.
	Also removed all explicit updating by connecting to curve signals
	and updating in the callback.


svn path=/trunk/; revision=24045
parent b572dec9
2007-11-02 Michael Natterer <mitch@gimp.org>
* app/core/gimpcurve.[ch]: added API to modify free-form curves
and properties to listen to curve changes.
* app/widgets/gimphistogramview.[ch]: added everything that's
needed for rendering a curve with all its color and cursor
indicators on top of a histogram. This code will move to a
subclass soon.
* app/tools/gimpcurvestool.[ch]: removed all curve rendering here.
Also removed all explicit updating by connecting to curve signals
and updating in the callback.
2007-11-02 Sven Neumann <sven@gimp.org>
* app/widgets/gimpcairo-utils.[ch]: added utility function to create
......
......@@ -37,7 +37,9 @@
enum
{
PROP_0,
PROP_CURVE_TYPE
PROP_CURVE_TYPE,
PROP_POINTS,
PROP_CURVE
};
......@@ -119,6 +121,18 @@ gimp_curve_class_init (GimpCurveClass *klass)
GIMP_CURVE_SMOOTH,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_POINTS,
g_param_spec_boolean ("points", NULL, NULL,
FALSE,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_CURVE,
g_param_spec_boolean ("curve", NULL, NULL,
FALSE,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
}
static void
......@@ -149,6 +163,10 @@ gimp_curve_set_property (GObject *object,
gimp_curve_set_curve_type (curve, g_value_get_enum (value));
break;
case PROP_POINTS:
case PROP_CURVE:
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
......@@ -169,6 +187,10 @@ gimp_curve_get_property (GObject *object,
g_value_set_enum (value, curve->curve_type);
break;
case PROP_POINTS:
case PROP_CURVE:
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
......@@ -313,9 +335,11 @@ gimp_curve_reset (GimpCurve *curve,
g_object_freeze_notify (G_OBJECT (curve));
/* g_object_notify (G_OBJECT (curve), "points"); */
/* g_object_notify (G_OBJECT (curve), "curve"); */
g_object_notify (G_OBJECT (curve), "curve-type");
g_object_notify (G_OBJECT (curve), "points");
g_object_notify (G_OBJECT (curve), "curve");
if (reset_type)
g_object_notify (G_OBJECT (curve), "curve-type");
g_object_thaw_notify (G_OBJECT (curve));
}
......@@ -328,6 +352,8 @@ gimp_curve_set_curve_type (GimpCurve *curve,
if (curve->curve_type != curve_type)
{
g_object_freeze_notify (G_OBJECT (curve));
curve->curve_type = curve_type;
if (curve_type == GIMP_CURVE_SMOOTH)
......@@ -350,6 +376,9 @@ gimp_curve_set_curve_type (GimpCurve *curve,
gimp_curve_calculate (curve);
g_object_notify (G_OBJECT (curve), "curve-type");
g_object_thaw_notify (G_OBJECT (curve));
gimp_data_dirty (GIMP_DATA (curve));
}
}
......@@ -401,10 +430,16 @@ gimp_curve_set_point (GimpCurve *curve,
if (curve->curve_type == GIMP_CURVE_FREE)
return;
g_object_freeze_notify (G_OBJECT (curve));
curve->points[point][0] = x;
curve->points[point][1] = y;
g_object_notify (G_OBJECT (curve), "points");
gimp_curve_calculate (curve);
g_object_thaw_notify (G_OBJECT (curve));
}
void
......@@ -417,9 +452,34 @@ gimp_curve_move_point (GimpCurve *curve,
if (curve->curve_type == GIMP_CURVE_FREE)
return;
g_object_freeze_notify (G_OBJECT (curve));
curve->points[point][1] = y;
g_object_notify (G_OBJECT (curve), "points");
gimp_curve_calculate (curve);
g_object_thaw_notify (G_OBJECT (curve));
}
void
gimp_curve_set_curve (GimpCurve *curve,
gint x,
gint y)
{
g_return_if_fail (GIMP_IS_CURVE (curve));
if (curve->curve_type == GIMP_CURVE_SMOOTH)
return;
g_object_freeze_notify (G_OBJECT (curve));
curve->curve[x] = y;
g_object_notify (G_OBJECT (curve), "curve");
g_object_thaw_notify (G_OBJECT (curve));
}
void
......@@ -480,6 +540,8 @@ gimp_curve_calculate (GimpCurve *curve)
curve->curve[x] = y;
}
g_object_notify (G_OBJECT (curve), "curve");
break;
case GIMP_CURVE_FREE:
......
......@@ -75,9 +75,14 @@ void gimp_curve_move_point (GimpCurve *curve,
gint point,
gint y);
void gimp_curve_set_curve (GimpCurve *curve,
gint x,
gint y);
void gimp_curve_get_uchar (GimpCurve *curve,
guchar *dest_array);
/* FIXME: make private */
void gimp_curve_calculate (GimpCurve *curve);
......
This diff is collapsed.
......@@ -59,12 +59,6 @@ struct _GimpCurvesTool
GtkWidget *yrange;
GtkWidget *graph;
GtkWidget *curve_type;
gint cursor_x;
gint cursor_y;
PangoLayout *xpos_layout;
PangoLayout *cursor_layout;
PangoRectangle cursor_rect;
};
struct _GimpCurvesToolClass
......
......@@ -18,6 +18,8 @@
#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#include "libgimpmath/gimpmath.h"
......@@ -26,6 +28,7 @@
#include "base/gimphistogram.h"
#include "core/gimpcurve.h"
#include "core/gimpmarshal.h"
#include "gimphistogramview.h"
......@@ -50,6 +53,7 @@ enum
};
static void gimp_histogram_view_dispose (GObject *object);
static void gimp_histogram_view_set_property (GObject *object,
guint property_id,
const GValue *value,
......@@ -58,6 +62,7 @@ static void gimp_histogram_view_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_histogram_view_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static gboolean gimp_histogram_view_expose (GtkWidget *widget,
......@@ -105,6 +110,7 @@ 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;
......@@ -152,6 +158,34 @@ 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
......@@ -285,11 +319,11 @@ gimp_histogram_view_expose (GtkWidget *widget,
max = gimp_histogram_view_get_maximum (view, view->channel);
gc_in = (view->light_histogram ?
gc_in = (view->curve ?
widget->style->mid_gc[GTK_STATE_SELECTED] :
widget->style->text_gc[GTK_STATE_SELECTED]);
gc_out = (view->light_histogram ?
gc_out = (view->curve ?
widget->style->mid_gc[GTK_STATE_NORMAL] :
widget->style->text_gc[GTK_STATE_NORMAL]);
......@@ -372,6 +406,147 @@ 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;
}
......@@ -589,3 +764,77 @@ 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_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));
}
......@@ -46,8 +46,17 @@ struct _GimpHistogramView
gint border_width;
gint subdivisions;
/* hack */
gboolean light_histogram;
/* 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
......@@ -83,5 +92,15 @@ 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_xpos (GimpHistogramView *view,
gint x);
void gimp_histogram_view_set_cusor (GimpHistogramView *view,
gint x,
gint y);
#endif /* __GIMP_HISTOGRAM_VIEW_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment