2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2004-07-10 03:14:59 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpbrushselect.c
|
|
|
|
* Copyright (C) 2004 Michael Natterer <mitch@gimp.org>
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2004-07-10 03:14:59 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2004-07-10 03:14:59 +08:00
|
|
|
* (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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2004-07-10 03:14:59 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2012-03-30 01:19:01 +08:00
|
|
|
#include <gegl.h>
|
2004-07-10 03:14:59 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2012-05-04 06:50:23 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2004-07-10 03:14:59 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "widgets-types.h"
|
|
|
|
|
|
|
|
#include "core/gimp.h"
|
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
#include "core/gimpbrush.h"
|
2006-04-04 04:54:55 +08:00
|
|
|
#include "core/gimpparamspecs.h"
|
2012-04-09 06:59:20 +08:00
|
|
|
#include "core/gimptempbuf.h"
|
2004-07-10 03:14:59 +08:00
|
|
|
|
2006-04-26 17:13:47 +08:00
|
|
|
#include "pdb/gimppdb.h"
|
2004-07-10 03:14:59 +08:00
|
|
|
|
|
|
|
#include "gimpbrushfactoryview.h"
|
|
|
|
#include "gimpbrushselect.h"
|
|
|
|
#include "gimpcontainerbox.h"
|
2011-11-25 20:57:28 +08:00
|
|
|
#include "gimpspinscale.h"
|
2004-07-10 03:14:59 +08:00
|
|
|
#include "gimpwidgets-constructors.h"
|
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_OPACITY,
|
|
|
|
PROP_PAINT_MODE,
|
|
|
|
PROP_SPACING
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-05-04 06:50:23 +08:00
|
|
|
static void gimp_brush_select_constructed (GObject *object);
|
|
|
|
static void gimp_brush_select_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2011-01-14 16:38:11 +08:00
|
|
|
|
2012-05-04 06:50:23 +08:00
|
|
|
static GimpValueArray * gimp_brush_select_run_callback (GimpPdbDialog *dialog,
|
|
|
|
GimpObject *object,
|
|
|
|
gboolean closing,
|
|
|
|
GError **error);
|
2011-01-14 16:38:11 +08:00
|
|
|
|
2012-05-04 06:50:23 +08:00
|
|
|
static void gimp_brush_select_opacity_changed (GimpContext *context,
|
|
|
|
gdouble opacity,
|
|
|
|
GimpBrushSelect *select);
|
|
|
|
static void gimp_brush_select_mode_changed (GimpContext *context,
|
|
|
|
GimpLayerModeEffects paint_mode,
|
|
|
|
GimpBrushSelect *select);
|
2011-01-14 16:38:11 +08:00
|
|
|
|
2012-05-04 06:50:23 +08:00
|
|
|
static void gimp_brush_select_opacity_update (GtkAdjustment *adj,
|
|
|
|
GimpBrushSelect *select);
|
|
|
|
static void gimp_brush_select_mode_update (GtkWidget *widget,
|
|
|
|
GimpBrushSelect *select);
|
|
|
|
static void gimp_brush_select_spacing_update (GtkAdjustment *adj,
|
|
|
|
GimpBrushSelect *select);
|
2004-07-10 03:14:59 +08:00
|
|
|
|
|
|
|
|
2006-05-15 17:46:31 +08:00
|
|
|
G_DEFINE_TYPE (GimpBrushSelect, gimp_brush_select, GIMP_TYPE_PDB_DIALOG)
|
2004-07-10 03:14:59 +08:00
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
#define parent_class gimp_brush_select_parent_class
|
2004-07-10 03:14:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_brush_select_class_init (GimpBrushSelectClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpPdbDialogClass *pdb_class = GIMP_PDB_DIALOG_CLASS (klass);
|
|
|
|
|
2011-01-14 16:38:11 +08:00
|
|
|
object_class->constructed = gimp_brush_select_constructed;
|
2004-07-10 03:14:59 +08:00
|
|
|
object_class->set_property = gimp_brush_select_set_property;
|
|
|
|
|
|
|
|
pdb_class->run_callback = gimp_brush_select_run_callback;
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_OPACITY,
|
|
|
|
g_param_spec_double ("opacity", NULL, NULL,
|
|
|
|
GIMP_OPACITY_TRANSPARENT,
|
|
|
|
GIMP_OPACITY_OPAQUE,
|
|
|
|
GIMP_OPACITY_OPAQUE,
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_WRITABLE |
|
2004-07-10 03:14:59 +08:00
|
|
|
G_PARAM_CONSTRUCT));
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_PAINT_MODE,
|
|
|
|
g_param_spec_enum ("paint-mode", NULL, NULL,
|
|
|
|
GIMP_TYPE_LAYER_MODE_EFFECTS,
|
|
|
|
GIMP_NORMAL_MODE,
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_WRITABLE |
|
2004-07-10 03:14:59 +08:00
|
|
|
G_PARAM_CONSTRUCT));
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_SPACING,
|
|
|
|
g_param_spec_int ("spacing", NULL, NULL,
|
|
|
|
-G_MAXINT, 1000, -1,
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_WRITABLE |
|
2004-07-10 03:14:59 +08:00
|
|
|
G_PARAM_CONSTRUCT));
|
|
|
|
}
|
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
static void
|
|
|
|
gimp_brush_select_init (GimpBrushSelect *select)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-01-14 16:38:11 +08:00
|
|
|
static void
|
|
|
|
gimp_brush_select_constructed (GObject *object)
|
2004-07-10 03:14:59 +08:00
|
|
|
{
|
2011-01-14 16:38:11 +08:00
|
|
|
GimpPdbDialog *dialog = GIMP_PDB_DIALOG (object);
|
|
|
|
GimpBrushSelect *select = GIMP_BRUSH_SELECT (object);
|
2009-03-23 00:35:53 +08:00
|
|
|
GtkWidget *content_area;
|
2011-11-25 20:57:28 +08:00
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *scale;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *label;
|
2004-07-10 03:14:59 +08:00
|
|
|
GtkAdjustment *spacing_adj;
|
|
|
|
|
2012-11-13 04:51:22 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->constructed (object);
|
2004-07-10 03:14:59 +08:00
|
|
|
|
|
|
|
gimp_context_set_opacity (dialog->context, select->initial_opacity);
|
|
|
|
gimp_context_set_paint_mode (dialog->context, select->initial_mode);
|
|
|
|
|
2005-05-28 00:51:39 +08:00
|
|
|
g_signal_connect (dialog->context, "opacity-changed",
|
2004-07-10 03:14:59 +08:00
|
|
|
G_CALLBACK (gimp_brush_select_opacity_changed),
|
|
|
|
dialog);
|
2005-05-28 00:51:39 +08:00
|
|
|
g_signal_connect (dialog->context, "paint-mode-changed",
|
2004-07-10 03:14:59 +08:00
|
|
|
G_CALLBACK (gimp_brush_select_mode_changed),
|
|
|
|
dialog);
|
|
|
|
|
|
|
|
dialog->view =
|
|
|
|
gimp_brush_factory_view_new (GIMP_VIEW_TYPE_GRID,
|
|
|
|
dialog->context->gimp->brush_factory,
|
|
|
|
dialog->context,
|
|
|
|
FALSE,
|
2004-08-29 19:58:05 +08:00
|
|
|
GIMP_VIEW_SIZE_MEDIUM, 1,
|
2004-07-10 03:14:59 +08:00
|
|
|
dialog->menu_factory);
|
|
|
|
|
|
|
|
gimp_container_box_set_size_request (GIMP_CONTAINER_BOX (GIMP_CONTAINER_EDITOR (dialog->view)->view),
|
2004-08-29 19:58:05 +08:00
|
|
|
5 * (GIMP_VIEW_SIZE_MEDIUM + 2),
|
|
|
|
5 * (GIMP_VIEW_SIZE_MEDIUM + 2));
|
2004-07-10 03:14:59 +08:00
|
|
|
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (dialog->view), 12);
|
2009-03-23 00:35:53 +08:00
|
|
|
|
|
|
|
content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
|
2010-10-30 21:42:25 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (content_area), dialog->view, TRUE, TRUE, 0);
|
2004-07-10 03:14:59 +08:00
|
|
|
gtk_widget_show (dialog->view);
|
|
|
|
|
2011-11-25 20:57:28 +08:00
|
|
|
vbox = GTK_WIDGET (GIMP_CONTAINER_EDITOR (dialog->view)->view);
|
2004-07-10 03:14:59 +08:00
|
|
|
|
|
|
|
/* Create the opacity scale widget */
|
|
|
|
select->opacity_data =
|
2011-11-25 20:57:28 +08:00
|
|
|
GTK_ADJUSTMENT (gtk_adjustment_new (gimp_context_get_opacity (dialog->context) * 100.0,
|
|
|
|
0.0, 100.0,
|
|
|
|
1.0, 10.0, 0.0));
|
|
|
|
|
|
|
|
scale = gimp_spin_scale_new (select->opacity_data,
|
|
|
|
_("Opacity"), 1);
|
|
|
|
gtk_box_pack_end (GTK_BOX (vbox), scale, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (scale);
|
2004-07-10 03:14:59 +08:00
|
|
|
|
2005-05-28 00:51:39 +08:00
|
|
|
g_signal_connect (select->opacity_data, "value-changed",
|
2004-07-10 03:14:59 +08:00
|
|
|
G_CALLBACK (gimp_brush_select_opacity_update),
|
|
|
|
select);
|
|
|
|
|
|
|
|
/* Create the paint mode option menu */
|
2011-11-25 20:57:28 +08:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
|
|
|
|
gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
|
|
|
label = gtk_label_new (_("Mode:"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
2006-10-22 02:46:49 +08:00
|
|
|
select->paint_mode_menu = gimp_paint_mode_menu_new (TRUE, FALSE);
|
2011-11-25 20:57:28 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), select->paint_mode_menu, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (select->paint_mode_menu);
|
2004-07-10 03:14:59 +08:00
|
|
|
|
2005-02-09 04:07:08 +08:00
|
|
|
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (select->paint_mode_menu),
|
|
|
|
gimp_context_get_paint_mode (dialog->context),
|
|
|
|
G_CALLBACK (gimp_brush_select_mode_update),
|
2006-04-12 20:49:29 +08:00
|
|
|
select);
|
2005-02-09 04:07:08 +08:00
|
|
|
|
2004-07-10 03:14:59 +08:00
|
|
|
spacing_adj = GIMP_BRUSH_FACTORY_VIEW (dialog->view)->spacing_adjustment;
|
|
|
|
|
|
|
|
/* Use passed spacing instead of brushes default */
|
|
|
|
if (select->spacing >= 0)
|
|
|
|
gtk_adjustment_set_value (spacing_adj, select->spacing);
|
|
|
|
|
2005-05-28 00:51:39 +08:00
|
|
|
g_signal_connect (spacing_adj, "value-changed",
|
2004-07-10 03:14:59 +08:00
|
|
|
G_CALLBACK (gimp_brush_select_spacing_update),
|
|
|
|
select);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_brush_select_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpPdbDialog *dialog = GIMP_PDB_DIALOG (object);
|
|
|
|
GimpBrushSelect *select = GIMP_BRUSH_SELECT (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_OPACITY:
|
|
|
|
if (dialog->view)
|
|
|
|
gimp_context_set_opacity (dialog->context, g_value_get_double (value));
|
|
|
|
else
|
|
|
|
select->initial_opacity = g_value_get_double (value);
|
|
|
|
break;
|
|
|
|
case PROP_PAINT_MODE:
|
|
|
|
if (dialog->view)
|
|
|
|
gimp_context_set_paint_mode (dialog->context, g_value_get_enum (value));
|
|
|
|
else
|
|
|
|
select->initial_mode = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
case PROP_SPACING:
|
|
|
|
if (dialog->view)
|
|
|
|
{
|
|
|
|
if (g_value_get_int (value) >= 0)
|
|
|
|
gtk_adjustment_set_value (GIMP_BRUSH_FACTORY_VIEW (dialog->view)->spacing_adjustment,
|
|
|
|
g_value_get_int (value));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
select->spacing = g_value_get_int (value);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-04 06:50:23 +08:00
|
|
|
static GimpValueArray *
|
2007-12-03 02:05:54 +08:00
|
|
|
gimp_brush_select_run_callback (GimpPdbDialog *dialog,
|
|
|
|
GimpObject *object,
|
|
|
|
gboolean closing,
|
|
|
|
GError **error)
|
2004-07-10 03:14:59 +08:00
|
|
|
{
|
2012-05-04 06:50:23 +08:00
|
|
|
GimpBrush *brush = GIMP_BRUSH (object);
|
2014-10-12 07:16:32 +08:00
|
|
|
GimpTempBuf *mask = gimp_brush_get_mask (brush);
|
2012-05-04 06:50:23 +08:00
|
|
|
GimpArray *array;
|
|
|
|
GimpValueArray *return_vals;
|
2006-04-04 04:54:55 +08:00
|
|
|
|
2014-10-12 07:16:32 +08:00
|
|
|
array = gimp_array_new (gimp_temp_buf_get_data (mask),
|
|
|
|
gimp_temp_buf_get_data_size (mask),
|
2006-04-04 04:54:55 +08:00
|
|
|
TRUE);
|
|
|
|
|
|
|
|
return_vals =
|
2006-04-26 17:13:47 +08:00
|
|
|
gimp_pdb_execute_procedure_by_name (dialog->pdb,
|
|
|
|
dialog->caller_context,
|
2007-12-03 02:05:54 +08:00
|
|
|
NULL, error,
|
2006-04-26 17:13:47 +08:00
|
|
|
dialog->callback_name,
|
2009-08-29 18:40:40 +08:00
|
|
|
G_TYPE_STRING, gimp_object_get_name (object),
|
2006-04-26 17:13:47 +08:00
|
|
|
G_TYPE_DOUBLE, gimp_context_get_opacity (dialog->context) * 100.0,
|
|
|
|
GIMP_TYPE_INT32, GIMP_BRUSH_SELECT (dialog)->spacing,
|
|
|
|
GIMP_TYPE_INT32, gimp_context_get_paint_mode (dialog->context),
|
2014-10-12 07:16:32 +08:00
|
|
|
GIMP_TYPE_INT32, gimp_brush_get_width (brush),
|
|
|
|
GIMP_TYPE_INT32, gimp_brush_get_height (brush),
|
2006-04-26 17:13:47 +08:00
|
|
|
GIMP_TYPE_INT32, array->length,
|
|
|
|
GIMP_TYPE_INT8_ARRAY, array,
|
|
|
|
GIMP_TYPE_INT32, closing,
|
|
|
|
G_TYPE_NONE);
|
2006-04-04 04:54:55 +08:00
|
|
|
|
|
|
|
gimp_array_free (array);
|
|
|
|
|
|
|
|
return return_vals;
|
2004-07-10 03:14:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_brush_select_opacity_changed (GimpContext *context,
|
|
|
|
gdouble opacity,
|
|
|
|
GimpBrushSelect *select)
|
|
|
|
{
|
|
|
|
g_signal_handlers_block_by_func (select->opacity_data,
|
|
|
|
gimp_brush_select_opacity_update,
|
2006-04-12 20:49:29 +08:00
|
|
|
select);
|
2004-07-10 03:14:59 +08:00
|
|
|
|
2011-05-15 23:00:41 +08:00
|
|
|
gtk_adjustment_set_value (select->opacity_data, opacity * 100.0);
|
2004-07-10 03:14:59 +08:00
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (select->opacity_data,
|
2006-04-12 20:49:29 +08:00
|
|
|
gimp_brush_select_opacity_update,
|
|
|
|
select);
|
2004-07-10 03:14:59 +08:00
|
|
|
|
|
|
|
gimp_pdb_dialog_run_callback (GIMP_PDB_DIALOG (select), FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_brush_select_mode_changed (GimpContext *context,
|
|
|
|
GimpLayerModeEffects paint_mode,
|
|
|
|
GimpBrushSelect *select)
|
|
|
|
{
|
2005-02-09 04:07:08 +08:00
|
|
|
g_signal_handlers_block_by_func (select->paint_mode_menu,
|
|
|
|
gimp_brush_select_mode_update,
|
2006-04-12 20:49:29 +08:00
|
|
|
select);
|
2005-02-09 04:07:08 +08:00
|
|
|
|
|
|
|
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (select->paint_mode_menu),
|
|
|
|
paint_mode);
|
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (select->paint_mode_menu,
|
|
|
|
gimp_brush_select_mode_update,
|
|
|
|
select);
|
2004-07-10 03:14:59 +08:00
|
|
|
|
|
|
|
gimp_pdb_dialog_run_callback (GIMP_PDB_DIALOG (select), FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_brush_select_opacity_update (GtkAdjustment *adjustment,
|
|
|
|
GimpBrushSelect *select)
|
|
|
|
{
|
|
|
|
gimp_context_set_opacity (GIMP_PDB_DIALOG (select)->context,
|
2008-06-29 21:41:24 +08:00
|
|
|
gtk_adjustment_get_value (adjustment) / 100.0);
|
2004-07-10 03:14:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_brush_select_mode_update (GtkWidget *widget,
|
|
|
|
GimpBrushSelect *select)
|
|
|
|
{
|
2005-02-09 04:07:08 +08:00
|
|
|
gint paint_mode;
|
2004-07-10 03:14:59 +08:00
|
|
|
|
2005-02-09 04:07:08 +08:00
|
|
|
if (gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget),
|
|
|
|
&paint_mode))
|
|
|
|
{
|
|
|
|
gimp_context_set_paint_mode (GIMP_PDB_DIALOG (select)->context,
|
|
|
|
(GimpLayerModeEffects) paint_mode);
|
|
|
|
}
|
2004-07-10 03:14:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_brush_select_spacing_update (GtkAdjustment *adjustment,
|
|
|
|
GimpBrushSelect *select)
|
|
|
|
{
|
2008-06-29 21:41:24 +08:00
|
|
|
gdouble value = gtk_adjustment_get_value (adjustment);
|
|
|
|
|
|
|
|
if (select->spacing != value)
|
2004-07-10 03:14:59 +08:00
|
|
|
{
|
2008-06-29 21:41:24 +08:00
|
|
|
select->spacing = value;
|
2004-07-10 03:14:59 +08:00
|
|
|
|
|
|
|
gimp_pdb_dialog_run_callback (GIMP_PDB_DIALOG (select), FALSE);
|
|
|
|
}
|
|
|
|
}
|