2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-25 06:05:25 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1997-11-25 06:05:25 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1997-11-25 06:05:25 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-02-22 23:14:54 +08:00
|
|
|
|
2000-12-17 05:37:03 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2012-03-30 01:19:01 +08:00
|
|
|
#include <gegl.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2002-06-08 20:15:11 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
2001-01-24 07:56:18 +08:00
|
|
|
|
2002-03-15 01:07:02 +08:00
|
|
|
#include "widgets-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-07-07 20:17:23 +08:00
|
|
|
#include "core/gimp.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
|
2004-09-24 04:41:40 +08:00
|
|
|
#include "gimpcolordialog.h"
|
2003-05-16 19:53:50 +08:00
|
|
|
#include "gimpdialogfactory.h"
|
2004-05-27 20:41:22 +08:00
|
|
|
#include "gimpfgbgeditor.h"
|
2002-03-15 01:07:02 +08:00
|
|
|
#include "gimptoolbox.h"
|
|
|
|
#include "gimptoolbox-color-area.h"
|
2001-05-09 03:29:15 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2001-01-21 21:41:07 +08:00
|
|
|
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
/* local function prototypes */
|
2001-10-29 19:47:11 +08:00
|
|
|
|
2014-09-17 05:54:58 +08:00
|
|
|
static void color_area_foreground_changed (GimpContext *context,
|
|
|
|
const GimpRGB *color,
|
|
|
|
GimpColorDialog *dialog);
|
|
|
|
static void color_area_background_changed (GimpContext *context,
|
|
|
|
const GimpRGB *color,
|
|
|
|
GimpColorDialog *dialog);
|
|
|
|
|
|
|
|
static void color_area_dialog_update (GimpColorDialog *dialog,
|
|
|
|
const GimpRGB *color,
|
|
|
|
GimpColorDialogState state,
|
|
|
|
GimpContext *context);
|
|
|
|
|
|
|
|
static void color_area_color_clicked (GimpFgBgEditor *editor,
|
|
|
|
GimpActiveColor active_color,
|
|
|
|
GimpContext *context);
|
2001-10-29 19:47:11 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-05-27 20:41:22 +08:00
|
|
|
/* local variables */
|
|
|
|
|
2004-09-24 04:41:40 +08:00
|
|
|
static GtkWidget *color_area = NULL;
|
|
|
|
static GtkWidget *color_dialog = NULL;
|
2004-09-13 23:15:23 +08:00
|
|
|
static gboolean color_dialog_active = FALSE;
|
2014-09-17 05:54:58 +08:00
|
|
|
static GimpActiveColor edit_color = GIMP_ACTIVE_COLOR_FOREGROUND;
|
2004-05-27 20:41:22 +08:00
|
|
|
static GimpRGB revert_fg;
|
|
|
|
static GimpRGB revert_bg;
|
1999-08-22 19:45:31 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-10-29 19:47:11 +08:00
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
GtkWidget *
|
2002-03-15 01:07:02 +08:00
|
|
|
gimp_toolbox_color_area_create (GimpToolbox *toolbox,
|
|
|
|
gint width,
|
2002-06-08 20:15:11 +08:00
|
|
|
gint height)
|
2001-10-29 19:47:11 +08:00
|
|
|
{
|
2002-03-15 01:07:02 +08:00
|
|
|
GimpContext *context;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_TOOLBOX (toolbox), NULL);
|
|
|
|
|
2009-12-06 04:20:18 +08:00
|
|
|
context = gimp_toolbox_get_context (toolbox);
|
2001-10-29 19:47:11 +08:00
|
|
|
|
2004-05-27 20:41:22 +08:00
|
|
|
color_area = gimp_fg_bg_editor_new (context);
|
2001-12-29 21:26:29 +08:00
|
|
|
gtk_widget_set_size_request (color_area, width, height);
|
2004-05-27 20:41:22 +08:00
|
|
|
gtk_widget_add_events (color_area,
|
2002-06-08 20:15:11 +08:00
|
|
|
GDK_ENTER_NOTIFY_MASK |
|
2006-04-12 20:49:29 +08:00
|
|
|
GDK_LEAVE_NOTIFY_MASK);
|
2001-10-29 19:47:11 +08:00
|
|
|
|
2007-11-09 19:17:00 +08:00
|
|
|
gimp_help_set_help_data
|
2007-11-22 21:59:06 +08:00
|
|
|
(color_area, _("Foreground & background colors.\n"
|
2007-11-09 19:17:00 +08:00
|
|
|
"The black and white squares reset colors.\n"
|
|
|
|
"The arrows swap colors.\n"
|
|
|
|
"Click to open the color selection dialog."), NULL);
|
|
|
|
|
2004-05-27 20:41:22 +08:00
|
|
|
g_signal_connect (color_area, "color-clicked",
|
2006-04-12 20:49:29 +08:00
|
|
|
G_CALLBACK (color_area_color_clicked),
|
|
|
|
context);
|
2001-10-29 19:47:11 +08:00
|
|
|
|
|
|
|
return color_area;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2014-09-17 05:54:58 +08:00
|
|
|
static void
|
|
|
|
color_area_foreground_changed (GimpContext *context,
|
|
|
|
const GimpRGB *color,
|
|
|
|
GimpColorDialog *dialog)
|
|
|
|
{
|
|
|
|
if (edit_color == GIMP_ACTIVE_COLOR_FOREGROUND)
|
|
|
|
{
|
|
|
|
g_signal_handlers_block_by_func (dialog,
|
|
|
|
color_area_dialog_update,
|
|
|
|
context);
|
|
|
|
|
|
|
|
/* FIXME this should use GimpColorDialog API */
|
|
|
|
gimp_color_selection_set_color (GIMP_COLOR_SELECTION (dialog->selection),
|
|
|
|
color);
|
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (dialog,
|
|
|
|
color_area_dialog_update,
|
|
|
|
context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
color_area_background_changed (GimpContext *context,
|
|
|
|
const GimpRGB *color,
|
|
|
|
GimpColorDialog *dialog)
|
|
|
|
{
|
|
|
|
if (edit_color == GIMP_ACTIVE_COLOR_BACKGROUND)
|
|
|
|
{
|
|
|
|
g_signal_handlers_block_by_func (dialog,
|
|
|
|
color_area_dialog_update,
|
|
|
|
context);
|
|
|
|
|
|
|
|
/* FIXME this should use GimpColorDialog API */
|
|
|
|
gimp_color_selection_set_color (GIMP_COLOR_SELECTION (dialog->selection),
|
|
|
|
color);
|
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (dialog,
|
|
|
|
color_area_dialog_update,
|
|
|
|
context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
2004-09-24 04:41:40 +08:00
|
|
|
color_area_dialog_update (GimpColorDialog *dialog,
|
|
|
|
const GimpRGB *color,
|
|
|
|
GimpColorDialogState state,
|
|
|
|
GimpContext *context)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-09-24 04:41:40 +08:00
|
|
|
switch (state)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-09-24 04:41:40 +08:00
|
|
|
case GIMP_COLOR_DIALOG_OK:
|
|
|
|
gtk_widget_hide (color_dialog);
|
|
|
|
color_dialog_active = FALSE;
|
|
|
|
/* Fallthrough */
|
|
|
|
|
|
|
|
case GIMP_COLOR_DIALOG_UPDATE:
|
|
|
|
if (edit_color == GIMP_ACTIVE_COLOR_FOREGROUND)
|
2014-09-17 05:54:58 +08:00
|
|
|
{
|
|
|
|
g_signal_handlers_block_by_func (context,
|
|
|
|
color_area_foreground_changed,
|
|
|
|
dialog);
|
|
|
|
|
|
|
|
gimp_context_set_foreground (context, color);
|
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (context,
|
|
|
|
color_area_foreground_changed,
|
|
|
|
dialog);
|
|
|
|
}
|
2004-09-24 04:41:40 +08:00
|
|
|
else
|
2014-09-17 05:54:58 +08:00
|
|
|
{
|
|
|
|
g_signal_handlers_block_by_func (context,
|
|
|
|
color_area_foreground_changed,
|
|
|
|
dialog);
|
|
|
|
|
|
|
|
gimp_context_set_background (context, color);
|
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (context,
|
|
|
|
color_area_foreground_changed,
|
|
|
|
dialog);
|
|
|
|
}
|
2004-09-24 04:41:40 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_COLOR_DIALOG_CANCEL:
|
|
|
|
gtk_widget_hide (color_dialog);
|
|
|
|
color_dialog_active = FALSE;
|
|
|
|
gimp_context_set_foreground (context, &revert_fg);
|
|
|
|
gimp_context_set_background (context, &revert_bg);
|
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-05-27 20:41:22 +08:00
|
|
|
color_area_color_clicked (GimpFgBgEditor *editor,
|
|
|
|
GimpActiveColor active_color,
|
|
|
|
GimpContext *context)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2003-05-16 19:53:50 +08:00
|
|
|
GimpRGB color;
|
|
|
|
const gchar *title;
|
1999-10-27 02:27:27 +08:00
|
|
|
|
2004-09-13 23:15:23 +08:00
|
|
|
if (! color_dialog_active)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-10-29 19:47:11 +08:00
|
|
|
gimp_context_get_foreground (context, &revert_fg);
|
|
|
|
gimp_context_get_background (context, &revert_bg);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
1999-08-23 22:19:26 +08:00
|
|
|
|
2004-05-27 20:41:22 +08:00
|
|
|
if (active_color == GIMP_ACTIVE_COLOR_FOREGROUND)
|
|
|
|
{
|
|
|
|
gimp_context_get_foreground (context, &color);
|
|
|
|
title = _("Change Foreground Color");
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
2004-05-27 20:41:22 +08:00
|
|
|
{
|
|
|
|
gimp_context_get_background (context, &color);
|
|
|
|
title = _("Change Background Color");
|
|
|
|
}
|
1999-10-27 02:27:27 +08:00
|
|
|
|
1999-08-23 22:19:26 +08:00
|
|
|
edit_color = active_color;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-09-13 23:15:23 +08:00
|
|
|
if (! color_dialog)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2006-09-26 16:55:41 +08:00
|
|
|
color_dialog = gimp_color_dialog_new (NULL, context,
|
|
|
|
NULL, NULL, NULL,
|
2004-09-24 04:41:40 +08:00
|
|
|
GTK_WIDGET (editor),
|
2010-03-01 06:20:57 +08:00
|
|
|
gimp_dialog_factory_get_singleton (),
|
2004-09-24 04:41:40 +08:00
|
|
|
"gimp-toolbox-color-dialog",
|
2006-05-10 19:23:11 +08:00
|
|
|
&color,
|
2004-09-24 04:41:40 +08:00
|
|
|
TRUE, FALSE);
|
|
|
|
|
2014-09-17 05:54:58 +08:00
|
|
|
g_signal_connect_object (color_dialog, "update",
|
|
|
|
G_CALLBACK (color_area_dialog_update),
|
|
|
|
G_OBJECT (context), 0);
|
|
|
|
|
|
|
|
g_signal_connect_object (context, "foreground-changed",
|
|
|
|
G_CALLBACK (color_area_foreground_changed),
|
|
|
|
G_OBJECT (color_dialog), 0);
|
|
|
|
g_signal_connect_object (context, "background-changed",
|
|
|
|
G_CALLBACK (color_area_background_changed),
|
|
|
|
G_OBJECT (color_dialog), 0);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2002-09-08 17:26:45 +08:00
|
|
|
|
2006-05-10 19:23:11 +08:00
|
|
|
gtk_window_set_title (GTK_WINDOW (color_dialog), title);
|
|
|
|
gimp_color_dialog_set_color (GIMP_COLOR_DIALOG (color_dialog), &color);
|
|
|
|
|
|
|
|
gtk_window_present (GTK_WINDOW (color_dialog));
|
|
|
|
color_dialog_active = TRUE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|