gimp/app/gui/brush-select.c
Michael Natterer a74a8997b4 devel-docs/Makefile.am new file documenting the core's include policy.
2002-05-03  Michael Natterer  <mitch@gimp.org>

	* devel-docs/Makefile.am
	* devel-docs/includes.txt: new file documenting the core's
	include policy.

	* HACKING: mention it here.

	* libgimptool/gimptooltypes.h: removed GimpToolOptions here.

	* app/core/core-types.h: and added it here. This is a temp hack
	needed because GimpToolInfo needs to know the GimpToolOptions
	type.

	* libgimpproxy/gimpproxytypes.h: regenerated.

	* libgimptool/gimptoolmodule.h: don't include gimptooltypes.h here...
	* libgimptool/gimptoolmodule.c: ...but here.

	* app/config/gimpconfig-params.c: include "libgimpbase/gimpbase.h"
	entirely, not single files from it.

	* app/core/gimp.c
	* app/core/gimpcontext.c
	* app/core/gimpcoreconfig.c
	* app/core/gimpdatafactory.c
	* app/core/gimpdocuments.c
	* app/core/gimpdrawable-blend.c
	* app/core/gimpdrawable-bucket-fill.c
	* app/core/gimpdrawable-offset.c
	* app/core/gimpdrawable-transform.c
	* app/core/gimpdrawable.c
	* app/core/gimpedit.c
	* app/core/gimpimage-convert.c
	* app/core/gimpimage-crop.c
	* app/core/gimpimage-duplicate.c
	* app/core/gimpimage-guides.c
	* app/core/gimpimage-mask.c
	* app/core/gimpimage-merge.c
	* app/core/gimpimage-new.c
	* app/core/gimpimage-projection.c
	* app/core/gimpimage-qmask.c
	* app/core/gimpimage-resize.c
	* app/core/gimpimage-scale.c
	* app/core/gimpimage.c
	* app/core/gimpitem.c
	* app/core/gimpmodules.c
	* app/core/gimppaintinfo.c
	* app/core/gimpparasite.c
	* app/core/gimppreviewcache.c
	* app/core/gimptoolinfo.c
	* app/core/gimpunit.c: include "core-types.h" and no other types file.

	* app/display/gimpdisplay.c
	* app/display/gimpdisplayshell-callbacks.c
	* app/display/gimpdisplayshell.c: include "tools/tools-types.h"
	instead of "libgimptool/gimptooltypes.h", warn about inclusion
	on "gui/gui-types.h"

	* app/file/file-open.c
	* app/file/file-save.c: don't include "libgimptool/gimptooltypes.h".

	* app/gui/about-dialog.c
	* app/gui/brush-select.c
	* app/gui/brushes-commands.c
	* app/gui/color-select.c
	* app/gui/data-commands.c
	* app/gui/device-status-dialog.c
	* app/gui/dialogs.c
	* app/gui/gradients-commands.c
	* app/gui/help-commands.c
	* app/gui/info-window.c
	* app/gui/palettes-commands.c
	* app/gui/patterns-commands.c
	* app/gui/resize-dialog.c
	* app/gui/tips-dialog.c
	* app/gui/tool-options-dialog.c: include "gui-types.h" and no
	other types file.

	* app/paint/gimpairbrush.c
	* app/paint/gimpclone.c
	* app/paint/gimpconvolve.c
	* app/paint/gimpdodgeburn.c
	* app/paint/gimperaser.c
	* app/paint/gimppaintbrush.c
	* app/paint/gimppaintcore-stroke.c
	* app/paint/gimppaintcore.c
	* app/paint/gimppaintoptions.c
	* app/paint/gimppencil.c
	* app/paint/gimpsmudge.c
	* app/paint/paint.c: include "paint-types.h" and no other types file.

	* app/pdb/pdb-types.h: don't include "libgimptool/gimptooltypes.h".

	* app/plug-in/plug-in-progress.c: warn about inclusion of
	"display/display-types.h"

	* app/tools/tools-types.h: include "libgimptool/gimptooltypes.h".

	* app/tools/gimpairbrushtool.c
	* app/tools/gimpbezierselecttool.c
	* app/tools/gimpblendtool.c
	* app/tools/gimpbrightnesscontrasttool.c
	* app/tools/gimpbucketfilltool.c
	* app/tools/gimpbycolorselecttool.c
	* app/tools/gimpclonetool.c
	* app/tools/gimpcolorbalancetool.c
	* app/tools/gimpcolorpickertool.c
	* app/tools/gimpconvolvetool.c
	* app/tools/gimpcroptool.c
	* app/tools/gimpcurvestool.c
	* app/tools/gimpdodgeburntool.c
	* app/tools/gimpdrawtool.c
	* app/tools/gimpeditselectiontool.c
	* app/tools/gimpellipseselecttool.c
	* app/tools/gimperasertool.c
	* app/tools/gimpfliptool.c
	* app/tools/gimpfreeselecttool.c
	* app/tools/gimpfuzzyselecttool.c
	* app/tools/gimphistogramtool.c
	* app/tools/gimphuesaturationtool.c
	* app/tools/gimpinktool.c
	* app/tools/gimplevelstool.c
	* app/tools/gimpmagnifytool.c
	* app/tools/gimpmeasuretool.c
	* app/tools/gimpmovetool.c
	* app/tools/gimppaintbrushtool.c
	* app/tools/gimppainttool.c
	* app/tools/gimppathtool.c
	* app/tools/gimppenciltool.c
	* app/tools/gimpperspectivetool.c
	* app/tools/gimpposterizetool.c
	* app/tools/gimprectselecttool.c
	* app/tools/gimprotatetool.c
	* app/tools/gimpscaletool.c
	* app/tools/gimpselectiontool.c
	* app/tools/gimpsheartool.c
	* app/tools/gimpsmudgetool.c
	* app/tools/gimptexttool.c
	* app/tools/gimpthresholdtool.c
	* app/tools/gimptoolcontrol.c
	* app/tools/gimptoolcontrol.h
	* app/tools/gimptransformtool.c
	* app/tools/gimpvectortool.c
	* app/tools/tools.c: include "tools-types.h" and no other types file,
	warn about inclusion of "gui/gui-types.h".

	* app/widgets/gimpcolorpanel.c
	* app/widgets/gimptoolbox-color-area.c: warn about inclusion of
	"gui/gui-types.h".

	* app/xcf/xcf-load.c
	* app/xcf/xcf.c: don't include "libgimptool/gimptooltypes.h".

	Split tool-safe-mode up in two files, one including libgimpproxy,
	one libgimp.

	* plug-ins/tools/Makefile.am
	* plug-ins/tools/tool-safe-mode-plug-in.[ch]: new files including
	libgimp/ stuff only.

	* plug-ins/tools/tool-safe-mode.[ch]: include libgimpproxy/ and
	libgimptool/ but don't include libgimp/ because of conflicting
	declarations.

	Unrelated:

	* app/tools/gimpclonetool.c: create the clone core so we don't crash.

	* app/gui/file-open-dialog.c: changed the way we create previews
	so that only out-of-date previews are created on a click in the
	preview area. Unconditional creation can still be forced by
	<Ctrl>+click. Changed the tooltip to document this.
