app/dialogs/Makefile.am new files implementing the channel options dialog

2004-10-19  Michael Natterer  <mitch@gimp.org>

	* app/dialogs/Makefile.am
	* app/dialogs/channel-options-dialog.[ch]: new files implementing
	the channel options dialog with a horrid number of 13 construction
	parameters. Still better than having the same code twice, only
	differing in strings used...

	* app/actions/channels-commands.c
	* app/actions/qmask-commands.c: removed the dialog code here and
	use channel_options_dialog_new().
This commit is contained in:
Michael Natterer 2004-10-19 09:17:37 +00:00 committed by Michael Natterer
parent 165cf42ed9
commit 39294079b7
7 changed files with 379 additions and 479 deletions

View File

@ -1,3 +1,15 @@
2004-10-19 Michael Natterer <mitch@gimp.org>
* app/dialogs/Makefile.am
* app/dialogs/channel-options-dialog.[ch]: new files implementing
the channel options dialog with a horrid number of 13 construction
parameters. Still better than having the same code twice, only
differing in strings used...
* app/actions/channels-commands.c
* app/actions/qmask-commands.c: removed the dialog code here and
use channel_options_dialog_new().
2004-10-19 Jay Cox <jaycox@gimp.org>
* plug-ins/common/psd_save.c: don't try to save psd files that are

View File

