added event handling and completely edit the curve here.

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

	* app/widgets/gimpcurveview.[ch]: added event handling and
	completely edit the curve here.

	* app/tools/gimpcurvestool.[ch]: remove all event handling and
	curve editing code and only listen to curve signals.


svn path=/trunk/; revision=24060
This commit is contained in:
Michael Natterer 2007-11-05 08:59:09 +00:00 committed by Michael Natterer
parent a07756d894
commit 2d827be2f3
5 changed files with 330 additions and 452 deletions

View File

@ -1,3 +1,11 @@
2007-11-05 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpcurveview.[ch]: added event handling and
completely edit the curve here.
* app/tools/gimpcurvestool.[ch]: remove all event handling and
curve editing code and only listen to curve signals.
2007-11-04 Martin Nordholts <martinn@svn.gnome.org>
Do not do shell darkening while GimpRectangleTool rectangles are

View File

@ -23,7 +23,6 @@
#include <string.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include "libgimpmath/gimpmath.h"
#include "libgimpcolor/gimpcolor.h"
@ -32,8 +31,6 @@
#include "tools-types.h"
#include "config/gimpguiconfig.h"
#include "base/curves.h"
#include "base/gimphistogram.h"
#include "base/gimplut.h"
@ -44,10 +41,8 @@
#include "core/gimpdrawable-histogram.h"
#include "core/gimpimage.h"
#include "core/gimpimagemap.h"
#include "core/gimptoolinfo.h"
#include "widgets/gimpcolorbar.h"
#include "widgets/gimpcursor.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpcurveview.h"
@ -55,7 +50,6 @@
#include "gimpcurvestool.h"
#include "gimphistogramoptions.h"
#include "gimptoolcontrol.h"
#include "gimp-intl.h"
@ -101,9 +95,6 @@ static gboolean gimp_curves_tool_settings_load (GimpImageMapTool *image_map
static gboolean gimp_curves_tool_settings_save (GimpImageMapTool *image_map_tool,
gpointer fp);
static gboolean curves_key_press (GimpCurvesTool *tool,
GdkEventKey *kevent);
static void curves_curve_callback (GimpCurve *curve,
const GParamSpec *pspec,
GimpCurvesTool *tool);
@ -117,9 +108,6 @@ static gboolean curves_menu_sensitivity (gint value,
static void curves_curve_type_callback (GtkWidget *widget,
GimpCurvesTool *tool);
static gboolean curves_graph_events (GtkWidget *widget,
GdkEvent *event,
GimpCurvesTool *tool);
G_DEFINE_TYPE (GimpCurvesTool, gimp_curves_tool, GIMP_TYPE_IMAGE_MAP_TOOL)
@ -250,10 +238,6 @@ gimp_curves_tool_initialize (GimpTool *tool,
c_tool->color = gimp_drawable_is_rgb (drawable);
c_tool->alpha = gimp_drawable_has_alpha (drawable);
c_tool->selected = 0;
c_tool->grabbed = FALSE;
c_tool->last = 0;
GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error);
/* always pick colors */
@ -292,16 +276,17 @@ gimp_curves_tool_button_release (GimpTool *tool,
if (state & GDK_SHIFT_MASK)
{
GimpCurve *curve = c_tool->curve[c_tool->channel];
gint closest;
c_tool->selected =
closest =
gimp_curve_get_closest_point (curve,
c_tool->col_value[c_tool->channel]);
gimp_curve_view_set_selected (GIMP_CURVE_VIEW (c_tool->graph),
c_tool->selected);
closest);
gimp_curve_set_point (curve,
c_tool->selected,
closest,
c_tool->col_value[c_tool->channel],
curve->curve[c_tool->col_value[c_tool->channel]]);
}
@ -312,16 +297,17 @@ gimp_curves_tool_button_release (GimpTool *tool,
for (i = 0; i < 5; i++)
{
GimpCurve *curve = c_tool->curve[i];
gint closest;
c_tool->selected =
closest =
gimp_curve_get_closest_point (curve,
c_tool->col_value[i]);
gimp_curve_view_set_selected (GIMP_CURVE_VIEW (c_tool->graph),
c_tool->selected);
closest);
gimp_curve_set_point (curve,
c_tool->selected,
closest,
c_tool->col_value[i],
curve->curve[c_tool->col_value[i]]);
}
@ -337,7 +323,9 @@ gimp_curves_tool_key_press (GimpTool *tool,
GdkEventKey *kevent,
GimpDisplay *display)
{
return curves_key_press (GIMP_CURVES_TOOL (tool), kevent);
GimpCurvesTool *c_tool = GIMP_CURVES_TOOL (tool);
return gtk_widget_event (c_tool->graph, (GdkEvent *) kevent);
}
static void
@ -409,80 +397,6 @@ gimp_curves_tool_color_picked (GimpColorTool *color_tool,
tool->col_value[channel]);
}
static gboolean
curves_key_press (GimpCurvesTool *tool,
GdkEventKey *kevent)
{
GimpCurve *curve = tool->curve[tool->channel];
gint i = tool->selected;
gint y = curve->points[i][1];
if (tool->grabbed || curve->curve_type == GIMP_CURVE_FREE)
return FALSE;
switch (kevent->keyval)
{
case GDK_Left:
for (i = i - 1; i >= 0; i--)
{
if (curve->points[i][0] != -1)
{
tool->selected = i;
gimp_curve_view_set_selected (GIMP_CURVE_VIEW (tool->graph), i);
return TRUE;
}
}
break;
case GDK_Right:
for (i = i + 1; i < GIMP_CURVE_NUM_POINTS; i++)
{
if (curve->points[i][0] != -1)
{
tool->selected = i;
gimp_curve_view_set_selected (GIMP_CURVE_VIEW (tool->graph), i);
return TRUE;
}
}
break;
case GDK_Up:
if (y < 255)
{
y = y + (kevent->state & GDK_SHIFT_MASK ? 16 : 1);
gimp_curve_move_point (curve, i, CLAMP0255 (y));
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (tool));
return TRUE;
}
break;
case GDK_Down:
if (y > 0)
{
y = y - (kevent->state & GDK_SHIFT_MASK ? 16 : 1);
gimp_curve_move_point (curve, i, CLAMP0255 (y));
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (tool));
return TRUE;
}
break;
default:
break;
}
return FALSE;
}
static void
gimp_curves_tool_map (GimpImageMapTool *image_map_tool)
{
@ -610,10 +524,6 @@ gimp_curves_tool_dialog (GimpImageMapTool *image_map_tool)
gtk_container_add (GTK_CONTAINER (frame), tool->graph);
gtk_widget_show (tool->graph);
g_signal_connect (tool->graph, "event",
G_CALLBACK (curves_graph_events),
tool);
gimp_histogram_options_connect_view (GIMP_HISTOGRAM_OPTIONS (tool_options),
GIMP_HISTOGRAM_VIEW (tool->graph));
@ -693,8 +603,6 @@ gimp_curves_tool_reset (GimpImageMapTool *image_map_tool)
GimpCurvesTool *tool = GIMP_CURVES_TOOL (image_map_tool);
GimpHistogramChannel channel;
tool->grabbed = FALSE;
for (channel = GIMP_HISTOGRAM_VALUE;
channel <= GIMP_HISTOGRAM_ALPHA;
channel++)
@ -806,7 +714,10 @@ curves_curve_callback (GimpCurve *curve,
const GParamSpec *pspec,
GimpCurvesTool *tool)
{
if (curve == tool->curve[tool->channel] && tool->xrange)
if (curve != tool->curve[tool->channel])
return;
if (tool->xrange)
{
GimpHistogramChannel channel;
@ -837,6 +748,9 @@ curves_curve_callback (GimpCurve *curve,
break;
}
}
if (GIMP_IMAGE_MAP_TOOL (tool)->drawable)
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (tool));
}
static void
@ -873,11 +787,7 @@ static void
curves_channel_reset_callback (GtkWidget *widget,
GimpCurvesTool *tool)
{
tool->grabbed = FALSE;
gimp_curve_reset (tool->curve[tool->channel], FALSE);
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (tool));
}
static gboolean
@ -918,235 +828,5 @@ curves_curve_type_callback (GtkWidget *widget,
if (tool->curve[tool->channel]->curve_type != curve_type)
{
gimp_curve_set_curve_type (tool->curve[tool->channel], curve_type);
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (tool));
}
}
static void
curves_set_cursor (GimpCurvesTool *tool,
GimpCursorType new_cursor)
{
static GimpCursorType cursor_type = GDK_TOP_LEFT_ARROW;
if (new_cursor != cursor_type)
{
Gimp *gimp = GIMP_TOOL (tool)->tool_info->gimp;
cursor_type = new_cursor;
gimp_cursor_set (tool->graph,
GIMP_GUI_CONFIG (gimp->config)->cursor_format,
cursor_type,
GIMP_TOOL_CURSOR_NONE,
GIMP_CURSOR_MODIFIER_NONE);
}
}
static gboolean
curves_graph_events (GtkWidget *widget,
GdkEvent *event,
GimpCurvesTool *tool)
{
GimpCurve *curve = tool->curve[tool->channel];
GimpCursorType new_cursor = GDK_X_CURSOR;
gint i;
gint tx, ty;
gint x, y;
gint width, height;
gint closest_point;
gint x1, x2, y1, y2;
width = widget->allocation.width - 2 * RADIUS;
height = widget->allocation.height - 2 * RADIUS;
/* get the pointer position */
gdk_window_get_pointer (tool->graph->window, &tx, &ty, NULL);
x = ROUND (((gdouble) (tx - RADIUS) / (gdouble) width) * 255.0);
y = ROUND (((gdouble) (ty - RADIUS) / (gdouble) height) * 255.0);
x = CLAMP0255 (x);
y = CLAMP0255 (y);
closest_point = gimp_curve_get_closest_point (curve, x);
switch (event->type)
{
case GDK_BUTTON_PRESS:
{
GdkEventButton *bevent = (GdkEventButton *) event;
if (bevent->button != 1)
return TRUE;
tool->grabbed = TRUE;
curves_set_cursor (tool, GDK_TCROSS);
switch (curve->curve_type)
{
case GIMP_CURVE_SMOOTH:
/* determine the leftmost and rightmost points */
tool->leftmost = -1;
for (i = closest_point - 1; i >= 0; i--)
if (curve->points[i][0] != -1)
{
tool->leftmost = curve->points[i][0];
break;
}
tool->rightmost = 256;
for (i = closest_point + 1; i < GIMP_CURVE_NUM_POINTS; i++)
if (curve->points[i][0] != -1)
{
tool->rightmost = curve->points[i][0];
break;
}
tool->selected = closest_point;
gimp_curve_view_set_selected (GIMP_CURVE_VIEW (tool->graph),
closest_point);
gimp_curve_set_point (curve, tool->selected, x, 255 - y);
break;
case GIMP_CURVE_FREE:
gimp_curve_set_curve (curve, x, 255 - y);
tool->selected = x;
tool->last = y;
gimp_curve_view_set_selected (GIMP_CURVE_VIEW (tool->graph), x);
break;
}
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (tool));
if (! GTK_WIDGET_HAS_FOCUS (widget))
gtk_widget_grab_focus (widget);
}
return TRUE;
case GDK_BUTTON_RELEASE:
{
GdkEventButton *bevent = (GdkEventButton *) event;
if (bevent->button != 1)
return TRUE;
tool->grabbed = FALSE;
curves_set_cursor (tool, GDK_FLEUR);
}
return TRUE;
case GDK_MOTION_NOTIFY:
{
GdkEventMotion *mevent = (GdkEventMotion *) event;
switch (curve->curve_type)
{
case GIMP_CURVE_SMOOTH:
/* If no point is grabbed... */
if (! tool->grabbed)
{
if (curve->points[closest_point][0] != -1)
new_cursor = GDK_FLEUR;
else
new_cursor = GDK_TCROSS;
}
/* Else, drag the grabbed point */
else
{
new_cursor = GDK_TCROSS;
gimp_curve_set_point (curve, tool->selected, -1, -1);
if (x > tool->leftmost && x < tool->rightmost)
{
closest_point = (x + 8) / 16;
if (curve->points[closest_point][0] == -1)
{
tool->selected = closest_point;
gimp_curve_view_set_selected (GIMP_CURVE_VIEW (tool->graph),
closest_point);
}
gimp_curve_set_point (curve, tool->selected, x, 255 - y);
}
}
break;
case GIMP_CURVE_FREE:
if (tool->grabbed)
{
if (tool->selected > x)
{
x1 = x;
x2 = tool->selected;
y1 = y;
y2 = tool->last;
}
else
{
x1 = tool->selected;
x2 = x;
y1 = tool->last;
y2 = y;
}
if (x2 != x1)
{
for (i = x1; i <= x2; i++)
gimp_curve_set_curve (curve, i,
255 - (y1 + ((y2 - y1) * (i - x1)) / (x2 - x1)));
}
else
{
gimp_curve_set_curve (curve, x, 255 - y);
}
tool->selected = x;
tool->last = y;
gimp_curve_view_set_selected (GIMP_CURVE_VIEW (tool->graph), x);
}
if (mevent->state & GDK_BUTTON1_MASK)
new_cursor = GDK_TCROSS;
else
new_cursor = GDK_PENCIL;
break;
}
curves_set_cursor (tool, new_cursor);
gimp_curve_view_set_cusor (GIMP_CURVE_VIEW (tool->graph), x, y);
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (tool));
}
return TRUE;
case GDK_KEY_PRESS:
if (curves_key_press (tool, (GdkEventKey *) event))
{
curves_set_cursor (tool, GDK_TCROSS);
return TRUE;
}
break;
case GDK_LEAVE_NOTIFY:
gimp_curve_view_set_cusor (GIMP_CURVE_VIEW (tool->graph), -1, -1);
return TRUE;
default:
break;
}
return FALSE;
}

