mirror of https://github.com/GNOME/gimp.git
app/gui/Makefile.am new files implementing the color history which used to
2002-10-25 Michael Natterer <mitch@gimp.org> * app/gui/Makefile.am * app/gui/color-history.[ch]: new files implementing the color history which used to live in color-notebook.* * app/gui/color-notebook.[ch] * app/gui/session.c: changed accordingly.
This commit is contained in:
parent
491bbe0481
commit
ed3067f71a
|
@ -1,3 +1,12 @@
|
|||
2002-10-25 Michael Natterer <mitch@gimp.org>
|
||||
|
||||
* app/gui/Makefile.am
|
||||
* app/gui/color-history.[ch]: new files implementing the color
|
||||
history which used to live in color-notebook.*
|
||||
|
||||
* app/gui/color-notebook.[ch]
|
||||
* app/gui/session.c: changed accordingly.
|
||||
|
||||
2002-10-25 Michael Natterer <mitch@gimp.org>
|
||||
|
||||
* app/widgets/gimpimagedock.c: removed #warning and inclusion of
|
||||
|
|
|
@ -34,13 +34,14 @@
|
|||
|
||||
#include "widgets/gimpviewabledialog.h"
|
||||
|
||||
#include "color-history.h"
|
||||
#include "color-notebook.h"
|
||||
|
||||
#include "libgimp/gimpintl.h"
|
||||
|
||||
|
||||
#define COLOR_AREA_SIZE 20
|
||||
#define COLOR_HISTORY_SIZE 16
|
||||
#define COLOR_AREA_SIZE 20
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
|
@ -135,7 +136,6 @@ static gint color_notebook_hex_entry_events (GtkWidget *widget,
|
|||
GdkEvent *event,
|
||||
gpointer data);
|
||||
|
||||
static void color_history_init (void);
|
||||
static void color_history_color_clicked (GtkWidget *widget,
|
||||
gpointer data);
|
||||
static void color_history_color_changed (GtkWidget *widget,
|
||||
|
@ -144,10 +144,7 @@ static void color_history_add_clicked (GtkWidget *widget,
|
|||
gpointer data);
|
||||
|
||||
|
||||
static GList *color_notebooks = NULL;
|
||||
|
||||
static GimpRGB color_history[COLOR_HISTORY_SIZE];
|
||||
static gboolean color_history_initialized = FALSE;
|
||||
static GList *color_notebooks = NULL;
|
||||
|
||||
|
||||
ColorNotebook *
|
||||
|
@ -276,9 +273,6 @@ color_notebook_new_internal (GimpViewable *viewable,
|
|||
|
||||
g_return_val_if_fail (color != NULL, NULL);
|
||||
|
||||
if (! color_history_initialized)
|
||||
color_history_init ();
|
||||
|
||||
cnp = g_new0 (ColorNotebook, 1);
|
||||
|
||||
cnp->callback = callback;
|
||||
|
@ -589,6 +583,10 @@ color_notebook_new_internal (GimpViewable *viewable,
|
|||
|
||||
for (i = 0; i < COLOR_HISTORY_SIZE; i++)
|
||||
{
|
||||
GimpRGB history_color;
|
||||
|
||||
color_history_get (i, &history_color);
|
||||
|
||||
button = gtk_button_new ();
|
||||
gtk_widget_set_size_request (button, COLOR_AREA_SIZE, COLOR_AREA_SIZE);
|
||||
gtk_table_attach_defaults (GTK_TABLE (table), button,
|
||||
|
@ -597,7 +595,7 @@ color_notebook_new_internal (GimpViewable *viewable,
|
|||
i > 7 ? 1 : 0,
|
||||
i > 7 ? 2 : 1);
|
||||
|
||||
cnp->history[i] = gimp_color_area_new (&color_history[i],
|
||||
cnp->history[i] = gimp_color_area_new (&history_color,
|
||||
GIMP_COLOR_AREA_SMALL_CHECKS,
|
||||
GDK_BUTTON2_MASK);
|
||||
gtk_container_add (GTK_CONTAINER (button), cnp->history[i]);
|
||||
|
@ -610,7 +608,7 @@ color_notebook_new_internal (GimpViewable *viewable,
|
|||
|
||||
g_signal_connect (G_OBJECT (cnp->history[i]), "color_changed",
|
||||
G_CALLBACK (color_history_color_changed),
|
||||
&color_history[i]);
|
||||
GINT_TO_POINTER (i));
|
||||
}
|
||||
|
||||
/* The hex triplet entry */
|
||||
|
@ -1166,58 +1164,6 @@ color_notebook_hex_entry_events (GtkWidget *widget,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
color_history_add_color_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;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
color_history_write (FILE *fp)
|
||||
{
|
||||
gint i;
|
||||
|
||||
fprintf (fp, "(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);
|
||||
|
||||
fprintf (fp, "\n (color-rgba %s %s %s %s)",
|
||||
buf[0], buf[1], buf[2], buf[3]);
|
||||
}
|
||||
|
||||
fprintf (fp, ")\n\n");
|
||||
}
|
||||
|
||||
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_color_clicked (GtkWidget *widget,
|
||||
gpointer data)
|
||||
|
@ -1245,42 +1191,34 @@ static void
|
|||
color_history_color_changed (GtkWidget *widget,
|
||||
gpointer data)
|
||||
{
|
||||
GimpRGB *color;
|
||||
GimpRGB changed_color;
|
||||
gint i;
|
||||
GimpRGB changed_color;
|
||||
gint color_index;
|
||||
GList *list;
|
||||
ColorNotebook *notebook;
|
||||
|
||||
color = (GimpRGB *) data;
|
||||
color_index = GPOINTER_TO_INT (data);
|
||||
|
||||
gimp_color_area_get_color (GIMP_COLOR_AREA (widget), &changed_color);
|
||||
|
||||
for (i = 0; i < COLOR_HISTORY_SIZE; i++)
|
||||
color_history_set (color_index, &changed_color);
|
||||
|
||||
for (list = color_notebooks; list; list = g_list_next (list))
|
||||
{
|
||||
if (color == &color_history[i])
|
||||
{
|
||||
GList *list;
|
||||
ColorNotebook *notebook;
|
||||
notebook = (ColorNotebook *) list->data;
|
||||
|
||||
color_history[i] = changed_color;
|
||||
if (notebook->history[color_index] == widget)
|
||||
continue;
|
||||
|
||||
for (list = color_notebooks; list; list = g_list_next (list))
|
||||
{
|
||||
notebook = (ColorNotebook *) list->data;
|
||||
g_signal_handlers_block_by_func (G_OBJECT (notebook->history[color_index]),
|
||||
color_history_color_changed,
|
||||
data);
|
||||
|
||||
if (notebook->history[i] == widget)
|
||||
continue;
|
||||
gimp_color_area_set_color
|
||||
(GIMP_COLOR_AREA (notebook->history[color_index]), &changed_color);
|
||||
|
||||
g_signal_handlers_block_by_func (G_OBJECT (notebook->history[i]),
|
||||
color_history_color_changed,
|
||||
data);
|
||||
|
||||
gimp_color_area_set_color
|
||||
(GIMP_COLOR_AREA (notebook->history[i]), &changed_color);
|
||||
|
||||
g_signal_handlers_unblock_by_func (G_OBJECT (notebook->history[i]),
|
||||
color_history_color_changed,
|
||||
data);
|
||||
}
|
||||
}
|
||||
g_signal_handlers_unblock_by_func (G_OBJECT (notebook->history[color_index]),
|
||||
color_history_color_changed,
|
||||
data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1289,55 +1227,19 @@ color_history_add_clicked (GtkWidget *widget,
|
|||
gpointer data)
|
||||
{
|
||||
ColorNotebook *cnp;
|
||||
gint shift_begin = -1;
|
||||
gint i, j;
|
||||
gint shift_begin;
|
||||
gint i;
|
||||
|
||||
cnp = (ColorNotebook *) data;
|
||||
|
||||
/* is the added color already there? */
|
||||
for (i = 0; i < COLOR_HISTORY_SIZE; i++)
|
||||
shift_begin = color_history_add (&cnp->rgb);
|
||||
|
||||
for (i = shift_begin; i >= 0; i--)
|
||||
{
|
||||
if (gimp_rgba_distance (&color_history[i], &cnp->rgb) < 0.0001)
|
||||
{
|
||||
shift_begin = i;
|
||||
GimpRGB color;
|
||||
|
||||
goto doit;
|
||||
}
|
||||
color_history_get (i, &color);
|
||||
|
||||
gimp_color_area_set_color (GIMP_COLOR_AREA (cnp->history[i]), &color);
|
||||
}
|
||||
|
||||
/* 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--)
|
||||
{
|
||||
gimp_color_area_set_color (GIMP_COLOR_AREA (cnp->history[i]),
|
||||
&color_history[i - 1]);
|
||||
}
|
||||
|
||||
gimp_color_area_set_color (GIMP_COLOR_AREA (cnp->history[0]),
|
||||
&cnp->rgb);
|
||||
}
|
||||
|
|
|
@ -20,9 +20,6 @@
|
|||
#define __COLOR_NOTEBOOK_H__
|
||||
|
||||
|
||||
#include <stdio.h> /* for FILE */
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
COLOR_NOTEBOOK_OK,
|
||||
|
@ -69,10 +66,4 @@ void color_notebook_get_color (ColorNotebook *cnb,
|
|||
GimpRGB *color);
|
||||
|
||||
|
||||
/* color history functions */
|
||||
|
||||
void color_history_add_color_from_rc (GimpRGB *color);
|
||||
void color_history_write (FILE *fp);
|
||||
|
||||
|
||||
#endif /* __COLOR_NOTEBOOK_H__ */
|
||||
|
|
|
@ -14,6 +14,8 @@ libappgui_a_SOURCES = \
|
|||
buffers-commands.h \
|
||||
channels-commands.c \
|
||||
channels-commands.h \
|
||||
color-history.c \
|
||||
color-history.h \
|
||||
color-notebook.c \
|
||||
color-notebook.h \
|
||||
colormap-editor-commands.c \
|
||||
|
|
|
@ -0,0 +1,182 @@
|
|||
/* The GIMP -- an image manipulation program
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* color-history.c
|
||||
* Copyright (C) 2002 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "libgimpcolor/gimpcolor.h"
|
||||
|
||||
#include "gui-types.h"
|
||||
|
||||
#include "color-history.h"
|
||||
|
||||
|
||||
#define COLOR_HISTORY_SIZE 16
|
||||
|
||||
|
||||
static void color_history_init (void);
|
||||
|
||||
|
||||
static GimpRGB color_history[COLOR_HISTORY_SIZE];
|
||||
static gboolean color_history_initialized = FALSE;
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
color_history_write (FILE *fp)
|
||||
{
|
||||
gint i;
|
||||
|
||||
if (! color_history_initialized)
|
||||
color_history_init ();
|
||||
|
||||
fprintf (fp, "(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);
|
||||
|
||||
fprintf (fp, "\n (color-rgba %s %s %s %s)",
|
||||
buf[0], buf[1], buf[2], buf[3]);
|
||||
}
|
||||
|
||||
fprintf (fp, ")\n\n");
|
||||
}
|
||||
|
||||
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 ();
|
||||
|
||||
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;
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
/* The GIMP -- an image manipulation program
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* color-history.h
|
||||
* Copyright (C) 2002 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __COLOR_HISTORY_H__
|
||||
#define __COLOR_HISTORY_H__
|
||||
|
||||
#include <stdio.h> /* FILE */
|
||||
|
||||
#define COLOR_HISTORY_SIZE 16
|
||||
|
||||
|
||||
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_add_from_rc (GimpRGB *color);
|
||||
void color_history_write (FILE *fp);
|
||||
|
||||
|
||||
#endif /* __COLOR_HISTORY_H__ */
|
|
@ -34,13 +34,14 @@
|
|||
|
||||
#include "widgets/gimpviewabledialog.h"
|
||||
|
||||
#include "color-history.h"
|
||||
#include "color-notebook.h"
|
||||
|
||||
#include "libgimp/gimpintl.h"
|
||||
|
||||
|
||||
#define COLOR_AREA_SIZE 20
|
||||
#define COLOR_HISTORY_SIZE 16
|
||||
#define COLOR_AREA_SIZE 20
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
|
@ -135,7 +136,6 @@ static gint color_notebook_hex_entry_events (GtkWidget *widget,
|
|||
GdkEvent *event,
|
||||
gpointer data);
|
||||
|
||||
static void color_history_init (void);
|
||||
static void color_history_color_clicked (GtkWidget *widget,
|
||||
gpointer data);
|
||||
static void color_history_color_changed (GtkWidget *widget,
|
||||
|
@ -144,10 +144,7 @@ static void color_history_add_clicked (GtkWidget *widget,
|
|||
gpointer data);
|
||||
|
||||
|
||||
static GList *color_notebooks = NULL;
|
||||
|
||||
static GimpRGB color_history[COLOR_HISTORY_SIZE];
|
||||
static gboolean color_history_initialized = FALSE;
|
||||
static GList *color_notebooks = NULL;
|
||||
|
||||
|
||||
ColorNotebook *
|
||||
|
@ -276,9 +273,6 @@ color_notebook_new_internal (GimpViewable *viewable,
|
|||
|
||||
g_return_val_if_fail (color != NULL, NULL);
|
||||
|
||||
if (! color_history_initialized)
|
||||
color_history_init ();
|
||||
|
||||
cnp = g_new0 (ColorNotebook, 1);
|
||||
|
||||
cnp->callback = callback;
|
||||
|
@ -589,6 +583,10 @@ color_notebook_new_internal (GimpViewable *viewable,
|
|||
|
||||
for (i = 0; i < COLOR_HISTORY_SIZE; i++)
|
||||
{
|
||||
GimpRGB history_color;
|
||||
|
||||
color_history_get (i, &history_color);
|
||||
|
||||
button = gtk_button_new ();
|
||||
gtk_widget_set_size_request (button, COLOR_AREA_SIZE, COLOR_AREA_SIZE);
|
||||
gtk_table_attach_defaults (GTK_TABLE (table), button,
|
||||
|
@ -597,7 +595,7 @@ color_notebook_new_internal (GimpViewable *viewable,
|
|||
i > 7 ? 1 : 0,
|
||||
i > 7 ? 2 : 1);
|
||||
|
||||
cnp->history[i] = gimp_color_area_new (&color_history[i],
|
||||
cnp->history[i] = gimp_color_area_new (&history_color,
|
||||
GIMP_COLOR_AREA_SMALL_CHECKS,
|
||||
GDK_BUTTON2_MASK);
|
||||
gtk_container_add (GTK_CONTAINER (button), cnp->history[i]);
|
||||
|
@ -610,7 +608,7 @@ color_notebook_new_internal (GimpViewable *viewable,
|
|||
|
||||
g_signal_connect (G_OBJECT (cnp->history[i]), "color_changed",
|
||||
G_CALLBACK (color_history_color_changed),
|
||||
&color_history[i]);
|
||||
GINT_TO_POINTER (i));
|
||||
}
|
||||
|
||||
/* The hex triplet entry */
|
||||
|
@ -1166,58 +1164,6 @@ color_notebook_hex_entry_events (GtkWidget *widget,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
color_history_add_color_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;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
color_history_write (FILE *fp)
|
||||
{
|
||||
gint i;
|
||||
|
||||
fprintf (fp, "(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);
|
||||
|
||||
fprintf (fp, "\n (color-rgba %s %s %s %s)",
|
||||
buf[0], buf[1], buf[2], buf[3]);
|
||||
}
|
||||
|
||||
fprintf (fp, ")\n\n");
|
||||
}
|
||||
|
||||
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_color_clicked (GtkWidget *widget,
|
||||
gpointer data)
|
||||
|
@ -1245,42 +1191,34 @@ static void
|
|||
color_history_color_changed (GtkWidget *widget,
|
||||
gpointer data)
|
||||
{
|
||||
GimpRGB *color;
|
||||
GimpRGB changed_color;
|
||||
gint i;
|
||||
GimpRGB changed_color;
|
||||
gint color_index;
|
||||
GList *list;
|
||||
ColorNotebook *notebook;
|
||||
|
||||
color = (GimpRGB *) data;
|
||||
color_index = GPOINTER_TO_INT (data);
|
||||
|
||||
gimp_color_area_get_color (GIMP_COLOR_AREA (widget), &changed_color);
|
||||
|
||||
for (i = 0; i < COLOR_HISTORY_SIZE; i++)
|
||||
color_history_set (color_index, &changed_color);
|
||||
|
||||
for (list = color_notebooks; list; list = g_list_next (list))
|
||||
{
|
||||
if (color == &color_history[i])
|
||||
{
|
||||
GList *list;
|
||||
ColorNotebook *notebook;
|
||||
notebook = (ColorNotebook *) list->data;
|
||||
|
||||
color_history[i] = changed_color;
|
||||
if (notebook->history[color_index] == widget)
|
||||
continue;
|
||||
|
||||
for (list = color_notebooks; list; list = g_list_next (list))
|
||||
{
|
||||
notebook = (ColorNotebook *) list->data;
|
||||
g_signal_handlers_block_by_func (G_OBJECT (notebook->history[color_index]),
|
||||
color_history_color_changed,
|
||||
data);
|
||||
|
||||
if (notebook->history[i] == widget)
|
||||
continue;
|
||||
gimp_color_area_set_color
|
||||
(GIMP_COLOR_AREA (notebook->history[color_index]), &changed_color);
|
||||
|
||||
g_signal_handlers_block_by_func (G_OBJECT (notebook->history[i]),
|
||||
color_history_color_changed,
|
||||
data);
|
||||
|
||||
gimp_color_area_set_color
|
||||
(GIMP_COLOR_AREA (notebook->history[i]), &changed_color);
|
||||
|
||||
g_signal_handlers_unblock_by_func (G_OBJECT (notebook->history[i]),
|
||||
color_history_color_changed,
|
||||
data);
|
||||
}
|
||||
}
|
||||
g_signal_handlers_unblock_by_func (G_OBJECT (notebook->history[color_index]),
|
||||
color_history_color_changed,
|
||||
data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1289,55 +1227,19 @@ color_history_add_clicked (GtkWidget *widget,
|
|||
gpointer data)
|
||||
{
|
||||
ColorNotebook *cnp;
|
||||
gint shift_begin = -1;
|
||||
gint i, j;
|
||||
gint shift_begin;
|
||||
gint i;
|
||||
|
||||
cnp = (ColorNotebook *) data;
|
||||
|
||||
/* is the added color already there? */
|
||||
for (i = 0; i < COLOR_HISTORY_SIZE; i++)
|
||||
shift_begin = color_history_add (&cnp->rgb);
|
||||
|
||||
for (i = shift_begin; i >= 0; i--)
|
||||
{
|
||||
if (gimp_rgba_distance (&color_history[i], &cnp->rgb) < 0.0001)
|
||||
{
|
||||
shift_begin = i;
|
||||
GimpRGB color;
|
||||
|
||||
goto doit;
|
||||
}
|
||||
color_history_get (i, &color);
|
||||
|
||||
gimp_color_area_set_color (GIMP_COLOR_AREA (cnp->history[i]), &color);
|
||||
}
|
||||
|
||||
/* 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--)
|
||||
{
|
||||
gimp_color_area_set_color (GIMP_COLOR_AREA (cnp->history[i]),
|
||||
&color_history[i - 1]);
|
||||
}
|
||||
|
||||
gimp_color_area_set_color (GIMP_COLOR_AREA (cnp->history[0]),
|
||||
&cnp->rgb);
|
||||
}
|
||||
|
|
|
@ -20,9 +20,6 @@
|
|||
#define __COLOR_NOTEBOOK_H__
|
||||
|
||||
|
||||
#include <stdio.h> /* for FILE */
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
COLOR_NOTEBOOK_OK,
|
||||
|
@ -69,10 +66,4 @@ void color_notebook_get_color (ColorNotebook *cnb,
|
|||
GimpRGB *color);
|
||||
|
||||
|
||||
/* color history functions */
|
||||
|
||||
void color_history_add_color_from_rc (GimpRGB *color);
|
||||
void color_history_write (FILE *fp);
|
||||
|
||||
|
||||
#endif /* __COLOR_NOTEBOOK_H__ */
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
|
||||
#include "widgets/gimpdialogfactory.h"
|
||||
|
||||
#include "color-notebook.h"
|
||||
#include "color-history.h"
|
||||
#include "session.h"
|
||||
|
||||
#include "gimprc.h"
|
||||
|
@ -138,7 +138,7 @@ session_init (Gimp *gimp)
|
|||
if (! gimp_scanner_parse_color (scanner, &color))
|
||||
goto error;
|
||||
|
||||
color_history_add_color_from_rc (&color);
|
||||
color_history_add_from_rc (&color);
|
||||
}
|
||||
}
|
||||
else if (scanner->value.v_symbol == GINT_TO_POINTER (LAST_TIP_SHOWN))
|
||||
|
|
|
@ -34,13 +34,14 @@
|
|||
|
||||
#include "widgets/gimpviewabledialog.h"
|
||||
|
||||
#include "color-history.h"
|
||||
#include "color-notebook.h"
|
||||
|
||||
#include "libgimp/gimpintl.h"
|
||||
|
||||
|
||||
#define COLOR_AREA_SIZE 20
|
||||
#define COLOR_HISTORY_SIZE 16
|
||||
#define COLOR_AREA_SIZE 20
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
|
@ -135,7 +136,6 @@ static gint color_notebook_hex_entry_events (GtkWidget *widget,
|
|||
GdkEvent *event,
|
||||
gpointer data);
|
||||
|
||||
static void color_history_init (void);
|
||||
static void color_history_color_clicked (GtkWidget *widget,
|
||||
gpointer data);
|
||||
static void color_history_color_changed (GtkWidget *widget,
|
||||
|
@ -144,10 +144,7 @@ static void color_history_add_clicked (GtkWidget *widget,
|
|||
gpointer data);
|
||||
|
||||
|
||||
static GList *color_notebooks = NULL;
|
||||
|
||||
static GimpRGB color_history[COLOR_HISTORY_SIZE];
|
||||
static gboolean color_history_initialized = FALSE;
|
||||
static GList *color_notebooks = NULL;
|
||||
|
||||
|
||||
ColorNotebook *
|
||||
|
@ -276,9 +273,6 @@ color_notebook_new_internal (GimpViewable *viewable,
|
|||
|
||||
g_return_val_if_fail (color != NULL, NULL);
|
||||
|
||||
if (! color_history_initialized)
|
||||
color_history_init ();
|
||||
|
||||
cnp = g_new0 (ColorNotebook, 1);
|
||||
|
||||
cnp->callback = callback;
|
||||
|
@ -589,6 +583,10 @@ color_notebook_new_internal (GimpViewable *viewable,
|
|||
|
||||
for (i = 0; i < COLOR_HISTORY_SIZE; i++)
|
||||
{
|
||||
GimpRGB history_color;
|
||||
|
||||
color_history_get (i, &history_color);
|
||||
|
||||
button = gtk_button_new ();
|
||||
gtk_widget_set_size_request (button, COLOR_AREA_SIZE, COLOR_AREA_SIZE);
|
||||
gtk_table_attach_defaults (GTK_TABLE (table), button,
|
||||
|
@ -597,7 +595,7 @@ color_notebook_new_internal (GimpViewable *viewable,
|
|||
i > 7 ? 1 : 0,
|
||||
i > 7 ? 2 : 1);
|
||||
|
||||
cnp->history[i] = gimp_color_area_new (&color_history[i],
|
||||
cnp->history[i] = gimp_color_area_new (&history_color,
|
||||
GIMP_COLOR_AREA_SMALL_CHECKS,
|
||||
GDK_BUTTON2_MASK);
|
||||
gtk_container_add (GTK_CONTAINER (button), cnp->history[i]);
|
||||
|
@ -610,7 +608,7 @@ color_notebook_new_internal (GimpViewable *viewable,
|
|||
|
||||
g_signal_connect (G_OBJECT (cnp->history[i]), "color_changed",
|
||||
G_CALLBACK (color_history_color_changed),
|
||||
&color_history[i]);
|
||||
GINT_TO_POINTER (i));
|
||||
}
|
||||
|
||||
/* The hex triplet entry */
|
||||
|
@ -1166,58 +1164,6 @@ color_notebook_hex_entry_events (GtkWidget *widget,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
color_history_add_color_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;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
color_history_write (FILE *fp)
|
||||
{
|
||||
gint i;
|
||||
|
||||
fprintf (fp, "(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);
|
||||
|
||||
fprintf (fp, "\n (color-rgba %s %s %s %s)",
|
||||
buf[0], buf[1], buf[2], buf[3]);
|
||||
}
|
||||
|
||||
fprintf (fp, ")\n\n");
|
||||
}
|
||||
|
||||
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_color_clicked (GtkWidget *widget,
|
||||
gpointer data)
|
||||
|
@ -1245,42 +1191,34 @@ static void
|
|||
color_history_color_changed (GtkWidget *widget,
|
||||
gpointer data)
|
||||
{
|
||||
GimpRGB *color;
|
||||
GimpRGB changed_color;
|
||||
gint i;
|
||||
GimpRGB changed_color;
|
||||
gint color_index;
|
||||
GList *list;
|
||||
ColorNotebook *notebook;
|
||||
|
||||
color = (GimpRGB *) data;
|
||||
color_index = GPOINTER_TO_INT (data);
|
||||
|
||||
gimp_color_area_get_color (GIMP_COLOR_AREA (widget), &changed_color);
|
||||
|
||||
for (i = 0; i < COLOR_HISTORY_SIZE; i++)
|
||||
color_history_set (color_index, &changed_color);
|
||||
|
||||
for (list = color_notebooks; list; list = g_list_next (list))
|
||||
{
|
||||
if (color == &color_history[i])
|
||||
{
|
||||
GList *list;
|
||||
ColorNotebook *notebook;
|
||||
notebook = (ColorNotebook *) list->data;
|
||||
|
||||
color_history[i] = changed_color;
|
||||
if (notebook->history[color_index] == widget)
|
||||
continue;
|
||||
|
||||
for (list = color_notebooks; list; list = g_list_next (list))
|
||||
{
|
||||
notebook = (ColorNotebook *) list->data;
|
||||
g_signal_handlers_block_by_func (G_OBJECT (notebook->history[color_index]),
|
||||
color_history_color_changed,
|
||||
data);
|
||||
|
||||
if (notebook->history[i] == widget)
|
||||
continue;
|
||||
gimp_color_area_set_color
|
||||
(GIMP_COLOR_AREA (notebook->history[color_index]), &changed_color);
|
||||
|
||||
g_signal_handlers_block_by_func (G_OBJECT (notebook->history[i]),
|
||||
color_history_color_changed,
|
||||
data);
|
||||
|
||||
gimp_color_area_set_color
|
||||
(GIMP_COLOR_AREA (notebook->history[i]), &changed_color);
|
||||
|
||||
g_signal_handlers_unblock_by_func (G_OBJECT (notebook->history[i]),
|
||||
color_history_color_changed,
|
||||
data);
|
||||
}
|
||||
}
|
||||
g_signal_handlers_unblock_by_func (G_OBJECT (notebook->history[color_index]),
|
||||
color_history_color_changed,
|
||||
data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1289,55 +1227,19 @@ color_history_add_clicked (GtkWidget *widget,
|
|||
gpointer data)
|
||||
{
|
||||
ColorNotebook *cnp;
|
||||
gint shift_begin = -1;
|
||||
gint i, j;
|
||||
gint shift_begin;
|
||||
gint i;
|
||||
|
||||
cnp = (ColorNotebook *) data;
|
||||
|
||||
/* is the added color already there? */
|
||||
for (i = 0; i < COLOR_HISTORY_SIZE; i++)
|
||||
shift_begin = color_history_add (&cnp->rgb);
|
||||
|
||||
for (i = shift_begin; i >= 0; i--)
|
||||
{
|
||||
if (gimp_rgba_distance (&color_history[i], &cnp->rgb) < 0.0001)
|
||||
{
|
||||
shift_begin = i;
|
||||
GimpRGB color;
|
||||
|
||||
goto doit;
|
||||
}
|
||||
color_history_get (i, &color);
|
||||
|
||||
gimp_color_area_set_color (GIMP_COLOR_AREA (cnp->history[i]), &color);
|
||||
}
|
||||
|
||||
/* 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--)
|
||||
{
|
||||
gimp_color_area_set_color (GIMP_COLOR_AREA (cnp->history[i]),
|
||||
&color_history[i - 1]);
|
||||
}
|
||||
|
||||
gimp_color_area_set_color (GIMP_COLOR_AREA (cnp->history[0]),
|
||||
&cnp->rgb);
|
||||
}
|
||||
|
|
|
@ -20,9 +20,6 @@
|
|||
#define __COLOR_NOTEBOOK_H__
|
||||
|
||||
|
||||
#include <stdio.h> /* for FILE */
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
COLOR_NOTEBOOK_OK,
|
||||
|
@ -69,10 +66,4 @@ void color_notebook_get_color (ColorNotebook *cnb,
|
|||
GimpRGB *color);
|
||||
|
||||
|
||||
/* color history functions */
|
||||
|
||||
void color_history_add_color_from_rc (GimpRGB *color);
|
||||
void color_history_write (FILE *fp);
|
||||
|
||||
|
||||
#endif /* __COLOR_NOTEBOOK_H__ */
|
||||
|
|
Loading…
Reference in New Issue