@ -38,7 +38,8 @@
#include "widgets/gimpcomponenteditor.h"
#include "widgets/gimpdock.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpviewabledialog.h"
#include "dialogs/channel-options-dialog.h"
#include "actions.h"
#include "channels-commands.h"
@ -46,36 +47,14 @@
#include "gimp-intl.h"
typedef struct _ChannelOptions ChannelOptions;
struct _ChannelOptions
{
GtkWidget *query_box;
GtkWidget *name_entry;
GtkWidget *color_panel;
GimpImage *gimage;
GimpContext *context;
GimpChannel *channel;
};
/* local function prototypes */
static ChannelOptions * channel_options_new (GimpImage *gimage,
GimpContext *context,
GimpChannel *channel,
GtkWidget *parent);
static void channels_new_channel_response (GtkWidget *widget,
gint response_id,
ChannelOptions *options);
static void channels_edit_channel_response (GtkWidget *widget,
gint response_id,
ChannelOptions *options);
static void channels_opacity_update (GtkAdjustment *adjustment,
gpointer data);
static void channels_color_changed (GimpColorButton *button,
gpointer data);
static void channels_new_channel_response (GtkWidget *widget,
gint response_id,
ChannelOptionsDialog *options);
static void channels_edit_channel_response (GtkWidget *widget,
gint response_id,
ChannelOptionsDialog *options);
/* private variables */
@ -90,42 +69,64 @@ void
channels_edit_attributes_cmd_callback (GtkAction *action,
gpointer data)
{
ChannelOptions *options;
GimpImage *gimage;
GimpChannel *channel;
GtkWidget *widget;
ChannelOptionsDialog *options;
GimpImage *gimage;
GimpChannel *channel;
GtkWidget *widget;
return_if_no_channel (gimage, channel, data);
return_if_no_widget (widget, data);
options = channel_options_new (gimp_item_get_image (GIMP_ITEM (channel)),
action_data_get_context (data),
channel, widget);
options = channel_options_dialog_new (gimage,
action_data_get_context (data),
channel,
widget,
&channel->color,
gimp_object_get_name (GIMP_OBJECT (channel)),
_("Channel Attributes"),
"gimp-channel-edit",
GIMP_STOCK_EDIT,
_("Edit Channel Attributes"),
GIMP_HELP_CHANNEL_EDIT,
_("Edit Channel Color"),
_("Fill Opacity:"));
g_signal_connect (options->query_box, "response",
g_signal_connect (options->dialog, "response",
G_CALLBACK (channels_edit_channel_response),
options);
gtk_widget_show (options->query_box);
gtk_widget_show (options->dialog);
}
void
channels_new_cmd_callback (GtkAction *action,
gpointer data)
{
ChannelOptions *options;
GimpImage *gimage;
GtkWidget *widget;
ChannelOptionsDialog *options;
GimpImage *gimage;
GtkWidget *widget;
return_if_no_image (gimage, data);
return_if_no_widget (widget, data);
options = channel_options_new (gimage, action_data_get_context (data),
NULL, widget);
options = channel_options_dialog_new (gimage,
action_data_get_context (data),
NULL,
widget,
&channel_color,
channel_name ? channel_name :
_("New Channel"),
_("New Channel"),
"gimp-channel-new",
GIMP_STOCK_CHANNEL,
_("New Channel Options"),
GIMP_HELP_CHANNEL_NEW,
_("New Channel Color"),
_("Fill Opacity:"));
g_signal_connect (options->query_box, "response",
g_signal_connect (options->dialog, "response",
G_CALLBACK (channels_new_channel_response),
options);
gtk_widget_show (options->query_box);
gtk_widget_show (options->dialog);
}
void
@ -319,128 +320,10 @@ channels_to_selection_cmd_callback (GtkAction *action,
/* private functions */
static ChannelOptions *
channel_options_new (GimpImage *gimage,
GimpContext *context,
GimpChannel *channel,
GtkWidget *parent)
{
ChannelOptions *options;
GtkWidget *hbox;
GtkWidget *vbox;
GtkWidget *table;
GtkObject *opacity_scale_data;
options = g_new0 (ChannelOptions, 1);
options->gimage = gimage;
options->context = context;
options->channel = channel;
if (channel)
channel_color = channel->color;
options->color_panel = gimp_color_panel_new (channel ?
_("Edit Channel Color") :
_("New Channel Color"),
&channel_color,
GIMP_COLOR_AREA_LARGE_CHECKS,
48, 64);
gimp_color_panel_set_context (GIMP_COLOR_PANEL (options->color_panel),
context);
if (channel)
{
options->query_box =
gimp_viewable_dialog_new (GIMP_VIEWABLE (channel),
_("Channel Attributes"), "gimp-channel-edit",
GIMP_STOCK_EDIT,
_("Edit Channel Attributes"),
parent,
gimp_standard_help_func,
GIMP_HELP_CHANNEL_EDIT,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
NULL);
}
else
{
options->query_box =
gimp_viewable_dialog_new (GIMP_VIEWABLE (gimage),
_("New Channel"), "gimp-channel-new",
GIMP_STOCK_CHANNEL,
_("New Channel Options"),
parent,
gimp_standard_help_func,
GIMP_HELP_CHANNEL_NEW,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
NULL);
}
g_object_weak_ref (G_OBJECT (options->query_box),
(GWeakNotify) g_free,
options);
hbox = gtk_hbox_new (FALSE, 12);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 12);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (options->query_box)->vbox),
hbox);
gtk_widget_show (hbox);
vbox = gtk_vbox_new (FALSE, 6);
gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
gtk_widget_show (vbox);
table = gtk_table_new (2, 3, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
gtk_table_set_row_spacings (GTK_TABLE (table), 6);
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
gtk_widget_show (table);
options->name_entry = gtk_entry_new ();
gtk_entry_set_activates_default (GTK_ENTRY (options->name_entry), TRUE);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("Channel Name:"), 0.0, 0.5,
options->name_entry, 2, FALSE);
if (channel)
gtk_entry_set_text (GTK_ENTRY (options->name_entry),
gimp_object_get_name (GIMP_OBJECT (channel)));
else
gtk_entry_set_text (GTK_ENTRY (options->name_entry),
channel_name ? channel_name : _("New Channel"));
opacity_scale_data = gimp_scale_entry_new (GTK_TABLE (table), 0, 1,
_("Fill Opacity:"), 100, -1,
channel_color.a * 100.0,
0.0, 100.0, 1.0, 10.0, 1,
TRUE, 0.0, 0.0,
NULL, NULL);
g_signal_connect (opacity_scale_data, "value_changed",
G_CALLBACK (channels_opacity_update),
options->color_panel);
gtk_box_pack_start (GTK_BOX (hbox), options->color_panel,
TRUE, TRUE, 0);
gtk_widget_show (options->color_panel);
g_signal_connect (options->color_panel, "color_changed",
G_CALLBACK (channels_color_changed),
opacity_scale_data);
return options;
}
static void
channels_new_channel_response (GtkWidget *widget,
gint response_id,
ChannelOptions *options)
channels_new_channel_response (GtkWidget *widget,
gint response_id,
ChannelOptionsDialog *options)
{
if (response_id == GTK_RESPONSE_OK)
{
@ -468,13 +351,13 @@ channels_new_channel_response (GtkWidget *widget,
gimp_image_flush (options->gimage);
}
gtk_widget_destroy (options->query_box);
gtk_widget_destroy (options->dialog);
}
static void
channels_edit_channel_response (GtkWidget *widget,
gint response_id,
ChannelOptions *options)
channels_edit_channel_response (GtkWidget *widget,
gint response_id,
ChannelOptionsDialog *options)
{
if (response_id == GTK_RESPONSE_OK)
{
@ -513,27 +396,5 @@ channels_edit_channel_response (GtkWidget *widget,
gimp_image_flush (options->gimage);
}
gtk_widget_destroy (options->query_box);
}
static void
channels_opacity_update (GtkAdjustment *adjustment,
gpointer data)
{
GimpRGB color;
gimp_color_button_get_color (GIMP_COLOR_BUTTON (data), &color);
gimp_rgb_set_alpha (&color, adjustment->value / 100.0);
gimp_color_button_set_color (GIMP_COLOR_BUTTON (data), &color);
}
static void
channels_color_changed (GimpColorButton *button,
gpointer data)
{
GtkAdjustment *adj = GTK_ADJUSTMENT (data);
GimpRGB color;
gimp_color_button_get_color (button, &color);
gtk_adjustment_set_value (adj, color.a * 100.0);
gtk_widget_destroy (options->dialog);
}

View File

@ -30,12 +30,9 @@
#include "core/gimpimage.h"
#include "core/gimpimage-qmask.h"
#include "widgets/gimpcolorpanel.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpviewabledialog.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
#include "dialogs/channel-options-dialog.h"
#include "actions.h"
#include "qmask-commands.h"
@ -43,28 +40,11 @@
#include "gimp-intl.h"
typedef struct _EditQmaskOptions EditQmaskOptions;
struct _EditQmaskOptions
{
GtkWidget *query_box;
GtkWidget *name_entry;
GtkWidget *color_panel;
GimpImage *gimage;
};
/* local function prototypes */
static void qmask_channel_query (GimpDisplayShell *shell);
static void qmask_query_response (GtkWidget *widget,
gint response_id,
EditQmaskOptions *options);
static void qmask_query_scale_update (GtkAdjustment *adjustment,
GtkWidget *panel);
static void qmask_query_color_changed (GimpColorButton *button,
GtkAdjustment *adj);
static void qmask_configure_response (GtkWidget *widget,
gint response_id,
ChannelOptionsDialog *options);
/* public functionss */
@ -108,110 +88,43 @@ void
qmask_configure_cmd_callback (GtkAction *action,
gpointer data)
{
GimpDisplay *gdisp;
return_if_no_display (gdisp, data);
ChannelOptionsDialog *options;
GimpImage *gimage;
GtkWidget *widget;
GimpRGB color;
return_if_no_image (gimage, data);
return_if_no_widget (widget, data);
qmask_channel_query (GIMP_DISPLAY_SHELL (gdisp->shell));
gimp_image_get_qmask_color (gimage, &color);
options = channel_options_dialog_new (gimage,
action_data_get_context (data),
NULL,
widget,
&color,
NULL,
_("Quick Mask Attributes"),
"gimp-qmask-edit",
GIMP_STOCK_QMASK_ON,
_("Edit Quick Mask Attributes"),
GIMP_HELP_QMASK_EDIT,
_("Edit Quick Mask Color"),
_("Mask Opacity:"));
g_signal_connect (options->dialog, "response",
G_CALLBACK (qmask_configure_response),
options);
gtk_widget_show (options->dialog);
}
/* private functions */
static void
qmask_channel_query (GimpDisplayShell *shell)
{
EditQmaskOptions *options;
GtkWidget *hbox;
GtkWidget *vbox;
GtkWidget *table;
GtkWidget *opacity_scale;
GtkObject *opacity_scale_data;
GimpRGB color;
gimp_image_get_qmask_color (shell->gdisp->gimage, &color);
/* the new options structure */
options = g_new0 (EditQmaskOptions, 1);
options->gimage = shell->gdisp->gimage;
options->color_panel = gimp_color_panel_new (_("Edit Quick Mask Color"),
&color,
GIMP_COLOR_AREA_LARGE_CHECKS,
48, 64);
gimp_color_panel_set_context (GIMP_COLOR_PANEL (options->color_panel),
gimp_get_user_context (options->gimage->gimp));
/* The dialog */
options->query_box =
gimp_viewable_dialog_new (GIMP_VIEWABLE (shell->gdisp->gimage),
_("Quick Mask Attributes"), "gimp-qmask-edit",
GIMP_STOCK_QMASK_ON,
_("Edit Quick Mask Attributes"),
GTK_WIDGET (shell),
gimp_standard_help_func,
GIMP_HELP_QMASK_EDIT,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
NULL);
g_signal_connect (options->query_box, "response",
G_CALLBACK (qmask_query_response),
options);
g_object_weak_ref (G_OBJECT (options->query_box),
(GWeakNotify) g_free, options);
/* The main hbox */
hbox = gtk_hbox_new (FALSE, 6);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 12);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (options->query_box)->vbox),
hbox);
gtk_widget_show (hbox);
/* The vbox */
vbox = gtk_vbox_new (FALSE, 2);
gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
gtk_widget_show (vbox);
/* The table */
table = gtk_table_new (1, 2, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
gtk_widget_show (table);
/* The opacity scale */
opacity_scale_data = gtk_adjustment_new (color.a * 100.0,
0.0, 100.0, 1.0, 1.0, 0.0);
opacity_scale = gtk_hscale_new (GTK_ADJUSTMENT (opacity_scale_data));
gtk_widget_set_size_request (opacity_scale, 100, -1);
gtk_scale_set_value_pos (GTK_SCALE (opacity_scale), GTK_POS_TOP);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("Mask Opacity:"), 0.0, 1.0,
opacity_scale, 1, FALSE);
g_signal_connect (opacity_scale_data, "value_changed",
G_CALLBACK (qmask_query_scale_update),
options->color_panel);
/* The color panel */
gtk_box_pack_start (GTK_BOX (hbox), options->color_panel,
TRUE, TRUE, 0);
gtk_widget_show (options->color_panel);
g_signal_connect (options->color_panel, "color_changed",
G_CALLBACK (qmask_query_color_changed),
opacity_scale_data);
gtk_widget_show (options->query_box);
}
static void
qmask_query_response (GtkWidget *widget,
gint response_id,
EditQmaskOptions *options)
qmask_configure_response (GtkWidget *widget,
gint response_id,
ChannelOptionsDialog *options)
{
if (response_id == GTK_RESPONSE_OK)
{
@ -230,26 +143,5 @@ qmask_query_response (GtkWidget *widget,
}
}
gtk_widget_destroy (options->query_box);
}
static void
qmask_query_scale_update (GtkAdjustment *adjustment,
GtkWidget *panel)
{
GimpRGB color;
gimp_color_button_get_color (GIMP_COLOR_BUTTON (panel), &color);
gimp_rgb_set_alpha (&color, adjustment->value / 100.0);
gimp_color_button_set_color (GIMP_COLOR_BUTTON (panel), &color);
}
static void
qmask_query_color_changed (GimpColorButton *button,
GtkAdjustment *adj)
{
GimpRGB color;
gimp_color_button_get_color (button, &color);
gtk_adjustment_set_value (adj, color.a * 100.0);
gtk_widget_destroy (options->dialog);
}

