mirror of
https://gitlab.gnome.org/GNOME/gimp
synced 2024-10-22 20:41:43 +00:00
14d0a3ff07
2001-12-29 Michael Natterer <mitch@gimp.org> * app/gimpprogress.c * app/nav_window.c * app/ops_buttons.c * app/undo_history.c * app/display/gimpdisplayshell.c * app/gui/about-dialog.c * app/gui/brush-editor.c * app/gui/channels-commands.c * app/gui/color-area.c * app/gui/color-notebook.c * app/gui/color-select.c * app/gui/colormap-dialog.c * app/gui/convert-dialog.c * app/gui/device-status-dialog.c * app/gui/file-new-dialog.c * app/gui/file-open-dialog.c * app/gui/file-save-dialog.c * app/gui/gradient-editor.c * app/gui/info-dialog.c * app/gui/layers-commands.c * app/gui/module-browser.c * app/gui/offset-dialog.c * app/gui/palette-editor.c * app/gui/palettes-commands.c * app/gui/paths-dialog.c * app/gui/qmask-commands.c * app/gui/resize-dialog.c * app/gui/resolution-calibrate-dialog.c * app/gui/splash.c * app/gui/tips-dialog.c * app/gui/toolbox.c * app/gui/user-install-dialog.c * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpbycolorselecttool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcolorpickertool.c * app/tools/gimpcroptool.c * app/tools/gimpcurvestool.c * app/tools/gimphuesaturationtool.c * app/tools/gimpinktool.c * app/tools/gimplevelstool.c * app/tools/gimpposterizetool.c * app/tools/gimprotatetool.c * app/tools/gimpthresholdtool.c * app/tools/paint_options.c * app/tools/selection_options.c * app/widgets/gimpchannellistview.c * app/widgets/gimpcolorpanel.c * app/widgets/gimpcomponentlistitem.c * app/widgets/gimpconstrainedhwrapbox.c * app/widgets/gimpcontainergridview.c * app/widgets/gimpcontainerlistview.c * app/widgets/gimpcontainermenuimpl.c * app/widgets/gimpdialogfactory.c * app/widgets/gimpdnd.c * app/widgets/gimpdock.c * app/widgets/gimpdockbook.c * app/widgets/gimpdrawablelistitem.c * app/widgets/gimpdrawablelistview.c * app/widgets/gimpfontselection-dialog.c * app/widgets/gimphistogramview.c * app/widgets/gimpitemfactory.c * app/widgets/gimplayerlistitem.c * app/widgets/gimplistitem.[ch] * app/widgets/gimpmenuitem.c * app/widgets/gimppreview.[ch] * app/widgets/gtkhwrapbox.c * app/widgets/gtkvwrapbox.c * app/widgets/gtkwrapbox.c * libgimp/gimpbrushmenu.c * libgimp/gimpexport.c * libgimp/gimpgradientmenu.c * libgimp/gimpmenu.c * libgimp/gimppatternmenu.c * libgimpwidgets/gimpbutton.c * libgimpwidgets/gimpchainbutton.[ch] * libgimpwidgets/gimpcolorarea.h * libgimpwidgets/gimpcolorbutton.c * libgimpwidgets/gimpfileselection.c * libgimpwidgets/gimphelpui.c * libgimpwidgets/gimpoffsetarea.c * libgimpwidgets/gimppatheditor.c * libgimpwidgets/gimppixmap.h * libgimpwidgets/gimpquerybox.c * libgimpwidgets/gimpstock.[ch] * libgimpwidgets/gimpwidgets.h * plug-ins/FractalExplorer/Dialogs.c * plug-ins/FractalExplorer/Events.c * plug-ins/FractalExplorer/FractalExplorer.c * plug-ins/Lighting/lighting_ui.c * plug-ins/MapObject/mapobject_ui.c * plug-ins/bmp/bmpwrite.c * plug-ins/dbbrowser/dbbrowser_utils.c * plug-ins/fits/fits.c * plug-ins/flame/flame.c * plug-ins/fp/fp_gtk.c * plug-ins/fp/fp_misc.c * plug-ins/gfig/gfig.c * plug-ins/gflare/gflare.c * plug-ins/gfli/gfli.c * plug-ins/gimpressionist/*.c * plug-ins/imagemap/*.[ch] * plug-ins/maze/maze_face.c * plug-ins/mosaic/mosaic.c * plug-ins/pagecurl/pagecurl.c * plug-ins/print/print_gimp.h * plug-ins/rcm/rcm_callback.c * plug-ins/rcm/rcm_dialog.c * plug-ins/rcm/rcm_misc.c * plug-ins/script-fu/script-fu-console.c * plug-ins/script-fu/script-fu-scripts.c * plug-ins/script-fu/script-fu-server.c * plug-ins/sel2path/sel2path.c * plug-ins/sel2path/sel2path_adv_dialog.c * plug-ins/sgi/sgi.c * plug-ins/webbrowser/webbrowser.c * plug-ins/xjt/xjt.c * plug-ins/common/[A-n]*.c: compile with GTK_DISABLE_DEPRECATED defined. Not everything is fully ported yet, had to #undef GTK_DISABLE_DEPRECATED in many places and added #warnings when doing so. * pixmaps/Makefile.am * pixmaps/chain.xpm: removed. * themes/Default/Makefile.am * themes/Default/images/Makefile.am * themes/Default/images/stock-button-hchain-broken.png * themes/Default/images/stock-button-hchain.png * themes/Default/images/stock-button-vchain-broken.png * themes/Default/images/stock-button-vchain.png: new stock icons.
324 lines
7.8 KiB
C
324 lines
7.8 KiB
C
/* The GIMP -- an image manipulation program
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
#include "widgets-types.h"
|
|
|
|
#include "base/gimphistogram.h"
|
|
|
|
#include "core/gimpmarshal.h"
|
|
|
|
#include "gimphistogramview.h"
|
|
|
|
|
|
#define WAITING 0
|
|
#define WORKING 1
|
|
|
|
#define WORK_DELAY 1
|
|
|
|
#define HISTOGRAM_MASK GDK_EXPOSURE_MASK | \
|
|
GDK_BUTTON_PRESS_MASK | \
|
|
GDK_BUTTON_RELEASE_MASK | \
|
|
GDK_BUTTON1_MOTION_MASK
|
|
|
|
#define HISTOGRAM 0x1
|
|
#define RANGE 0x2
|
|
#define ALL 0xF
|
|
|
|
|
|
enum
|
|
{
|
|
RANGE_CHANGED,
|
|
LAST_SIGNAL
|
|
};
|
|
|
|
|
|
static void gimp_histogram_view_class_init (GimpHistogramViewClass *klass);
|
|
static void gimp_histogram_view_init (GimpHistogramView *view);
|
|
|
|
|
|
static guint histogram_view_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
static GtkDrawingAreaClass *parent_class = NULL;
|
|
|
|
|
|
GType
|
|
gimp_histogram_view_get_type (void)
|
|
{
|
|
static GType view_type = 0;
|
|
|
|
if (! view_type)
|
|
{
|
|
static const GTypeInfo view_info =
|
|
{
|
|
sizeof (GimpHistogramViewClass),
|
|
NULL, /* base_init */
|
|
NULL, /* base_finalize */
|
|
(GClassInitFunc) gimp_histogram_view_class_init,
|
|
NULL, /* class_finalize */
|
|
NULL, /* class_data */
|
|
sizeof (GimpHistogramView),
|
|
0, /* n_preallocs */
|
|
(GInstanceInitFunc) gimp_histogram_view_init,
|
|
};
|
|
|
|
view_type = g_type_register_static (GTK_TYPE_DRAWING_AREA,
|
|
"GimpHistogramView",
|
|
&view_info, 0);
|
|
}
|
|
|
|
return view_type;
|
|
}
|
|
|
|
static void
|
|
gimp_histogram_view_class_init (GimpHistogramViewClass *klass)
|
|
{
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
histogram_view_signals[RANGE_CHANGED] =
|
|
g_signal_new ("range_changed",
|
|
G_TYPE_FROM_CLASS (klass),
|
|
G_SIGNAL_RUN_FIRST,
|
|
G_STRUCT_OFFSET (GimpHistogramViewClass, range_changed),
|
|
NULL, NULL,
|
|
gimp_marshal_VOID__INT_INT,
|
|
G_TYPE_NONE, 2,
|
|
G_TYPE_INT,
|
|
G_TYPE_INT);
|
|
|
|
klass->range_changed = NULL;
|
|
}
|
|
|
|
static void
|
|
gimp_histogram_view_init (GimpHistogramView *view)
|
|
{
|
|
view->histogram = NULL;
|
|
view->channel = GIMP_HISTOGRAM_VALUE;
|
|
view->start = 0;
|
|
view->end = 255;
|
|
}
|
|
|
|
static void
|
|
gimp_histogram_view_draw (GimpHistogramView *view,
|
|
gint update)
|
|
{
|
|
GtkWidget *widget;
|
|
gdouble max;
|
|
gdouble v;
|
|
gint i, x, y;
|
|
gint x1, x2;
|
|
gint width, height;
|
|
|
|
widget = GTK_WIDGET (view);
|
|
|
|
width = widget->allocation.width - 2;
|
|
height = widget->allocation.height - 2;
|
|
|
|
if (update & HISTOGRAM)
|
|
{
|
|
/* find the maximum value */
|
|
max = gimp_histogram_get_maximum (view->histogram,
|
|
view->channel);
|
|
|
|
if (max > 0.0)
|
|
max = log (max);
|
|
else
|
|
max = 1.0;
|
|
|
|
/* clear the histogram */
|
|
gdk_window_clear (widget->window);
|
|
|
|
/* Draw the axis */
|
|
gdk_draw_line (widget->window,
|
|
widget->style->black_gc,
|
|
1, height + 1, width, height + 1);
|
|
|
|
/* Draw the spikes */
|
|
for (i = 0; i < 256; i++)
|
|
{
|
|
x = (width * i) / 256 + 1;
|
|
v = gimp_histogram_get_value (view->histogram,
|
|
view->channel, i);
|
|
if (v > 0.0)
|
|
y = (int) ((height * log (v)) / max);
|
|
else
|
|
y = 0;
|
|
gdk_draw_line (widget->window,
|
|
widget->style->black_gc,
|
|
x, height + 1,
|
|
x, height + 1 - y);
|
|
}
|
|
}
|
|
|
|
if ((update & RANGE) && view->start >= 0)
|
|
{
|
|
x1 = (width * MIN (view->start, view->end)) / 256 + 1;
|
|
x2 = (width * MAX (view->start, view->end)) / 256 + 1;
|
|
|
|
gdk_gc_set_function (widget->style->black_gc, GDK_INVERT);
|
|
gdk_draw_rectangle (widget->window,
|
|
widget->style->black_gc, TRUE,
|
|
x1, 1, (x2 - x1) + 1, height);
|
|
gdk_gc_set_function (widget->style->black_gc, GDK_COPY);
|
|
}
|
|
}
|
|
|
|
static gint
|
|
gimp_histogram_view_events (GimpHistogramView *view,
|
|
GdkEvent *event)
|
|
{
|
|
GtkWidget *widget;
|
|
GdkEventButton *bevent;
|
|
GdkEventMotion *mevent;
|
|
gint width;
|
|
|
|
widget = GTK_WIDGET (view);
|
|
|
|
switch (event->type)
|
|
{
|
|
case GDK_EXPOSE:
|
|
gimp_histogram_view_draw (view, ALL);
|
|
break;
|
|
|
|
case GDK_BUTTON_PRESS:
|
|
bevent = (GdkEventButton *) event;
|
|
|
|
if (bevent->button != 1)
|
|
break;
|
|
|
|
gdk_pointer_grab (widget->window, FALSE,
|
|
GDK_BUTTON_RELEASE_MASK | GDK_BUTTON1_MOTION_MASK,
|
|
NULL, NULL, bevent->time);
|
|
|
|
width = widget->allocation.width - 2;
|
|
|
|
gimp_histogram_view_draw (view, RANGE);
|
|
|
|
view->start = CLAMP ((((bevent->x - 1) * 256) / width), 0, 255);
|
|
view->end = view->start;
|
|
|
|
gimp_histogram_view_draw (view, RANGE);
|
|
break;
|
|
|
|
case GDK_BUTTON_RELEASE:
|
|
bevent = (GdkEventButton *) event;
|
|
|
|
gdk_pointer_ungrab (bevent->time);
|
|
|
|
g_signal_emit (G_OBJECT (view),
|
|
histogram_view_signals[RANGE_CHANGED], 0,
|
|
MIN (view->start, view->end),
|
|
MAX (view->start, view->end));
|
|
break;
|
|
|
|
case GDK_MOTION_NOTIFY:
|
|
mevent = (GdkEventMotion *) event;
|
|
width = widget->allocation.width - 2;
|
|
|
|
gimp_histogram_view_draw (view, RANGE);
|
|
|
|
view->start = CLAMP ((((mevent->x - 1) * 256) / width), 0, 255);
|
|
|
|
gimp_histogram_view_draw (view, RANGE);
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
GimpHistogramView *
|
|
gimp_histogram_view_new (gint width,
|
|
gint height)
|
|
{
|
|
GimpHistogramView *view;
|
|
|
|
view = g_object_new (GIMP_TYPE_HISTOGRAM_VIEW, NULL);
|
|
|
|
gtk_widget_set_size_request (GTK_WIDGET (view), width + 2, height + 2);
|
|
gtk_widget_set_events (GTK_WIDGET (view), HISTOGRAM_MASK);
|
|
|
|
g_signal_connect (G_OBJECT (view), "event",
|
|
G_CALLBACK (gimp_histogram_view_events),
|
|
view);
|
|
|
|
return view;
|
|
}
|
|
|
|
void
|
|
gimp_histogram_view_update (GimpHistogramView *view,
|
|
GimpHistogram *histogram)
|
|
{
|
|
view->histogram = histogram;
|
|
|
|
if (! histogram)
|
|
return;
|
|
|
|
if (view->channel >= gimp_histogram_nchannels (histogram))
|
|
gimp_histogram_view_channel (view, 0);
|
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (view));
|
|
|
|
g_signal_emit (G_OBJECT (view),
|
|
histogram_view_signals[RANGE_CHANGED], 0,
|
|
MIN (view->start, view->end),
|
|
MAX (view->start, view->end));
|
|
}
|
|
|
|
void
|
|
gimp_histogram_view_range (GimpHistogramView *view,
|
|
gint start,
|
|
gint end)
|
|
{
|
|
gimp_histogram_view_draw (view, RANGE);
|
|
|
|
view->start = start;
|
|
view->end = end;
|
|
|
|
gimp_histogram_view_draw (view, RANGE);
|
|
}
|
|
|
|
void
|
|
gimp_histogram_view_channel (GimpHistogramView *view,
|
|
gint channel)
|
|
{
|
|
view->channel = channel;
|
|
|
|
gimp_histogram_view_draw (view, ALL);
|
|
|
|
g_signal_emit (G_OBJECT (view),
|
|
histogram_view_signals[RANGE_CHANGED], 0,
|
|
MIN (view->start, view->end),
|
|
MAX (view->start, view->end));
|
|
}
|
|
|
|
GimpHistogram *
|
|
gimp_histogram_view_histogram (GimpHistogramView *view)
|
|
{
|
|
g_return_val_if_fail (GIMP_IS_HISTOGRAM_VIEW (view), NULL);
|
|
|
|
return view->histogram;
|
|
}
|