[gimp] app: make the coordinates display in the curve view configurable
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: make the coordinates display in the curve view configurable
- Date: Tue, 23 Feb 2010 10:40:57 +0000 (UTC)
commit 088368079c4cf754c8c32cf67d01194be7cd6dcb
Author: Michael Natterer <mitch gimp org>
Date: Tue Feb 23 11:39:35 2010 +0100
app: make the coordinates display in the curve view configurable
Add API for X and Y ranges, default to 0.0..1.0 and configure the view
for 0..255 in the curves tool.
app/tools/gimpcurvestool.c | 2 +
app/widgets/gimpcurveview.c | 67 +++++++++++++++++++++++++++++++++++++++---
app/widgets/gimpcurveview.h | 11 +++++++
3 files changed, 75 insertions(+), 5 deletions(-)
---
diff --git a/app/tools/gimpcurvestool.c b/app/tools/gimpcurvestool.c
index 6d3c632..a455a9d 100644
--- a/app/tools/gimpcurvestool.c
+++ b/app/tools/gimpcurvestool.c
@@ -521,6 +521,8 @@ gimp_curves_tool_dialog (GimpImageMapTool *image_map_tool)
gtk_widget_show (frame);
tool->graph = gimp_curve_view_new ();
+ gimp_curve_view_set_range_x (GIMP_CURVE_VIEW (tool->graph), 0, 255);
+ gimp_curve_view_set_range_y (GIMP_CURVE_VIEW (tool->graph), 0, 255);
gtk_widget_set_size_request (tool->graph,
GRAPH_SIZE + RADIUS * 2,
GRAPH_SIZE + RADIUS * 2);
diff --git a/app/widgets/gimpcurveview.c b/app/widgets/gimpcurveview.c
index dcade68..97706c3 100644
--- a/app/widgets/gimpcurveview.c
+++ b/app/widgets/gimpcurveview.c
@@ -202,6 +202,10 @@ gimp_curve_view_init (GimpCurveView *view)
view->xpos = -1.0;
view->cursor_x = -1.0;
view->cursor_y = -1.0;
+ view->range_x_min = 0.0;
+ view->range_x_max = 1.0;
+ view->range_y_min = 0.0;
+ view->range_y_max = 1.0;
gtk_widget_set_can_focus (GTK_WIDGET (view), TRUE);
gtk_widget_add_events (GTK_WIDGET (view),
@@ -605,8 +609,19 @@ gimp_curve_view_expose (GtkWidget *widget,
if (! view->cursor_layout)
{
- view->cursor_layout = gtk_widget_create_pango_layout (widget,
- "x:888 y:888");
+ /* stupid heuristic: special-case for 0..255 */
+ if (view->range_x_max == 255.0 &&
+ view->range_y_max == 255.0)
+ {
+ view->cursor_layout =
+ gtk_widget_create_pango_layout (widget, "x:888 y:888");
+ }
+ else
+ {
+ view->cursor_layout =
+ gtk_widget_create_pango_layout (widget, "x:0.888 y:0.888");
+ }
+
pango_layout_get_pixel_extents (view->cursor_layout,
NULL, &view->cursor_rect);
}
@@ -626,9 +641,29 @@ gimp_curve_view_expose (GtkWidget *widget,
cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
cairo_stroke (cr);
- g_snprintf (buf, sizeof (buf), "x:%3d y:%3d",
- (gint) (view->cursor_x * 255.999),
- (gint) ((1.0 - view->cursor_y) * 255.999));
+ /* stupid heuristic: special-case for 0..255 */
+ if (view->range_x_max == 255.0 &&
+ view->range_y_max == 255.0)
+ {
+ g_snprintf (buf, sizeof (buf), "x:%3d y:%3d",
+ (gint) (view->cursor_x *
+ (view->range_x_max - view->range_x_min) +
+ view->range_x_min),
+ (gint) ((1.0 - view->cursor_y) *
+ (view->range_y_max - view->range_y_min) +
+ view->range_y_min));
+ }
+ else
+ {
+ g_snprintf (buf, sizeof (buf), "x:%0.3f y:%0.3f",
+ view->cursor_x *
+ (view->range_x_max - view->range_x_min) +
+ view->range_x_min,
+ (1.0 - view->cursor_y) *
+ (view->range_y_max - view->range_y_min) +
+ view->range_y_min);
+ }
+
pango_layout_set_text (view->cursor_layout, buf, -1);
gdk_cairo_set_source_color (cr, &style->base[GTK_STATE_NORMAL]);
@@ -1165,6 +1200,28 @@ gimp_curve_view_set_selected (GimpCurveView *view,
}
void
+gimp_curve_view_set_range_x (GimpCurveView *view,
+ gdouble min,
+ gdouble max)
+{
+ g_return_if_fail (GIMP_IS_CURVE_VIEW (view));
+
+ view->range_x_min = min;
+ view->range_x_max = max;
+}
+
+void
+gimp_curve_view_set_range_y (GimpCurveView *view,
+ gdouble min,
+ gdouble max)
+{
+ g_return_if_fail (GIMP_IS_CURVE_VIEW (view));
+
+ view->range_y_min = min;
+ view->range_y_max = max;
+}
+
+void
gimp_curve_view_set_xpos (GimpCurveView *view,
gdouble x)
{
diff --git a/app/widgets/gimpcurveview.h b/app/widgets/gimpcurveview.h
index b313d53..1fe6a4a 100644
--- a/app/widgets/gimpcurveview.h
+++ b/app/widgets/gimpcurveview.h
@@ -58,6 +58,11 @@ struct _GimpCurveView
gdouble xpos;
PangoLayout *xpos_layout;
+ gdouble range_x_min;
+ gdouble range_x_max;
+ gdouble range_y_min;
+ gdouble range_y_max;
+
gdouble cursor_x;
gdouble cursor_y;
PangoLayout *cursor_layout;
@@ -90,6 +95,12 @@ void gimp_curve_view_remove_background (GimpCurveView *view,
void gimp_curve_view_set_selected (GimpCurveView *view,
gint selected);
+void gimp_curve_view_set_range_x (GimpCurveView *view,
+ gdouble min,
+ gdouble max);
+void gimp_curve_view_set_range_y (GimpCurveView *view,
+ gdouble min,
+ gdouble max);
void gimp_curve_view_set_xpos (GimpCurveView *view,
gdouble x);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]