port the "xpos" API to [0.0..1.0] doubles too.

2008-02-09  Michael Natterer  <mitch@gimp.org>

	* app/widgets/gimpcurveview.[ch]: port the "xpos" API
	to [0.0..1.0] doubles too.

	* app/tools/gimpcurvestool.[ch]: rename "col_value" member to
	"picked_color" and use gdouble instead of gint. Also use GimpCurve
	API to map the values instead of accessing the curve directly.
	Fixes setting curve anchor points by color picking.


svn path=/trunk/; revision=24838
This commit is contained in:
Michael Natterer 2008-02-09 10:56:25 +00:00 committed by Michael Natterer
parent 044359f93d
commit e831300587
5 changed files with 39 additions and 40 deletions

View File

@ -1,3 +1,13 @@
2008-02-09 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpcurveview.[ch]: port the "xpos" API
to [0.0..1.0] doubles too.
* app/tools/gimpcurvestool.[ch]: rename "col_value" member to
"picked_color" and use gdouble instead of gint. Also use GimpCurve
API to map the values instead of accessing the curve directly.
Fixes setting curve anchor points by color picking.
2008-02-09 Michael Natterer <mitch@gimp.org>
* app/core/gimpcurve.[ch]: changed all values to be [0.0..1.0]

View File

@ -178,8 +178,8 @@ gimp_curves_tool_init (GimpCurvesTool *tool)
tool->lut = gimp_lut_new ();
for (i = 0; i < G_N_ELEMENTS (tool->col_value); i++)
tool->col_value[i] = -1;
for (i = 0; i < G_N_ELEMENTS (tool->picked_color); i++)
tool->picked_color[i] = -1.0;
im_tool->apply_func = (GimpImageMapApplyFunc) gimp_lut_process;
im_tool->apply_data = tool->lut;
@ -248,19 +248,16 @@ gimp_curves_tool_button_release (GimpTool *tool,
if (state & GDK_SHIFT_MASK)
{
GimpCurve *curve = config->curve[config->channel];
gdouble value = c_tool->picked_color[config->channel];
gint closest;
closest =
gimp_curve_get_closest_point (curve,
c_tool->col_value[config->channel]);
closest = gimp_curve_get_closest_point (curve, value);
gimp_curve_view_set_selected (GIMP_CURVE_VIEW (c_tool->graph),
closest);
gimp_curve_set_point (curve,
closest,
c_tool->col_value[config->channel],
curve->curve[c_tool->col_value[config->channel]]);
gimp_curve_set_point (curve, closest,
value, gimp_curve_map (curve, value));
}
else if (state & GDK_CONTROL_MASK)
{
@ -269,19 +266,16 @@ gimp_curves_tool_button_release (GimpTool *tool,
for (i = 0; i < 5; i++)
{
GimpCurve *curve = config->curve[i];
gdouble value = c_tool->picked_color[i];
gint closest;
closest =
gimp_curve_get_closest_point (curve,
c_tool->col_value[i]);
closest = gimp_curve_get_closest_point (curve, value);
gimp_curve_view_set_selected (GIMP_CURVE_VIEW (c_tool->graph),
closest);
gimp_curve_set_point (curve,
closest,
c_tool->col_value[i],
curve->curve[c_tool->col_value[i]]);
gimp_curve_set_point (curve, closest,
value, gimp_curve_map (curve, value));
}
}
@ -341,26 +335,21 @@ gimp_curves_tool_color_picked (GimpColorTool *color_tool,
{
GimpCurvesTool *tool = GIMP_CURVES_TOOL (color_tool);
GimpDrawable *drawable;
guchar r, g, b, a;
drawable = GIMP_IMAGE_MAP_TOOL (tool)->drawable;
gimp_rgba_get_uchar (color, &r, &g, &b, &a);
tool->col_value[GIMP_HISTOGRAM_RED] = r;
tool->col_value[GIMP_HISTOGRAM_GREEN] = g;
tool->col_value[GIMP_HISTOGRAM_BLUE] = b;
tool->picked_color[GIMP_HISTOGRAM_RED] = color->r;
tool->picked_color[GIMP_HISTOGRAM_GREEN] = color->g;
tool->picked_color[GIMP_HISTOGRAM_BLUE] = color->b;
if (gimp_drawable_has_alpha (drawable))
tool->col_value[GIMP_HISTOGRAM_ALPHA] = a;
tool->picked_color[GIMP_HISTOGRAM_ALPHA] = color->a;
if (gimp_drawable_is_indexed (drawable))
tool->col_value[GIMP_HISTOGRAM_ALPHA] = color_index;
tool->col_value[GIMP_HISTOGRAM_VALUE] = MAX (MAX (r, g), b);
tool->picked_color[GIMP_HISTOGRAM_VALUE] = MAX (MAX (color->r, color->g),
color->b);
gimp_curve_view_set_xpos (GIMP_CURVE_VIEW (tool->graph),
tool->col_value[tool->config->channel]);
tool->picked_color[tool->config->channel]);
}
static GeglNode *
@ -669,7 +658,7 @@ gimp_curves_tool_config_notify (GObject *object,
gimp_histogram_view_set_channel (GIMP_HISTOGRAM_VIEW (tool->graph),
config->channel);
gimp_curve_view_set_xpos (GIMP_CURVE_VIEW (tool->graph),
tool->col_value[config->channel]);
tool->picked_color[config->channel]);
gimp_color_bar_set_channel (GIMP_COLOR_BAR (tool->yrange),
config->channel);

View File

@ -41,7 +41,7 @@ struct _GimpCurvesTool
GimpLut *lut;
/* dialog */
gint col_value[5];
gdouble picked_color[5];
GtkWidget *channel_menu;
GtkWidget *xrange;

View File

@ -125,7 +125,7 @@ gimp_curve_view_init (GimpCurveView *view)
view->last_x = 0.0;
view->last_y = 0.0;
view->cursor_type = -1;
view->xpos = -1;
view->xpos = -1.0;
view->cursor_x = -1;
view->cursor_y = -1;
@ -410,7 +410,7 @@ gimp_curve_view_expose (GtkWidget *widget,
}
}
if (view->xpos >= 0)
if (view->xpos >= 0.0)
{
gint layout_x;
gint layout_y;
@ -420,15 +420,15 @@ gimp_curve_view_expose (GtkWidget *widget,
/* draw the color line */
cairo_move_to (cr,
border + ROUND ((gdouble) width * view->xpos / 256.0),
border + ROUND ((gdouble) width * view->xpos),
border);
cairo_line_to (cr,
border + ROUND ((gdouble) width * view->xpos / 256.0),
border + ROUND ((gdouble) width * view->xpos),
border + height - 1);
cairo_stroke (cr);
/* and xpos indicator */
g_snprintf (buf, sizeof (buf), "x:%d", view->xpos);
g_snprintf (buf, sizeof (buf), "x:%d", (gint) (view->xpos * 255.999));
if (! view->xpos_layout)
view->xpos_layout = gtk_widget_create_pango_layout (widget, NULL);
@ -436,13 +436,13 @@ gimp_curve_view_expose (GtkWidget *widget,
pango_layout_set_text (view->xpos_layout, buf, -1);
pango_layout_get_pixel_size (view->xpos_layout, &layout_x, &layout_y);
if (view->xpos < 127)
if (view->xpos < 0.5)
layout_x = border;
else
layout_x = -(layout_x + border);
cairo_move_to (cr,
border + (gdouble) width * view->xpos / 256.0 + layout_x,
border + (gdouble) width * view->xpos + layout_x,
border + height - border - layout_y);
pango_cairo_show_layout (cr, view->xpos_layout);
cairo_fill (cr);
@ -864,7 +864,7 @@ gimp_curve_view_set_selected (GimpCurveView *view,
void
gimp_curve_view_set_xpos (GimpCurveView *view,
gint x)
gdouble x)
{
g_return_if_fail (GIMP_IS_CURVE_VIEW (view));

View File

@ -52,7 +52,7 @@ struct _GimpCurveView
GdkCursorType cursor_type;
gint xpos;
gdouble xpos;
PangoLayout *xpos_layout;
gint cursor_x;
@ -78,7 +78,7 @@ 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);
gdouble x);
#endif /* __GIMP_CURVE_VIEW_H__ */