Commit 2d827be2 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

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
parent a07756d8
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
......
......@@ -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;
}
......@@ -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;
......
......@@ -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_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 void gimp_curve_view_finalize (GObject *object);
static void gimp_curve_view_dispose (GObject *object);
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: