[gimp] Bug 739489 - Add palette of recently used colors
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] Bug 739489 - Add palette of recently used colors
- Date: Wed, 26 Nov 2014 22:51:10 +0000 (UTC)
commit 09628cfa4c33cecd39ac806a9d68a851c4b4c88e
Author: Michael Natterer <mitch gimp org>
Date: Wed Nov 26 23:48:19 2014 +0100
Bug 739489 - Add palette of recently used colors
Add a generated palette which contains the color history. For now it's
only updated when the color dialog's color history gets updated, but
should be updated whenever a color is chosen in any way.
app/core/Makefile.am | 4 +
app/core/core-types.h | 1 +
app/core/gimp-palettes.c | 92 ++++++++++++++
app/core/gimp-palettes.h | 30 +++++
app/core/gimp.c | 4 +
app/core/gimppalettemru.c | 256 ++++++++++++++++++++++++++++++++++++++
app/core/gimppalettemru.h | 62 +++++++++
app/gui/color-history.c | 230 +++--------------------------------
app/gui/color-history.h | 10 +--
app/widgets/gimpcolordialog.c | 101 +++++++++------
app/widgets/gimpcolordialog.h | 5 +-
app/widgets/gimpviewabledialog.c | 3 +-
po/POTFILES.in | 4 +-
13 files changed, 535 insertions(+), 267 deletions(-)
---
diff --git a/app/core/Makefile.am b/app/core/Makefile.am
index ca09141..c66b61e 100644
--- a/app/core/Makefile.am
+++ b/app/core/Makefile.am
@@ -41,6 +41,8 @@ libappcore_a_sources = \
gimp-memsize.h \
gimp-modules.c \
gimp-modules.h \
+ gimp-palettes.c \
+ gimp-palettes.h \
gimp-parasites.c \
gimp-parasites.h \
gimp-tags.c \
@@ -314,6 +316,8 @@ libappcore_a_sources = \
gimppalette-load.h \
gimppalette-save.c \
gimppalette-save.h \
+ gimppalettemru.c \
+ gimppalettemru.h \
gimpparamspecs.c \
gimpparamspecs.h \
gimpparamspecs-desc.c \
diff --git a/app/core/core-types.h b/app/core/core-types.h
index e78583b..018857c 100644
--- a/app/core/core-types.h
+++ b/app/core/core-types.h
@@ -134,6 +134,7 @@ typedef struct _GimpDynamics GimpDynamics;
typedef struct _GimpDynamicsOutput GimpDynamicsOutput;
typedef struct _GimpGradient GimpGradient;
typedef struct _GimpPalette GimpPalette;
+typedef struct _GimpPaletteMru GimpPaletteMru;
typedef struct _GimpPattern GimpPattern;
typedef struct _GimpPatternClipboard GimpPatternClipboard;
typedef struct _GimpToolPreset GimpToolPreset;
diff --git a/app/core/gimp-palettes.c b/app/core/gimp-palettes.c
new file mode 100644
index 0000000..3059bf6
--- /dev/null
+++ b/app/core/gimp-palettes.c
@@ -0,0 +1,92 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995-2002 Spencer Kimball, Peter Mattis, and others
+ *
+ * gimp-gradients.c
+ * Copyright (C) 2014 Michael Natterer <mitch gimp org>
+ *
+ * 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gegl.h>
+
+#include "core-types.h"
+
+#include "gimp.h"
+#include "gimp-palettes.h"
+#include "gimpcontext.h"
+#include "gimpcontainer.h"
+#include "gimpdatafactory.h"
+#include "gimppalettemru.h"
+
+#include "gimp-intl.h"
+
+
+#define COLOR_HISTORY_KEY "gimp-palette-color-history"
+
+
+/* local function prototypes */
+
+static GimpPalette * gimp_palettes_add_palette (Gimp *gimp,
+ const gchar *name,
+ const gchar *id);
+
+
+/* public functions */
+
+void
+gimp_palettes_init (Gimp *gimp)
+{
+ GimpPalette *palette;
+
+ g_return_if_fail (GIMP_IS_GIMP (gimp));
+
+ palette = gimp_palettes_add_palette (gimp,
+ _("Color History"),
+ COLOR_HISTORY_KEY);
+ gimp_context_set_palette (gimp->user_context, palette);
+}
+
+GimpPalette *
+gimp_palettes_get_color_history (Gimp *gimp)
+{
+ g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
+
+ return g_object_get_data (G_OBJECT (gimp), COLOR_HISTORY_KEY);
+}
+
+
+/* private functions */
+
+static GimpPalette *
+gimp_palettes_add_palette (Gimp *gimp,
+ const gchar *name,
+ const gchar *id)
+{
+ GimpData *palette;
+
+ palette = gimp_palette_mru_new (name);
+
+ gimp_data_make_internal (palette, id);
+
+ gimp_container_add (gimp_data_factory_get_container (gimp->palette_factory),
+ GIMP_OBJECT (palette));
+ g_object_unref (palette);
+
+ g_object_set_data (G_OBJECT (gimp), id, palette);
+
+ return GIMP_PALETTE (palette);
+}
diff --git a/app/core/gimp-palettes.h b/app/core/gimp-palettes.h
new file mode 100644
index 0000000..0d7e950
--- /dev/null
+++ b/app/core/gimp-palettes.h
@@ -0,0 +1,30 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995-2002 Spencer Kimball, Peter Mattis, and others
+ *
+ * gimp-palettes.h
+ * Copyright (C) 2014 Michael Natterer <mitch gimp org>
+ *
+ * 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_PALETTES__
+#define __GIMP_PALETTES__
+
+
+void gimp_palettes_init (Gimp *gimp);
+
+GimpPalette * gimp_palettes_get_color_history (Gimp *gimp);
+
+
+#endif /* __GIMP_PALETTES__ */
diff --git a/app/core/gimp.c b/app/core/gimp.c
index 3c27874..aceb3cc 100644
--- a/app/core/gimp.c
+++ b/app/core/gimp.c
@@ -47,6 +47,7 @@
#include "gimp-gradients.h"
#include "gimp-memsize.h"
#include "gimp-modules.h"
+#include "gimp-palettes.h"
#include "gimp-parasites.h"
#include "gimp-templates.h"
#include "gimp-units.h"
@@ -746,6 +747,9 @@ gimp_real_initialize (Gimp *gimp,
/* add the builtin FG -> BG etc. gradients */
gimp_gradients_init (gimp);
+ /* add the color history palette */
+ gimp_palettes_init (gimp);
+
/* add the clipboard brush */
clipboard_brush = gimp_brush_clipboard_new (gimp);
gimp_data_make_internal (GIMP_DATA (clipboard_brush),
diff --git a/app/core/gimppalettemru.c b/app/core/gimppalettemru.c
new file mode 100644
index 0000000..49a4151
--- /dev/null
+++ b/app/core/gimppalettemru.c
@@ -0,0 +1,256 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimppalettemru.c
+ * Copyright (C) 2014 Michael Natterer <mitch gimp org>
+ *
+ * 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <cairo.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gegl.h>
+
+#include "libgimpcolor/gimpcolor.h"
+#include "libgimpconfig/gimpconfig.h"
+
+#include "core-types.h"
+
+#include "gimppalettemru.h"
+
+#include "gimp-intl.h"
+
+
+enum
+{
+ COLOR_HISTORY = 1
+};
+
+
+G_DEFINE_TYPE (GimpPaletteMru, gimp_palette_mru, GIMP_TYPE_PALETTE)
+
+#define parent_class gimp_palette_mru_parent_class
+
+
+static void
+gimp_palette_mru_class_init (GimpPaletteMruClass *klass)
+{
+}
+
+static void
+gimp_palette_mru_init (GimpPaletteMru *palette)
+{
+}
+
+
+/* public functions */
+
+GimpData *
+gimp_palette_mru_new (const gchar *name)
+{
+ GimpPaletteMru *palette;
+
+ g_return_val_if_fail (name != NULL, NULL);
+ g_return_val_if_fail (*name != '\0', NULL);
+
+ palette = g_object_new (GIMP_TYPE_PALETTE_MRU,
+ "name", name,
+ "mime-type", "application/x-gimp-palette",
+ NULL);
+
+ return GIMP_DATA (palette);
+}
+
+void
+gimp_palette_mru_load (GimpPaletteMru *mru,
+ GFile *file)
+{
+ GimpPalette *palette;
+ GScanner *scanner;
+ GTokenType token;
+
+ g_return_if_fail (GIMP_IS_PALETTE_MRU (mru));
+ g_return_if_fail (G_IS_FILE (file));
+
+ palette = GIMP_PALETTE (mru);
+
+ scanner = gimp_scanner_new_gfile (file, NULL);
+ if (! scanner)
+ return;
+
+ g_scanner_scope_add_symbol (scanner, 0, "color-history",
+ GINT_TO_POINTER (COLOR_HISTORY));
+
+ token = G_TOKEN_LEFT_PAREN;
+
+ while (g_scanner_peek_next_token (scanner) == token)
+ {
+ token = g_scanner_get_next_token (scanner);
+
+ switch (token)
+ {
+ case G_TOKEN_LEFT_PAREN:
+ token = G_TOKEN_SYMBOL;
+ break;
+
+ case G_TOKEN_SYMBOL:
+ if (scanner->value.v_symbol == GINT_TO_POINTER (COLOR_HISTORY))
+ {
+ while (g_scanner_peek_next_token (scanner) == G_TOKEN_LEFT_PAREN)
+ {
+ GimpRGB color;
+
+ if (! gimp_scanner_parse_color (scanner, &color))
+ goto error;
+
+ gimp_palette_add_entry (palette, -1,
+ _("History Color"), &color);
+ }
+ }
+ token = G_TOKEN_RIGHT_PAREN;
+ break;
+
+ case G_TOKEN_RIGHT_PAREN:
+ token = G_TOKEN_LEFT_PAREN;
+ break;
+
+ default: /* do nothing */
+ break;
+ }
+ }
+
+ error:
+ gimp_scanner_destroy (scanner);
+}
+
+void
+gimp_palette_mru_save (GimpPaletteMru *mru,
+ GFile *file)
+{
+ GimpPalette *palette;
+ GimpConfigWriter *writer;
+ GList *list;
+
+ g_return_if_fail (GIMP_IS_PALETTE_MRU (mru));
+ g_return_if_fail (G_IS_FILE (file));
+
+ writer = gimp_config_writer_new_gfile (file,
+ TRUE,
+ "GIMP colorrc\n\n"
+ "This file holds a list of "
+ "recently used colors.",
+ NULL);
+ if (! writer)
+ return;
+
+ palette = GIMP_PALETTE (mru);
+
+ gimp_config_writer_open (writer, "color-history");
+
+ for (list = palette->colors; list; list = g_list_next (list))
+ {
+ GimpPaletteEntry *entry = list->data;
+ gchar buf[4][G_ASCII_DTOSTR_BUF_SIZE];
+
+ g_ascii_formatd (buf[0],
+ G_ASCII_DTOSTR_BUF_SIZE, "%f", entry->color.r);
+ g_ascii_formatd (buf[1],
+ G_ASCII_DTOSTR_BUF_SIZE, "%f", entry->color.g);
+ g_ascii_formatd (buf[2],
+ G_ASCII_DTOSTR_BUF_SIZE, "%f", entry->color.b);
+ g_ascii_formatd (buf[3],
+ G_ASCII_DTOSTR_BUF_SIZE, "%f", entry->color.a);
+
+ gimp_config_writer_open (writer, "color-rgba");
+ gimp_config_writer_printf (writer, "%s %s %s %s",
+ buf[0], buf[1], buf[2], buf[3]);
+ gimp_config_writer_close (writer);
+ }
+
+ gimp_config_writer_close (writer);
+
+ gimp_config_writer_finish (writer, "end of colorrc", NULL);
+}
+
+gint
+gimp_palette_mru_add (GimpPaletteMru *mru,
+ const GimpRGB *color)
+{
+ GimpPalette *palette;
+ GimpPaletteEntry *found = NULL;
+ GList *list;
+ gint max_changed;
+
+ g_return_if_fail (GIMP_IS_PALETTE_MRU (mru));
+ g_return_if_fail (color != NULL);
+
+ palette = GIMP_PALETTE (mru);
+
+ max_changed = gimp_palette_get_n_colors (palette);
+
+ /* is the added color already there? */
+ for (list = gimp_palette_get_colors (palette);
+ list;
+ list = g_list_next (list))
+ {
+ GimpPaletteEntry *entry = list->data;
+
+ if (gimp_rgba_distance (&entry->color, color) < 0.0001)
+ {
+ found = entry;
+
+ goto doit;
+ }
+ }
+
+ /* if not, are there two equal colors? */
+ if (! found)
+ {
+ for (list = gimp_palette_get_colors (palette);
+ list;
+ list = g_list_next (list))
+ {
+ GimpPaletteEntry *entry = list->data;
+ GList *list2;
+
+ for (list2 = g_list_next (list); list2; list2 = g_list_next (list2))
+ {
+ GimpPaletteEntry *entry2 = list2->data;
+
+ if (gimp_rgba_distance (&entry->color,
+ &entry2->color) < 0.0001)
+ {
+ found = entry2;
+
+ goto doit;
+ }
+ }
+ }
+ }
+
+ doit:
+
+ if (found)
+ {
+ max_changed = found->position;
+
+ gimp_palette_delete_entry (palette, found);
+ }
+
+ found = gimp_palette_add_entry (palette, 0, _("History Color"), color);
+
+ return max_changed;
+}
diff --git a/app/core/gimppalettemru.h b/app/core/gimppalettemru.h
new file mode 100644
index 0000000..9864a27
--- /dev/null
+++ b/app/core/gimppalettemru.h
@@ -0,0 +1,62 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimppalettemru.h
+ * Copyright (C) 2014 Michael Natterer <mitch gimp org>
+ *
+ * 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_PALETTE_MRU_H__
+#define __GIMP_PALETTE_MRU_H__
+
+
+#include "gimppalette.h"
+
+
+#define GIMP_TYPE_PALETTE_MRU (gimp_palette_mru_get_type ())
+#define GIMP_PALETTE_MRU(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_PALETTE_MRU,
GimpPaletteMru))
+#define GIMP_PALETTE_MRU_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_PALETTE_MRU,
GimpPaletteMruClass))
+#define GIMP_IS_PALETTE_MRU(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_PALETTE_MRU))
+#define GIMP_IS_PALETTE_MRU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_PALETTE_MRU))
+#define GIMP_PALETTE_MRU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_PALETTE_MRU,
GimpPaletteMruClass))
+
+
+typedef struct _GimpPaletteMruClass GimpPaletteMruClass;
+
+struct _GimpPaletteMru
+{
+ GimpPalette parent_instance;
+};
+
+struct _GimpPaletteMruClass
+{
+ GimpPaletteClass parent_class;
+};
+
+
+GType gimp_palette_mru_get_type (void) G_GNUC_CONST;
+
+GimpData * gimp_palette_mru_new (const gchar *name);
+
+void gimp_palette_mru_load (GimpPaletteMru *mru,
+ GFile *file);
+void gimp_palette_mru_save (GimpPaletteMru *mru,
+ GFile *file);
+
+gint gimp_palette_mru_add (GimpPaletteMru *mru,
+ const GimpRGB *color);
+
+
+#endif /* __GIMP_PALETTE_MRU_H__ */
diff --git a/app/gui/color-history.c b/app/gui/color-history.c
index c766d43..7d5fd01 100644
--- a/app/gui/color-history.c
+++ b/app/gui/color-history.c
@@ -24,254 +24,54 @@
#include <gtk/gtk.h>
#include "libgimpbase/gimpbase.h"
-#include "libgimpcolor/gimpcolor.h"
-#include "libgimpconfig/gimpconfig.h"
#include "gui-types.h"
#include "core/gimp.h"
+#include "core/gimp-palettes.h"
+#include "core/gimppalettemru.h"
#include "color-history.h"
-
-enum
-{
- COLOR_HISTORY = 1
-};
-
-
-static void color_history_init (void);
-static void color_history_add_from_rc (GimpRGB *color);
-
-
-static GimpRGB color_history[COLOR_HISTORY_SIZE];
-static gboolean color_history_initialized = FALSE;
+#include "gimp-intl.h"
void
color_history_save (Gimp *gimp)
{
- GimpConfigWriter *writer;
- GFile *file;
- gint i;
+ GimpPalette *palette;
+ GFile *file;
g_return_if_fail (GIMP_IS_GIMP (gimp));
+ palette = gimp_palettes_get_color_history (gimp);
+
file = gimp_directory_file ("colorrc", NULL);
if (gimp->be_verbose)
g_print ("Writing '%s'\n", gimp_file_get_utf8_name (file));
- writer = gimp_config_writer_new_gfile (file,
- TRUE,
- "GIMP colorrc\n\n"
- "This file holds a list of "
- "recently used colors.",
- NULL);
- g_object_unref (file);
-
- if (!writer)
- return;
+ gimp_palette_mru_save (GIMP_PALETTE_MRU (palette), file);
- if (! color_history_initialized)
- color_history_init ();
-
- gimp_config_writer_open (writer, "color-history");
-
- for (i = 0; i < COLOR_HISTORY_SIZE; i++)
- {
- gchar buf[4][G_ASCII_DTOSTR_BUF_SIZE];
-
- g_ascii_formatd (buf[0],
- G_ASCII_DTOSTR_BUF_SIZE, "%f", color_history[i].r);
- g_ascii_formatd (buf[1],
- G_ASCII_DTOSTR_BUF_SIZE, "%f", color_history[i].g);
- g_ascii_formatd (buf[2],
- G_ASCII_DTOSTR_BUF_SIZE, "%f", color_history[i].b);
- g_ascii_formatd (buf[3],
- G_ASCII_DTOSTR_BUF_SIZE, "%f", color_history[i].a);
-
- gimp_config_writer_open (writer, "color-rgba");
- gimp_config_writer_printf (writer, "%s %s %s %s",
- buf[0], buf[1], buf[2], buf[3]);
- gimp_config_writer_close (writer);
- }
-
- gimp_config_writer_close (writer);
-
- gimp_config_writer_finish (writer, "end of colorrc", NULL);
+ g_object_unref (file);
}
void
color_history_restore (Gimp *gimp)
{
- GFile *file;
- GScanner *scanner;
- GTokenType token;
+ GimpPalette *palette;
+ GFile *file;
g_return_if_fail (GIMP_IS_GIMP (gimp));
+ palette = gimp_palettes_get_color_history (gimp);
+
file = gimp_directory_file ("colorrc", NULL);
if (gimp->be_verbose)
g_print ("Parsing '%s'\n", gimp_file_get_utf8_name (file));
- scanner = gimp_scanner_new_gfile (file, NULL);
- g_object_unref (file);
-
- if (! scanner)
- return;
-
- g_scanner_scope_add_symbol (scanner, 0, "color-history",
- GINT_TO_POINTER (COLOR_HISTORY));
-
- token = G_TOKEN_LEFT_PAREN;
-
- while (g_scanner_peek_next_token (scanner) == token)
- {
- token = g_scanner_get_next_token (scanner);
-
- switch (token)
- {
- case G_TOKEN_LEFT_PAREN:
- token = G_TOKEN_SYMBOL;
- break;
-
- case G_TOKEN_SYMBOL:
- if (scanner->value.v_symbol == GINT_TO_POINTER (COLOR_HISTORY))
- {
- while (g_scanner_peek_next_token (scanner) == G_TOKEN_LEFT_PAREN)
- {
- GimpRGB color;
-
- if (! gimp_scanner_parse_color (scanner, &color))
- goto error;
-
- color_history_add_from_rc (&color);
- }
- }
- token = G_TOKEN_RIGHT_PAREN;
- break;
-
- case G_TOKEN_RIGHT_PAREN:
- token = G_TOKEN_LEFT_PAREN;
- break;
-
- default: /* do nothing */
- break;
- }
- }
-
- error:
- gimp_scanner_destroy (scanner);
-}
-
-void
-color_history_set (gint index,
- const GimpRGB *rgb)
-{
- g_return_if_fail (index >= 0);
- g_return_if_fail (index < COLOR_HISTORY_SIZE);
- g_return_if_fail (rgb != NULL);
-
- if (! color_history_initialized)
- color_history_init ();
+ gimp_palette_mru_load (GIMP_PALETTE_MRU (palette), file);
- color_history[index] = *rgb;
-}
-
-void
-color_history_get (gint index,
- GimpRGB *rgb)
-{
- g_return_if_fail (index >= 0);
- g_return_if_fail (index < COLOR_HISTORY_SIZE);
- g_return_if_fail (rgb != NULL);
-
- if (! color_history_initialized)
- color_history_init ();
-
- *rgb = color_history[index];
-}
-
-gint
-color_history_add (const GimpRGB *rgb)
-{
- gint shift_begin = -1;
- gint i, j;
-
- g_return_val_if_fail (rgb != NULL, 0);
-
- if (! color_history_initialized)
- color_history_init ();
-
- /* is the added color already there? */
- for (i = 0; i < COLOR_HISTORY_SIZE; i++)
- {
- if (gimp_rgba_distance (&color_history[i], rgb) < 0.0001)
- {
- shift_begin = i;
-
- goto doit;
- }
- }
-
- /* if not, are there two equal colors? */
- if (shift_begin == -1)
- {
- for (i = 0; i < COLOR_HISTORY_SIZE; i++)
- {
- for (j = i + 1; j < COLOR_HISTORY_SIZE; j++)
- {
- if (gimp_rgba_distance (&color_history[i],
- &color_history[j]) < 0.0001)
- {
- shift_begin = i;
-
- goto doit;
- }
- }
- }
- }
-
- /* if not, shift them all */
- if (shift_begin == -1)
- shift_begin = COLOR_HISTORY_SIZE - 1;
-
- doit:
-
- for (i = shift_begin; i > 0; i--)
- color_history[i] = color_history[i - 1];
-
- color_history[0] = *rgb;
-
- return shift_begin;
-}
-
-
-/* private functions */
-
-static void
-color_history_init (void)
-{
- gint i;
-
- for (i = 0; i < COLOR_HISTORY_SIZE; i++)
- gimp_rgba_set (&color_history[i], 1.0, 1.0, 1.0, GIMP_OPACITY_OPAQUE);
-
- color_history_initialized = TRUE;
-}
-
-static void
-color_history_add_from_rc (GimpRGB *color)
-{
- static gint index = 0;
-
- if (! color_history_initialized)
- color_history_init ();
-
- if (color && index < COLOR_HISTORY_SIZE)
- {
- color_history[index++] = *color;
- }
+ g_object_unref (file);
}
diff --git a/app/gui/color-history.h b/app/gui/color-history.h
index 9e7b980..2c410e7 100644
--- a/app/gui/color-history.h
+++ b/app/gui/color-history.h
@@ -24,14 +24,8 @@
#define COLOR_HISTORY_SIZE 12
-void color_history_save (Gimp *gimp);
-void color_history_restore (Gimp *gimp);
-
-gint color_history_add (const GimpRGB *rgb);
-void color_history_set (gint index,
- const GimpRGB *rgb);
-void color_history_get (gint index,
- GimpRGB *rgb);
+void color_history_save (Gimp *gimp);
+void color_history_restore (Gimp *gimp);
#endif /* __COLOR_HISTORY_H__ */
diff --git a/app/widgets/gimpcolordialog.c b/app/widgets/gimpcolordialog.c
index caec5cd..c7d748f 100644
--- a/app/widgets/gimpcolordialog.c
+++ b/app/widgets/gimpcolordialog.c
@@ -31,8 +31,10 @@
#include "config/gimpcoreconfig.h"
#include "core/gimp.h"
+#include "core/gimp-palettes.h"
#include "core/gimpcontext.h"
#include "core/gimpmarshal.h"
+#include "core/gimppalettemru.h"
#include "core/gimpviewable.h"
#include "gimpcolordialog.h"
@@ -54,6 +56,7 @@ enum
};
+static void gimp_color_dialog_constructed (GObject *object);
static void gimp_color_dialog_dispose (GObject *object);
static void gimp_color_dialog_response (GtkDialog *dialog,
@@ -87,9 +90,10 @@ gimp_color_dialog_class_init (GimpColorDialogClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
- object_class->dispose = gimp_color_dialog_dispose;
+ object_class->constructed = gimp_color_dialog_constructed;
+ object_class->dispose = gimp_color_dialog_dispose;
- dialog_class->response = gimp_color_dialog_response;
+ dialog_class->response = gimp_color_dialog_response;
color_dialog_signals[UPDATE] =
g_signal_new ("update",
@@ -106,11 +110,6 @@ gimp_color_dialog_class_init (GimpColorDialogClass *klass)
static void
gimp_color_dialog_init (GimpColorDialog *dialog)
{
- GtkWidget *table;
- GtkWidget *button;
- GtkWidget *arrow;
- gint i;
-
color_dialogs = g_list_prepend (color_dialogs, dialog);
gtk_dialog_add_buttons (GTK_DIALOG (dialog),
@@ -135,9 +134,22 @@ gimp_color_dialog_init (GimpColorDialog *dialog)
g_signal_connect (dialog->selection, "color-changed",
G_CALLBACK (gimp_color_dialog_color_changed),
dialog);
+}
+
+static void
+gimp_color_dialog_constructed (GObject *object)
+{
+ GimpColorDialog *dialog = GIMP_COLOR_DIALOG (object);
+ GtkWidget *table;
+ GtkWidget *button;
+ GtkWidget *arrow;
+ GimpPalette *history;
+ gint i;
+
+ G_OBJECT_CLASS (parent_class)->constructed (object);
/* The color history */
- table = gtk_table_new (2, 1 + COLOR_HISTORY_SIZE / 2, TRUE);
+ table = gtk_table_new (2, 1 + GIMP_COLOR_DIALOG_HISTORY_SIZE / 2, TRUE);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
gtk_table_set_col_spacing (GTK_TABLE (table), 0, 4);
@@ -160,13 +172,16 @@ gimp_color_dialog_init (GimpColorDialog *dialog)
gtk_container_add (GTK_CONTAINER (button), arrow);
gtk_widget_show (arrow);
- for (i = 0; i < COLOR_HISTORY_SIZE; i++)
+ history = gimp_palettes_get_color_history (GIMP_VIEWABLE_DIALOG (dialog)->context->gimp);
+
+ for (i = 0; i < GIMP_COLOR_DIALOG_HISTORY_SIZE; i++)
{
- GimpRGB history_color;
- gint row, column;
+ GimpPaletteEntry *entry = gimp_palette_get_entry (history, i);
+ GimpRGB black = { 0.0, 0.0, 0.0, 1.0 };
+ gint row, column;
- column = i % (COLOR_HISTORY_SIZE / 2);
- row = i / (COLOR_HISTORY_SIZE / 2);
+ column = i % (GIMP_COLOR_DIALOG_HISTORY_SIZE / 2);
+ row = i / (GIMP_COLOR_DIALOG_HISTORY_SIZE / 2);
button = gtk_button_new ();
gtk_widget_set_size_request (button, COLOR_AREA_SIZE, COLOR_AREA_SIZE);
@@ -174,9 +189,7 @@ gimp_color_dialog_init (GimpColorDialog *dialog)
column + 1, column + 2, row, row + 1);
gtk_widget_show (button);
- color_history_get (i, &history_color);
-
- dialog->history[i] = gimp_color_area_new (&history_color,
+ dialog->history[i] = gimp_color_area_new (entry ? &entry->color : &black,
GIMP_COLOR_AREA_SMALL_CHECKS,
GDK_BUTTON2_MASK);
gtk_container_add (GTK_CONTAINER (button), dialog->history[i]);
@@ -255,7 +268,7 @@ gimp_color_dialog_new (GimpViewable *viewable,
const gchar *role;
g_return_val_if_fail (viewable == NULL || GIMP_IS_VIEWABLE (viewable), NULL);
- g_return_val_if_fail (context == NULL || GIMP_IS_CONTEXT (context), NULL);
+ g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
g_return_val_if_fail (GTK_IS_WIDGET (parent), NULL);
g_return_val_if_fail (dialog_factory == NULL ||
GIMP_IS_DIALOG_FACTORY (dialog_factory), NULL);
@@ -263,9 +276,6 @@ gimp_color_dialog_new (GimpViewable *viewable,
NULL);
g_return_val_if_fail (color != NULL, NULL);
- if (! context)
- g_warning ("gimp_color_dialog_new() called with a NULL context");
-
role = dialog_identifier ? dialog_identifier : "gimp-color-selector";
dialog = g_object_new (GIMP_TYPE_COLOR_DIALOG,
@@ -273,8 +283,9 @@ gimp_color_dialog_new (GimpViewable *viewable,
"role", role,
"help-func", gimp_color_dialog_help_func,
"help-id", GIMP_HELP_COLOR_DIALOG,
- "icon_name", icon_name,
+ "icon-name", icon_name,
"description", desc,
+ "context", context,
"parent", parent,
NULL);
@@ -306,17 +317,14 @@ gimp_color_dialog_new (GimpViewable *viewable,
gimp_color_selection_set_show_alpha (GIMP_COLOR_SELECTION (dialog->selection),
show_alpha);
- if (context)
- {
- g_object_set_data (G_OBJECT (context->gimp->config->color_management),
- "gimp-context", context);
+ g_object_set_data (G_OBJECT (context->gimp->config->color_management),
+ "gimp-context", context);
- gimp_color_selection_set_config (GIMP_COLOR_SELECTION (dialog->selection),
- context->gimp->config->color_management);
+ gimp_color_selection_set_config (GIMP_COLOR_SELECTION (dialog->selection),
+ context->gimp->config->color_management);
- g_object_set_data (G_OBJECT (context->gimp->config->color_management),
- "gimp-context", NULL);
- }
+ g_object_set_data (G_OBJECT (context->gimp->config->color_management),
+ "gimp-context", NULL);
gimp_color_selection_set_color (GIMP_COLOR_SELECTION (dialog->selection),
color);
@@ -412,15 +420,21 @@ static void
gimp_color_history_color_changed (GtkWidget *widget,
gpointer data)
{
- GimpRGB changed_color;
- gint color_index;
- GList *list;
+ GimpViewableDialog *viewable_dialog;
+ GimpPalette *history;
+ GimpRGB changed_color;
+ gint color_index;
+ GList *list;
+
+ viewable_dialog = GIMP_VIEWABLE_DIALOG (gtk_widget_get_toplevel (widget));
+
+ history = gimp_palettes_get_color_history (viewable_dialog->context->gimp);
gimp_color_area_get_color (GIMP_COLOR_AREA (widget), &changed_color);
color_index = GPOINTER_TO_INT (data);
- color_history_set (color_index, &changed_color);
+ gimp_palette_set_entry_color (history, color_index, &changed_color);
for (list = color_dialogs; list; list = g_list_next (list))
{
@@ -446,19 +460,26 @@ static void
gimp_color_history_add_clicked (GtkWidget *widget,
GimpColorDialog *dialog)
{
- GimpRGB color;
- gint shift_begin;
- gint i;
+ GimpPalette *history;
+ GimpRGB color;
+ gint shift_begin;
+ gint i;
+
+ history = gimp_palettes_get_color_history (GIMP_VIEWABLE_DIALOG (dialog)->context->gimp);
gimp_color_selection_get_color (GIMP_COLOR_SELECTION (dialog->selection),
&color);
- shift_begin = color_history_add (&color);
+ shift_begin = gimp_palette_mru_add (GIMP_PALETTE_MRU (history), &color);
for (i = shift_begin; i >= 0; i--)
{
- color_history_get (i, &color);
+ if (i < GIMP_COLOR_DIALOG_HISTORY_SIZE)
+ {
+ GimpPaletteEntry *entry = gimp_palette_get_entry (history, i);
- gimp_color_area_set_color (GIMP_COLOR_AREA (dialog->history[i]), &color);
+ gimp_color_area_set_color (GIMP_COLOR_AREA (dialog->history[i]),
+ &entry->color);
+ }
}
}
diff --git a/app/widgets/gimpcolordialog.h b/app/widgets/gimpcolordialog.h
index 0b21228..64d3187 100644
--- a/app/widgets/gimpcolordialog.h
+++ b/app/widgets/gimpcolordialog.h
@@ -23,7 +23,8 @@
#include "gimpviewabledialog.h"
-#include "gui/color-history.h"
+
+#define GIMP_COLOR_DIALOG_HISTORY_SIZE 12
#define GIMP_TYPE_COLOR_DIALOG (gimp_color_dialog_get_type ())
@@ -43,7 +44,7 @@ struct _GimpColorDialog
gboolean wants_updates;
GtkWidget *selection;
- GtkWidget *history[COLOR_HISTORY_SIZE];
+ GtkWidget *history[GIMP_COLOR_DIALOG_HISTORY_SIZE];
};
struct _GimpColorDialogClass
diff --git a/app/widgets/gimpviewabledialog.c b/app/widgets/gimpviewabledialog.c
index 8001d38..6056f33 100644
--- a/app/widgets/gimpviewabledialog.c
+++ b/app/widgets/gimpviewabledialog.c
@@ -83,7 +83,8 @@ gimp_viewable_dialog_class_init (GimpViewableDialogClass *klass)
g_object_class_install_property (object_class, PROP_CONTEXT,
g_param_spec_object ("context", NULL, NULL,
GIMP_TYPE_CONTEXT,
- GIMP_PARAM_READWRITE));
+ GIMP_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_ICON_NAME,
g_param_spec_string ("icon-name", NULL, NULL,
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 2a9ddab..2d889bf 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -100,6 +100,7 @@ app/core/gimp-edit.c
app/core/gimp-gradients.c
app/core/gimp-gui.c
app/core/gimp-modules.c
+app/core/gimp-palettes.c
app/core/gimp-tags.c
app/core/gimp-units.c
app/core/gimp-user-install.c
@@ -160,8 +161,9 @@ app/core/gimppalette.c
app/core/gimppalette-import.c
app/core/gimppalette-load.c
app/core/gimppalette-save.c
-app/core/gimppattern-load.c
+app/core/gimppalettemru.c
app/core/gimppattern.c
+app/core/gimppattern-load.c
app/core/gimppatternclipboard.c
app/core/gimppdbprogress.c
app/core/gimpprogress.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]