
2006-08-29 Michael Natterer <mitch@gimp.org> Changed GimpViewable preview rendering to have a context to get FG/BG/whatever from. Use the context to enable dynamic FG/BG colors in gradients. Fixes bug #127676 and bug #352214. Addresses bug #128367 (doesn't fix it because there's no loading/saving and no GUI yet). * app/core/core-enums.[ch]: added enum GimpGradientColor to enable specifying gradient colors in terms of foreground and background. * app/core/gimpgradient.[ch]: added color_type members to the GimpGradientSegment struct and honor them in gimp_gradient_get_color_at(). Added GimpContext parameters to all functions which finally call get_color_at(). * app/core/gimp-gradients.c: use the new method to implement the builtin gradients. * app/core/gimpviewable.[ch]: added GimpContext parameters to all get_preview() and get_pixbuf() functions. * app/core/gimpbrush.c * app/core/gimpbuffer.c * app/core/gimpdrawable-preview.[ch] * app/core/gimpgradient.c * app/core/gimpimage-preview.[ch] * app/core/gimpimagefile.c * app/core/gimppalette.c * app/core/gimppattern.c * app/core/gimpundo.[ch] * app/text/gimpfont.c * app/vectors/gimpvectors-preview.[ch]: changed ::get_preview() and ::get_pixbuf() implementations accordingly. * app/core/gimpdrawable-blend.c * app/core/gimppalette-import.[ch] * app/dialogs/dialogs-constructors.c * app/dialogs/palette-import-dialog.c * app/dialogs/resize-dialog.c * app/display/gimpdisplayshell-layer-select.c * app/display/gimpdisplayshell.c * app/display/gimpnavigationeditor.c * app/paint/gimppaintoptions.c * app/tools/gimpeditselectiontool.c * app/tools/gimptexttool.c * app/actions/gradient-editor-commands.c * app/widgets/gimpaction.c * app/widgets/gimpbrusheditor.[ch] * app/widgets/gimpbufferview.c * app/widgets/gimpcellrendererviewable.c * app/widgets/gimpchanneltreeview.c * app/widgets/gimpclipboard.c * app/widgets/gimpcoloreditor.c * app/widgets/gimpcomponenteditor.c * app/widgets/gimpcontainerbox.c * app/widgets/gimpcontainercombobox.c * app/widgets/gimpcontainereditor.c * app/widgets/gimpcontainerentry.c * app/widgets/gimpcontainergridview.c * app/widgets/gimpcontainertreeview.[ch] * app/widgets/gimpdataeditor.[ch] * app/widgets/gimpdevicestatus.c * app/widgets/gimpdnd.[ch] * app/widgets/gimpdrawabletreeview.c * app/widgets/gimpfiledialog.c * app/widgets/gimpgradienteditor.[ch] * app/widgets/gimpgradientselect.c * app/widgets/gimpitemtreeview.c * app/widgets/gimplayertreeview.c * app/widgets/gimppaletteeditor.[ch] * app/widgets/gimppropwidgets.[ch] * app/widgets/gimpselectioneditor.c * app/widgets/gimpthumbbox.[ch] * app/widgets/gimptoolbox-image-area.c * app/widgets/gimptoolbox-indicator-area.c * app/widgets/gimptooloptionseditor.c * app/widgets/gimpundoeditor.c * app/widgets/gimpvectorstreeview.c * app/widgets/gimpview-popup.[ch] * app/widgets/gimpview.[ch] * app/widgets/gimpviewablebutton.c * app/widgets/gimpviewabledialog.c * app/widgets/gimpviewrenderer.[ch] * app/widgets/gimpviewrenderer-frame.c * app/widgets/gimpviewrendererbrush.c * app/widgets/gimpviewrendererbuffer.c * app/widgets/gimpviewrendererdrawable.c * app/widgets/gimpviewrenderergradient.c * app/widgets/gimpviewrendererimage.c * tools/pdbgen/pdb/drawable.pdb * tools/pdbgen/pdb/gradient.pdb * tools/pdbgen/pdb/gradients.pdb * tools/pdbgen/pdb/image.pdb: added tons of GimpContext members and parameters, implement GimpDocked::set_context() in many widgets. Pass these locally remembered contexts to GimpViewable functions. Did some minor cleanups on the way. There are still some minor FIXMEs around where the code uses a NULL context (which is allowed by the APIs) * app/pdb/drawable_cmds.c * app/pdb/gradient_cmds.c * app/pdb/gradients_cmds.c * app/pdb/image_cmds.c: regenerated.
235 lines
8.0 KiB
C
235 lines
8.0 KiB
C
/* 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 <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
#include "widgets-types.h"
|
|
|
|
#include "core/gimpbrush.h"
|
|
#include "core/gimpcontext.h"
|
|
#include "core/gimpgradient.h"
|
|
#include "core/gimppattern.h"
|
|
|
|
#include "gimpdialogfactory.h"
|
|
#include "gimpdnd.h"
|
|
#include "gimpview.h"
|
|
#include "gimptoolbox.h"
|
|
#include "gimptoolbox-indicator-area.h"
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
#define CELL_SIZE 26 /* The size of the previews */
|
|
#define GRAD_CELL_WIDTH 54 /* The width of the gradient preview */
|
|
#define GRAD_CELL_HEIGHT 14 /* The height of the gradient preview */
|
|
#define CELL_SPACING 2 /* How much between brush and pattern cells */
|
|
|
|
|
|
static void
|
|
brush_preview_clicked (GtkWidget *widget,
|
|
GdkModifierType state,
|
|
GimpToolbox *toolbox)
|
|
{
|
|
gimp_dialog_factory_dialog_raise (GIMP_DOCK (toolbox)->dialog_factory,
|
|
gtk_widget_get_screen (widget),
|
|
"gimp-brush-grid|gimp-brush-list", -1);
|
|
}
|
|
|
|
static void
|
|
brush_preview_drop_brush (GtkWidget *widget,
|
|
gint x,
|
|
gint y,
|
|
GimpViewable *viewable,
|
|
gpointer data)
|
|
{
|
|
GimpContext *context = GIMP_CONTEXT (data);
|
|
|
|
gimp_context_set_brush (context, GIMP_BRUSH (viewable));
|
|
}
|
|
|
|
static void
|
|
pattern_preview_clicked (GtkWidget *widget,
|
|
GdkModifierType state,
|
|
GimpToolbox *toolbox)
|
|
{
|
|
gimp_dialog_factory_dialog_raise (GIMP_DOCK (toolbox)->dialog_factory,
|
|
gtk_widget_get_screen (widget),
|
|
"gimp-pattern-grid|gimp-pattern-list", -1);
|
|
}
|
|
|
|
static void
|
|
pattern_preview_drop_pattern (GtkWidget *widget,
|
|
gint x,
|
|
gint y,
|
|
GimpViewable *viewable,
|
|
gpointer data)
|
|
{
|
|
GimpContext *context = GIMP_CONTEXT (data);
|
|
|
|
gimp_context_set_pattern (context, GIMP_PATTERN (viewable));
|
|
}
|
|
|
|
static void
|
|
gradient_preview_clicked (GtkWidget *widget,
|
|
GdkModifierType state,
|
|
GimpToolbox *toolbox)
|
|
{
|
|
gimp_dialog_factory_dialog_raise (GIMP_DOCK (toolbox)->dialog_factory,
|
|
gtk_widget_get_screen (widget),
|
|
"gimp-gradient-list|gimp-gradient-grid", -1);
|
|
}
|
|
|
|
static void
|
|
gradient_preview_drop_gradient (GtkWidget *widget,
|
|
gint x,
|
|
gint y,
|
|
GimpViewable *viewable,
|
|
gpointer data)
|
|
{
|
|
GimpContext *context = GIMP_CONTEXT (data);
|
|
|
|
gimp_context_set_gradient (context, GIMP_GRADIENT (viewable));
|
|
}
|
|
|
|
|
|
/* public functions */
|
|
|
|
GtkWidget *
|
|
gimp_toolbox_indicator_area_create (GimpToolbox *toolbox)
|
|
{
|
|
GimpContext *context;
|
|
GtkWidget *indicator_table;
|
|
GtkWidget *brush_view;
|
|
GtkWidget *pattern_view;
|
|
GtkWidget *gradient_view;
|
|
|
|
g_return_val_if_fail (GIMP_IS_TOOLBOX (toolbox), NULL);
|
|
|
|
context = GIMP_DOCK (toolbox)->context;
|
|
|
|
indicator_table = gtk_table_new (2, 2, FALSE);
|
|
gtk_table_set_row_spacings (GTK_TABLE (indicator_table), CELL_SPACING);
|
|
gtk_table_set_col_spacings (GTK_TABLE (indicator_table), CELL_SPACING);
|
|
|
|
/* brush view */
|
|
|
|
brush_view =
|
|
gimp_view_new_full_by_types (context,
|
|
GIMP_TYPE_VIEW, GIMP_TYPE_BRUSH,
|
|
CELL_SIZE, CELL_SIZE, 0,
|
|
FALSE, TRUE, TRUE);
|
|
gimp_view_set_viewable (GIMP_VIEW (brush_view),
|
|
GIMP_VIEWABLE (gimp_context_get_brush (context)));
|
|
gtk_table_attach_defaults (GTK_TABLE (indicator_table), brush_view,
|
|
0, 1, 0, 1);
|
|
gtk_widget_show (brush_view);
|
|
|
|
gimp_help_set_help_data (brush_view,
|
|
_("The active brush.\n"
|
|
"Click to open the Brush Dialog."), NULL);
|
|
|
|
g_signal_connect_object (context, "brush-changed",
|
|
G_CALLBACK (gimp_view_set_viewable),
|
|
brush_view,
|
|
G_CONNECT_SWAPPED);
|
|
|
|
g_signal_connect (brush_view, "clicked",
|
|
G_CALLBACK (brush_preview_clicked),
|
|
toolbox);
|
|
|
|
gimp_dnd_viewable_dest_add (brush_view,
|
|
GIMP_TYPE_BRUSH,
|
|
brush_preview_drop_brush,
|
|
context);
|
|
|
|
/* pattern view */
|
|
|
|
pattern_view =
|
|
gimp_view_new_full_by_types (context,
|
|
GIMP_TYPE_VIEW, GIMP_TYPE_PATTERN,
|
|
CELL_SIZE, CELL_SIZE, 0,
|
|
FALSE, TRUE, TRUE);
|
|
gimp_view_set_viewable (GIMP_VIEW (pattern_view),
|
|
GIMP_VIEWABLE (gimp_context_get_pattern (context)));
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (indicator_table), pattern_view,
|
|
1, 2, 0, 1);
|
|
gtk_widget_show (pattern_view);
|
|
|
|
gimp_help_set_help_data (pattern_view,
|
|
_("The active pattern.\n"
|
|
"Click to open the Pattern Dialog."), NULL);
|
|
|
|
g_signal_connect_object (context, "pattern-changed",
|
|
G_CALLBACK (gimp_view_set_viewable),
|
|
pattern_view,
|
|
G_CONNECT_SWAPPED);
|
|
|
|
g_signal_connect (pattern_view, "clicked",
|
|
G_CALLBACK (pattern_preview_clicked),
|
|
toolbox);
|
|
|
|
gimp_dnd_viewable_dest_add (pattern_view,
|
|
GIMP_TYPE_PATTERN,
|
|
pattern_preview_drop_pattern,
|
|
context);
|
|
|
|
/* gradient view */
|
|
|
|
gradient_view =
|
|
gimp_view_new_full_by_types (context,
|
|
GIMP_TYPE_VIEW, GIMP_TYPE_GRADIENT,
|
|
GRAD_CELL_WIDTH, GRAD_CELL_HEIGHT, 0,
|
|
FALSE, TRUE, TRUE);
|
|
gimp_view_set_viewable (GIMP_VIEW (gradient_view),
|
|
GIMP_VIEWABLE (gimp_context_get_gradient (context)));
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (indicator_table), gradient_view,
|
|
0, 2, 1, 2);
|
|
gtk_widget_show (gradient_view);
|
|
|
|
gimp_help_set_help_data (gradient_view,
|
|
_("The active gradient.\n"
|
|
"Click to open the Gradient Dialog."), NULL);
|
|
|
|
g_signal_connect_object (context, "gradient-changed",
|
|
G_CALLBACK (gimp_view_set_viewable),
|
|
gradient_view,
|
|
G_CONNECT_SWAPPED);
|
|
|
|
g_signal_connect (gradient_view, "clicked",
|
|
G_CALLBACK (gradient_preview_clicked),
|
|
toolbox);
|
|
|
|
gimp_dnd_viewable_dest_add (gradient_view,
|
|
GIMP_TYPE_GRADIENT,
|
|
gradient_preview_drop_gradient,
|
|
context);
|
|
|
|
gtk_widget_show (indicator_table);
|
|
|
|
return indicator_table;
|
|
}
|