1997-11-25 06:05:25 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* Gradient editor module copyight (C) 1996-1997 Federico Mena Quintero
|
|
|
|
* federico@nuclecu.unam.mx
|
|
|
|
*
|
|
|
|
* 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 PURIGHTE. 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
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Special thanks to:
|
|
|
|
*
|
|
|
|
* Luis Albarran (luis4@mindspring.com) - Nice UI suggestions
|
|
|
|
*
|
|
|
|
* Miguel de Icaza (miguel@nuclecu.unam.mx) - Pop-up menu suggestion
|
|
|
|
*
|
|
|
|
* Marcelo Malheiros (malheiro@dca.fee.unicamp.br) - many, many
|
|
|
|
* suggestions, nice gradient files
|
|
|
|
*
|
|
|
|
* Adam Moss (adam@uunet.pipex.com) - idea for the hint bar
|
|
|
|
*
|
|
|
|
* Everyone on #gimp - many suggestions
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* TODO:
|
|
|
|
*
|
|
|
|
* - Add all of Marcelo's neat suggestions:
|
|
|
|
* - Hue rotate, saturation, brightness, contrast.
|
|
|
|
*
|
|
|
|
* - Better handling of bogus gradient files and inconsistent
|
|
|
|
* segments. Do not loop indefinitely in seg_get_segment_at() if
|
|
|
|
* there is a missing segment between two others.
|
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
1999-02-21 07:20:54 +08:00
|
|
|
#include "config.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2000-12-17 05:37:03 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2001-01-24 02:49:44 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
2001-01-24 07:56:18 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2001-05-22 04:30:16 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2001-01-25 06:36:18 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
2001-01-24 02:49:44 +08:00
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
#include "widgets-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-07-05 03:31:35 +08:00
|
|
|
#include "core/gimp.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpcontainer.h"
|
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
#include "core/gimpdatafactory.h"
|
|
|
|
#include "core/gimpgradient.h"
|
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
#include "gimpdnd.h"
|
|
|
|
#include "gimpgradienteditor.h"
|
2003-08-24 21:52:51 +08:00
|
|
|
#include "gimphelp-ids.h"
|
2004-08-25 01:16:46 +08:00
|
|
|
#include "gimpview.h"
|
2004-08-26 22:20:30 +08:00
|
|
|
#include "gimpviewrenderergradient.h"
|
2002-12-20 00:33:29 +08:00
|
|
|
#include "gimpwidgets-utils.h"
|
1998-11-23 22:47:09 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2000-04-28 01:27:28 +08:00
|
|
|
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#define EPSILON 1e-10
|
|
|
|
|
1999-10-28 23:05:49 +08:00
|
|
|
#define GRAD_SCROLLBAR_STEP_SIZE 0.05
|
|
|
|
#define GRAD_SCROLLBAR_PAGE_SIZE 0.75
|
|
|
|
|
2004-08-26 22:20:30 +08:00
|
|
|
#define GRAD_VIEW_WIDTH 128
|
|
|
|
#define GRAD_VIEW_HEIGHT 96
|
1999-11-14 18:50:19 +08:00
|
|
|
#define GRAD_CONTROL_HEIGHT 10
|
1999-10-28 23:05:49 +08:00
|
|
|
|
|
|
|
#define GRAD_MOVE_TIME 150 /* ms between mouse click and detection of movement in gradient control */
|
|
|
|
|
2001-02-13 08:12:15 +08:00
|
|
|
|
2004-08-26 22:20:30 +08:00
|
|
|
#define GRAD_VIEW_EVENT_MASK (GDK_EXPOSURE_MASK | \
|
|
|
|
GDK_LEAVE_NOTIFY_MASK | \
|
|
|
|
GDK_POINTER_MOTION_MASK | \
|
|
|
|
GDK_POINTER_MOTION_HINT_MASK | \
|
|
|
|
GDK_BUTTON_PRESS_MASK | \
|
|
|
|
GDK_BUTTON_RELEASE_MASK)
|
1999-11-14 18:50:19 +08:00
|
|
|
|
2001-02-13 08:12:15 +08:00
|
|
|
#define GRAD_CONTROL_EVENT_MASK (GDK_EXPOSURE_MASK | \
|
2004-08-25 01:16:46 +08:00
|
|
|
GDK_LEAVE_NOTIFY_MASK | \
|
|
|
|
GDK_POINTER_MOTION_MASK | \
|
|
|
|
GDK_POINTER_MOTION_HINT_MASK | \
|
|
|
|
GDK_BUTTON_PRESS_MASK | \
|
|
|
|
GDK_BUTTON_RELEASE_MASK | \
|
|
|
|
GDK_BUTTON1_MOTION_MASK)
|
1999-10-28 23:05:49 +08:00
|
|
|
|
2001-02-13 08:12:15 +08:00
|
|
|
|
2001-11-27 23:44:02 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
static void gimp_gradient_editor_class_init (GimpGradientEditorClass *klass);
|
|
|
|
static void gimp_gradient_editor_init (GimpGradientEditor *editor);
|
|
|
|
|
2004-10-25 04:38:35 +08:00
|
|
|
static GObject * gimp_gradient_editor_constructor (GType type,
|
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params);
|
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
static void gimp_gradient_editor_set_data (GimpDataEditor *editor,
|
|
|
|
GimpData *data);
|
|
|
|
|
2004-05-31 06:04:16 +08:00
|
|
|
static void gimp_gradient_editor_gradient_dirty (GimpGradientEditor *editor,
|
|
|
|
GimpGradient *gradient);
|
2002-03-08 08:27:45 +08:00
|
|
|
static void gradient_editor_drop_gradient (GtkWidget *widget,
|
2004-12-31 22:36:30 +08:00
|
|
|
gint x,
|
|
|
|
gint y,
|
2002-03-08 08:27:45 +08:00
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer data);
|
2005-03-03 00:18:47 +08:00
|
|
|
static void gradient_editor_drop_color (GtkWidget *widget,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
const GimpRGB *color,
|
|
|
|
gpointer data);
|
|
|
|
static void gradient_editor_control_drop_color (GtkWidget *widget,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
const GimpRGB *color,
|
|
|
|
gpointer data);
|
2002-03-08 08:27:45 +08:00
|
|
|
static void gradient_editor_scrollbar_update (GtkAdjustment *adj,
|
|
|
|
GimpGradientEditor *editor);
|
|
|
|
static void gradient_editor_instant_update_update (GtkWidget *widget,
|
|
|
|
GimpGradientEditor *editor);
|
|
|
|
|
|
|
|
static void gradient_editor_set_hint (GimpGradientEditor *editor,
|
|
|
|
const gchar *str1,
|
|
|
|
const gchar *str2,
|
2004-08-25 01:16:46 +08:00
|
|
|
const gchar *str3,
|
2004-06-05 19:14:38 +08:00
|
|
|
const gchar *str4);
|
2001-02-13 08:12:15 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-08-26 22:20:30 +08:00
|
|
|
/* Gradient view functions */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-05-05 21:59:32 +08:00
|
|
|
static gboolean view_events (GtkWidget *widget,
|
2004-08-25 01:16:46 +08:00
|
|
|
GdkEvent *event,
|
|
|
|
GimpGradientEditor *editor);
|
2004-08-26 22:20:30 +08:00
|
|
|
static void view_set_hint (GimpGradientEditor *editor,
|
2004-08-25 01:16:46 +08:00
|
|
|
gint x);
|
2002-03-08 08:27:45 +08:00
|
|
|
|
2004-08-26 22:20:30 +08:00
|
|
|
static void view_set_foreground (GimpGradientEditor *editor,
|
2004-08-25 01:16:46 +08:00
|
|
|
gint x);
|
2004-08-26 22:20:30 +08:00
|
|
|
static void view_set_background (GimpGradientEditor *editor,
|
2004-08-25 01:16:46 +08:00
|
|
|
gint x);
|
2002-03-08 08:27:45 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Gradient control functions */
|
|
|
|
|
2005-05-05 21:59:32 +08:00
|
|
|
static gboolean control_events (GtkWidget *widget,
|
2004-08-25 01:16:46 +08:00
|
|
|
GdkEvent *event,
|
|
|
|
GimpGradientEditor *editor);
|
2002-03-08 08:27:45 +08:00
|
|
|
static void control_do_hint (GimpGradientEditor *editor,
|
2004-08-25 01:16:46 +08:00
|
|
|
gint x,
|
|
|
|
gint y);
|
2002-03-08 08:27:45 +08:00
|
|
|
static void control_button_press (GimpGradientEditor *editor,
|
2004-08-25 01:16:46 +08:00
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
guint button,
|
|
|
|
guint state);
|
2002-03-08 08:27:45 +08:00
|
|
|
static gboolean control_point_in_handle (GimpGradientEditor *editor,
|
2004-08-25 01:16:46 +08:00
|
|
|
GimpGradient *gradient,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
GimpGradientSegment *seg,
|
|
|
|
GradientEditorDragMode handle);
|
2002-03-08 08:27:45 +08:00
|
|
|
static void control_select_single_segment (GimpGradientEditor *editor,
|
2004-08-25 01:16:46 +08:00
|
|
|
GimpGradientSegment *seg);
|
2002-03-08 08:27:45 +08:00
|
|
|
static void control_extend_selection (GimpGradientEditor *editor,
|
2004-08-25 01:16:46 +08:00
|
|
|
GimpGradientSegment *seg,
|
|
|
|
gdouble pos);
|
2002-03-08 08:27:45 +08:00
|
|
|
static void control_motion (GimpGradientEditor *editor,
|
2004-08-25 01:16:46 +08:00
|
|
|
GimpGradient *gradient,
|
|
|
|
gint x);
|
2000-12-20 05:49:46 +08:00
|
|
|
|
2004-05-31 06:04:16 +08:00
|
|
|
static void control_compress_left (GimpGradient *gradient,
|
|
|
|
GimpGradientSegment *range_l,
|
2004-08-25 01:16:46 +08:00
|
|
|
GimpGradientSegment *range_r,
|
|
|
|
GimpGradientSegment *drag_seg,
|
|
|
|
gdouble pos);
|
2000-12-20 05:49:46 +08:00
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
static double control_move (GimpGradientEditor *editor,
|
2004-08-25 01:16:46 +08:00
|
|
|
GimpGradientSegment *range_l,
|
|
|
|
GimpGradientSegment *range_r,
|
|
|
|
gdouble delta);
|
1999-07-24 23:37:03 +08:00
|
|
|
|
|
|
|
/* Control update/redraw functions */
|
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
static void control_update (GimpGradientEditor *editor,
|
2003-03-10 22:07:22 +08:00
|
|
|
GimpGradient *gradient,
|
2004-08-25 01:16:46 +08:00
|
|
|
gboolean recalculate);
|
2002-03-08 08:27:45 +08:00
|
|
|
static void control_draw (GimpGradientEditor *editor,
|
2004-08-25 01:16:46 +08:00
|
|
|
GimpGradient *gradient,
|
|
|
|
GdkPixmap *pixmap,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gdouble left,
|
|
|
|
gdouble right);
|
2002-03-08 08:27:45 +08:00
|
|
|
static void control_draw_normal_handle (GimpGradientEditor *editor,
|
2004-08-25 01:16:46 +08:00
|
|
|
GdkPixmap *pixmap,
|
|
|
|
gdouble pos,
|
2005-05-05 21:59:32 +08:00
|
|
|
gint height,
|
|
|
|
GtkStateType state);
|
2002-03-08 08:27:45 +08:00
|
|
|
static void control_draw_middle_handle (GimpGradientEditor *editor,
|
2004-08-25 01:16:46 +08:00
|
|
|
GdkPixmap *pixmap,
|
|
|
|
gdouble pos,
|
2005-05-05 21:59:32 +08:00
|
|
|
gint height,
|
|
|
|
GtkStateType state);
|
2002-03-08 08:27:45 +08:00
|
|
|
static void control_draw_handle (GdkPixmap *pixmap,
|
2004-08-25 01:16:46 +08:00
|
|
|
GdkGC *border_gc,
|
|
|
|
GdkGC *fill_gc,
|
|
|
|
gint xpos,
|
|
|
|
gint height);
|
2002-03-08 08:27:45 +08:00
|
|
|
|
|
|
|
static gint control_calc_p_pos (GimpGradientEditor *editor,
|
2004-08-25 01:16:46 +08:00
|
|
|
gdouble pos);
|
2002-03-08 08:27:45 +08:00
|
|
|
static gdouble control_calc_g_pos (GimpGradientEditor *editor,
|
2004-08-25 01:16:46 +08:00
|
|
|
gint pos);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Segment functions */
|
|
|
|
|
2001-02-11 09:39:24 +08:00
|
|
|
static void seg_get_closest_handle (GimpGradient *grad,
|
2004-05-31 06:04:16 +08:00
|
|
|
gdouble pos,
|
|
|
|
GimpGradientSegment **seg,
|
|
|
|
GradientEditorDragMode *handle);
|
2005-05-05 21:59:32 +08:00
|
|
|
static gboolean seg_in_selection (GimpGradient *grad,
|
|
|
|
GimpGradientSegment *seg,
|
|
|
|
GimpGradientSegment *left,
|
|
|
|
GimpGradientSegment *right);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-02-09 04:08:13 +08:00
|
|
|
static GtkWidget * gradient_hint_label_add (GtkBox *box);
|
|
|
|
|
2000-12-21 19:56:58 +08:00
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
static GimpDataEditorClass *parent_class = NULL;
|
2001-02-14 09:42:12 +08:00
|
|
|
|
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
GType
|
|
|
|
gimp_gradient_editor_get_type (void)
|
|
|
|
{
|
|
|
|
static GType type = 0;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
if (! type)
|
|
|
|
{
|
|
|
|
static const GTypeInfo info =
|
|
|
|
{
|
|
|
|
sizeof (GimpGradientEditorClass),
|
|
|
|
NULL, /* base_init */
|
|
|
|
NULL, /* base_finalize */
|
|
|
|
(GClassInitFunc) gimp_gradient_editor_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpGradientEditor),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_gradient_editor_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
type = g_type_register_static (GIMP_TYPE_DATA_EDITOR,
|
|
|
|
"GimpGradientEditor",
|
|
|
|
&info, 0);
|
|
|
|
}
|
1999-09-28 01:58:10 +08:00
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
return type;
|
|
|
|
}
|
1999-09-28 01:58:10 +08:00
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
static void
|
|
|
|
gimp_gradient_editor_class_init (GimpGradientEditorClass *klass)
|
|
|
|
{
|
2004-10-25 04:38:35 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2004-05-12 00:05:21 +08:00
|
|
|
GimpDataEditorClass *editor_class = GIMP_DATA_EDITOR_CLASS (klass);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2001-02-19 08:05:03 +08:00
|
|
|
|
2004-10-25 04:38:35 +08:00
|
|
|
object_class->constructor = gimp_gradient_editor_constructor;
|
|
|
|
|
|
|
|
editor_class->set_data = gimp_gradient_editor_set_data;
|
2005-04-17 04:48:33 +08:00
|
|
|
editor_class->title = _("Gradient Editor");
|
2002-03-08 08:27:45 +08:00
|
|
|
}
|
1999-11-03 17:58:46 +08:00
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
static void
|
|
|
|
gimp_gradient_editor_init (GimpGradientEditor *editor)
|
|
|
|
{
|
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *button;
|
2001-02-13 08:12:15 +08:00
|
|
|
|
2004-08-26 22:20:30 +08:00
|
|
|
/* Frame for gradient view and gradient control */
|
new ui for the "Layer Offset" dialog.
1999-07-22 Michael Natterer <mitschel@cs.tu-berlin.de>
* app/channel_ops.[ch]: new ui for the "Layer Offset" dialog.
* app/channels_dialog.c
* app/layers_dialog.c: major code cleanup: Folded some callbacks
into common ones, "widget" instead of "w", indentation, ...
* app/commands.c
* app/interface.[ch]
* app/global_edit.c: the query boxes must be shown by the caller
now. There's no need to split up the string for the message box
manually as the Gtk 1.2 label widget handles newlines corectly.
Added the "edge_lock" toggle to the "Shrink Selection" dialog.
Nicer spacings for the query and message boxes.
* app/ink.c: tried to grab the pointer in the blob preview but
failed. Left the code there as a reminder (commented out).
* app/menus.c: reordered <Image>/Select.
I was bored and grep-ed the sources for ancient or deprecated stuff:
* app/about_dialog.[ch]
* app/actionarea.[ch]
* app/app_procs.c
* app/brush_edit.c
* app/brush_select.c
* app/color_select.c
* app/convert.c
* app/devices.c
* app/gdisplay.c
* app/gdisplay_ops.c
* app/histogram_tool.[ch]
* app/info_window.c
* app/install.c
* app/ops_buttons.c
* app/palette.c
* app/palette_select.c
* app/paths_dialog.c
* app/pattern_select.c
* app/resize.c
* app/scale_toolc.c
* app/text_tool.c:
s/container_border_width/container_set_border_width/g,
s/sprintf/g_snprintf/g, replaced some constant string lengths with
strlen(x).
* app/bezier_select.c
* app/blend.c
* app/boundary.c
* app/errors.[ch]
* app/free_select.c
* app/gimpbrushlist.c
* app/gimprc.c
* app/iscissors.c
* app/main.c
* app/patterns.[ch]
* app/text_tool.c: namespace fanaticism: prefixed all gimp error
functions with "gimp_" and formated the messages more uniformly.
* app/gradient.c
* app/gradient_select.c: same stuff as above for the ui
code. There are still some sub-dialogs which need cleanup.
Did some cleanup in most of these files: prototypes, removed tons
of #include's, i18n fixes, s/w/widget/ as above, indentation, ...
1999-07-23 00:21:10 +08:00
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
|
2002-03-08 08:27:45 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (editor), frame, TRUE, TRUE, 0);
|
new ui for the "Layer Offset" dialog.
1999-07-22 Michael Natterer <mitschel@cs.tu-berlin.de>
* app/channel_ops.[ch]: new ui for the "Layer Offset" dialog.
* app/channels_dialog.c
* app/layers_dialog.c: major code cleanup: Folded some callbacks
into common ones, "widget" instead of "w", indentation, ...
* app/commands.c
* app/interface.[ch]
* app/global_edit.c: the query boxes must be shown by the caller
now. There's no need to split up the string for the message box
manually as the Gtk 1.2 label widget handles newlines corectly.
Added the "edge_lock" toggle to the "Shrink Selection" dialog.
Nicer spacings for the query and message boxes.
* app/ink.c: tried to grab the pointer in the blob preview but
failed. Left the code there as a reminder (commented out).
* app/menus.c: reordered <Image>/Select.
I was bored and grep-ed the sources for ancient or deprecated stuff:
* app/about_dialog.[ch]
* app/actionarea.[ch]
* app/app_procs.c
* app/brush_edit.c
* app/brush_select.c
* app/color_select.c
* app/convert.c
* app/devices.c
* app/gdisplay.c
* app/gdisplay_ops.c
* app/histogram_tool.[ch]
* app/info_window.c
* app/install.c
* app/ops_buttons.c
* app/palette.c
* app/palette_select.c
* app/paths_dialog.c
* app/pattern_select.c
* app/resize.c
* app/scale_toolc.c
* app/text_tool.c:
s/container_border_width/container_set_border_width/g,
s/sprintf/g_snprintf/g, replaced some constant string lengths with
strlen(x).
* app/bezier_select.c
* app/blend.c
* app/boundary.c
* app/errors.[ch]
* app/free_select.c
* app/gimpbrushlist.c
* app/gimprc.c
* app/iscissors.c
* app/main.c
* app/patterns.[ch]
* app/text_tool.c: namespace fanaticism: prefixed all gimp error
functions with "gimp_" and formated the messages more uniformly.
* app/gradient.c
* app/gradient_select.c: same stuff as above for the ui
code. There are still some sub-dialogs which need cleanup.
Did some cleanup in most of these files: prototypes, removed tons
of #include's, i18n fixes, s/w/widget/ as above, indentation, ...
1999-07-23 00:21:10 +08:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
vbox = gtk_vbox_new (FALSE, 0);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), vbox);
|
|
|
|
gtk_widget_show (vbox);
|
new ui for the "Layer Offset" dialog.
1999-07-22 Michael Natterer <mitschel@cs.tu-berlin.de>
* app/channel_ops.[ch]: new ui for the "Layer Offset" dialog.
* app/channels_dialog.c
* app/layers_dialog.c: major code cleanup: Folded some callbacks
into common ones, "widget" instead of "w", indentation, ...
* app/commands.c
* app/interface.[ch]
* app/global_edit.c: the query boxes must be shown by the caller
now. There's no need to split up the string for the message box
manually as the Gtk 1.2 label widget handles newlines corectly.
Added the "edge_lock" toggle to the "Shrink Selection" dialog.
Nicer spacings for the query and message boxes.
* app/ink.c: tried to grab the pointer in the blob preview but
failed. Left the code there as a reminder (commented out).
* app/menus.c: reordered <Image>/Select.
I was bored and grep-ed the sources for ancient or deprecated stuff:
* app/about_dialog.[ch]
* app/actionarea.[ch]
* app/app_procs.c
* app/brush_edit.c
* app/brush_select.c
* app/color_select.c
* app/convert.c
* app/devices.c
* app/gdisplay.c
* app/gdisplay_ops.c
* app/histogram_tool.[ch]
* app/info_window.c
* app/install.c
* app/ops_buttons.c
* app/palette.c
* app/palette_select.c
* app/paths_dialog.c
* app/pattern_select.c
* app/resize.c
* app/scale_toolc.c
* app/text_tool.c:
s/container_border_width/container_set_border_width/g,
s/sprintf/g_snprintf/g, replaced some constant string lengths with
strlen(x).
* app/bezier_select.c
* app/blend.c
* app/boundary.c
* app/errors.[ch]
* app/free_select.c
* app/gimpbrushlist.c
* app/gimprc.c
* app/iscissors.c
* app/main.c
* app/patterns.[ch]
* app/text_tool.c: namespace fanaticism: prefixed all gimp error
functions with "gimp_" and formated the messages more uniformly.
* app/gradient.c
* app/gradient_select.c: same stuff as above for the ui
code. There are still some sub-dialogs which need cleanup.
Did some cleanup in most of these files: prototypes, removed tons
of #include's, i18n fixes, s/w/widget/ as above, indentation, ...
1999-07-23 00:21:10 +08:00
|
|
|
|
|
|
|
/* Gradient preview */
|
2001-11-27 23:44:02 +08:00
|
|
|
editor->preview_last_x = 0;
|
|
|
|
editor->preview_button_down = FALSE;
|
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
editor->preview = gimp_view_new_full_by_types (GIMP_TYPE_VIEW,
|
|
|
|
GIMP_TYPE_GRADIENT,
|
2004-08-26 22:20:30 +08:00
|
|
|
GRAD_VIEW_WIDTH,
|
|
|
|
GRAD_VIEW_HEIGHT, 0,
|
2004-08-25 01:16:46 +08:00
|
|
|
FALSE, FALSE, FALSE);
|
2001-12-29 21:26:29 +08:00
|
|
|
gtk_widget_set_size_request (editor->preview,
|
2004-08-26 22:20:30 +08:00
|
|
|
GRAD_VIEW_WIDTH, GRAD_VIEW_HEIGHT);
|
|
|
|
gtk_widget_set_events (editor->preview, GRAD_VIEW_EVENT_MASK);
|
2004-08-25 01:16:46 +08:00
|
|
|
gimp_view_set_expand (GIMP_VIEW (editor->preview), TRUE);
|
2003-03-10 22:07:22 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), editor->preview, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (editor->preview);
|
2001-08-15 00:33:28 +08:00
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (editor->preview, "event",
|
2004-08-26 22:20:30 +08:00
|
|
|
G_CALLBACK (view_events),
|
2004-08-25 01:16:46 +08:00
|
|
|
editor);
|
1999-10-28 23:05:49 +08:00
|
|
|
|
2002-09-02 22:39:08 +08:00
|
|
|
gimp_dnd_viewable_dest_add (GTK_WIDGET (editor->preview),
|
2001-02-13 08:12:15 +08:00
|
|
|
GIMP_TYPE_GRADIENT,
|
|
|
|
gradient_editor_drop_gradient,
|
2001-11-27 23:44:02 +08:00
|
|
|
editor);
|
1999-10-28 23:05:49 +08:00
|
|
|
|
2005-03-03 00:18:47 +08:00
|
|
|
gimp_dnd_color_dest_add (GTK_WIDGET (editor->preview),
|
|
|
|
gradient_editor_drop_color,
|
|
|
|
editor);
|
|
|
|
|
new ui for the "Layer Offset" dialog.
1999-07-22 Michael Natterer <mitschel@cs.tu-berlin.de>
* app/channel_ops.[ch]: new ui for the "Layer Offset" dialog.
* app/channels_dialog.c
* app/layers_dialog.c: major code cleanup: Folded some callbacks
into common ones, "widget" instead of "w", indentation, ...
* app/commands.c
* app/interface.[ch]
* app/global_edit.c: the query boxes must be shown by the caller
now. There's no need to split up the string for the message box
manually as the Gtk 1.2 label widget handles newlines corectly.
Added the "edge_lock" toggle to the "Shrink Selection" dialog.
Nicer spacings for the query and message boxes.
* app/ink.c: tried to grab the pointer in the blob preview but
failed. Left the code there as a reminder (commented out).
* app/menus.c: reordered <Image>/Select.
I was bored and grep-ed the sources for ancient or deprecated stuff:
* app/about_dialog.[ch]
* app/actionarea.[ch]
* app/app_procs.c
* app/brush_edit.c
* app/brush_select.c
* app/color_select.c
* app/convert.c
* app/devices.c
* app/gdisplay.c
* app/gdisplay_ops.c
* app/histogram_tool.[ch]
* app/info_window.c
* app/install.c
* app/ops_buttons.c
* app/palette.c
* app/palette_select.c
* app/paths_dialog.c
* app/pattern_select.c
* app/resize.c
* app/scale_toolc.c
* app/text_tool.c:
s/container_border_width/container_set_border_width/g,
s/sprintf/g_snprintf/g, replaced some constant string lengths with
strlen(x).
* app/bezier_select.c
* app/blend.c
* app/boundary.c
* app/errors.[ch]
* app/free_select.c
* app/gimpbrushlist.c
* app/gimprc.c
* app/iscissors.c
* app/main.c
* app/patterns.[ch]
* app/text_tool.c: namespace fanaticism: prefixed all gimp error
functions with "gimp_" and formated the messages more uniformly.
* app/gradient.c
* app/gradient_select.c: same stuff as above for the ui
code. There are still some sub-dialogs which need cleanup.
Did some cleanup in most of these files: prototypes, removed tons
of #include's, i18n fixes, s/w/widget/ as above, indentation, ...
1999-07-23 00:21:10 +08:00
|
|
|
/* Gradient control */
|
2002-06-12 21:48:47 +08:00
|
|
|
editor->control_pixmap = NULL;
|
|
|
|
editor->control_drag_segment = NULL;
|
|
|
|
editor->control_sel_l = NULL;
|
|
|
|
editor->control_sel_r = NULL;
|
|
|
|
editor->control_drag_mode = GRAD_DRAG_NONE;
|
|
|
|
editor->control_click_time = 0;
|
|
|
|
editor->control_compress = FALSE;
|
|
|
|
editor->control_last_x = 0;
|
|
|
|
editor->control_last_gx = 0.0;
|
|
|
|
editor->control_orig_pos = 0.0;
|
2001-11-27 23:44:02 +08:00
|
|
|
|
|
|
|
editor->control = gtk_drawing_area_new ();
|
2001-12-29 21:26:29 +08:00
|
|
|
gtk_widget_set_size_request (editor->control,
|
2004-08-26 22:20:30 +08:00
|
|
|
GRAD_VIEW_WIDTH, GRAD_CONTROL_HEIGHT);
|
2001-11-27 23:44:02 +08:00
|
|
|
gtk_widget_set_events (editor->control, GRAD_CONTROL_EVENT_MASK);
|
2002-03-08 08:27:45 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), editor->control, FALSE, FALSE, 0);
|
2001-11-27 23:44:02 +08:00
|
|
|
gtk_widget_show (editor->control);
|
new ui for the "Layer Offset" dialog.
1999-07-22 Michael Natterer <mitschel@cs.tu-berlin.de>
* app/channel_ops.[ch]: new ui for the "Layer Offset" dialog.
* app/channels_dialog.c
* app/layers_dialog.c: major code cleanup: Folded some callbacks
into common ones, "widget" instead of "w", indentation, ...
* app/commands.c
* app/interface.[ch]
* app/global_edit.c: the query boxes must be shown by the caller
now. There's no need to split up the string for the message box
manually as the Gtk 1.2 label widget handles newlines corectly.
Added the "edge_lock" toggle to the "Shrink Selection" dialog.
Nicer spacings for the query and message boxes.
* app/ink.c: tried to grab the pointer in the blob preview but
failed. Left the code there as a reminder (commented out).
* app/menus.c: reordered <Image>/Select.
I was bored and grep-ed the sources for ancient or deprecated stuff:
* app/about_dialog.[ch]
* app/actionarea.[ch]
* app/app_procs.c
* app/brush_edit.c
* app/brush_select.c
* app/color_select.c
* app/convert.c
* app/devices.c
* app/gdisplay.c
* app/gdisplay_ops.c
* app/histogram_tool.[ch]
* app/info_window.c
* app/install.c
* app/ops_buttons.c
* app/palette.c
* app/palette_select.c
* app/paths_dialog.c
* app/pattern_select.c
* app/resize.c
* app/scale_toolc.c
* app/text_tool.c:
s/container_border_width/container_set_border_width/g,
s/sprintf/g_snprintf/g, replaced some constant string lengths with
strlen(x).
* app/bezier_select.c
* app/blend.c
* app/boundary.c
* app/errors.[ch]
* app/free_select.c
* app/gimpbrushlist.c
* app/gimprc.c
* app/iscissors.c
* app/main.c
* app/patterns.[ch]
* app/text_tool.c: namespace fanaticism: prefixed all gimp error
functions with "gimp_" and formated the messages more uniformly.
* app/gradient.c
* app/gradient_select.c: same stuff as above for the ui
code. There are still some sub-dialogs which need cleanup.
Did some cleanup in most of these files: prototypes, removed tons
of #include's, i18n fixes, s/w/widget/ as above, indentation, ...
1999-07-23 00:21:10 +08:00
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (editor->control, "event",
|
2004-08-25 01:16:46 +08:00
|
|
|
G_CALLBACK (control_events),
|
|
|
|
editor);
|
2001-08-15 00:33:28 +08:00
|
|
|
|
2005-03-03 00:18:47 +08:00
|
|
|
gimp_dnd_color_dest_add (GTK_WIDGET (editor->control),
|
|
|
|
gradient_editor_control_drop_color,
|
|
|
|
editor);
|
|
|
|
|
2001-02-19 08:05:03 +08:00
|
|
|
/* Scrollbar */
|
2001-11-27 23:44:02 +08:00
|
|
|
editor->zoom_factor = 1;
|
|
|
|
|
|
|
|
editor->scroll_data = gtk_adjustment_new (0.0, 0.0, 1.0,
|
2002-03-08 08:27:45 +08:00
|
|
|
GRAD_SCROLLBAR_STEP_SIZE,
|
|
|
|
GRAD_SCROLLBAR_PAGE_SIZE,
|
2001-11-27 23:44:02 +08:00
|
|
|
1.0);
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (editor->scroll_data, "value_changed",
|
2004-08-25 01:16:46 +08:00
|
|
|
G_CALLBACK (gradient_editor_scrollbar_update),
|
|
|
|
editor);
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (editor->scroll_data, "changed",
|
2004-08-25 01:16:46 +08:00
|
|
|
G_CALLBACK (gradient_editor_scrollbar_update),
|
|
|
|
editor);
|
2001-11-27 23:44:02 +08:00
|
|
|
|
|
|
|
editor->scrollbar = gtk_hscrollbar_new (GTK_ADJUSTMENT (editor->scroll_data));
|
|
|
|
gtk_range_set_update_policy (GTK_RANGE (editor->scrollbar),
|
2004-08-25 01:16:46 +08:00
|
|
|
GTK_UPDATE_CONTINUOUS);
|
2002-03-08 08:27:45 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (editor), editor->scrollbar, FALSE, FALSE, 0);
|
2001-11-27 23:44:02 +08:00
|
|
|
gtk_widget_show (editor->scrollbar);
|
2001-02-19 08:05:03 +08:00
|
|
|
|
|
|
|
/* Instant update toggle */
|
2001-11-27 23:44:02 +08:00
|
|
|
editor->instant_update = TRUE;
|
2001-02-19 08:05:03 +08:00
|
|
|
|
2004-06-03 01:56:02 +08:00
|
|
|
hbox = gtk_hbox_new (FALSE, 6);
|
2004-01-19 08:06:18 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (editor), hbox, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
2001-02-19 08:05:03 +08:00
|
|
|
button = gtk_check_button_new_with_label (_("Instant update"));
|
2003-03-10 22:07:22 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
|
|
|
|
editor->instant_update);
|
2001-02-19 08:05:03 +08:00
|
|
|
gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (button, "toggled",
|
2004-08-25 01:16:46 +08:00
|
|
|
G_CALLBACK (gradient_editor_instant_update_update),
|
|
|
|
editor);
|
2001-02-19 08:05:03 +08:00
|
|
|
|
|
|
|
/* Hint bar */
|
2005-02-09 04:08:13 +08:00
|
|
|
editor->hint_label1 = gradient_hint_label_add (GTK_BOX (editor));
|
|
|
|
editor->hint_label2 = gradient_hint_label_add (GTK_BOX (editor));
|
|
|
|
editor->hint_label3 = gradient_hint_label_add (GTK_BOX (editor));
|
|
|
|
editor->hint_label4 = gradient_hint_label_add (GTK_BOX (editor));
|
2004-06-05 19:14:38 +08:00
|
|
|
|
1999-07-23 04:42:59 +08:00
|
|
|
/* Initialize other data */
|
2001-11-27 23:44:02 +08:00
|
|
|
editor->left_saved_segments = NULL;
|
|
|
|
editor->left_saved_dirty = FALSE;
|
|
|
|
|
|
|
|
editor->right_saved_segments = NULL;
|
|
|
|
editor->right_saved_dirty = FALSE;
|
|
|
|
|
2003-03-10 22:07:22 +08:00
|
|
|
/* Black, 50% Gray, White, Clear */
|
|
|
|
gimp_rgba_set (&editor->saved_colors[0], 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE);
|
|
|
|
gimp_rgba_set (&editor->saved_colors[1], 0.5, 0.5, 0.5, GIMP_OPACITY_OPAQUE);
|
|
|
|
gimp_rgba_set (&editor->saved_colors[2], 1.0, 1.0, 1.0, GIMP_OPACITY_OPAQUE);
|
|
|
|
gimp_rgba_set (&editor->saved_colors[3], 0.0, 0.0, 0.0, GIMP_OPACITY_TRANSPARENT);
|
|
|
|
|
|
|
|
/* Red, Yellow, Green, Cyan, Blue, Magenta */
|
|
|
|
gimp_rgba_set (&editor->saved_colors[4], 1.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE);
|
|
|
|
gimp_rgba_set (&editor->saved_colors[5], 1.0, 1.0, 0.0, GIMP_OPACITY_OPAQUE);
|
|
|
|
gimp_rgba_set (&editor->saved_colors[6], 0.0, 1.0, 0.0, GIMP_OPACITY_OPAQUE);
|
|
|
|
gimp_rgba_set (&editor->saved_colors[7], 0.0, 1.0, 1.0, GIMP_OPACITY_OPAQUE);
|
|
|
|
gimp_rgba_set (&editor->saved_colors[8], 0.0, 0.0, 1.0, GIMP_OPACITY_OPAQUE);
|
|
|
|
gimp_rgba_set (&editor->saved_colors[9], 1.0, 0.0, 1.0, GIMP_OPACITY_OPAQUE);
|
1999-10-28 23:05:49 +08:00
|
|
|
}
|
|
|
|
|
2004-10-25 04:38:35 +08:00
|
|
|
static GObject *
|
|
|
|
gimp_gradient_editor_constructor (GType type,
|
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params)
|
|
|
|
{
|
|
|
|
GObject *object;
|
|
|
|
GimpGradientEditor *editor;
|
|
|
|
|
|
|
|
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
|
|
|
|
|
|
|
|
editor = GIMP_GRADIENT_EDITOR (object);
|
|
|
|
|
|
|
|
gimp_editor_add_action_button (GIMP_EDITOR (editor), "gradient-editor",
|
|
|
|
"gradient-editor-zoom-out", NULL);
|
|
|
|
|
|
|
|
gimp_editor_add_action_button (GIMP_EDITOR (editor), "gradient-editor",
|
|
|
|
"gradient-editor-zoom-in", NULL);
|
|
|
|
|
|
|
|
gimp_editor_add_action_button (GIMP_EDITOR (editor), "gradient-editor",
|
|
|
|
"gradient-editor-zoom-all", NULL);
|
|
|
|
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
static void
|
|
|
|
gimp_gradient_editor_set_data (GimpDataEditor *editor,
|
|
|
|
GimpData *data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-05-12 00:05:21 +08:00
|
|
|
GimpGradientEditor *gradient_editor = GIMP_GRADIENT_EDITOR (editor);
|
2004-05-31 06:04:16 +08:00
|
|
|
GimpData *old_data;
|
|
|
|
|
|
|
|
old_data = gimp_data_editor_get_data (editor);
|
|
|
|
|
|
|
|
if (old_data)
|
|
|
|
g_signal_handlers_disconnect_by_func (old_data,
|
|
|
|
gimp_gradient_editor_gradient_dirty,
|
|
|
|
gradient_editor);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
GIMP_DATA_EDITOR_CLASS (parent_class)->set_data (editor, data);
|
|
|
|
|
2004-05-31 06:04:16 +08:00
|
|
|
if (data)
|
|
|
|
g_signal_connect_swapped (data, "dirty",
|
|
|
|
G_CALLBACK (gimp_gradient_editor_gradient_dirty),
|
|
|
|
gradient_editor);
|
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
gimp_view_set_viewable (GIMP_VIEW (gradient_editor->preview),
|
2005-05-05 21:59:32 +08:00
|
|
|
GIMP_VIEWABLE (data));
|
2003-03-10 22:07:22 +08:00
|
|
|
|
2004-09-13 23:15:23 +08:00
|
|
|
if (gradient_editor->color_dialog)
|
GimpViewableDialogs everywhere, cleanup:
2002-09-01 Michael Natterer <mitch@gimp.org>
GimpViewableDialogs everywhere, cleanup:
* libgimpwidgets/gimpstock.c: added texts for the RESIZE, SCALE
and CROP stock items.
* app/widgets/gimpviewabledialog.c: update the title when the
viewable's name changes.
* app/gui/color-notebook.[ch]: added color_notebook_viewable_new()
which creates a GimpViewableDialog.
* app/widgets/gimpgradienteditor.[ch]
* app/gui/colormap-editor-commands.c
* app/gui/file-new-dialog.c
* app/gui/gradient-editor-commands.c
* app/gui/palette-editor-commands.c
* app/undo_history.c: use GimpViewableDialogs and the new
color_notebook constructor.
* app/gui/convert-dialog.c: #include "widgets/gimpviewabledialog.h"
* app/gui/image-commands.c
* app/gui/info-dialog.c
* app/gui/resize-dialog.c: minor cleanups.
* app/gui/info-window.c: cleaned up the whole thing, esp. the
"Extended" page. Added HSV color display to the color picker
frame. Set the icons as frame titles, stuff...
* app/tools/gimpimagemaptool.[ch]: removed "shell_title",
"shell_name" and "stock_id" from the GimpImageMapTool struct
because they can be obtained from the tool's GimpToolInfo object.
* app/tools/gimpbrightnesscontrasttool.c
* app/tools/gimpcolorbalancetool.c
* app/tools/gimpcurvestool.c
* app/tools/gimphuesaturationtool.c
* app/tools/gimplevelstool.c
* app/tools/gimpposterizetool.c
* app/tools/gimpthresholdtool.c: changed accordingly.
* app/tools/gimphistogramtool.c: same here: take values from
tool->tool_info instead of hardcoding them.
* app/tools/gimpcroptool.[ch]: removed the static crop dialog
variables and added them to the GimpCropTool struct. Feels safer
and makes the callback code much simpler. Use stock items for the
dialog's "Resize" and "Crop" buttons.
* app/tools/gimpmeasuretool.c
* app/tools/gimprotatetool.c: for consistency don't name the tools
"Blah Tool", also the dialog titles need to match the menu
entries.
Unrelated:
* libgimpwidgets/gimpwidgets.c: the recently changed, gtk-doc
comment was correct, as gtk-doc takes the parameter names from
the header, not the .c file.
* app/tools/gimptransformtool.c: set the transform tool's state to
TRANSFORM_CREATING after changing displays, so the initial matrix
components are saved correctly for the "Reset" function.
2002-09-01 16:44:57 +08:00
|
|
|
{
|
2004-09-24 04:41:40 +08:00
|
|
|
gtk_widget_destroy (gradient_editor->color_dialog);
|
2004-09-13 23:15:23 +08:00
|
|
|
gradient_editor->color_dialog = NULL;
|
2003-03-10 22:07:22 +08:00
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (editor), TRUE);
|
GimpViewableDialogs everywhere, cleanup:
2002-09-01 Michael Natterer <mitch@gimp.org>
GimpViewableDialogs everywhere, cleanup:
* libgimpwidgets/gimpstock.c: added texts for the RESIZE, SCALE
and CROP stock items.
* app/widgets/gimpviewabledialog.c: update the title when the
viewable's name changes.
* app/gui/color-notebook.[ch]: added color_notebook_viewable_new()
which creates a GimpViewableDialog.
* app/widgets/gimpgradienteditor.[ch]
* app/gui/colormap-editor-commands.c
* app/gui/file-new-dialog.c
* app/gui/gradient-editor-commands.c
* app/gui/palette-editor-commands.c
* app/undo_history.c: use GimpViewableDialogs and the new
color_notebook constructor.
* app/gui/convert-dialog.c: #include "widgets/gimpviewabledialog.h"
* app/gui/image-commands.c
* app/gui/info-dialog.c
* app/gui/resize-dialog.c: minor cleanups.
* app/gui/info-window.c: cleaned up the whole thing, esp. the
"Extended" page. Added HSV color display to the color picker
frame. Set the icons as frame titles, stuff...
* app/tools/gimpimagemaptool.[ch]: removed "shell_title",
"shell_name" and "stock_id" from the GimpImageMapTool struct
because they can be obtained from the tool's GimpToolInfo object.
* app/tools/gimpbrightnesscontrasttool.c
* app/tools/gimpcolorbalancetool.c
* app/tools/gimpcurvestool.c
* app/tools/gimphuesaturationtool.c
* app/tools/gimplevelstool.c
* app/tools/gimpposterizetool.c
* app/tools/gimpthresholdtool.c: changed accordingly.
* app/tools/gimphistogramtool.c: same here: take values from
tool->tool_info instead of hardcoding them.
* app/tools/gimpcroptool.[ch]: removed the static crop dialog
variables and added them to the GimpCropTool struct. Feels safer
and makes the callback code much simpler. Use stock items for the
dialog's "Resize" and "Crop" buttons.
* app/tools/gimpmeasuretool.c
* app/tools/gimprotatetool.c: for consistency don't name the tools
"Blah Tool", also the dialog titles need to match the menu
entries.
Unrelated:
* libgimpwidgets/gimpwidgets.c: the recently changed, gtk-doc
comment was correct, as gtk-doc takes the parameter names from
the header, not the .c file.
* app/tools/gimptransformtool.c: set the transform tool's state to
TRANSFORM_CREATING after changing displays, so the initial matrix
components are saved correctly for the "Reset" function.
2002-09-01 16:44:57 +08:00
|
|
|
}
|
|
|
|
|
2003-03-10 22:07:22 +08:00
|
|
|
gtk_widget_set_sensitive (gradient_editor->control, editor->data_editable);
|
2002-06-12 21:48:47 +08:00
|
|
|
|
2005-05-05 21:59:32 +08:00
|
|
|
control_update (gradient_editor, GIMP_GRADIENT (data), TRUE);
|
1999-07-24 23:37:03 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-05-31 06:04:16 +08:00
|
|
|
static void
|
|
|
|
gimp_gradient_editor_gradient_dirty (GimpGradientEditor *editor,
|
|
|
|
GimpGradient *gradient)
|
|
|
|
{
|
|
|
|
GimpGradientSegment *segment;
|
|
|
|
gboolean left_seen = FALSE;
|
|
|
|
gboolean right_seen = FALSE;
|
|
|
|
|
|
|
|
for (segment = gradient->segments; segment; segment = segment->next)
|
|
|
|
{
|
|
|
|
if (segment == editor->control_sel_l)
|
|
|
|
left_seen = TRUE;
|
|
|
|
|
|
|
|
if (segment == editor->control_sel_r)
|
|
|
|
right_seen = TRUE;
|
|
|
|
|
|
|
|
if (right_seen && ! left_seen)
|
|
|
|
{
|
|
|
|
GimpGradientSegment *tmp;
|
|
|
|
|
|
|
|
tmp = editor->control_sel_l;
|
|
|
|
editor->control_sel_l = editor->control_sel_r;
|
|
|
|
editor->control_sel_r = tmp;
|
|
|
|
|
|
|
|
right_seen = FALSE;
|
|
|
|
left_seen = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
control_update (editor, gradient, ! (left_seen && right_seen));
|
|
|
|
}
|
|
|
|
|
1999-09-30 18:50:36 +08:00
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
/* public functions */
|
1999-09-30 18:50:36 +08:00
|
|
|
|
2004-09-27 02:41:29 +08:00
|
|
|
GtkWidget *
|
2003-01-11 01:55:53 +08:00
|
|
|
gimp_gradient_editor_new (Gimp *gimp,
|
|
|
|
GimpMenuFactory *menu_factory)
|
2002-03-08 08:27:45 +08:00
|
|
|
{
|
2004-09-27 03:41:56 +08:00
|
|
|
GimpGradient *gradient;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
|
|
|
|
gradient = gimp_context_get_gradient (gimp_get_user_context (gimp));
|
|
|
|
|
2004-09-27 03:26:37 +08:00
|
|
|
return g_object_new (GIMP_TYPE_GRADIENT_EDITOR,
|
|
|
|
"menu-factory", menu_factory,
|
|
|
|
"menu-identifier", "<GradientEditor>",
|
|
|
|
"ui-path", "/gradient-editor-popup",
|
|
|
|
"data-factory", gimp->gradient_factory,
|
2004-09-27 03:41:56 +08:00
|
|
|
"data", gradient,
|
2004-09-27 03:26:37 +08:00
|
|
|
NULL);
|
2001-11-27 23:44:02 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
void
|
2003-03-10 22:07:22 +08:00
|
|
|
gimp_gradient_editor_update (GimpGradientEditor *editor)
|
1998-10-13 07:31:08 +08:00
|
|
|
{
|
2003-03-10 22:07:22 +08:00
|
|
|
GimpGradient *gradient = NULL;
|
1998-10-13 07:31:08 +08:00
|
|
|
|
2003-03-10 22:07:22 +08:00
|
|
|
g_return_if_fail (GIMP_IS_GRADIENT_EDITOR (editor));
|
2001-02-18 05:20:10 +08:00
|
|
|
|
2003-03-10 22:07:22 +08:00
|
|
|
if (GIMP_DATA_EDITOR (editor)->data)
|
|
|
|
gradient = GIMP_GRADIENT (GIMP_DATA_EDITOR (editor)->data);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-03-10 22:07:22 +08:00
|
|
|
control_update (editor, gradient, FALSE);
|
1999-07-23 04:42:59 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-10-25 04:38:35 +08:00
|
|
|
void
|
|
|
|
gimp_gradient_editor_zoom (GimpGradientEditor *editor,
|
|
|
|
GimpZoomType zoom_type)
|
|
|
|
{
|
|
|
|
GtkAdjustment *adjustment;
|
|
|
|
gdouble old_value;
|
|
|
|
gdouble old_page_size;
|
|
|
|
gdouble value = 0.0;
|
|
|
|
gdouble page_size = 1.0;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_GRADIENT_EDITOR (editor));
|
|
|
|
|
|
|
|
adjustment = GTK_ADJUSTMENT (editor->scroll_data);
|
|
|
|
|
|
|
|
old_value = adjustment->value;
|
|
|
|
old_page_size = adjustment->page_size;
|
|
|
|
|
|
|
|
switch (zoom_type)
|
|
|
|
{
|
|
|
|
case GIMP_ZOOM_IN:
|
|
|
|
editor->zoom_factor++;
|
|
|
|
|
|
|
|
page_size = 1.0 / editor->zoom_factor;
|
|
|
|
value = old_value + (old_page_size - page_size) / 2.0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_ZOOM_OUT:
|
|
|
|
if (editor->zoom_factor <= 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
editor->zoom_factor--;
|
|
|
|
|
|
|
|
page_size = 1.0 / editor->zoom_factor;
|
|
|
|
value = old_value - (page_size - old_page_size) / 2.0;
|
|
|
|
|
|
|
|
if (value < 0.0)
|
|
|
|
value = 0.0;
|
|
|
|
else if ((value + page_size) > 1.0)
|
|
|
|
value = 1.0 - page_size;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_ZOOM_TO: /* abused as ZOOM_ALL */
|
|
|
|
editor->zoom_factor = 1;
|
|
|
|
|
|
|
|
value = 0.0;
|
|
|
|
page_size = 1.0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
adjustment->value = value;
|
|
|
|
adjustment->page_size = page_size;
|
|
|
|
adjustment->step_increment = page_size * GRAD_SCROLLBAR_STEP_SIZE;
|
|
|
|
adjustment->page_increment = page_size * GRAD_SCROLLBAR_PAGE_SIZE;
|
|
|
|
|
|
|
|
gtk_adjustment_changed (GTK_ADJUSTMENT (editor->scroll_data));
|
|
|
|
}
|
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
|
|
|
|
/* private functions */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
static void
|
2001-11-27 23:44:02 +08:00
|
|
|
gradient_editor_drop_gradient (GtkWidget *widget,
|
2004-12-31 22:36:30 +08:00
|
|
|
gint x,
|
|
|
|
gint y,
|
2004-08-25 01:16:46 +08:00
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-03-08 08:27:45 +08:00
|
|
|
gimp_data_editor_set_data (GIMP_DATA_EDITOR (data), GIMP_DATA (viewable));
|
1999-07-24 23:37:03 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-03-03 00:18:47 +08:00
|
|
|
static void
|
|
|
|
gradient_editor_drop_color (GtkWidget *widget,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
const GimpRGB *color,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2005-05-05 21:59:32 +08:00
|
|
|
GimpGradientEditor *editor = GIMP_GRADIENT_EDITOR (data);
|
|
|
|
GimpGradient *gradient;
|
2005-03-03 00:18:47 +08:00
|
|
|
gdouble xpos;
|
|
|
|
GimpGradientSegment *seg, *lseg, *rseg;
|
|
|
|
|
|
|
|
gradient = GIMP_GRADIENT (GIMP_DATA_EDITOR (editor)->data);
|
|
|
|
|
|
|
|
xpos = control_calc_g_pos (editor, x);
|
|
|
|
seg = gimp_gradient_get_segment_at (gradient, xpos);
|
|
|
|
|
|
|
|
gimp_data_freeze (GIMP_DATA (gradient));
|
|
|
|
|
|
|
|
gimp_gradient_segment_split_midpoint (gradient, seg, &lseg, &rseg);
|
|
|
|
|
|
|
|
if (lseg)
|
|
|
|
{
|
|
|
|
lseg->right = xpos;
|
|
|
|
lseg->middle = (lseg->left + lseg->right) / 2.0;
|
|
|
|
lseg->right_color = *color;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rseg)
|
|
|
|
{
|
|
|
|
rseg->left = xpos;
|
|
|
|
rseg->middle = (rseg->left + rseg->right) / 2.0;
|
|
|
|
rseg->left_color = *color;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_data_thaw (GIMP_DATA (gradient));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gradient_editor_control_drop_color (GtkWidget *widget,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
const GimpRGB *color,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2005-05-05 21:59:32 +08:00
|
|
|
GimpGradientEditor *editor = GIMP_GRADIENT_EDITOR (data);
|
|
|
|
GimpGradient *gradient;
|
2005-03-03 00:18:47 +08:00
|
|
|
gdouble xpos;
|
|
|
|
GimpGradientSegment *seg, *lseg, *rseg;
|
|
|
|
GradientEditorDragMode handle;
|
|
|
|
|
|
|
|
gradient = GIMP_GRADIENT (GIMP_DATA_EDITOR (editor)->data);
|
|
|
|
|
|
|
|
xpos = control_calc_g_pos (editor, x);
|
|
|
|
seg_get_closest_handle (gradient, xpos, &seg, &handle);
|
|
|
|
|
|
|
|
if (seg)
|
|
|
|
{
|
|
|
|
if (handle == GRAD_DRAG_LEFT)
|
|
|
|
{
|
|
|
|
lseg = seg->prev;
|
|
|
|
rseg = seg;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lseg = gimp_gradient_get_segment_at (gradient, xpos);
|
|
|
|
rseg = NULL;
|
|
|
|
}
|
2005-05-05 21:59:32 +08:00
|
|
|
|
2005-03-03 00:18:47 +08:00
|
|
|
gimp_data_freeze (GIMP_DATA (gradient));
|
|
|
|
|
|
|
|
if (lseg)
|
|
|
|
lseg->right_color = *color;
|
|
|
|
|
|
|
|
if (rseg)
|
|
|
|
rseg->left_color = *color;
|
|
|
|
|
|
|
|
gimp_data_thaw (GIMP_DATA (gradient));
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
2002-03-08 08:27:45 +08:00
|
|
|
gradient_editor_scrollbar_update (GtkAdjustment *adjustment,
|
|
|
|
GimpGradientEditor *editor)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-08-26 22:20:30 +08:00
|
|
|
GimpViewRendererGradient *renderer;
|
|
|
|
gchar *str1;
|
|
|
|
gchar *str2;
|
2002-03-08 08:27:45 +08:00
|
|
|
|
|
|
|
str1 = g_strdup_printf (_("Zoom factor: %d:1"),
|
|
|
|
editor->zoom_factor);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
str2 = g_strdup_printf (_("Displaying [%0.6f, %0.6f]"),
|
|
|
|
adjustment->value,
|
|
|
|
adjustment->value + adjustment->page_size);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-06-05 19:14:38 +08:00
|
|
|
gradient_editor_set_hint (editor, str1, str2, NULL, NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
g_free (str1);
|
|
|
|
g_free (str2);
|
|
|
|
|
2004-08-26 22:20:30 +08:00
|
|
|
renderer = GIMP_VIEW_RENDERER_GRADIENT (GIMP_VIEW (editor->preview)->renderer);
|
2003-03-10 22:07:22 +08:00
|
|
|
|
2004-08-26 22:20:30 +08:00
|
|
|
gimp_view_renderer_gradient_set_offsets (renderer,
|
|
|
|
adjustment->value,
|
|
|
|
adjustment->value +
|
|
|
|
adjustment->page_size,
|
|
|
|
editor->instant_update);
|
2003-03-10 22:07:22 +08:00
|
|
|
gimp_gradient_editor_update (editor);
|
1999-07-24 23:37:03 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
static void
|
2002-03-08 08:27:45 +08:00
|
|
|
gradient_editor_instant_update_update (GtkWidget *widget,
|
|
|
|
GimpGradientEditor *editor)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-07-24 23:37:03 +08:00
|
|
|
if (GTK_TOGGLE_BUTTON (widget)->active)
|
|
|
|
{
|
2001-11-27 23:44:02 +08:00
|
|
|
editor->instant_update = TRUE;
|
|
|
|
gtk_range_set_update_policy (GTK_RANGE (editor->scrollbar),
|
2004-08-25 01:16:46 +08:00
|
|
|
GTK_UPDATE_CONTINUOUS);
|
1999-07-24 23:37:03 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-11-27 23:44:02 +08:00
|
|
|
editor->instant_update = FALSE;
|
|
|
|
gtk_range_set_update_policy (GTK_RANGE (editor->scrollbar),
|
2004-08-25 01:16:46 +08:00
|
|
|
GTK_UPDATE_DELAYED);
|
1999-07-24 23:37:03 +08:00
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-27 23:44:02 +08:00
|
|
|
static void
|
2002-03-08 08:27:45 +08:00
|
|
|
gradient_editor_set_hint (GimpGradientEditor *editor,
|
|
|
|
const gchar *str1,
|
|
|
|
const gchar *str2,
|
2004-06-05 19:14:38 +08:00
|
|
|
const gchar *str3,
|
2004-08-25 01:16:46 +08:00
|
|
|
const gchar *str4)
|
2001-11-27 23:44:02 +08:00
|
|
|
{
|
2002-03-08 08:27:45 +08:00
|
|
|
gtk_label_set_text (GTK_LABEL (editor->hint_label1), str1);
|
|
|
|
gtk_label_set_text (GTK_LABEL (editor->hint_label2), str2);
|
|
|
|
gtk_label_set_text (GTK_LABEL (editor->hint_label3), str3);
|
2004-06-05 19:14:38 +08:00
|
|
|
gtk_label_set_text (GTK_LABEL (editor->hint_label4), str4);
|
|
|
|
|
2001-11-27 23:44:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-26 22:20:30 +08:00
|
|
|
/***** Gradient view functions *****/
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
static gboolean
|
2004-08-26 22:20:30 +08:00
|
|
|
view_events (GtkWidget *widget,
|
|
|
|
GdkEvent *event,
|
|
|
|
GimpGradientEditor *editor)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2005-05-05 21:59:32 +08:00
|
|
|
gint x, y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
if (! GIMP_DATA_EDITOR (editor)->data)
|
|
|
|
return TRUE;
|
|
|
|
|
1999-07-24 23:37:03 +08:00
|
|
|
switch (event->type)
|
|
|
|
{
|
|
|
|
case GDK_LEAVE_NOTIFY:
|
2004-06-05 19:14:38 +08:00
|
|
|
gradient_editor_set_hint (editor, NULL, NULL, NULL, NULL);
|
1999-07-24 23:37:03 +08:00
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-07-24 23:37:03 +08:00
|
|
|
case GDK_MOTION_NOTIFY:
|
2005-05-05 21:59:32 +08:00
|
|
|
{
|
|
|
|
GdkEventMotion *mevent = (GdkEventMotion *) event;
|
|
|
|
|
|
|
|
gtk_widget_get_pointer (editor->preview, &x, &y);
|
|
|
|
|
|
|
|
if (x != editor->preview_last_x)
|
|
|
|
{
|
|
|
|
editor->preview_last_x = x;
|
|
|
|
|
|
|
|
if (editor->preview_button_down)
|
|
|
|
{
|
|
|
|
if (mevent->state & GDK_CONTROL_MASK)
|
|
|
|
view_set_background (editor, x);
|
|
|
|
else
|
|
|
|
view_set_foreground (editor, x);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
view_set_hint (editor, x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-07-24 23:37:03 +08:00
|
|
|
break;
|
1999-07-23 04:42:59 +08:00
|
|
|
|
1999-07-24 23:37:03 +08:00
|
|
|
case GDK_BUTTON_PRESS:
|
2005-05-05 21:59:32 +08:00
|
|
|
{
|
|
|
|
GdkEventButton *bevent = (GdkEventButton *) event;
|
|
|
|
|
|
|
|
gtk_widget_get_pointer (editor->preview, &x, &y);
|
|
|
|
|
|
|
|
switch (bevent->button)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
editor->preview_last_x = x;
|
|
|
|
editor->preview_button_down = TRUE;
|
|
|
|
if (bevent->state & GDK_CONTROL_MASK)
|
|
|
|
view_set_background (editor, x);
|
|
|
|
else
|
|
|
|
view_set_foreground (editor, x);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
if (GIMP_DATA_EDITOR (editor)->data_editable)
|
|
|
|
gimp_editor_popup_menu (GIMP_EDITOR (editor), NULL, NULL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-08-10 00:39:08 +08:00
|
|
|
break;
|
1999-07-25 00:27:47 +08:00
|
|
|
|
2001-08-10 00:39:08 +08:00
|
|
|
case GDK_SCROLL:
|
2005-05-05 21:59:32 +08:00
|
|
|
{
|
|
|
|
GdkEventScroll *sevent = (GdkEventScroll *) event;
|
|
|
|
|
|
|
|
if (sevent->state & GDK_SHIFT_MASK)
|
|
|
|
{
|
|
|
|
if (sevent->direction == GDK_SCROLL_UP)
|
|
|
|
gimp_gradient_editor_zoom (editor, GIMP_ZOOM_IN);
|
|
|
|
else
|
|
|
|
gimp_gradient_editor_zoom (editor, GIMP_ZOOM_OUT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkAdjustment *adj = GTK_ADJUSTMENT (editor->scroll_data);
|
|
|
|
|
|
|
|
gfloat new_value = adj->value + ((sevent->direction == GDK_SCROLL_UP) ?
|
|
|
|
-adj->page_increment / 2 :
|
|
|
|
adj->page_increment / 2);
|
|
|
|
|
|
|
|
new_value = CLAMP (new_value, adj->lower, adj->upper - adj->page_size);
|
|
|
|
|
|
|
|
gtk_adjustment_set_value (adj, new_value);
|
|
|
|
}
|
|
|
|
}
|
1999-07-24 23:37:03 +08:00
|
|
|
break;
|
1999-07-23 04:42:59 +08:00
|
|
|
|
1999-07-24 23:37:03 +08:00
|
|
|
case GDK_BUTTON_RELEASE:
|
2001-11-27 23:44:02 +08:00
|
|
|
if (editor->preview_button_down)
|
2004-08-25 01:16:46 +08:00
|
|
|
{
|
2005-05-05 21:59:32 +08:00
|
|
|
GdkEventButton *bevent = (GdkEventButton *) event;
|
2004-08-25 01:16:46 +08:00
|
|
|
|
2005-05-05 21:59:32 +08:00
|
|
|
gtk_widget_get_pointer (editor->preview, &x, &y);
|
2004-08-25 01:16:46 +08:00
|
|
|
|
|
|
|
editor->preview_last_x = x;
|
|
|
|
editor->preview_button_down = FALSE;
|
|
|
|
if (bevent->state & GDK_CONTROL_MASK)
|
2004-08-26 22:20:30 +08:00
|
|
|
view_set_background (editor, x);
|
2004-08-25 01:16:46 +08:00
|
|
|
else
|
2004-08-26 22:20:30 +08:00
|
|
|
view_set_foreground (editor, x);
|
2004-08-25 01:16:46 +08:00
|
|
|
break;
|
|
|
|
}
|
1999-07-24 23:37:03 +08:00
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-07-24 23:37:03 +08:00
|
|
|
default:
|
2003-03-10 22:07:22 +08:00
|
|
|
return FALSE;
|
1999-07-24 23:37:03 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-08-10 00:39:08 +08:00
|
|
|
return TRUE;
|
1999-07-24 23:37:03 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
static void
|
2004-08-26 22:20:30 +08:00
|
|
|
view_set_hint (GimpGradientEditor *editor,
|
|
|
|
gint x)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-03-08 08:27:45 +08:00
|
|
|
GimpDataEditor *data_editor;
|
|
|
|
gdouble xpos;
|
|
|
|
GimpRGB rgb;
|
|
|
|
GimpHSV hsv;
|
|
|
|
gchar *str1;
|
|
|
|
gchar *str2;
|
|
|
|
gchar *str3;
|
2004-06-05 19:14:38 +08:00
|
|
|
gchar *str4;
|
2002-03-08 08:27:45 +08:00
|
|
|
|
|
|
|
data_editor = GIMP_DATA_EDITOR (editor);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-27 23:44:02 +08:00
|
|
|
xpos = control_calc_g_pos (editor, x);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-02-27 07:55:50 +08:00
|
|
|
gimp_gradient_get_color_at (GIMP_GRADIENT (data_editor->data), NULL,
|
2003-07-22 22:24:11 +08:00
|
|
|
xpos, FALSE, &rgb);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-21 00:28:05 +08:00
|
|
|
gimp_rgb_to_hsv (&rgb, &hsv);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
str1 = g_strdup_printf (_("Position: %0.6f"), xpos);
|
|
|
|
|
2004-06-05 19:14:38 +08:00
|
|
|
str2 = g_strdup_printf (_("RGB (%0.3f, %0.3f, %0.3f)"),
|
|
|
|
rgb.r, rgb.g, rgb.b);
|
2002-03-08 08:27:45 +08:00
|
|
|
|
|
|
|
str3 = g_strdup_printf (_("HSV (%0.3f, %0.3f, %0.3f)"),
|
|
|
|
hsv.h * 360.0, hsv.s, hsv.v);
|
2004-06-05 19:14:38 +08:00
|
|
|
str4 = g_strdup_printf (_("Intensity: %0.3f Opacity: %0.3f"),
|
|
|
|
GIMP_RGB_INTENSITY (rgb.r, rgb.g, rgb.b), rgb.a);
|
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
|
2004-06-05 19:14:38 +08:00
|
|
|
gradient_editor_set_hint (editor, str1, str2, str3, str4);
|
2002-03-08 08:27:45 +08:00
|
|
|
|
|
|
|
g_free (str1);
|
|
|
|
g_free (str2);
|
|
|
|
g_free (str3);
|
2004-06-05 19:14:38 +08:00
|
|
|
g_free (str4);
|
1999-07-24 23:37:03 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
static void
|
2004-08-26 22:20:30 +08:00
|
|
|
view_set_foreground (GimpGradientEditor *editor,
|
|
|
|
gint x)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-03-08 08:27:45 +08:00
|
|
|
GimpGradient *gradient;
|
|
|
|
GimpContext *user_context;
|
|
|
|
GimpRGB color;
|
|
|
|
gdouble xpos;
|
|
|
|
gchar *str2;
|
|
|
|
gchar *str3;
|
|
|
|
|
|
|
|
gradient = GIMP_GRADIENT (GIMP_DATA_EDITOR (editor)->data);
|
|
|
|
|
2003-10-12 00:50:35 +08:00
|
|
|
user_context = gimp_get_user_context (GIMP_DATA_EDITOR (editor)->data_factory->gimp);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-27 23:44:02 +08:00
|
|
|
xpos = control_calc_g_pos (editor, x);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-02-27 07:55:50 +08:00
|
|
|
gimp_gradient_get_color_at (gradient, NULL, xpos, FALSE, &color);
|
2002-03-08 08:27:45 +08:00
|
|
|
|
|
|
|
gimp_context_set_foreground (user_context, &color);
|
2001-11-27 23:44:02 +08:00
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
str2 = g_strdup_printf (_("RGB (%d, %d, %d)"),
|
|
|
|
(gint) (color.r * 255.0),
|
|
|
|
(gint) (color.g * 255.0),
|
|
|
|
(gint) (color.b * 255.0));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-06-09 20:53:42 +08:00
|
|
|
str3 = g_strdup_printf ("(%0.3f, %0.3f, %0.3f)", color.r, color.g, color.b);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-06-05 19:14:38 +08:00
|
|
|
gradient_editor_set_hint (editor,
|
|
|
|
_("Foreground color set to:"), str2, str3, NULL);
|
2002-03-08 08:27:45 +08:00
|
|
|
|
|
|
|
g_free (str2);
|
|
|
|
g_free (str3);
|
1999-07-23 04:42:59 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-07-23 04:42:59 +08:00
|
|
|
static void
|
2004-08-26 22:20:30 +08:00
|
|
|
view_set_background (GimpGradientEditor *editor,
|
|
|
|
gint x)
|
1999-07-23 04:42:59 +08:00
|
|
|
{
|
2002-03-08 08:27:45 +08:00
|
|
|
GimpGradient *gradient;
|
|
|
|
GimpContext *user_context;
|
|
|
|
GimpRGB color;
|
|
|
|
gdouble xpos;
|
|
|
|
gchar *str2;
|
|
|
|
gchar *str3;
|
|
|
|
|
|
|
|
gradient = GIMP_GRADIENT (GIMP_DATA_EDITOR (editor)->data);
|
|
|
|
|
2003-10-12 00:50:35 +08:00
|
|
|
user_context = gimp_get_user_context (GIMP_DATA_EDITOR (editor)->data_factory->gimp);
|
1999-07-23 04:42:59 +08:00
|
|
|
|
2001-11-27 23:44:02 +08:00
|
|
|
xpos = control_calc_g_pos (editor, x);
|
2002-03-08 08:27:45 +08:00
|
|
|
|
2005-02-27 07:55:50 +08:00
|
|
|
gimp_gradient_get_color_at (gradient, NULL, xpos, FALSE, &color);
|
2002-03-08 08:27:45 +08:00
|
|
|
|
|
|
|
gimp_context_set_background (user_context, &color);
|
|
|
|
|
|
|
|
str2 = g_strdup_printf (_("RGB (%d, %d, %d)"),
|
|
|
|
(gint) (color.r * 255.0),
|
|
|
|
(gint) (color.g * 255.0),
|
|
|
|
(gint) (color.b * 255.0));
|
|
|
|
|
|
|
|
str3 = g_strdup_printf (_("(%0.3f, %0.3f, %0.3f)"),
|
|
|
|
color.r, color.g, color.b);
|
|
|
|
|
2004-06-05 19:14:38 +08:00
|
|
|
gradient_editor_set_hint (editor,
|
|
|
|
_("Background color set to:"), str2, str3, NULL);
|
2002-03-08 08:27:45 +08:00
|
|
|
|
|
|
|
g_free (str2);
|
|
|
|
g_free (str3);
|
1999-07-23 04:42:59 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/***** Gradient control functions *****/
|
|
|
|
|
|
|
|
/* *** WARNING *** WARNING *** WARNING ***
|
|
|
|
*
|
|
|
|
* All the event-handling code for the gradient control widget is
|
|
|
|
* extremely hairy. You are not expected to understand it. If you
|
|
|
|
* find bugs, mail me unless you are very brave and you want to fix
|
|
|
|
* them yourself ;-)
|
|
|
|
*/
|
|
|
|
|
2005-05-05 21:59:32 +08:00
|
|
|
static gboolean
|
2002-03-08 08:27:45 +08:00
|
|
|
control_events (GtkWidget *widget,
|
2004-08-25 01:16:46 +08:00
|
|
|
GdkEvent *event,
|
|
|
|
GimpGradientEditor *editor)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-02-13 08:12:15 +08:00
|
|
|
GimpGradient *gradient;
|
2001-02-11 03:35:29 +08:00
|
|
|
GimpGradientSegment *seg;
|
2001-02-13 08:12:15 +08:00
|
|
|
gint x, y;
|
|
|
|
guint32 time;
|
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
if (! GIMP_DATA_EDITOR (editor)->data)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
gradient = GIMP_GRADIENT (GIMP_DATA_EDITOR (editor)->data);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-07-24 23:37:03 +08:00
|
|
|
switch (event->type)
|
|
|
|
{
|
|
|
|
case GDK_EXPOSE:
|
2001-11-27 23:44:02 +08:00
|
|
|
control_update (editor, gradient, FALSE);
|
1999-07-24 23:37:03 +08:00
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-07-24 23:37:03 +08:00
|
|
|
case GDK_LEAVE_NOTIFY:
|
2004-06-05 19:14:38 +08:00
|
|
|
gradient_editor_set_hint (editor, NULL, NULL, NULL, NULL);
|
1999-07-24 23:37:03 +08:00
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-07-24 23:37:03 +08:00
|
|
|
case GDK_BUTTON_PRESS:
|
2001-11-27 23:44:02 +08:00
|
|
|
if (editor->control_drag_mode == GRAD_DRAG_NONE)
|
2004-08-25 01:16:46 +08:00
|
|
|
{
|
2005-05-05 21:59:32 +08:00
|
|
|
GdkEventButton *bevent = (GdkEventButton *) event;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-05-05 21:59:32 +08:00
|
|
|
gtk_widget_get_pointer (editor->control, &x, &y);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
editor->control_last_x = x;
|
|
|
|
editor->control_click_time = bevent->time;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
control_button_press (editor,
|
|
|
|
x, y, bevent->button, bevent->state);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
if (editor->control_drag_mode != GRAD_DRAG_NONE)
|
2004-05-31 06:04:16 +08:00
|
|
|
{
|
|
|
|
gtk_grab_add (widget);
|
|
|
|
|
|
|
|
g_signal_handlers_block_by_func (gradient,
|
|
|
|
gimp_gradient_editor_gradient_dirty,
|
|
|
|
editor);
|
|
|
|
|
|
|
|
if (! editor->instant_update)
|
2004-06-13 06:13:31 +08:00
|
|
|
gimp_data_freeze (GIMP_DATA (gradient));
|
2004-05-31 06:04:16 +08:00
|
|
|
}
|
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
}
|
1999-07-24 23:37:03 +08:00
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-03-10 22:07:22 +08:00
|
|
|
case GDK_SCROLL:
|
2005-05-05 21:59:32 +08:00
|
|
|
{
|
|
|
|
GdkEventScroll *sevent = (GdkEventScroll *) event;
|
|
|
|
|
|
|
|
if (sevent->state & GDK_SHIFT_MASK)
|
|
|
|
{
|
|
|
|
if (sevent->direction == GDK_SCROLL_UP)
|
|
|
|
gimp_gradient_editor_zoom (editor, GIMP_ZOOM_IN);
|
|
|
|
else
|
|
|
|
gimp_gradient_editor_zoom (editor, GIMP_ZOOM_OUT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkAdjustment *adj = GTK_ADJUSTMENT (editor->scroll_data);
|
|
|
|
|
|
|
|
gfloat new_value = adj->value + ((sevent->direction == GDK_SCROLL_UP) ?
|
|
|
|
-adj->page_increment / 2 :
|
|
|
|
adj->page_increment / 2);
|
|
|
|
|
|
|
|
new_value = CLAMP (new_value, adj->lower, adj->upper - adj->page_size);
|
|
|
|
|
|
|
|
gtk_adjustment_set_value (adj, new_value);
|
|
|
|
}
|
|
|
|
}
|
2003-03-10 22:07:22 +08:00
|
|
|
break;
|
|
|
|
|
1999-07-24 23:37:03 +08:00
|
|
|
case GDK_BUTTON_RELEASE:
|
2004-06-05 19:14:38 +08:00
|
|
|
gradient_editor_set_hint (editor, NULL, NULL, NULL, NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-27 23:44:02 +08:00
|
|
|
if (editor->control_drag_mode != GRAD_DRAG_NONE)
|
2004-08-25 01:16:46 +08:00
|
|
|
{
|
2004-05-31 06:04:16 +08:00
|
|
|
if (! editor->instant_update)
|
2004-06-13 06:13:31 +08:00
|
|
|
gimp_data_thaw (GIMP_DATA (gradient));
|
2004-05-31 06:04:16 +08:00
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (gradient,
|
|
|
|
gimp_gradient_editor_gradient_dirty,
|
|
|
|
editor);
|
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
gtk_grab_remove (widget);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
gtk_widget_get_pointer (editor->control, &x, &y);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
time = ((GdkEventButton *) event)->time;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
if ((time - editor->control_click_time) >= GRAD_MOVE_TIME)
|
|
|
|
{
|
|
|
|
/* stuff was done in motion */
|
|
|
|
}
|
|
|
|
else if ((editor->control_drag_mode == GRAD_DRAG_MIDDLE) ||
|
|
|
|
(editor->control_drag_mode == GRAD_DRAG_ALL))
|
|
|
|
{
|
|
|
|
seg = editor->control_drag_segment;
|
2000-12-20 05:49:46 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
if ((editor->control_drag_mode == GRAD_DRAG_ALL) &&
|
|
|
|
editor->control_compress)
|
|
|
|
control_extend_selection (editor, seg,
|
|
|
|
control_calc_g_pos (editor,
|
|
|
|
x));
|
|
|
|
else
|
|
|
|
control_select_single_segment (editor, seg);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
gimp_gradient_editor_update (editor);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
editor->control_drag_mode = GRAD_DRAG_NONE;
|
|
|
|
editor->control_compress = FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
control_do_hint (editor, x, y);
|
|
|
|
}
|
1999-07-24 23:37:03 +08:00
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-07-24 23:37:03 +08:00
|
|
|
case GDK_MOTION_NOTIFY:
|
2001-11-27 23:44:02 +08:00
|
|
|
gtk_widget_get_pointer (editor->control, &x, &y);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-27 23:44:02 +08:00
|
|
|
if (x != editor->control_last_x)
|
2004-08-25 01:16:46 +08:00
|
|
|
{
|
|
|
|
editor->control_last_x = x;
|
|
|
|
|
|
|
|
if (editor->control_drag_mode != GRAD_DRAG_NONE)
|
|
|
|
{
|
|
|
|
time = ((GdkEventButton *) event)->time;
|
|
|
|
|
|
|
|
if ((time - editor->control_click_time) >= GRAD_MOVE_TIME)
|
|
|
|
control_motion (editor, gradient, x);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_gradient_editor_update (editor);
|
|
|
|
|
|
|
|
control_do_hint (editor, x, y);
|
|
|
|
}
|
|
|
|
}
|
1999-07-24 23:37:03 +08:00
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-07-24 23:37:03 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
return TRUE;
|
1999-07-24 23:37:03 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
static void
|
2002-03-08 08:27:45 +08:00
|
|
|
control_do_hint (GimpGradientEditor *editor,
|
2004-08-25 01:16:46 +08:00
|
|
|
gint x,
|
|
|
|
gint y)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-11-27 23:44:02 +08:00
|
|
|
GimpGradient *gradient;
|
|
|
|
GimpGradientSegment *seg;
|
|
|
|
GradientEditorDragMode handle;
|
|
|
|
gboolean in_handle;
|
2002-12-20 00:33:29 +08:00
|
|
|
gdouble pos;
|
|
|
|
gchar *str;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
gradient = GIMP_GRADIENT (GIMP_DATA_EDITOR (editor)->data);
|
2001-02-13 08:12:15 +08:00
|
|
|
|
2001-11-27 23:44:02 +08:00
|
|
|
pos = control_calc_g_pos (editor, x);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
if ((pos < 0.0) || (pos > 1.0))
|
|
|
|
return;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-13 08:12:15 +08:00
|
|
|
seg_get_closest_handle (gradient, pos, &seg, &handle);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-27 23:44:02 +08:00
|
|
|
in_handle = control_point_in_handle (editor, gradient,
|
2004-08-25 01:16:46 +08:00
|
|
|
x, y, seg, handle);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
if (in_handle)
|
|
|
|
{
|
|
|
|
switch (handle)
|
2004-08-25 01:16:46 +08:00
|
|
|
{
|
|
|
|
case GRAD_DRAG_LEFT:
|
|
|
|
if (seg != NULL)
|
|
|
|
{
|
|
|
|
if (seg->prev != NULL)
|
2002-12-20 00:33:29 +08:00
|
|
|
{
|
|
|
|
str = g_strdup_printf (_("%s%sDrag: move & compress"),
|
2004-06-29 07:30:57 +08:00
|
|
|
gimp_get_mod_string (GDK_SHIFT_MASK),
|
2002-12-20 00:33:29 +08:00
|
|
|
gimp_get_mod_separator ());
|
|
|
|
|
|
|
|
gradient_editor_set_hint (editor,
|
2004-06-05 19:14:38 +08:00
|
|
|
NULL,
|
2002-12-20 00:33:29 +08:00
|
|
|
_("Drag: move"),
|
2004-06-05 19:14:38 +08:00
|
|
|
str,
|
2004-08-25 01:16:46 +08:00
|
|
|
NULL);
|
2002-12-20 00:33:29 +08:00
|
|
|
g_free (str);
|
|
|
|
}
|
2004-08-25 01:16:46 +08:00
|
|
|
else
|
2002-12-20 00:33:29 +08:00
|
|
|
{
|
|
|
|
str = g_strdup_printf (_("%s%sClick: extend selection"),
|
2004-06-29 07:30:57 +08:00
|
|
|
gimp_get_mod_string (GDK_SHIFT_MASK),
|
2002-12-20 00:33:29 +08:00
|
|
|
gimp_get_mod_separator ());
|
|
|
|
|
|
|
|
gradient_editor_set_hint (editor,
|
2004-06-05 19:14:38 +08:00
|
|
|
NULL,
|
2002-12-20 00:33:29 +08:00
|
|
|
_("Click: select"),
|
2004-06-05 19:14:38 +08:00
|
|
|
str,
|
2004-08-25 01:16:46 +08:00
|
|
|
NULL);
|
2002-12-20 00:33:29 +08:00
|
|
|
g_free (str);
|
|
|
|
}
|
2004-08-25 01:16:46 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-12-20 00:33:29 +08:00
|
|
|
str = g_strdup_printf (_("%s%sClick: extend selection"),
|
2004-06-29 07:30:57 +08:00
|
|
|
gimp_get_mod_string (GDK_SHIFT_MASK),
|
2002-12-20 00:33:29 +08:00
|
|
|
gimp_get_mod_separator ());
|
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
gradient_editor_set_hint (editor,
|
2004-06-05 19:14:38 +08:00
|
|
|
NULL,
|
2002-03-08 08:27:45 +08:00
|
|
|
_("Click: select"),
|
2004-06-05 19:14:38 +08:00
|
|
|
str,
|
2004-08-25 01:16:46 +08:00
|
|
|
NULL);
|
2002-12-20 00:33:29 +08:00
|
|
|
g_free (str);
|
2004-08-25 01:16:46 +08:00
|
|
|
}
|
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
case GRAD_DRAG_MIDDLE:
|
2002-12-20 00:33:29 +08:00
|
|
|
str = g_strdup_printf (_("%s%sClick: extend selection"),
|
2004-06-29 07:30:57 +08:00
|
|
|
gimp_get_mod_string (GDK_SHIFT_MASK),
|
2002-12-20 00:33:29 +08:00
|
|
|
gimp_get_mod_separator ());
|
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
gradient_editor_set_hint (editor,
|
2004-06-05 19:14:38 +08:00
|
|
|
NULL,
|
2002-03-08 08:27:45 +08:00
|
|
|
_("Click: select Drag: move"),
|
2004-06-05 19:14:38 +08:00
|
|
|
str,
|
2004-08-25 01:16:46 +08:00
|
|
|
NULL);
|
2002-12-20 00:33:29 +08:00
|
|
|
g_free (str);
|
2004-08-25 01:16:46 +08:00
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
default:
|
2001-11-27 23:44:02 +08:00
|
|
|
g_warning ("%s: in_handle is true, but received handle type %d.",
|
2004-05-12 16:13:33 +08:00
|
|
|
G_STRFUNC, in_handle);
|
2004-08-25 01:16:46 +08:00
|
|
|
break;
|
|
|
|
}
|
1999-09-28 01:58:10 +08:00
|
|
|
}
|
|
|
|
else
|
2001-11-27 23:44:02 +08:00
|
|
|
{
|
2002-12-20 00:33:29 +08:00
|
|
|
gchar *str2;
|
|
|
|
|
|
|
|
str = g_strdup_printf (_("%s%sClick: extend selection"),
|
2004-06-29 07:30:57 +08:00
|
|
|
gimp_get_mod_string (GDK_SHIFT_MASK),
|
2002-12-20 00:33:29 +08:00
|
|
|
gimp_get_mod_separator ());
|
|
|
|
str2 = g_strdup_printf (_("%s%sDrag: move & compress"),
|
2004-06-29 07:30:57 +08:00
|
|
|
gimp_get_mod_string (GDK_SHIFT_MASK),
|
2002-12-20 00:33:29 +08:00
|
|
|
gimp_get_mod_separator ());
|
|
|
|
|
2001-11-27 23:44:02 +08:00
|
|
|
gradient_editor_set_hint (editor,
|
2002-03-08 08:27:45 +08:00
|
|
|
_("Click: select Drag: move"),
|
2002-12-20 00:33:29 +08:00
|
|
|
str,
|
2004-06-05 19:14:38 +08:00
|
|
|
str2,
|
2004-08-25 01:16:46 +08:00
|
|
|
NULL);
|
2002-12-20 00:33:29 +08:00
|
|
|
g_free (str);
|
|
|
|
g_free (str2);
|
2001-11-27 23:44:02 +08:00
|
|
|
}
|
1999-09-28 01:58:10 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
static void
|
2002-03-08 08:27:45 +08:00
|
|
|
control_button_press (GimpGradientEditor *editor,
|
2004-08-25 01:16:46 +08:00
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
guint button,
|
|
|
|
guint state)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-11-27 23:44:02 +08:00
|
|
|
GimpGradient *gradient;
|
|
|
|
GimpGradientSegment *seg;
|
|
|
|
GradientEditorDragMode handle;
|
2003-04-30 22:31:27 +08:00
|
|
|
gdouble xpos;
|
2001-11-27 23:44:02 +08:00
|
|
|
gboolean in_handle;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
gradient = GIMP_GRADIENT (GIMP_DATA_EDITOR (editor)->data);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-03-10 22:07:22 +08:00
|
|
|
if (button == 3)
|
1999-07-25 00:27:47 +08:00
|
|
|
{
|
2004-05-17 21:38:03 +08:00
|
|
|
gimp_editor_popup_menu (GIMP_EDITOR (editor), NULL, NULL);
|
1999-07-25 00:27:47 +08:00
|
|
|
return;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-07-25 00:27:47 +08:00
|
|
|
/* Find the closest handle */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-27 23:44:02 +08:00
|
|
|
xpos = control_calc_g_pos (editor, x);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-13 08:12:15 +08:00
|
|
|
seg_get_closest_handle (gradient, xpos, &seg, &handle);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-03-10 22:07:22 +08:00
|
|
|
in_handle = control_point_in_handle (editor, gradient, x, y, seg, handle);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-07-25 00:27:47 +08:00
|
|
|
/* Now see what we have */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-07-25 00:27:47 +08:00
|
|
|
if (in_handle)
|
|
|
|
{
|
|
|
|
switch (handle)
|
2004-08-25 01:16:46 +08:00
|
|
|
{
|
|
|
|
case GRAD_DRAG_LEFT:
|
|
|
|
if (seg != NULL)
|
|
|
|
{
|
|
|
|
/* Left handle of some segment */
|
|
|
|
if (state & GDK_SHIFT_MASK)
|
|
|
|
{
|
|
|
|
if (seg->prev != NULL)
|
|
|
|
{
|
|
|
|
editor->control_drag_mode = GRAD_DRAG_LEFT;
|
|
|
|
editor->control_drag_segment = seg;
|
|
|
|
editor->control_compress = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
control_extend_selection (editor, seg, xpos);
|
|
|
|
gimp_gradient_editor_update (editor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (seg->prev != NULL)
|
|
|
|
{
|
|
|
|
editor->control_drag_mode = GRAD_DRAG_LEFT;
|
|
|
|
editor->control_drag_segment = seg;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
control_select_single_segment (editor, seg);
|
|
|
|
gimp_gradient_editor_update (editor);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else /* seg == NULL */
|
|
|
|
{
|
|
|
|
/* Right handle of last segment */
|
|
|
|
seg = gimp_gradient_segment_get_last (gradient->segments);
|
|
|
|
|
|
|
|
if (state & GDK_SHIFT_MASK)
|
|
|
|
{
|
|
|
|
control_extend_selection (editor, seg, xpos);
|
|
|
|
gimp_gradient_editor_update (editor);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
control_select_single_segment (editor, seg);
|
|
|
|
gimp_gradient_editor_update (editor);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GRAD_DRAG_MIDDLE:
|
|
|
|
if (state & GDK_SHIFT_MASK)
|
|
|
|
{
|
|
|
|
control_extend_selection (editor, seg, xpos);
|
|
|
|
gimp_gradient_editor_update (editor);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
editor->control_drag_mode = GRAD_DRAG_MIDDLE;
|
|
|
|
editor->control_drag_segment = seg;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
2001-11-27 23:44:02 +08:00
|
|
|
g_warning ("%s: in_handle is true, but received handle type %d.",
|
2004-05-12 16:13:33 +08:00
|
|
|
G_STRFUNC, in_handle);
|
2004-08-25 01:16:46 +08:00
|
|
|
return;
|
|
|
|
}
|
1999-07-25 00:27:47 +08:00
|
|
|
}
|
|
|
|
else /* !in_handle */
|
|
|
|
{
|
2001-02-13 08:12:15 +08:00
|
|
|
seg = gimp_gradient_get_segment_at (gradient, xpos);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-27 23:44:02 +08:00
|
|
|
editor->control_drag_mode = GRAD_DRAG_ALL;
|
|
|
|
editor->control_drag_segment = seg;
|
|
|
|
editor->control_last_gx = xpos;
|
|
|
|
editor->control_orig_pos = xpos;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-07-25 00:27:47 +08:00
|
|
|
if (state & GDK_SHIFT_MASK)
|
2004-08-25 01:16:46 +08:00
|
|
|
editor->control_compress = TRUE;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-07-25 00:27:47 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
static gboolean
|
2002-03-08 08:27:45 +08:00
|
|
|
control_point_in_handle (GimpGradientEditor *editor,
|
2004-08-25 01:16:46 +08:00
|
|
|
GimpGradient *gradient,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
GimpGradientSegment *seg,
|
|
|
|
GradientEditorDragMode handle)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-09-28 01:58:10 +08:00
|
|
|
gint handle_pos;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
switch (handle)
|
|
|
|
{
|
|
|
|
case GRAD_DRAG_LEFT:
|
|
|
|
if (seg)
|
2004-08-25 01:16:46 +08:00
|
|
|
{
|
|
|
|
handle_pos = control_calc_p_pos (editor, seg->left);
|
|
|
|
}
|
1999-09-28 01:58:10 +08:00
|
|
|
else
|
2004-08-25 01:16:46 +08:00
|
|
|
{
|
|
|
|
seg = gimp_gradient_segment_get_last (gradient->segments);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-08-25 01:16:46 +08:00
|
|
|
handle_pos = control_calc_p_pos (editor, seg->right);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
case GRAD_DRAG_MIDDLE:
|
2001-11-27 23:44:02 +08:00
|
|
|
handle_pos = control_calc_p_pos (editor, seg->middle);
|
1999-09-28 01:58:10 +08:00
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
default:
|
2004-05-12 16:13:33 +08:00
|
|
|
g_warning ("%s: Cannot handle drag mode %d.", G_STRFUNC, handle);
|
1999-09-28 01:58:10 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
y /= 2;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
if ((x >= (handle_pos - y)) && (x <= (handle_pos + y)))
|
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/*****/
|
|
|
|
|
|
|
|
static void
|
2002-03-08 08:27:45 +08:00
|
|
|
control_select_single_segment (GimpGradientEditor *editor,
|
2004-08-25 01:16:46 +08:00
|
|
|
GimpGradientSegment *seg)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-11-27 23:44:02 +08:00
|
|
|
editor->control_sel_l = seg;
|
|
|
|
editor->control_sel_r = seg;
|
1999-09-28 01:58:10 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
static void
|
2002-03-08 08:27:45 +08:00
|
|
|
control_extend_selection (GimpGradientEditor *editor,
|
2004-08-25 01:16:46 +08:00
|
|
|
GimpGradientSegment *seg,
|
|
|
|
gdouble pos)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-11-27 23:44:02 +08:00
|
|
|
if (fabs (pos - editor->control_sel_l->left) <
|
|
|
|
fabs (pos - editor->control_sel_r->right))
|
|
|
|
editor->control_sel_l = seg;
|
1999-09-28 01:58:10 +08:00
|
|
|
else
|
2001-11-27 23:44:02 +08:00
|
|
|
editor->control_sel_r = seg;
|
1999-09-28 01:58:10 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/*****/
|
|
|
|
|
|
|
|
static void
|
2002-03-08 08:27:45 +08:00
|
|
|
control_motion (GimpGradientEditor *editor,
|
2004-08-25 01:16:46 +08:00
|
|
|
GimpGradient *gradient,
|
|
|
|
gint x)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-06-05 19:14:38 +08:00
|
|
|
GimpGradientSegment *seg = editor->control_drag_segment;
|
2002-03-08 08:27:45 +08:00
|
|
|
gdouble pos;
|
|
|
|
gdouble delta;
|
|
|
|
gchar *str = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-27 23:44:02 +08:00
|
|
|
switch (editor->control_drag_mode)
|
1999-09-28 01:58:10 +08:00
|
|
|
{
|
|
|
|
case GRAD_DRAG_LEFT:
|
2001-11-27 23:44:02 +08:00
|
|
|
pos = control_calc_g_pos (editor, x);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-27 23:44:02 +08:00
|
|
|
if (! editor->control_compress)
|
2004-06-03 06:50:15 +08:00
|
|
|
gimp_gradient_segment_set_left_pos (gradient, seg, pos);
|
1999-09-28 01:58:10 +08:00
|
|
|
else
|
2004-08-25 01:16:46 +08:00
|
|
|
control_compress_left (gradient,
|
2004-05-31 06:04:16 +08:00
|
|
|
editor->control_sel_l,
|
2004-08-25 01:16:46 +08:00
|
|
|
editor->control_sel_r,
|
|
|
|
seg, pos);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-10 05:31:01 +08:00
|
|
|
str = g_strdup_printf (_("Handle position: %0.6f"), seg->left);
|
1999-09-28 01:58:10 +08:00
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
case GRAD_DRAG_MIDDLE:
|
2001-11-27 23:44:02 +08:00
|
|
|
pos = control_calc_g_pos (editor, x);
|
2004-06-03 06:50:15 +08:00
|
|
|
|
|
|
|
gimp_gradient_segment_set_middle_pos (gradient, seg, pos);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-10 05:31:01 +08:00
|
|
|
str = g_strdup_printf (_("Handle position: %0.6f"), seg->middle);
|
1999-09-28 01:58:10 +08:00
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
case GRAD_DRAG_ALL:
|
2001-11-27 23:44:02 +08:00
|
|
|
pos = control_calc_g_pos (editor, x);
|
|
|
|
delta = pos - editor->control_last_gx;
|
|
|
|
|
|
|
|
if ((seg->left >= editor->control_sel_l->left) &&
|
2004-08-25 01:16:46 +08:00
|
|
|
(seg->right <= editor->control_sel_r->right))
|
|
|
|
delta = control_move (editor,
|
|
|
|
editor->control_sel_l,
|
|
|
|
editor->control_sel_r, delta);
|
1999-09-28 01:58:10 +08:00
|
|
|
else
|
2004-08-25 01:16:46 +08:00
|
|
|
delta = control_move (editor, seg, seg, delta);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-27 23:44:02 +08:00
|
|
|
editor->control_last_gx += delta;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-10 05:31:01 +08:00
|
|
|
str = g_strdup_printf (_("Distance: %0.6f"),
|
2004-08-25 01:16:46 +08:00
|
|
|
editor->control_last_gx -
|
|
|
|
editor->control_orig_pos);
|
1999-09-28 01:58:10 +08:00
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
default:
|
2001-11-27 23:44:02 +08:00
|
|
|
g_warning ("%s: Attempting to move bogus handle %d.",
|
2004-05-12 16:13:33 +08:00
|
|
|
G_STRFUNC, editor->control_drag_mode);
|
1999-09-28 01:58:10 +08:00
|
|
|
break;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-06-05 19:14:38 +08:00
|
|
|
gradient_editor_set_hint (editor, str, NULL, NULL, NULL);
|
|
|
|
g_free (str);
|
2000-01-10 05:31:01 +08:00
|
|
|
|
2003-03-10 22:07:22 +08:00
|
|
|
gimp_gradient_editor_update (editor);
|
1999-09-28 01:58:10 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
static void
|
2004-05-31 06:04:16 +08:00
|
|
|
control_compress_left (GimpGradient *gradient,
|
|
|
|
GimpGradientSegment *range_l,
|
2004-08-25 01:16:46 +08:00
|
|
|
GimpGradientSegment *range_r,
|
|
|
|
GimpGradientSegment *drag_seg,
|
|
|
|
gdouble pos)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-02-11 03:35:29 +08:00
|
|
|
GimpGradientSegment *seg;
|
2001-02-13 08:12:15 +08:00
|
|
|
gdouble lbound, rbound;
|
|
|
|
gint k;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
/* Check what we have to compress */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
if (!((drag_seg->left >= range_l->left) &&
|
2004-08-25 01:16:46 +08:00
|
|
|
((drag_seg->right <= range_r->right) || (drag_seg == range_r->next))))
|
1999-09-28 01:58:10 +08:00
|
|
|
{
|
|
|
|
/* We are compressing a segment outside the selection */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
range_l = range_r = drag_seg;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
/* Calculate left bound for dragged hadle */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
if (drag_seg == range_l)
|
|
|
|
lbound = range_l->prev->left + 2.0 * EPSILON;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Count number of segments to the left of the dragged handle */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
seg = drag_seg;
|
|
|
|
k = 0;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
while (seg != range_l)
|
2004-08-25 01:16:46 +08:00
|
|
|
{
|
|
|
|
k++;
|
|
|
|
seg = seg->prev;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
/* 2*k handles have to fit */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
lbound = range_l->left + 2.0 * k * EPSILON;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
/* Calculate right bound for dragged handle */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
if (drag_seg == range_r->next)
|
|
|
|
rbound = range_r->next->right - 2.0 * EPSILON;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Count number of segments to the right of the dragged handle */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
seg = drag_seg;
|
|
|
|
k = 1;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
while (seg != range_r)
|
2004-08-25 01:16:46 +08:00
|
|
|
{
|
|
|
|
k++;
|
|
|
|
seg = seg->next;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
/* 2*k handles have to fit */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
rbound = range_r->right - 2.0 * k * EPSILON;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
/* Calculate position */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-26 07:06:12 +08:00
|
|
|
pos = CLAMP (pos, lbound, rbound);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
/* Compress segments to the left of the handle */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
if (drag_seg == range_l)
|
2004-05-31 06:04:16 +08:00
|
|
|
gimp_gradient_segment_range_compress (gradient,
|
|
|
|
range_l->prev, range_l->prev,
|
|
|
|
range_l->prev->left, pos);
|
1999-09-28 01:58:10 +08:00
|
|
|
else
|
2004-05-31 06:04:16 +08:00
|
|
|
gimp_gradient_segment_range_compress (gradient,
|
|
|
|
range_l, drag_seg->prev,
|
|
|
|
range_l->left, pos);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
/* Compress segments to the right of the handle */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
if (drag_seg != range_r->next)
|
2004-05-31 06:04:16 +08:00
|
|
|
gimp_gradient_segment_range_compress (gradient,
|
|
|
|
drag_seg, range_r,
|
|
|
|
pos, range_r->right);
|
1999-09-28 01:58:10 +08:00
|
|
|
else
|
2004-05-31 06:04:16 +08:00
|
|
|
gimp_gradient_segment_range_compress (gradient,
|
|
|
|
drag_seg, drag_seg,
|
|
|
|
pos, drag_seg->right);
|
1999-09-28 01:58:10 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/*****/
|
|
|
|
|
2000-12-20 05:49:46 +08:00
|
|
|
static gdouble
|
2002-03-08 08:27:45 +08:00
|
|
|
control_move (GimpGradientEditor *editor,
|
2004-08-25 01:16:46 +08:00
|
|
|
GimpGradientSegment *range_l,
|
|
|
|
GimpGradientSegment *range_r,
|
|
|
|
gdouble delta)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-06-05 19:14:38 +08:00
|
|
|
GimpGradient *gradient = GIMP_GRADIENT (GIMP_DATA_EDITOR (editor)->data);
|
2004-05-31 06:04:16 +08:00
|
|
|
gdouble ret;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-05-31 06:04:16 +08:00
|
|
|
ret = gimp_gradient_segment_range_move (gradient,
|
|
|
|
range_l,
|
|
|
|
range_r,
|
|
|
|
delta,
|
|
|
|
editor->control_compress);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-05-31 06:04:16 +08:00
|
|
|
return ret;
|
1999-09-28 01:58:10 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/*****/
|
|
|
|
|
|
|
|
static void
|
2002-03-08 08:27:45 +08:00
|
|
|
control_update (GimpGradientEditor *editor,
|
2004-08-25 01:16:46 +08:00
|
|
|
GimpGradient *gradient,
|
|
|
|
gboolean reset_selection)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-07-24 23:37:03 +08:00
|
|
|
GtkAdjustment *adjustment;
|
2000-12-20 05:49:46 +08:00
|
|
|
gint cwidth, cheight;
|
2002-03-08 08:27:45 +08:00
|
|
|
gint pwidth = 0;
|
|
|
|
gint pheight = 0;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-10-25 04:38:35 +08:00
|
|
|
if (! editor->control_sel_l || ! editor->control_sel_r)
|
|
|
|
reset_selection = TRUE;
|
|
|
|
|
|
|
|
if (reset_selection)
|
|
|
|
{
|
|
|
|
if (gradient)
|
|
|
|
control_select_single_segment (editor, gradient->segments);
|
|
|
|
else
|
|
|
|
control_select_single_segment (editor, NULL);
|
|
|
|
}
|
|
|
|
|
2001-11-27 23:44:02 +08:00
|
|
|
if (! GTK_WIDGET_DRAWABLE (editor->control))
|
1999-07-24 23:37:03 +08:00
|
|
|
return;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-07-24 23:37:03 +08:00
|
|
|
/* See whether we have to re-create the control pixmap
|
2004-08-26 22:20:30 +08:00
|
|
|
* depending on the view's width
|
1999-07-24 23:37:03 +08:00
|
|
|
*/
|
2001-11-27 23:44:02 +08:00
|
|
|
cwidth = editor->preview->allocation.width;
|
1999-07-24 23:37:03 +08:00
|
|
|
cheight = GRAD_CONTROL_HEIGHT;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-27 23:44:02 +08:00
|
|
|
if (editor->control_pixmap)
|
|
|
|
gdk_drawable_get_size (editor->control_pixmap, &pwidth, &pheight);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-03-08 08:27:45 +08:00
|
|
|
if (! editor->control_pixmap || (cwidth != pwidth) || (cheight != pheight))
|
1999-07-24 23:37:03 +08:00
|
|
|
{
|
2001-11-27 23:44:02 +08:00
|
|
|
if (editor->control_pixmap)
|
2004-08-25 01:16:46 +08:00
|
|
|
g_object_unref (editor->control_pixmap);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-27 23:44:02 +08:00
|
|
|
editor->control_pixmap =
|
2004-08-25 01:16:46 +08:00
|
|
|
gdk_pixmap_new (editor->control->window, cwidth, cheight, -1);
|
1999-07-24 23:37:03 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-07-24 23:37:03 +08:00
|
|
|
/* Redraw pixmap */
|
2001-11-27 23:44:02 +08:00
|
|
|
adjustment = GTK_ADJUSTMENT (editor->scroll_data);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-27 23:44:02 +08:00
|
|
|
control_draw (editor,
|
2004-08-25 01:16:46 +08:00
|
|
|
gradient,
|
|
|
|
editor->control_pixmap,
|
|
|
|
cwidth, cheight,
|
|
|
|
adjustment->value,
|
|
|
|
adjustment->value + adjustment->page_size);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-27 23:44:02 +08:00
|
|
|
gdk_draw_drawable (editor->control->window,
|
2004-08-25 01:16:46 +08:00
|
|
|
editor->control->style->black_gc,
|
|
|
|
editor->control_pixmap,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
cwidth, cheight);
|
1999-07-24 23:37:03 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
static void
|
2002-03-08 08:27:45 +08:00
|
|
|
control_draw (GimpGradientEditor *editor,
|
2004-08-25 01:16:46 +08:00
|
|
|
GimpGradient *gradient,
|
|
|
|
GdkPixmap *pixmap,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gdouble left,
|
|
|
|
gdouble right)
|
1999-09-28 01:58:10 +08:00
|
|
|
{
|
2004-08-25 01:16:46 +08:00
|
|
|
gint sel_l, sel_r;
|
2001-11-27 23:44:02 +08:00
|
|
|
gdouble g_pos;
|
|
|
|
GimpGradientSegment *seg;
|
|
|
|
GradientEditorDragMode handle;
|
2005-05-05 21:59:32 +08:00
|
|
|
GtkStateType handle_state;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
/* Clear the pixmap */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-05-05 21:59:32 +08:00
|
|
|
gdk_draw_rectangle (pixmap, editor->control->style->base_gc[GTK_STATE_NORMAL],
|
2004-08-25 01:16:46 +08:00
|
|
|
TRUE, 0, 0, width, height);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-03-10 22:07:22 +08:00
|
|
|
if (! gradient)
|
|
|
|
return;
|
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
/* Draw selection */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-05-31 06:04:16 +08:00
|
|
|
sel_l = control_calc_p_pos (editor, editor->control_sel_l->left);
|
|
|
|
sel_r = control_calc_p_pos (editor, editor->control_sel_r->right);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
gdk_draw_rectangle (pixmap,
|
2005-05-05 21:59:32 +08:00
|
|
|
editor->control->style->base_gc[GTK_STATE_SELECTED],
|
2004-08-25 01:16:46 +08:00
|
|
|
TRUE, sel_l, 0, sel_r - sel_l + 1, height);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
/* Draw handles */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-05-05 21:59:32 +08:00
|
|
|
handle_state = GTK_STATE_NORMAL;
|
|
|
|
|
2004-05-31 06:04:16 +08:00
|
|
|
for (seg = gradient->segments; seg; seg = seg->next)
|
1999-09-28 01:58:10 +08:00
|
|
|
{
|
2005-05-05 21:59:32 +08:00
|
|
|
if (seg == editor->control_sel_l)
|
|
|
|
handle_state = GTK_STATE_SELECTED;
|
|
|
|
|
|
|
|
control_draw_normal_handle (editor, pixmap, seg->left, height,
|
|
|
|
handle_state);
|
|
|
|
control_draw_middle_handle (editor, pixmap, seg->middle, height,
|
|
|
|
handle_state);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
/* Draw right handle only if this is the last segment */
|
|
|
|
if (seg->next == NULL)
|
2005-05-05 21:59:32 +08:00
|
|
|
control_draw_normal_handle (editor, pixmap, seg->right, height,
|
|
|
|
handle_state);
|
|
|
|
|
|
|
|
if (seg == editor->control_sel_r)
|
|
|
|
handle_state = GTK_STATE_NORMAL;
|
1999-09-28 01:58:10 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
/* Draw the handle which is closest to the mouse position */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-27 23:44:02 +08:00
|
|
|
g_pos = control_calc_g_pos (editor, editor->control_last_x);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-13 08:12:15 +08:00
|
|
|
seg_get_closest_handle (gradient, CLAMP (g_pos, 0.0, 1.0), &seg, &handle);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-05-05 21:59:32 +08:00
|
|
|
handle_state = GTK_STATE_NORMAL;
|
|
|
|
|
|
|
|
if (seg && seg_in_selection (gradient, seg,
|
|
|
|
editor->control_sel_l, editor->control_sel_r))
|
|
|
|
handle_state = GTK_STATE_SELECTED;
|
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
switch (handle)
|
|
|
|
{
|
|
|
|
case GRAD_DRAG_LEFT:
|
|
|
|
if (seg)
|
2004-08-25 01:16:46 +08:00
|
|
|
{
|
2005-05-05 21:59:32 +08:00
|
|
|
control_draw_normal_handle (editor, pixmap, seg->left, height,
|
|
|
|
handle_state);
|
2004-08-25 01:16:46 +08:00
|
|
|
}
|
1999-09-28 01:58:10 +08:00
|
|
|
else
|
2004-08-25 01:16:46 +08:00
|
|
|
{
|
|
|
|
seg = gimp_gradient_segment_get_last (gradient->segments);
|
2000-12-20 05:49:46 +08:00
|
|
|
|
2005-05-05 21:59:32 +08:00
|
|
|
if (seg == editor->control_sel_r)
|
|
|
|
handle_state = GTK_STATE_SELECTED;
|
|
|
|
|
|
|
|
control_draw_normal_handle (editor, pixmap, seg->right, height,
|
|
|
|
handle_state);
|
2004-08-25 01:16:46 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
case GRAD_DRAG_MIDDLE:
|
2005-05-05 21:59:32 +08:00
|
|
|
control_draw_middle_handle (editor, pixmap, seg->middle, height,
|
|
|
|
handle_state);
|
1999-09-28 01:58:10 +08:00
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
static void
|
2002-03-08 08:27:45 +08:00
|
|
|
control_draw_normal_handle (GimpGradientEditor *editor,
|
2004-08-25 01:16:46 +08:00
|
|
|
GdkPixmap *pixmap,
|
|
|
|
gdouble pos,
|
2005-05-05 21:59:32 +08:00
|
|
|
gint height,
|
|
|
|
GtkStateType state)
|
1999-09-28 01:58:10 +08:00
|
|
|
{
|
|
|
|
control_draw_handle (pixmap,
|
2005-05-05 21:59:32 +08:00
|
|
|
editor->control->style->text_aa_gc[state],
|
2004-08-25 01:16:46 +08:00
|
|
|
editor->control->style->black_gc,
|
|
|
|
control_calc_p_pos (editor, pos), height);
|
1999-09-28 01:58:10 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
static void
|
2002-03-08 08:27:45 +08:00
|
|
|
control_draw_middle_handle (GimpGradientEditor *editor,
|
2004-08-25 01:16:46 +08:00
|
|
|
GdkPixmap *pixmap,
|
|
|
|
gdouble pos,
|
2005-05-05 21:59:32 +08:00
|
|
|
gint height,
|
|
|
|
GtkStateType state)
|
1999-09-28 01:58:10 +08:00
|
|
|
{
|
|
|
|
control_draw_handle (pixmap,
|
2005-05-05 21:59:32 +08:00
|
|
|
editor->control->style->text_aa_gc[state],
|
|
|
|
editor->control->style->white_gc,
|
2004-08-25 01:16:46 +08:00
|
|
|
control_calc_p_pos (editor, pos), height);
|
1999-09-28 01:58:10 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
static void
|
1999-09-28 01:58:10 +08:00
|
|
|
control_draw_handle (GdkPixmap *pixmap,
|
2004-08-25 01:16:46 +08:00
|
|
|
GdkGC *border_gc,
|
|
|
|
GdkGC *fill_gc,
|
|
|
|
gint xpos,
|
|
|
|
gint height)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-12-20 05:49:46 +08:00
|
|
|
gint y;
|
|
|
|
gint left, right, bottom;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
for (y = 0; y < height; y++)
|
|
|
|
gdk_draw_line (pixmap, fill_gc, xpos - y / 2, y, xpos + y / 2, y);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
bottom = height - 1;
|
|
|
|
left = xpos - bottom / 2;
|
|
|
|
right = xpos + bottom / 2;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
gdk_draw_line (pixmap, border_gc, xpos, 0, left, bottom);
|
|
|
|
gdk_draw_line (pixmap, border_gc, xpos, 0, right, bottom);
|
|
|
|
gdk_draw_line (pixmap, border_gc, left, bottom, right, bottom);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/*****/
|
|
|
|
|
2000-12-20 05:49:46 +08:00
|
|
|
static gint
|
2002-03-08 08:27:45 +08:00
|
|
|
control_calc_p_pos (GimpGradientEditor *editor,
|
2004-08-25 01:16:46 +08:00
|
|
|
gdouble pos)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-09-28 01:58:10 +08:00
|
|
|
gint pwidth, pheight;
|
|
|
|
GtkAdjustment *adjustment;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
/* Calculate the position (in widget's coordinates) of the
|
|
|
|
* requested point from the gradient. Rounding is done to
|
2004-08-26 22:20:30 +08:00
|
|
|
* minimize mismatches between the rendered gradient view
|
1999-09-28 01:58:10 +08:00
|
|
|
* and the gradient control's handles.
|
|
|
|
*/
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-27 23:44:02 +08:00
|
|
|
adjustment = GTK_ADJUSTMENT (editor->scroll_data);
|
|
|
|
gdk_drawable_get_size (editor->control_pixmap, &pwidth, &pheight);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-12-20 05:49:46 +08:00
|
|
|
return RINT ((pwidth - 1) * (pos - adjustment->value) / adjustment->page_size);
|
1999-09-28 01:58:10 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-12-20 05:49:46 +08:00
|
|
|
static gdouble
|
2002-03-08 08:27:45 +08:00
|
|
|
control_calc_g_pos (GimpGradientEditor *editor,
|
2004-08-25 01:16:46 +08:00
|
|
|
gint pos)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-12-20 05:49:46 +08:00
|
|
|
gint pwidth, pheight;
|
1999-09-28 01:58:10 +08:00
|
|
|
GtkAdjustment *adjustment;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
/* Calculate the gradient position that corresponds to widget's coordinates */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-27 23:44:02 +08:00
|
|
|
adjustment = GTK_ADJUSTMENT (editor->scroll_data);
|
|
|
|
gdk_drawable_get_size (editor->control_pixmap, &pwidth, &pheight);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
return adjustment->page_size * pos / (pwidth - 1) + adjustment->value;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/***** Segment functions *****/
|
|
|
|
|
|
|
|
static void
|
2001-11-27 23:44:02 +08:00
|
|
|
seg_get_closest_handle (GimpGradient *grad,
|
2004-08-25 01:16:46 +08:00
|
|
|
gdouble pos,
|
|
|
|
GimpGradientSegment **seg,
|
|
|
|
GradientEditorDragMode *handle)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-02-13 08:12:15 +08:00
|
|
|
gdouble l_delta, m_delta, r_delta;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-11 03:35:29 +08:00
|
|
|
*seg = gimp_gradient_get_segment_at (grad, pos);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
m_delta = fabs (pos - (*seg)->middle);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
if (pos < (*seg)->middle)
|
|
|
|
{
|
|
|
|
l_delta = fabs (pos - (*seg)->left);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
if (l_delta < m_delta)
|
2004-08-25 01:16:46 +08:00
|
|
|
*handle = GRAD_DRAG_LEFT;
|
1999-09-28 01:58:10 +08:00
|
|
|
else
|
2004-08-25 01:16:46 +08:00
|
|
|
*handle = GRAD_DRAG_MIDDLE;
|
1999-09-28 01:58:10 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
r_delta = fabs (pos - (*seg)->right);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-09-28 01:58:10 +08:00
|
|
|
if (m_delta < r_delta)
|
2004-08-25 01:16:46 +08:00
|
|
|
{
|
|
|
|
*handle = GRAD_DRAG_MIDDLE;
|
|
|
|
}
|
1999-09-28 01:58:10 +08:00
|
|
|
else
|
2004-08-25 01:16:46 +08:00
|
|
|
{
|
|
|
|
*seg = (*seg)->next;
|
|
|
|
*handle = GRAD_DRAG_LEFT;
|
|
|
|
}
|
1999-09-28 01:58:10 +08:00
|
|
|
}
|
|
|
|
}
|
2005-02-09 04:08:13 +08:00
|
|
|
|
2005-05-05 21:59:32 +08:00
|
|
|
static gboolean
|
|
|
|
seg_in_selection (GimpGradient *grad,
|
|
|
|
GimpGradientSegment *seg,
|
|
|
|
GimpGradientSegment *left,
|
|
|
|
GimpGradientSegment *right)
|
|
|
|
{
|
|
|
|
GimpGradientSegment *s;
|
|
|
|
|
|
|
|
for (s = left; s; s = s->next)
|
|
|
|
{
|
|
|
|
if (s == seg)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (s == right)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-02-09 04:08:13 +08:00
|
|
|
static GtkWidget *
|
|
|
|
gradient_hint_label_add (GtkBox *box)
|
|
|
|
{
|
|
|
|
GtkWidget *label = g_object_new (GTK_TYPE_LABEL,
|
|
|
|
"xalign", 0.0,
|
|
|
|
"yalign", 0.5,
|
|
|
|
"single-line-mode", TRUE,
|
|
|
|
NULL);
|
|
|
|
gtk_box_pack_start (box, label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
return label;
|
|
|
|
}
|