applied (modified) patch from Ed Halley which adds "quintile marks". Fixes

2003-12-11  Michael Natterer  <mitch@gimp.org>

	* app/widgets/gimphistogramview.[ch]: applied (modified) patch
	from Ed Halley which adds "quintile marks". Fixes bug #129050.
	Render the histogram on a base_gc background and use text_gc and
	text_aa_gc for rendering the histogram and the helper lines.
	Fixed rendering of the 1px border around the histogram. Removed
	separate drawing of baseline, left and right helper lines and draw
	a rectangle which marks the entire area of possible values. Fixed
	size_request calculation. Added missing getters. Cleanup.

	* app/tools/gimpcurvestool.c: use the same color scheme as the
	histogram.

	* app/tools/gimpcurvestool.c (curves_load,save_callback)
	* app/tools/gimplevelstool.c (levels_load,save_callback):
	gtk_window_present() the file dialog if it is already visible.
This commit is contained in:
Michael Natterer 2003-12-11 13:57:03 +00:00 committed by Michael Natterer
parent 1bc30847cc
commit e72b406a5f
5 changed files with 204 additions and 107 deletions

View file

@ -1,3 +1,21 @@
2003-12-11 Michael Natterer <mitch@gimp.org>
* app/widgets/gimphistogramview.[ch]: applied (modified) patch
from Ed Halley which adds "quintile marks". Fixes bug #129050.
Render the histogram on a base_gc background and use text_gc and
text_aa_gc for rendering the histogram and the helper lines.
Fixed rendering of the 1px border around the histogram. Removed
separate drawing of baseline, left and right helper lines and draw
a rectangle which marks the entire area of possible values. Fixed
size_request calculation. Added missing getters. Cleanup.
* app/tools/gimpcurvestool.c: use the same color scheme as the
histogram.
* app/tools/gimpcurvestool.c (curves_load,save_callback)
* app/tools/gimplevelstool.c (levels_load,save_callback):
gtk_window_present() the file dialog if it is already visible.
2003-12-11 Sven Neumann <sven@gimp.org>
* app/display/gimpdisplayshell-callbacks.c (gimp_display_shell_events):

View file