2002-05-03 12:45:22 +00:00

454 lines
13 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 <string.h>
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "gui-types.h"
#include "base/temp-buf.h"
#include "core/gimp.h"
#include "core/gimpbrush.h"
#include "core/gimpcontainer.h"
#include "core/gimpcontext.h"
#include "core/gimpdatafactory.h"
#include "pdb/procedural_db.h"
#include "widgets/gimpbrushfactoryview.h"
#include "widgets/gimpitemfactory.h"
#include "widgets/gimpwidgets-constructors.h"
#include "brush-select.h"
#include "dialogs-constructors.h"
#include "gimprc.h"
#include "libgimp/gimpintl.h"
#define MIN_CELL_SIZE 25
#define STD_BRUSH_COLUMNS 5
#define STD_BRUSH_ROWS 5
/* local function prototypes */
static void brush_select_change_callbacks (BrushSelect *bsp,
gboolean closing);
static void brush_select_brush_changed (GimpContext *context,
GimpBrush *brush,
BrushSelect *bsp);
static void brush_select_opacity_changed (GimpContext *context,
gdouble opacity,
BrushSelect *bsp);
static void brush_select_paint_mode_changed (GimpContext *context,
GimpLayerModeEffects paint_mode,
BrushSelect *bsp);
static void opacity_scale_update (GtkAdjustment *adj,
BrushSelect *bsp);
static void paint_mode_menu_callback (GtkWidget *widget,
BrushSelect *bsp);
static void spacing_scale_update (GtkAdjustment *adj,
BrushSelect *bsp);
static void brush_select_close_callback (GtkWidget *widget,
BrushSelect *bsp);
/* list of active dialogs */
static GSList *brush_active_dialogs = NULL;
/* public functions */
BrushSelect *
brush_select_new (Gimp *gimp,
GimpContext *context,
const gchar *title,
const gchar *initial_brush,
gdouble initial_opacity,
GimpLayerModeEffects initial_mode,
gint initial_spacing,
const gchar *callback_name)
{
BrushSelect *bsp;
GtkWidget *sep;
GtkWidget *table;
GtkWidget *slider;
GtkAdjustment *spacing_adj;
GimpBrush *active = NULL;
static gboolean first_call = TRUE;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (! context || GIMP_IS_CONTEXT (context), NULL);
g_return_val_if_fail (title != NULL, NULL);
if (gimp->no_data && first_call)
gimp_data_factory_data_init (gimp->brush_factory, FALSE);
first_call = FALSE;
if (initial_brush && strlen (initial_brush))
{
active = (GimpBrush *)
gimp_container_get_child_by_name (gimp->brush_factory->container,
initial_brush);
}
if (! active)
{
if (context)
active = gimp_context_get_brush (context);
else
active = gimp_context_get_brush (gimp_get_current_context (gimp));
}
if (! active)
return NULL;
bsp = g_new0 (BrushSelect, 1);
/* Add to active brush dialogs list */
brush_active_dialogs = g_slist_append (brush_active_dialogs, bsp);
bsp->context = gimp_context_new (gimp, title, context);
bsp->callback_name = g_strdup (callback_name);
if (context)
{
gimp_context_define_properties (bsp->context,
GIMP_CONTEXT_OPACITY_MASK |
GIMP_CONTEXT_PAINT_MODE_MASK |
GIMP_CONTEXT_BRUSH_MASK,
FALSE);
gimp_context_set_parent (bsp->context, context);
}
gimp_context_set_brush (bsp->context, active);
gimp_context_set_paint_mode (bsp->context, initial_mode);
gimp_context_set_opacity (bsp->context, initial_opacity);
bsp->spacing_value = initial_spacing;
g_signal_connect (G_OBJECT (bsp->context), "brush_changed",
G_CALLBACK (brush_select_brush_changed),
bsp);
g_signal_connect (G_OBJECT (bsp->context), "opacity_changed",
G_CALLBACK (brush_select_opacity_changed),
bsp);
g_signal_connect (G_OBJECT (bsp->context), "paint_mode_changed",
G_CALLBACK (brush_select_paint_mode_changed),
bsp);
/* The shell */
bsp->shell = gimp_dialog_new (title, "brush_selection",
gimp_standard_help_func,
"dialogs/brush_selection.html",
GTK_WIN_POS_MOUSE,
FALSE, TRUE, FALSE,
"_delete_event_", brush_select_close_callback,
bsp, NULL, NULL, TRUE, TRUE,
NULL);
gtk_dialog_set_has_separator (GTK_DIALOG (bsp->shell), FALSE);
gtk_widget_hide (GTK_DIALOG (bsp->shell)->action_area);
/* The Brush Grid */
bsp->view =
gimp_brush_factory_view_new (GIMP_VIEW_TYPE_GRID,
gimp->brush_factory,
dialogs_edit_brush_func,
bsp->context,
title ? FALSE : TRUE,
MIN_CELL_SIZE,
STD_BRUSH_COLUMNS,
STD_BRUSH_ROWS,
gimp_item_factory_from_path ("<Brushes>"));
gtk_container_set_border_width (GTK_CONTAINER (bsp->view), 2);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (bsp->shell)->vbox), bsp->view);
gtk_widget_show (bsp->view);
/* Create the frame and the table for the options */
table = gtk_table_new (2, 2, FALSE);
gtk_table_set_col_spacing (GTK_TABLE (table), 0, 4);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_box_pack_start (GTK_BOX (bsp->view), table, FALSE, FALSE, 2);
gtk_widget_show (table);
/* Create the opacity scale widget */
bsp->opacity_data =
GTK_ADJUSTMENT (gtk_adjustment_new
(gimp_context_get_opacity (bsp->context) * 100.0,
0.0, 100.0, 1.0, 1.0, 0.0));
slider = gtk_hscale_new (bsp->opacity_data);
gtk_scale_set_value_pos (GTK_SCALE (slider), GTK_POS_TOP);
gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED);
g_signal_connect (G_OBJECT (bsp->opacity_data), "value_changed",
G_CALLBACK (opacity_scale_update),
bsp);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("Opacity:"), 1.0, 1.0,
slider, 1, FALSE);
/* Create the paint mode option menu */
bsp->option_menu =
gimp_paint_mode_menu_new (G_CALLBACK (paint_mode_menu_callback),
bsp,
TRUE,
gimp_context_get_paint_mode (bsp->context));
gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
_("Mode:"), 1.0, 0.5,
bsp->option_menu, 1, TRUE);
/* A separator after the paint options */
sep = gtk_hseparator_new ();
gtk_box_pack_start (GTK_BOX (bsp->view), sep, FALSE, FALSE, 0);
gtk_widget_show (sep);
spacing_adj = GIMP_BRUSH_FACTORY_VIEW (bsp->view)->spacing_adjustment;
if (initial_spacing >= 0)
{
/* Use passed spacing instead of brushes default */
gtk_adjustment_set_value (spacing_adj, initial_spacing);
}
g_signal_connect (G_OBJECT (spacing_adj), "value_changed",
G_CALLBACK (spacing_scale_update),
bsp);
gtk_widget_show (table);
gtk_widget_show (bsp->shell);
return bsp;
}
void
brush_select_free (BrushSelect *bsp)
{
g_return_if_fail (bsp != NULL);
gtk_widget_destroy (bsp->shell);
/* remove from active list */
brush_active_dialogs = g_slist_remove (brush_active_dialogs, bsp);
if (bsp->callback_name)
g_free (bsp->callback_name);
if (bsp->context)
g_object_unref (G_OBJECT (bsp->context));
g_free (bsp);
}
BrushSelect *
brush_select_get_by_callback (const gchar *callback_name)
{
GSList *list;
BrushSelect *bsp;
for (list = brush_active_dialogs; list; list = g_slist_next (list))
{
bsp = (BrushSelect *) list->data;
if (bsp->callback_name && ! strcmp (callback_name, bsp->callback_name))
return bsp;
}
return NULL;
}
void
brush_select_dialogs_check (void)
{
BrushSelect *bsp;
GSList *list;
ProcRecord *proc = NULL;
list = brush_active_dialogs;
while (list)
{
bsp = (BrushSelect *) list->data;
list = g_slist_next (list);
if (bsp->callback_name)
{
proc = procedural_db_lookup (bsp->context->gimp, bsp->callback_name);
if (! proc)
brush_select_close_callback (NULL, bsp);
}
}
}
/* private functions */
static void
brush_select_change_callbacks (BrushSelect *bsp,
gboolean closing)
{
ProcRecord *proc = NULL;
GimpBrush *brush;
Argument *return_vals;
gint nreturn_vals;
static gboolean busy = FALSE;
if (! (bsp && bsp->callback_name) || busy)
return;
busy = TRUE;
brush = gimp_context_get_brush (bsp->context);
/* If its still registered run it */
proc = procedural_db_lookup (bsp->context->gimp, bsp->callback_name);
if (proc && brush)
{
return_vals =
procedural_db_run_proc (bsp->context->gimp,
bsp->callback_name,
&nreturn_vals,
GIMP_PDB_STRING, GIMP_OBJECT (brush)->name,
GIMP_PDB_FLOAT, gimp_context_get_opacity (bsp->context) * 100.0,
GIMP_PDB_INT32, bsp->spacing_value,
GIMP_PDB_INT32, (gint) gimp_context_get_paint_mode (bsp->context),
GIMP_PDB_INT32, brush->mask->width,
GIMP_PDB_INT32, brush->mask->height,
GIMP_PDB_INT32, (brush->mask->width *
brush->mask->height),
GIMP_PDB_INT8ARRAY, temp_buf_data (brush->mask),
GIMP_PDB_INT32, (gint) closing,
GIMP_PDB_END);
if (!return_vals || return_vals[0].value.pdb_int != GIMP_PDB_SUCCESS)
g_message (_("Unable to run brush callback.\n"
"The corresponding plug-in may have crashed."));
if (return_vals)
procedural_db_destroy_args (return_vals, nreturn_vals);
}
busy = FALSE;
}
static void
brush_select_brush_changed (GimpContext *context,
GimpBrush *brush,
BrushSelect *bsp)
{
if (brush)
{
brush_select_change_callbacks (bsp, FALSE);
}
}
static void
brush_select_opacity_changed (GimpContext *context,
gdouble opacity,
BrushSelect *bsp)
{
g_signal_handlers_block_by_func (G_OBJECT (bsp->opacity_data),
opacity_scale_update,
bsp);
gtk_adjustment_set_value (GTK_ADJUSTMENT (bsp->opacity_data),
opacity * 100.0);
g_signal_handlers_unblock_by_func (G_OBJECT (bsp->opacity_data),
opacity_scale_update,
bsp);
brush_select_change_callbacks (bsp, FALSE);
}
static void
brush_select_paint_mode_changed (GimpContext *context,
GimpLayerModeEffects paint_mode,
BrushSelect *bsp)
{
gimp_option_menu_set_history (GTK_OPTION_MENU (bsp->option_menu),
GINT_TO_POINTER (paint_mode));
brush_select_change_callbacks (bsp, FALSE);
}
static void
opacity_scale_update (GtkAdjustment *adjustment,
BrushSelect *bsp)
{
g_signal_handlers_block_by_func (G_OBJECT (bsp->context),
brush_select_opacity_changed,
bsp);
gimp_context_set_opacity (bsp->context, adjustment->value / 100.0);
g_signal_handlers_unblock_by_func (G_OBJECT (bsp->context),
brush_select_opacity_changed,
bsp);
}
static void
paint_mode_menu_callback (GtkWidget *widget,
BrushSelect *bsp)
{
GimpLayerModeEffects paint_mode;
paint_mode = (GimpLayerModeEffects)
GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), "gimp-item-data"));
gimp_context_set_paint_mode (bsp->context, paint_mode);
}
static void
spacing_scale_update (GtkAdjustment *adjustment,
BrushSelect *bsp)
{
if (bsp->spacing_value != adjustment->value)
{
bsp->spacing_value = adjustment->value;
brush_select_change_callbacks (bsp, FALSE);
}
}
static void
brush_select_close_callback (GtkWidget *widget,
BrushSelect *bsp)
{
brush_select_change_callbacks (bsp, TRUE);
brush_select_free (bsp);
}