View File

@ -45,12 +45,7 @@ struct _GimpCurvesTool
gboolean alpha;
GimpHistogramChannel channel;
gint selected;
gint last;
gint leftmost;
gint rightmost;
gint col_value[5];
gboolean grabbed;
GimpHistogram *hist;

View File

@ -21,6 +21,7 @@
#include <string.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include "libgimpmath/gimpmath.h"
@ -32,35 +33,21 @@
#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_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);
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);
static gboolean gimp_curve_view_leave_notify (GtkWidget *widget,
GdkEventCrossing *cevent);
static gboolean gimp_curve_view_key_press (GtkWidget *widget,
GdkEventKey *kevent);
G_DEFINE_TYPE (GimpCurveView, gimp_curve_view,
@ -76,58 +63,29 @@ gimp_curve_view_class_init (GimpCurveViewClass *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;
object_class->finalize = gimp_curve_view_finalize;
object_class->dispose = gimp_curve_view_dispose;
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;
widget_class->leave_notify_event = gimp_curve_view_leave_notify;
widget_class->key_press_event = gimp_curve_view_key_press;
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
hist_class->light_histogram = TRUE;
}
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;
view->curve = NULL;
view->selected = 0;
view->last = 0;
view->cursor_type = -1;
view->xpos = -1;
view->cursor_x = -1;
view->cursor_y = -1;
GTK_WIDGET_SET_FLAGS (view, GTK_CAN_FOCUS);
@ -169,38 +127,6 @@ gimp_curve_view_dispose (GObject *object)
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)
@ -358,13 +284,90 @@ gimp_curve_view_expose (GtkWidget *widget,
return FALSE;
}
static void
set_cursor (GimpCurveView *view,
GdkCursorType new_cursor)
{
if (new_cursor != view->cursor_type)
{
GdkDisplay *display = gtk_widget_get_display (GTK_WIDGET (view));
GdkCursor *cursor = gdk_cursor_new_for_display (display, new_cursor);
gdk_window_set_cursor (GTK_WIDGET (view)->window, cursor);
gdk_cursor_unref (cursor);
view->cursor_type = new_cursor;
}
}
static gboolean
gimp_curve_view_button_press (GtkWidget *widget,
GdkEventButton *bevent)
{
GimpCurveView *view = GIMP_CURVE_VIEW (widget);
GimpCurveView *view = GIMP_CURVE_VIEW (widget);
GimpCurve *curve = view->curve;
gint border;
gint width, height;
gint x, y;
gint closest_point;
gint i;
return GTK_WIDGET_CLASS (parent_class)->button_press_event (widget, bevent);
if (! curve || bevent->button != 1)
return TRUE;
border = GIMP_HISTOGRAM_VIEW (view)->border_width;
width = widget->allocation.width - 2 * border;
height = widget->allocation.height - 2 * border;
x = ROUND (((gdouble) (bevent->x - border) / (gdouble) width) * 255.0);
y = ROUND (((gdouble) (bevent->y - border) / (gdouble) height) * 255.0);
x = CLAMP0255 (x);
y = CLAMP0255 (y);
closest_point = gimp_curve_get_closest_point (curve, x);
view->grabbed = TRUE;
set_cursor (view, GDK_TCROSS);
switch (curve->curve_type)
{
case GIMP_CURVE_SMOOTH:
/* determine the leftmost and rightmost points */
view->leftmost = -1;
for (i = closest_point - 1; i >= 0; i--)
if (curve->points[i][0] != -1)
{
view->leftmost = curve->points[i][0];
break;
}
view->rightmost = 256;
for (i = closest_point + 1; i < GIMP_CURVE_NUM_POINTS; i++)
if (curve->points[i][0] != -1)
{
view->rightmost = curve->points[i][0];
break;
}
gimp_curve_view_set_selected (view, closest_point);
gimp_curve_set_point (curve, view->selected, x, 255 - y);
break;
case GIMP_CURVE_FREE:
gimp_curve_view_set_selected (view, x);
view->last = y;
gimp_curve_set_curve (curve, x, 255 - y);
break;
}
if (! GTK_WIDGET_HAS_FOCUS (widget))
gtk_widget_grab_focus (widget);
return TRUE;
}
static gboolean
@ -373,16 +376,201 @@ gimp_curve_view_button_release (GtkWidget *widget,
{
GimpCurveView *view = GIMP_CURVE_VIEW (widget);
return GTK_WIDGET_CLASS (parent_class)->button_release_event (widget, bevent);
if (bevent->button != 1)
return TRUE;
view->grabbed = FALSE;
set_cursor (view, GDK_FLEUR);
return TRUE;
}
static gboolean
gimp_curve_view_motion_notify (GtkWidget *widget,
GdkEventMotion *mevent)
{
GimpCurveView *view = GIMP_CURVE_VIEW (widget);
GimpCurve *curve = view->curve;
GimpCursorType new_cursor = GDK_X_CURSOR;
gint border;
gint width, height;
gint x, y;
gint closest_point;
gint i;
if (! curve)
return TRUE;
border = GIMP_HISTOGRAM_VIEW (view)->border_width;
width = widget->allocation.width - 2 * border;
height = widget->allocation.height - 2 * border;
x = ROUND (((gdouble) (mevent->x - border) / (gdouble) width) * 255.0);
y = ROUND (((gdouble) (mevent->y - border) / (gdouble) height) * 255.0);
x = CLAMP0255 (x);
y = CLAMP0255 (y);
closest_point = gimp_curve_get_closest_point (curve, x);
switch (curve->curve_type)
{
case GIMP_CURVE_SMOOTH:
if (! view->grabbed) /* If no point is grabbed... */
{
if (curve->points[closest_point][0] != -1)
new_cursor = GDK_FLEUR;
else
new_cursor = GDK_TCROSS;
}
else /* Else, drag the grabbed point */
{
new_cursor = GDK_TCROSS;
gimp_curve_set_point (curve, view->selected, -1, -1);
if (x > view->leftmost && x < view->rightmost)
{
closest_point = (x + 8) / 16;
if (curve->points[closest_point][0] == -1)
gimp_curve_view_set_selected (view, closest_point);
gimp_curve_set_point (curve, view->selected, x, 255 - y);
}
}
break;
case GIMP_CURVE_FREE:
if (view->grabbed)
{
gint x1, x2, y1, y2;
if (view->selected > x)
{
x1 = x;
x2 = view->selected;
y1 = y;
y2 = view->last;
}
else
{
x1 = view->selected;
x2 = x;
y1 = view->last;
y2 = y;
}
if (x2 != x1)
{
for (i = x1; i <= x2; i++)
gimp_curve_set_curve (curve, i,
255 - (y1 + ((y2 - y1) * (i - x1)) / (x2 - x1)));
}
else
{
gimp_curve_set_curve (curve, x, 255 - y);
}
gimp_curve_view_set_selected (view, x);
view->last = y;
}
if (mevent->state & GDK_BUTTON1_MASK)
new_cursor = GDK_TCROSS;
else
new_cursor = GDK_PENCIL;
break;
}
set_cursor (view, new_cursor);
gimp_curve_view_set_cursor (view, x, y);
return TRUE;
}
static gboolean
gimp_curve_view_leave_notify (GtkWidget *widget,
GdkEventCrossing *cevent)
{
GimpCurveView *view = GIMP_CURVE_VIEW (widget);
return GTK_WIDGET_CLASS (parent_class)->motion_notify_event (widget, mevent);
gimp_curve_view_set_cursor (view, -1, -1);
return TRUE;
}
static gboolean
gimp_curve_view_key_press (GtkWidget *widget,
GdkEventKey *kevent)
{
GimpCurveView *view = GIMP_CURVE_VIEW (widget);
GimpCurve *curve = view->curve;
gint i = view->selected;
gint y = curve->points[i][1];
gboolean retval = FALSE;
if (view->grabbed || ! curve || curve->curve_type == GIMP_CURVE_FREE)
return FALSE;
switch (kevent->keyval)
{
case GDK_Left:
for (i = i - 1; i >= 0 && ! retval; i--)
{
if (curve->points[i][0] != -1)
{
gimp_curve_view_set_selected (view, i);
retval = TRUE;
}
}
break;
case GDK_Right:
for (i = i + 1; i < GIMP_CURVE_NUM_POINTS && ! retval; i++)
{
if (curve->points[i][0] != -1)
{
gimp_curve_view_set_selected (view, i);
retval = TRUE;
}
}
break;
case GDK_Up:
if (y < 255)
{
y = y + (kevent->state & GDK_SHIFT_MASK ? 16 : 1);
gimp_curve_move_point (curve, i, CLAMP0255 (y));
retval = TRUE;
}
break;
case GDK_Down:
if (y > 0)
{
y = y - (kevent->state & GDK_SHIFT_MASK ? 16 : 1);
gimp_curve_move_point (curve, i, CLAMP0255 (y));
retval = TRUE;
}
break;
default:
break;
}
if (retval)
set_cursor (view, GDK_TCROSS);
return retval;
}
GtkWidget *
@ -471,9 +659,9 @@ gimp_curve_view_set_xpos (GimpCurveView *view,
}
void
gimp_curve_view_set_cusor (GimpCurveView *view,
gint x,
gint y)
gimp_curve_view_set_cursor (GimpCurveView *view,
gint x,
gint y)
{
g_return_if_fail (GIMP_IS_CURVE_VIEW (view));

View File

@ -38,7 +38,14 @@ struct _GimpCurveView
GimpHistogramView parent_instance;
GimpCurve *curve;
gint selected;
gint last;
gint leftmost;
gint rightmost;
gboolean grabbed;
GdkCursorType cursor_type;
gint xpos;
PangoLayout *xpos_layout;
@ -67,7 +74,7 @@ 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,
void gimp_curve_view_set_cursor (GimpCurveView *view,
gint x,
gint y);