View File

@ -30,12 +30,9 @@
#include "core/gimpimage.h"
#include "core/gimpimage-qmask.h"
#include "widgets/gimpcolorpanel.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpviewabledialog.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
#include "dialogs/channel-options-dialog.h"
#include "actions.h"
#include "qmask-commands.h"
@ -43,28 +40,11 @@
#include "gimp-intl.h"
typedef struct _EditQmaskOptions EditQmaskOptions;
struct _EditQmaskOptions
{
GtkWidget *query_box;
GtkWidget *name_entry;
GtkWidget *color_panel;
GimpImage *gimage;
};
/* local function prototypes */
static void qmask_channel_query (GimpDisplayShell *shell);
static void qmask_query_response (GtkWidget *widget,
gint response_id,
EditQmaskOptions *options);
static void qmask_query_scale_update (GtkAdjustment *adjustment,
GtkWidget *panel);
static void qmask_query_color_changed (GimpColorButton *button,
GtkAdjustment *adj);
static void qmask_configure_response (GtkWidget *widget,
gint response_id,
ChannelOptionsDialog *options);
/* public functionss */
@ -108,110 +88,43 @@ void
qmask_configure_cmd_callback (GtkAction *action,
gpointer data)
{
GimpDisplay *gdisp;
return_if_no_display (gdisp, data);
ChannelOptionsDialog *options;
GimpImage *gimage;
GtkWidget *widget;
GimpRGB color;
return_if_no_image (gimage, data);
return_if_no_widget (widget, data);
qmask_channel_query (GIMP_DISPLAY_SHELL (gdisp->shell));
gimp_image_get_qmask_color (gimage, &color);
options = channel_options_dialog_new (gimage,
action_data_get_context (data),
NULL,
widget,
&color,
NULL,
_("Quick Mask Attributes"),
"gimp-qmask-edit",
GIMP_STOCK_QMASK_ON,
_("Edit Quick Mask Attributes"),
GIMP_HELP_QMASK_EDIT,
_("Edit Quick Mask Color"),
_("Mask Opacity:"));
g_signal_connect (options->dialog, "response",
G_CALLBACK (qmask_configure_response),
options);
gtk_widget_show (options->dialog);
}
/* private functions */
static void
qmask_channel_query (GimpDisplayShell *shell)
{
EditQmaskOptions *options;
GtkWidget *hbox;
GtkWidget *vbox;
GtkWidget *table;
GtkWidget *opacity_scale;
GtkObject *opacity_scale_data;
GimpRGB color;
gimp_image_get_qmask_color (shell->gdisp->gimage, &color);
/* the new options structure */
options = g_new0 (EditQmaskOptions, 1);
options->gimage = shell->gdisp->gimage;
options->color_panel = gimp_color_panel_new (_("Edit Quick Mask Color"),
&color,
GIMP_COLOR_AREA_LARGE_CHECKS,
48, 64);
gimp_color_panel_set_context (GIMP_COLOR_PANEL (options->color_panel),
gimp_get_user_context (options->gimage->gimp));
/* The dialog */
options->query_box =
gimp_viewable_dialog_new (GIMP_VIEWABLE (shell->gdisp->gimage),
_("Quick Mask Attributes"), "gimp-qmask-edit",
GIMP_STOCK_QMASK_ON,
_("Edit Quick Mask Attributes"),
GTK_WIDGET (shell),
gimp_standard_help_func,
GIMP_HELP_QMASK_EDIT,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
NULL);
g_signal_connect (options->query_box, "response",
G_CALLBACK (qmask_query_response),
options);
g_object_weak_ref (G_OBJECT (options->query_box),
(GWeakNotify) g_free, options);
/* The main hbox */
hbox = gtk_hbox_new (FALSE, 6);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 12);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (options->query_box)->vbox),
hbox);
gtk_widget_show (hbox);
/* The vbox */
vbox = gtk_vbox_new (FALSE, 2);
gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
gtk_widget_show (vbox);
/* The table */
table = gtk_table_new (1, 2, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
gtk_widget_show (table);
/* The opacity scale */
opacity_scale_data = gtk_adjustment_new (color.a * 100.0,
0.0, 100.0, 1.0, 1.0, 0.0);
opacity_scale = gtk_hscale_new (GTK_ADJUSTMENT (opacity_scale_data));
gtk_widget_set_size_request (opacity_scale, 100, -1);
gtk_scale_set_value_pos (GTK_SCALE (opacity_scale), GTK_POS_TOP);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("Mask Opacity:"), 0.0, 1.0,
opacity_scale, 1, FALSE);
g_signal_connect (opacity_scale_data, "value_changed",
G_CALLBACK (qmask_query_scale_update),
options->color_panel);
/* The color panel */
gtk_box_pack_start (GTK_BOX (hbox), options->color_panel,
TRUE, TRUE, 0);
gtk_widget_show (options->color_panel);
g_signal_connect (options->color_panel, "color_changed",
G_CALLBACK (qmask_query_color_changed),
opacity_scale_data);
gtk_widget_show (options->query_box);
}
static void
qmask_query_response (GtkWidget *widget,
gint response_id,
EditQmaskOptions *options)
qmask_configure_response (GtkWidget *widget,
gint response_id,
ChannelOptionsDialog *options)
{
if (response_id == GTK_RESPONSE_OK)
{
@ -230,26 +143,5 @@ qmask_query_response (GtkWidget *widget,
}
}
gtk_widget_destroy (options->query_box);
}
static void
qmask_query_scale_update (GtkAdjustment *adjustment,
GtkWidget *panel)
{
GimpRGB color;
gimp_color_button_get_color (GIMP_COLOR_BUTTON (panel), &color);
gimp_rgb_set_alpha (&color, adjustment->value / 100.0);
gimp_color_button_set_color (GIMP_COLOR_BUTTON (panel), &color);
}
static void
qmask_query_color_changed (GimpColorButton *button,
GtkAdjustment *adj)
{
GimpRGB color;
gimp_color_button_get_color (button, &color);
gtk_adjustment_set_value (adj, color.a * 100.0);
gtk_widget_destroy (options->dialog);
}

