Commit ed7da929 authored by Michael Natterer's avatar Michael Natterer Committed by Michael Natterer

new function color_panel_set_color().

1999-08-24  Michael Natterer  <mitschel@cs.tu-berlin.de>

	* app/color_panel.[ch]: new function color_panel_set_color().

	* app/color_picker.c: added a color panel to the color picker info
	dialog and a toggle button to the color picker's tool options
	which allows color updates to be effective in the info dialog
	only.

	* app/info_dialog.[ch]: changed the packing parameters of the info
	table. Small fixes.

	* app/palette.c: the name created for dropped colors contained " "
	instead of "0".
parent bb0447f1
1999-08-24 Michael Natterer <mitschel@cs.tu-berlin.de>
* app/color_panel.[ch]: new function color_panel_set_color().
* app/color_picker.c: added a color panel to the color picker info
dialog and a toggle button to the color picker's tool options
which allows color updates to be effective in the info dialog
only.
* app/info_dialog.[ch]: changed the packing parameters of the info
table. Small fixes.
* app/palette.c: the name created for dropped colors contained " "
instead of "0".
1999-08-24 Michael Natterer <mitschel@cs.tu-berlin.de>
* app/channels_dialog.c
......
......@@ -140,6 +140,24 @@ color_panel_free (ColorPanel *color_panel)
g_free (color_panel);
}
void
color_panel_set_color (ColorPanel *color_panel,
guchar *col)
{
ColorPanelPrivate *private = color_panel->private_part;
color_panel->color[0] = col[0];
color_panel->color[1] = col[1];
color_panel->color[2] = col[2];
if (private->color_notebook_active)
color_notebook_set_color (private->color_notebook,
col[0], col[1], col[2], TRUE);
if (private->gc)
color_panel_draw (color_panel);
}
/* private functions */
static void
......
......@@ -32,9 +32,12 @@ struct _ColorPanel
void *private_part;
};
ColorPanel * color_panel_new (guchar *initial,
gint width,
gint height);
void color_panel_free (ColorPanel *color_panel);
ColorPanel * color_panel_new (guchar *initial,
gint width,
gint height);
void color_panel_free (ColorPanel *color_panel);
void color_panel_set_color (ColorPanel *color_panel,
guchar *col);
#endif /* __COLOR_PANEL_H__ */
......@@ -17,6 +17,7 @@
*/
#include "appenv.h"
#include "actionarea.h"
#include "color_panel.h"
#include "color_picker.h"
#include "draw_core.h"
#include "drawable.h"
......@@ -40,26 +41,30 @@ struct _ColorPickerOptions
{
ToolOptions tool_options;
gint sample_merged;
gint sample_merged_d;
gboolean sample_merged;
gboolean sample_merged_d;
GtkWidget *sample_merged_w;
gint sample_average;
gint sample_average_d;
gboolean sample_average;
gboolean sample_average_d;
GtkWidget *sample_average_w;
gdouble average_radius;
gdouble average_radius_d;
GtkObject *average_radius_w;
gboolean update_active;
gboolean update_active_d;
GtkWidget *update_active_w;
};
typedef struct _ColorPickerTool ColorPickerTool;
struct _ColorPickerTool
{
DrawCore *core; /* Core select object */
DrawCore *core; /* Core select object */
gint centerx; /* starting x coord */
gint centery; /* starting y coord */
gint centerx; /* starting x coord */
gint centery; /* starting y coord */
};
/* the color picker tool options */
......@@ -71,7 +76,8 @@ gint col_value[5] = { 0, 0, 0, 0, 0 };
/* the color picker dialog */
static gint update_type;
static GimpImageType sample_type;
static InfoDialog * color_picker_info = NULL;
static InfoDialog *color_picker_info = NULL;
static ColorPanel *color_panel = NULL;
static gchar red_buf [MAX_INFO_BUF];
static gchar green_buf [MAX_INFO_BUF];
static gchar blue_buf [MAX_INFO_BUF];
......@@ -83,15 +89,24 @@ static gchar hex_buf [MAX_INFO_BUF];
/* local function prototypes */
static void color_picker_button_press (Tool *, GdkEventButton *, gpointer);
static void color_picker_button_release (Tool *, GdkEventButton *, gpointer);
static void color_picker_motion (Tool *, GdkEventMotion *, gpointer);
static void color_picker_cursor_update (Tool *, GdkEventMotion *, gpointer);
static void color_picker_control (Tool *, ToolAction, gpointer);
static void color_picker_info_window_close_callback (GtkWidget *, gpointer);
static void color_picker_info_update (Tool *, gboolean);
static void color_picker_button_press (Tool *, GdkEventButton *, gpointer);
static void color_picker_button_release (Tool *, GdkEventButton *, gpointer);
static void color_picker_motion (Tool *, GdkEventMotion *, gpointer);
static void color_picker_cursor_update (Tool *, GdkEventMotion *, gpointer);
static void color_picker_control (Tool *, ToolAction, gpointer);
static void color_picker_info_window_close_callback (GtkWidget *, gpointer);
static void color_picker_info_update (Tool *, gboolean);
static gboolean pick_color_do (GimpImage *gimage,
GimpDrawable *drawable,
gint x,
gint y,
gboolean sample_merged,
gboolean sample_average,
gdouble average_radius,
gboolean update_active,
gint final);
/* functions */
......@@ -106,6 +121,8 @@ color_picker_options_reset (void)
options->sample_average_d);
gtk_adjustment_set_value (GTK_ADJUSTMENT (options->average_radius_w),
options->average_radius_d);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->update_active_w),
options->update_active_d);
}
static ColorPickerOptions *
......@@ -127,6 +144,7 @@ color_picker_options_new (void)
options->sample_merged = options->sample_merged_d = FALSE;
options->sample_average = options->sample_average_d = FALSE;
options->average_radius = options->average_radius_d = 1.0;
options->update_active = options->update_active_d = TRUE;
/* the main vbox */
vbox = options->tool_options.main_vbox;
......@@ -189,6 +207,17 @@ color_picker_options_new (void)
gtk_widget_show (scale);
gtk_widget_show (table);
/* the update active color toggle button */
options->update_active_w =
gtk_check_button_new_with_label (_("Update Active Color"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->update_active_w),
options->update_active_d);
gtk_box_pack_start (GTK_BOX (vbox), options->update_active_w, FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT (options->update_active_w), "toggled",
(GtkSignalFunc) tool_options_toggle_update,
&options->update_active);
gtk_widget_show (options->update_active_w);
return options;
}
......@@ -217,6 +246,8 @@ color_picker_button_press (Tool *tool,
/* create the info dialog if it doesn't exist */
if (! color_picker_info)
{
GtkWidget *hbox;
color_picker_info = info_dialog_new (_("Color Picker"));
/* if the gdisplay is for a color image, the dialog must have RGB */
......@@ -249,6 +280,18 @@ color_picker_button_press (Tool *tool,
break;
}
hbox = gtk_hbox_new (FALSE, 4);
gtk_box_pack_start (GTK_BOX (color_picker_info->vbox), hbox,
FALSE, FALSE, 0);
gtk_widget_show (hbox);
gtk_widget_reparent (color_picker_info->info_table, hbox);
color_panel = color_panel_new (NULL, 48, 64);
gtk_box_pack_start (GTK_BOX (hbox), color_panel->color_panel_widget,
FALSE, FALSE, 0);
gtk_widget_show (color_panel->color_panel_widget);
/* create the action area */
action_items[0].user_data = color_picker_info;
build_action_area (GTK_DIALOG (color_picker_info->shell),
......@@ -274,22 +317,24 @@ color_picker_button_press (Tool *tool,
*/
if (bevent->state & GDK_SHIFT_MASK)
{
color_picker_info_update (tool,
pick_color (gdisp->gimage, tool->drawable, x, y,
color_picker_options->sample_merged,
color_picker_options->sample_average,
color_picker_options->average_radius,
COLOR_NEW));
color_picker_info_update
(tool, pick_color_do (gdisp->gimage, tool->drawable, x, y,
color_picker_options->sample_merged,
color_picker_options->sample_average,
color_picker_options->average_radius,
color_picker_options->update_active,
COLOR_NEW));
update_type = COLOR_UPDATE_NEW;
}
else
{
color_picker_info_update (tool,
pick_color (gdisp->gimage, tool->drawable, x, y,
color_picker_options->sample_merged,
color_picker_options->sample_average,
color_picker_options->average_radius,
COLOR_UPDATE));
color_picker_info_update
(tool, pick_color_do (gdisp->gimage, tool->drawable, x, y,
color_picker_options->sample_merged,
color_picker_options->sample_average,
color_picker_options->average_radius,
color_picker_options->update_active,
COLOR_UPDATE));
update_type = COLOR_UPDATE;
}
......@@ -315,12 +360,13 @@ color_picker_button_release (Tool *tool,
gdisplay_untransform_coords (gdisp, bevent->x, bevent->y, &x, &y,
FALSE, FALSE);
color_picker_info_update (tool,
pick_color (gdisp->gimage, tool->drawable, x, y,
color_picker_options->sample_merged,
color_picker_options->sample_average,
color_picker_options->average_radius,
update_type));
color_picker_info_update
(tool, pick_color_do (gdisp->gimage, tool->drawable, x, y,
color_picker_options->sample_merged,
color_picker_options->sample_average,
color_picker_options->average_radius,
color_picker_options->update_active,
update_type));
draw_core_stop (cp_tool->core, tool);
tool->state = INACTIVE;
......@@ -333,7 +379,7 @@ color_picker_motion (Tool *tool,
{
GDisplay *gdisp;
ColorPickerTool *cp_tool;
int x, y;
gint x, y;
gdisp = (GDisplay *) gdisp_ptr;
cp_tool = (ColorPickerTool *) tool->private;
......@@ -349,12 +395,13 @@ color_picker_motion (Tool *tool,
&cp_tool->centerx, &cp_tool->centery,
FALSE, TRUE);
color_picker_info_update (tool,
pick_color (gdisp->gimage, tool->drawable, x, y,
color_picker_options->sample_merged,
color_picker_options->sample_average,
color_picker_options->average_radius,
update_type));
color_picker_info_update
(tool, pick_color_do (gdisp->gimage, tool->drawable, x, y,
color_picker_options->sample_merged,
color_picker_options->sample_average,
color_picker_options->average_radius,
color_picker_options->update_active,
update_type));
/* redraw the current tool */
draw_core_resume (cp_tool->core, tool);
......@@ -366,7 +413,7 @@ color_picker_cursor_update (Tool *tool,
gpointer gdisp_ptr)
{
GDisplay *gdisp;
int x, y;
gint x, y;
gdisp = (GDisplay *) gdisp_ptr;
......@@ -400,6 +447,7 @@ color_picker_control (Tool *tool,
case HALT :
draw_core_stop (cp_tool->core, tool);
info_dialog_popdown (color_picker_info);
break;
default:
......@@ -409,15 +457,16 @@ color_picker_control (Tool *tool,
typedef guchar * (*GetColorFunc) (GtkObject *, int, int);
gboolean
pick_color (GimpImage *gimage,
GimpDrawable *drawable,
gint x,
gint y,
gboolean sample_merged,
gboolean sample_average,
gdouble average_radius,
gint final)
static gboolean
pick_color_do (GimpImage *gimage,
GimpDrawable *drawable,
gint x,
gint y,
gboolean sample_merged,
gboolean sample_average,
gdouble average_radius,
gboolean update_active,
gint final)
{
guchar *color;
gint offx, offy;
......@@ -495,12 +544,32 @@ pick_color (GimpImage *gimage,
if (is_indexed)
col_value[4] = color[4];
palette_set_active_color (col_value [RED_PIX], col_value [GREEN_PIX],
col_value [BLUE_PIX], final);
if (update_active)
palette_set_active_color (col_value [RED_PIX], col_value [GREEN_PIX],
col_value [BLUE_PIX], final);
g_free (color);
return TRUE;
}
gboolean
pick_color (GimpImage *gimage,
GimpDrawable *drawable,
gint x,
gint y,
gboolean sample_merged,
gboolean sample_average,
gdouble average_radius,
gint final)
{
return pick_color_do (gimage, drawable,
x, y,
sample_merged,
sample_average,
average_radius,
TRUE,
final);
}
static void
colorpicker_draw (Tool *tool)
{
......@@ -545,6 +614,9 @@ color_picker_info_update (Tool *tool,
{
if (!valid)
{
if (GTK_WIDGET_IS_SENSITIVE (color_panel->color_panel_widget))
gtk_widget_set_sensitive (color_panel->color_panel_widget, FALSE);
g_snprintf (red_buf, MAX_INFO_BUF, _("N/A"));
g_snprintf (green_buf, MAX_INFO_BUF, _("N/A"));
g_snprintf (blue_buf, MAX_INFO_BUF, _("N/A"));
......@@ -555,6 +627,11 @@ color_picker_info_update (Tool *tool,
}
else
{
guchar col[3];
if (! GTK_WIDGET_IS_SENSITIVE (color_panel->color_panel_widget))
gtk_widget_set_sensitive (color_panel->color_panel_widget, TRUE);
switch (sample_type)
{
case RGB_GIMAGE: case RGBA_GIMAGE:
......@@ -569,6 +646,9 @@ color_picker_info_update (Tool *tool,
col_value [RED_PIX],
col_value [GREEN_PIX],
col_value [BLUE_PIX]);
col[0] = col_value [RED_PIX];
col[1] = col_value [GREEN_PIX];
col[2] = col_value [BLUE_PIX];
break;
case INDEXED_GIMAGE: case INDEXEDA_GIMAGE:
......@@ -584,6 +664,9 @@ color_picker_info_update (Tool *tool,
col_value [RED_PIX],
col_value [GREEN_PIX],
col_value [BLUE_PIX]);
col[0] = col_value [RED_PIX];
col[1] = col_value [GREEN_PIX];
col[2] = col_value [BLUE_PIX];
break;
case GRAY_GIMAGE: case GRAYA_GIMAGE:
......@@ -596,8 +679,13 @@ color_picker_info_update (Tool *tool,
col_value [GRAY_PIX],
col_value [GRAY_PIX],
col_value [GRAY_PIX]);
col[0] = col_value [GRAY_PIX];
col[1] = col_value [GRAY_PIX];
col[2] = col_value [GRAY_PIX];
break;
}
color_panel_set_color (color_panel, col);
}
info_dialog_update (color_picker_info);
......@@ -658,6 +746,7 @@ tools_free_color_picker (Tool *tool)
{
info_dialog_free (color_picker_info);
color_picker_info = NULL;
color_panel = NULL;
}
g_free (cp_tool);
......
......@@ -82,8 +82,8 @@ static void
update_field (InfoField *field)
{
gchar *old_text;
int num;
int i;
gint num;
gint i;
if (field->value_ptr == NULL)
return;
......@@ -130,17 +130,18 @@ update_field (InfoField *field)
}
static gint
info_dialog_delete_callback (GtkWidget *w,
GdkEvent *e,
gpointer client_data)
info_dialog_delete_callback (GtkWidget *widget,
GdkEvent *event,
gpointer data)
{
info_dialog_popdown ((InfoDialog *) client_data);
info_dialog_popdown ((InfoDialog *) data);
return TRUE;
}
static InfoDialog *
info_dialog_new_extended (char *title,gboolean inNotebook)
info_dialog_new_extended (gchar *title,
gboolean in_notebook)
{
InfoDialog *idialog;
GtkWidget *shell;
......@@ -150,7 +151,7 @@ info_dialog_new_extended (char *title,gboolean inNotebook)
idialog = g_new (InfoDialog, 1);
idialog->field_list = NULL;
idialog->nfields = 0;
idialog->nfields = 0;
shell = gtk_dialog_new ();
gtk_window_set_wmclass (GTK_WINDOW (shell), "info_dialog", "Gimp");
......@@ -163,30 +164,30 @@ info_dialog_new_extended (char *title,gboolean inNotebook)
vbox = gtk_vbox_new (FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (shell)->vbox), vbox, TRUE, TRUE, 0);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (shell)->vbox), vbox);
info_table = gtk_table_new (2, 0, FALSE);
if(inNotebook)
if( in_notebook)
{
info_notebook = gtk_notebook_new();
gtk_notebook_append_page(GTK_NOTEBOOK(info_notebook),
info_table,
gtk_label_new (_("General")));
gtk_box_pack_start (GTK_BOX (vbox), info_notebook, TRUE, TRUE, 0);
info_notebook = gtk_notebook_new ();
gtk_notebook_append_page (GTK_NOTEBOOK (info_notebook),
info_table,
gtk_label_new (_("General")));
gtk_box_pack_start (GTK_BOX (vbox), info_notebook, FALSE, FALSE, 0);
}
else
{
info_notebook = NULL;
gtk_box_pack_start (GTK_BOX (vbox), info_table, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (vbox), info_table, FALSE, FALSE, 0);
}
idialog->shell = shell;
idialog->vbox = vbox;
idialog->info_table = info_table;
idialog->info_notebook = info_notebook;
if(inNotebook)
if (in_notebook)
gtk_widget_show (idialog->info_notebook);
gtk_widget_show (idialog->info_table);
......@@ -198,15 +199,15 @@ info_dialog_new_extended (char *title,gboolean inNotebook)
/* public functions */
InfoDialog *
info_dialog_notebook_new (char *title)
info_dialog_notebook_new (gchar *title)
{
return info_dialog_new_extended(title,TRUE);
return info_dialog_new_extended (title, TRUE);
}
InfoDialog *
info_dialog_new (char *title)
info_dialog_new (gchar *title)
{
return info_dialog_new_extended(title,FALSE);
return info_dialog_new_extended (title, FALSE);
}
void
......@@ -217,13 +218,8 @@ info_dialog_free (InfoDialog *idialog)
g_return_if_fail (idialog != NULL);
/* Free each item in the field list */
list = idialog->field_list;
while (list)
{
g_free (list->data);
list = g_slist_next (list);
}
for (list = idialog->field_list; list; list = g_slist_next (list))
g_free (list->data);
/* Free the actual field linked list */
g_slist_free (idialog->field_list);
......@@ -241,10 +237,10 @@ info_dialog_free (InfoDialog *idialog)
void
info_dialog_popup (InfoDialog *idialog)
{
if (!idialog)
if (! idialog)
return;
if (!GTK_WIDGET_VISIBLE (idialog->shell))
if (! GTK_WIDGET_VISIBLE (idialog->shell))
gtk_widget_show (idialog->shell);
}
......@@ -252,7 +248,7 @@ info_dialog_popup (InfoDialog *idialog)
void
info_dialog_popdown (InfoDialog *idialog)
{
if (!idialog)
if (! idialog)
return;
if (GTK_WIDGET_VISIBLE (idialog->shell))
......@@ -264,16 +260,11 @@ info_dialog_update (InfoDialog *idialog)
{
GSList *list;
if (!idialog)
if (! idialog)
return;
list = idialog->field_list;
while (list)
{
update_field ((InfoField *) list->data);
list = g_slist_next (list);
}
for (list = idialog->field_list; list; list = g_slist_next (list))
update_field ((InfoField *) list->data);
}
GtkWidget *
......@@ -416,7 +407,7 @@ info_dialog_add_sizeentry (InfoDialog *idialog,
{
GtkWidget *alignment;
GtkWidget *sizeentry;
int i;
gint i;
g_return_val_if_fail (idialog != NULL, NULL);
......
......@@ -23,7 +23,8 @@
#include "libgimp/gimpsizeentry.h"
#include "libgimp/gimpunit.h"
typedef enum {
typedef enum
{
INFO_LABEL,
INFO_ENTRY,
INFO_SCALE,
......@@ -53,7 +54,7 @@ struct _InfoDialog
GtkWidget *info_notebook;
GSList *field_list;
int nfields;
gint nfields;
void *user_data;
};
......
......@@ -82,8 +82,8 @@ static void
update_field (InfoField *field)
{
gchar *old_text;
int num;
int i;
gint num;
gint i;
if (field->value_ptr == NULL)
return;
......@@ -130,17 +130,18 @@ update_field (InfoField *field)
}
static gint
info_dialog_delete_callback (GtkWidget *w,
GdkEvent *e,
gpointer client_data)
info_dialog_delete_callback (GtkWidget *widget,
GdkEvent *event,
gpointer data)
{
info_dialog_popdown ((InfoDialog *) client_data);
info_dialog_popdown ((InfoDialog *) data);
return TRUE;
}
static InfoDialog *
info_dialog_new_extended (char *title,gboolean inNotebook)
info_dialog_new_extended (gchar *title,
gboolean in_notebook)
{
InfoDialog *idialog;
GtkWidget *shell;
......@@ -150,7 +151,7 @@ info_dialog_new_extended (char *title,gboolean inNotebook)
idialog = g_new (InfoDialog, 1);
idialog->field_list = NULL;
idialog->nfields = 0;
idialog->nfields = 0;
shell = gtk_dialog_new ();
gtk_window_set_wmclass (GTK_WINDOW (shell), "info_dialog", "Gimp");
......@@ -163,30 +164,30 @@ info_dialog_new_extended (char *title,gboolean inNotebook)
vbox = gtk_vbox_new (FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (shell)->vbox), vbox, TRUE, TRUE, 0);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (shell)->vbox), vbox);
info_table = gtk_table_new (2, 0, FALSE);
if(inNotebook)
if( in_notebook)
{
info_notebook = gtk_notebook_new();
gtk_notebook_append_page(GTK_NOTEBOOK(info_notebook),
info_table,
gtk_label_new (_("General")));
gtk_box_pack_start (GTK_BOX (vbox), info_notebook, TRUE, TRUE, 0);
info_notebook = gtk_notebook_new ();
gtk_notebook_append_page (GTK_NOTEBOOK (info_notebook),
info_table,
gtk_label_new (_("General")));
gtk_box_pack_start (GTK_BOX (vbox), info_notebook, FALSE, FALSE, 0);
}
else
{
info_notebook = NULL;
gtk_box_pack_start (GTK_BOX (vbox), info_table, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (vbox), info_table, FALSE, FALSE, 0);
}
idialog->shell = shell;
idialog->vbox = vbox;
idialog->info_table = info_table;
idialog->info_notebook = info_notebook;
if(inNotebook)
if (in_notebook)
gtk_widget_show (idialog->info_notebook);
gtk_widget_show (idialog->info_table);
......@@ -198,15 +199,15 @@ info_dialog_new_extended (char *title,gboolean inNotebook)
/* public functions */
InfoDialog *
info_dialog_notebook_new (char *title)
info_dialog_notebook_new (gchar *title)
{
return info_dialog_new_extended(title,TRUE);
return info_dialog_new_extended (title, TRUE);
}
InfoDialog *
info_dialog_new (char *title)
info_dialog_new (gchar *title)
{
return info_dialog_new_extended(title,FALSE);
return info_dialog_new_extended (title, FALSE);
}
void
......@@ -217,13 +218,8 @@ info_dialog_free (InfoDialog *idialog)
g_return_if_fail (idialog != NULL);
/* Free each item in the field list */
list = idialog->field_list;
while (list)
{
g_free (list->data);
list = g_slist_next (list);
}
for (list = idialog->field_list; list; list = g_slist_next (list))
g_free (list->data);
/* Free the actual field linked list */
g_slist_free (idialog->field_list);
......@@ -241,10 +237,10 @@ info_dialog_free (InfoDialog *idialog)
void
info_dialog_popup (InfoDialog *idialog)
{
if (!idialog)
if (! idialog)
return;
if (!GTK_WIDGET_VISIBLE (idialog->shell))
if (! GTK_WIDGET_VISIBLE (idialog->shell))
gtk_widget_show (idialog->shell);