@ -1047,10 +1047,8 @@ curve_print_loc (GimpCurvesTool *c_tool)
gint x, y;
gint w, h;
if (c_tool->cursor_x < 0 || c_tool->cursor_x > 255)
return;
if (c_tool->cursor_y < 0 || c_tool->cursor_y > 255)
if (c_tool->cursor_x < 0 || c_tool->cursor_x > 255 ||
c_tool->cursor_y < 0 || c_tool->cursor_y > 255)
return;
if (! c_tool->cursor_layout)
@ -1067,11 +1065,11 @@ curve_print_loc (GimpCurvesTool *c_tool)
h = c_tool->cursor_rect.height + 4;
gdk_draw_rectangle (c_tool->graph->window,
c_tool->graph->style->bg_gc[GTK_STATE_ACTIVE],
c_tool->graph->style->base_gc[GTK_STATE_ACTIVE],
TRUE,
x, y, w + 1, h + 1);
gdk_draw_rectangle (c_tool->graph->window,
c_tool->graph->style->black_gc,
c_tool->graph->style->text_gc[GTK_STATE_NORMAL],
FALSE,
x, y, w, h);
@ -1080,7 +1078,7 @@ curve_print_loc (GimpCurvesTool *c_tool)
pango_layout_set_text (c_tool->cursor_layout, buf, 11);
gdk_draw_layout (c_tool->graph->window,
c_tool->graph->style->black_gc,
c_tool->graph->style->text_gc[GTK_STATE_ACTIVE],
x + 2, y + 2,
c_tool->cursor_layout);
}
@ -1110,15 +1108,22 @@ curves_graph_expose (GtkWidget *widget,
sel_channel = GIMP_HISTOGRAM_VALUE;
}
/* Draw the background */
gdk_draw_rectangle (widget->window,
widget->style->base_gc[GTK_STATE_NORMAL], TRUE,
0, 0,
widget->allocation.width,
widget->allocation.height);
/* Draw the grid lines */
for (i = 0; i < 5; i++)
{
gdk_draw_line (widget->window,
c_tool->graph->style->dark_gc[GTK_STATE_NORMAL],
c_tool->graph->style->text_aa_gc[GTK_STATE_NORMAL],
RADIUS, i * (GRAPH_HEIGHT / 4) + RADIUS,
GRAPH_WIDTH + RADIUS, i * (GRAPH_HEIGHT / 4) + RADIUS);
gdk_draw_line (widget->window,
c_tool->graph->style->dark_gc[GTK_STATE_NORMAL],
c_tool->graph->style->text_aa_gc[GTK_STATE_NORMAL],
i * (GRAPH_WIDTH / 4) + RADIUS, RADIUS,
i * (GRAPH_WIDTH / 4) + RADIUS, GRAPH_HEIGHT + RADIUS);
}
@ -1133,13 +1138,13 @@ curves_graph_expose (GtkWidget *widget,
if (c_tool->curves->curve_type[c_tool->channel] == GIMP_CURVE_FREE)
{
gdk_draw_points (widget->window,
c_tool->graph->style->black_gc,
c_tool->graph->style->text_gc[GTK_STATE_NORMAL],
points, 256);
}
else
{
gdk_draw_lines (widget->window,
c_tool->graph->style->black_gc,
c_tool->graph->style->text_gc[GTK_STATE_NORMAL],
points, 256);
/* Draw the points */
@ -1147,7 +1152,7 @@ curves_graph_expose (GtkWidget *widget,
{
if (c_tool->curves->points[c_tool->channel][i][0] != -1)
gdk_draw_arc (widget->window,
c_tool->graph->style->black_gc,
c_tool->graph->style->text_gc[GTK_STATE_NORMAL],
TRUE,
c_tool->curves->points[c_tool->channel][i][0],
255 - c_tool->curves->points[c_tool->channel][i][1],
@ -1159,7 +1164,7 @@ curves_graph_expose (GtkWidget *widget,
{
/* draw the color line */
gdk_draw_line (widget->window,
c_tool->graph->style->black_gc,
c_tool->graph->style->text_gc[GTK_STATE_NORMAL],
c_tool->col_value[sel_channel] + RADIUS,
RADIUS,
c_tool->col_value[sel_channel] + RADIUS,
@ -1183,7 +1188,7 @@ curves_graph_expose (GtkWidget *widget,
offset = - (offset + 2);
gdk_draw_layout (widget->window,
c_tool->graph->style->black_gc,
c_tool->graph->style->text_gc[GTK_STATE_NORMAL],
c_tool->col_value[sel_channel] + offset,
GRAPH_HEIGHT - height - 2,
c_tool->xpos_layout);
@ -1199,8 +1204,12 @@ curves_load_callback (GtkWidget *widget,
{
if (! c_tool->file_dialog)
file_dialog_create (c_tool);
else if (GTK_WIDGET_VISIBLE (c_tool->file_dialog))
return;
if (GTK_WIDGET_VISIBLE (c_tool->file_dialog))
{
gtk_window_present (GTK_WINDOW (c_tool->file_dialog));
return;
}
c_tool->is_save = FALSE;
@ -1214,8 +1223,12 @@ curves_save_callback (GtkWidget *widget,
{
if (! c_tool->file_dialog)
file_dialog_create (c_tool);
else if (GTK_WIDGET_VISIBLE (c_tool->file_dialog))
return;
if (GTK_WIDGET_VISIBLE (c_tool->file_dialog))
{
gtk_window_present (GTK_WINDOW (c_tool->file_dialog));
return;
}
c_tool->is_save = TRUE;

View file

@ -1405,8 +1405,12 @@ levels_load_callback (GtkWidget *widget,
{
if (! l_tool->file_dialog)
file_dialog_create (l_tool);
else if (GTK_WIDGET_VISIBLE (l_tool->file_dialog))
return;
if (GTK_WIDGET_VISIBLE (l_tool->file_dialog))
{
gtk_window_present (GTK_WINDOW (l_tool->file_dialog));
return;
}
l_tool->is_save = FALSE;
@ -1420,8 +1424,12 @@ levels_save_callback (GtkWidget *widget,
{
if (! l_tool->file_dialog)
file_dialog_create (l_tool);
else if (GTK_WIDGET_VISIBLE (l_tool->file_dialog))
return;
if (GTK_WIDGET_VISIBLE (l_tool->file_dialog))
{
gtk_window_present (GTK_WINDOW (l_tool->file_dialog));
return;
}
l_tool->is_save = TRUE;

View file

@ -31,6 +31,7 @@
#include "gimphistogramview.h"
#define MIN_WIDTH 32
#define MIN_HEIGHT 80
enum
@ -48,19 +49,27 @@ enum
static void gimp_histogram_view_class_init (GimpHistogramViewClass *klass);
static void gimp_histogram_view_init (GimpHistogramView *view);
static void gimp_histogram_view_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_histogram_view_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_histogram_view_unrealize (GtkWidget *widget);
static void gimp_histogram_view_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static gboolean gimp_histogram_view_expose (GtkWidget *widget,
GdkEventExpose *event);
static void gimp_histogram_view_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_histogram_view_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_histogram_view_unrealize (GtkWidget *widget);
static void gimp_histogram_view_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static gboolean gimp_histogram_view_expose (GtkWidget *widget,
GdkEventExpose *event);
static gboolean gimp_histogram_view_button_press (GtkWidget *widget,
GdkEventButton *bevent);
static gboolean gimp_histogram_view_button_release (GtkWidget *widget,
GdkEventButton *bevent);
static gboolean gimp_histogram_view_motion_notify (GtkWidget *widget,
GdkEventMotion *bevent);
static guint histogram_view_signals[LAST_SIGNAL] = { 0 };
@ -121,9 +130,12 @@ gimp_histogram_view_class_init (GimpHistogramViewClass *klass)
object_class->get_property = gimp_histogram_view_get_property;
object_class->set_property = gimp_histogram_view_set_property;
widget_class->unrealize = gimp_histogram_view_unrealize;
widget_class->size_request = gimp_histogram_view_size_request;
widget_class->expose_event = gimp_histogram_view_expose;
widget_class->unrealize = gimp_histogram_view_unrealize;
widget_class->size_request = gimp_histogram_view_size_request;
widget_class->expose_event = gimp_histogram_view_expose;
widget_class->button_press_event = gimp_histogram_view_button_press;
widget_class->button_release_event = gimp_histogram_view_button_release;
widget_class->motion_notify_event = gimp_histogram_view_motion_notify;
klass->range_changed = NULL;
@ -215,8 +227,8 @@ static void
gimp_histogram_view_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
requisition->width = widget->requisition.width + 2;
requisition->height = MAX (MIN_HEIGHT, widget->requisition.height) + 2;
requisition->width = MIN_WIDTH + 2;
requisition->height = MIN_HEIGHT + 2;
}
static gboolean
@ -228,6 +240,7 @@ gimp_histogram_view_expose (GtkWidget *widget,
gint x1, x2;
gint width, height;
gdouble max;
gint xstop, xstops;
if (!view->histogram)
return TRUE;
@ -251,12 +264,22 @@ gimp_histogram_view_expose (GtkWidget *widget,
break;
}
/* Draw the axis */
gdk_draw_line (widget->window,
widget->style->black_gc,
1, height + 1, width, height + 1);
/* Draw the background */
gdk_draw_rectangle (widget->window,
widget->style->base_gc[GTK_STATE_NORMAL], TRUE,
0, 0,
widget->allocation.width,
widget->allocation.height);
/* Draw the outer border */
gdk_draw_rectangle (widget->window,
widget->style->text_aa_gc[GTK_STATE_NORMAL], FALSE,
1, 1,
width - 1, height - 1);
/* Draw the spikes */
xstop = 1;
xstops = 5;
for (x = 0; x < width; x++)
{
gdouble v, value = 0.0;
@ -274,17 +297,26 @@ gimp_histogram_view_expose (GtkWidget *widget,
}
while (i < j);
if (x >= (xstop * width / xstops))
{
gdk_draw_line (widget->window,
widget->style->text_aa_gc[GTK_STATE_NORMAL],
x + 1, 1,
x + 1, height);
xstop++;
}
if (value <= 0.0)
continue;
switch (view->scale)
{
case GIMP_HISTOGRAM_SCALE_LINEAR:
y = (gint) ((height * value) / max);
y = (gint) (((height - 1) * value) / max);
break;
case GIMP_HISTOGRAM_SCALE_LOGARITHMIC:
y = (gint) ((height * log (value)) / max);
y = (gint) (((height - 1) * log (value)) / max);
break;
default:
@ -293,9 +325,9 @@ gimp_histogram_view_expose (GtkWidget *widget,
}
gdk_draw_line (widget->window,
widget->style->black_gc,
x + 1, height + 1,
x + 1, height + 1 - y);
widget->style->text_gc[GTK_STATE_NORMAL],
x + 1, height,
x + 1, height - y);
}
x1 = CLAMP (MIN (view->start, view->end), 0, 255);
@ -316,28 +348,22 @@ gimp_histogram_view_expose (GtkWidget *widget,
}
gdk_draw_rectangle (widget->window, view->range_gc, TRUE,
x1 + 1, 1, (x2 - x1), height);
x1 + 1, 1,
x2 - x1, height);
}
return TRUE;
}
static gboolean
gimp_histogram_view_events (GimpHistogramView *view,
GdkEvent *event)
gimp_histogram_view_button_press (GtkWidget *widget,
GdkEventButton *bevent)
{
GtkWidget *widget = GTK_WIDGET (view);
GdkEventButton *bevent;
GdkEventMotion *mevent;
gint width;
GimpHistogramView *view = GIMP_HISTOGRAM_VIEW (widget);
switch (event->type)
if (bevent->button == 1)
{
case GDK_BUTTON_PRESS:
bevent = (GdkEventButton *) event;
if (bevent->button != 1)
break;
gint width;
gdk_pointer_grab (widget->window, FALSE,
GDK_BUTTON_RELEASE_MASK | GDK_BUTTON1_MOTION_MASK,
@ -349,42 +375,51 @@ gimp_histogram_view_events (GimpHistogramView *view,
view->end = view->start;
gtk_widget_queue_draw (widget);
return TRUE;
}
case GDK_BUTTON_RELEASE:
bevent = (GdkEventButton *) event;
return TRUE;
}
static gboolean
gimp_histogram_view_button_release (GtkWidget *widget,
GdkEventButton *bevent)
{
GimpHistogramView *view = GIMP_HISTOGRAM_VIEW (widget);
if (bevent->button == 1)
{
gint start, end;
gdk_display_pointer_ungrab (gtk_widget_get_display (GTK_WIDGET (view)),
bevent->time);
{
gint start, end;
start = view->start;
end = view->end;
start = view->start;
end = view->end;
view->start = MIN (start, end);
view->end = MAX (start, end);
}
view->start = MIN (start, end);
view->end = MAX (start, end);
g_signal_emit (view, histogram_view_signals[RANGE_CHANGED], 0,
view->start, view->end);
return TRUE;
case GDK_MOTION_NOTIFY:
mevent = (GdkEventMotion *) event;
width = widget->allocation.width - 2;
view->start = CLAMP ((((mevent->x - 1) * 256) / width), 0, 255);
gtk_widget_queue_draw (widget);
return TRUE;
default:
break;
}
return FALSE;
return TRUE;
}
static gboolean
gimp_histogram_view_motion_notify (GtkWidget *widget,
GdkEventMotion *mevent)
{
GimpHistogramView *view = GIMP_HISTOGRAM_VIEW (widget);
gint width;
width = widget->allocation.width - 2;
view->start = CLAMP ((((mevent->x - 1) * 256) / width), 0, 255);
gtk_widget_queue_draw (widget);
return TRUE;
}
GtkWidget *
@ -405,10 +440,6 @@ gimp_histogram_view_new (gboolean range)
GIMP_HISTOGRAM_VIEW (view)->end = -1;
}
g_signal_connect (view, "event",
G_CALLBACK (gimp_histogram_view_events),
view);
return view;
}
@ -429,20 +460,12 @@ gimp_histogram_view_set_histogram (GimpHistogramView *view,
gtk_widget_queue_draw (GTK_WIDGET (view));
}
void
gimp_histogram_view_set_range (GimpHistogramView *view,
gint start,
gint end)
GimpHistogram *
gimp_histogram_view_get_histogram (GimpHistogramView *view)
{
g_return_if_fail (GIMP_IS_HISTOGRAM_VIEW (view));
g_return_val_if_fail (GIMP_IS_HISTOGRAM_VIEW (view), NULL);
view->start = MIN (start, end);
view->end = MAX (start, end);
gtk_widget_queue_draw (GTK_WIDGET (view));
g_signal_emit (view, histogram_view_signals[RANGE_CHANGED], 0,
view->start, view->end);
return view->histogram;
}
void
@ -471,10 +494,37 @@ gimp_histogram_view_set_scale (GimpHistogramView *view,
g_object_set (view, "histogram-scale", scale, NULL);
}
GimpHistogram *
gimp_histogram_view_get_histogram (GimpHistogramView *view)
GimpHistogramScale
gimp_histogram_view_get_scale (GimpHistogramView *view)
{
g_return_val_if_fail (GIMP_IS_HISTOGRAM_VIEW (view), NULL);
g_return_val_if_fail (GIMP_IS_HISTOGRAM_VIEW (view), 0);
return view->histogram;
return view->scale;
}
void
gimp_histogram_view_set_range (GimpHistogramView *view,
gint start,
gint end)
{
g_return_if_fail (GIMP_IS_HISTOGRAM_VIEW (view));
view->start = MIN (start, end);
view->end = MAX (start, end);
gtk_widget_queue_draw (GTK_WIDGET (view));
g_signal_emit (view, histogram_view_signals[RANGE_CHANGED], 0,
view->start, view->end);
}
void
gimp_histogram_view_get_range (GimpHistogramView *view,
gint *start,
gint *end)
{
g_return_if_fail (GIMP_IS_HISTOGRAM_VIEW (view));
if (start) *start = view->start;
if (end) *end = view->end;
}

View file

@ -59,17 +59,25 @@ struct _GimpHistogramViewClass
GType gimp_histogram_view_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_histogram_view_new (gboolean range);
void gimp_histogram_view_set_histogram (GimpHistogramView *view,
GimpHistogram *histogram);
GimpHistogram * gimp_histogram_view_get_histogram (GimpHistogramView *view);
void gimp_histogram_view_set_channel (GimpHistogramView *view,
GimpHistogramChannel channel);
GimpHistogramChannel gimp_histogram_view_get_channel (GimpHistogramView *view);
void gimp_histogram_view_set_scale (GimpHistogramView *view,
GimpHistogramScale scale);
GimpHistogramScale gimp_histogram_view_get_scale (GimpHistogramView *view);
void gimp_histogram_view_set_range (GimpHistogramView *view,
gint start,
gint end);
void gimp_histogram_view_get_range (GimpHistogramView *view,
gint *start,
gint *end);
#endif /* __GIMP_HISTOGRAM_VIEW_H__ */