View File

@ -12,6 +12,8 @@ libappdialogs_a_SOURCES = \
about-dialog.c \
about-dialog.h \
authors.h \
channel-options-dialog.c \
channel-options-dialog.h \
convert-dialog.c \
convert-dialog.h \
file-open-dialog.c \

View File

@ -0,0 +1,189 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 "libgimpwidgets/gimpwidgets.h"
#include "dialogs-types.h"
#include "core/gimpchannel.h"
#include "core/gimpcontext.h"
#include "core/gimpimage.h"
#include "widgets/gimpcolorpanel.h"
#include "widgets/gimpviewabledialog.h"
#include "channel-options-dialog.h"
#include "gimp-intl.h"
/* local function prototypes */
static void channel_options_opacity_update (GtkAdjustment *adjustment,
gpointer data);
static void channel_options_color_changed (GimpColorButton *button,
gpointer data);
/* public functions */
ChannelOptionsDialog *
channel_options_dialog_new (GimpImage *gimage,
GimpContext *context,
GimpChannel *channel,
GtkWidget *parent,
const GimpRGB *channel_color,
const gchar *channel_name,
const gchar *title,
const gchar *role,
const gchar *stock_id,
const gchar *desc,
const gchar *help_id,
const gchar *color_label,
const gchar *opacity_label)
{
ChannelOptionsDialog *options;
GimpViewable *viewable;
GtkWidget *hbox;
GtkWidget *vbox;
GtkWidget *table;
GtkObject *opacity_adj;
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
g_return_val_if_fail (channel == NULL || GIMP_IS_CHANNEL (channel), NULL);
g_return_val_if_fail (GTK_IS_WIDGET (parent), NULL);
g_return_val_if_fail (channel_color != NULL, NULL);
g_return_val_if_fail (title != NULL, NULL);
g_return_val_if_fail (role != NULL, NULL);
g_return_val_if_fail (stock_id != NULL, NULL);
g_return_val_if_fail (desc != NULL, NULL);
g_return_val_if_fail (help_id != NULL, NULL);
g_return_val_if_fail (color_label != NULL, NULL);
g_return_val_if_fail (opacity_label != NULL, NULL);
options = g_new0 (ChannelOptionsDialog, 1);
options->gimage = gimage;
options->context = context;
options->channel = channel;
options->color_panel = gimp_color_panel_new (color_label,
channel_color,
GIMP_COLOR_AREA_LARGE_CHECKS,
48, 64);
gimp_color_panel_set_context (GIMP_COLOR_PANEL (options->color_panel),
context);
if (channel)
viewable = GIMP_VIEWABLE (channel);
else
viewable = GIMP_VIEWABLE (gimage);
options->dialog =
gimp_viewable_dialog_new (viewable,
title, role, stock_id, desc,
parent,
gimp_standard_help_func, help_id,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
NULL);
g_object_weak_ref (G_OBJECT (options->dialog),
(GWeakNotify) g_free,
options);
hbox = gtk_hbox_new (FALSE, 12);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 12);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (options->dialog)->vbox), hbox);
gtk_widget_show (hbox);
vbox = gtk_vbox_new (FALSE, 6);
gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
gtk_widget_show (vbox);
table = gtk_table_new (channel_name ? 2 : 1, 3, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
gtk_table_set_row_spacings (GTK_TABLE (table), 6);
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
gtk_widget_show (table);
if (channel_name)
{
options->name_entry = gtk_entry_new ();
gtk_entry_set_activates_default (GTK_ENTRY (options->name_entry), TRUE);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("Channel Name:"), 0.0, 0.5,
options->name_entry, 2, FALSE);
gtk_entry_set_text (GTK_ENTRY (options->name_entry), channel_name);
}
opacity_adj = gimp_scale_entry_new (GTK_TABLE (table), 0, channel_name ? 1 : 0,
opacity_label, 100, -1,
channel_color->a * 100.0,
0.0, 100.0, 1.0, 10.0, 1,
TRUE, 0.0, 0.0,
NULL, NULL);
g_signal_connect (opacity_adj, "value_changed",
G_CALLBACK (channel_options_opacity_update),
options->color_panel);
gtk_box_pack_start (GTK_BOX (hbox), options->color_panel,
TRUE, TRUE, 0);
gtk_widget_show (options->color_panel);
g_signal_connect (options->color_panel, "color_changed",
G_CALLBACK (channel_options_color_changed),
opacity_adj);
return options;
}
/* private functions */
static void
channel_options_opacity_update (GtkAdjustment *adjustment,
gpointer data)
{
GimpRGB color;
gimp_color_button_get_color (GIMP_COLOR_BUTTON (data), &color);
gimp_rgb_set_alpha (&color, adjustment->value / 100.0);
gimp_color_button_set_color (GIMP_COLOR_BUTTON (data), &color);
}
static void
channel_options_color_changed (GimpColorButton *button,
gpointer data)
{
GtkAdjustment *adj = GTK_ADJUSTMENT (data);
GimpRGB color;
gimp_color_button_get_color (button, &color);
gtk_adjustment_set_value (adj, color.a * 100.0);
}

View File

@ -0,0 +1,52 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 __CHANNEL_OPTIONS_DIALOG_H__
#define __CHANNEL_OPTIONS_DIALOG_H__
typedef struct _ChannelOptionsDialog ChannelOptionsDialog;
struct _ChannelOptionsDialog
{
GtkWidget *dialog;
GtkWidget *name_entry;
GtkWidget *color_panel;
GimpImage *gimage;
GimpContext *context;
GimpChannel *channel;
};
ChannelOptionsDialog * channel_options_dialog_new (GimpImage *gimage,
GimpContext *context,
GimpChannel *channel,
GtkWidget *parent,
const GimpRGB *channel_color,
const gchar *channel_name,
const gchar *title,
const gchar *role,
const gchar *stock_id,
const gchar *desc,
const gchar *help_id,
const gchar *color_label,
const gchar *opacity_label);
#endif /* __CHANNEL_OPTIONS_DIALOG_H__ */