1
/* LIBGIMP - The GIMP Library
2
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Lesser General Public
8
* License as published by the Free Software Foundation; either
9
* version 2 of the License, or (at your option) any later version.
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Library General Public License for more details.
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with this library; if not, write to the
18
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
* Boston, MA 02111-1307, USA.
27
typedef struct _GimpBrushData GimpBrushData;
31
gchar *brush_callback;
39
guchar *brush_mask_data;
40
GimpRunBrushCallback callback;
46
/* local function prototypes */
48
static void gimp_temp_brush_run (const gchar *name,
50
const GimpParam *param,
52
GimpParam **return_vals);
53
static gboolean gimp_temp_brush_run_idle (GimpBrushData *brush_data);
56
/* private variables */
58
static GHashTable *gimp_brush_select_ht = NULL;
61
/* public functions */
64
gimp_brush_select_new (const gchar *title,
65
const gchar *brush_name,
68
GimpLayerModeEffects paint_mode,
69
GimpRunBrushCallback callback,
72
static GimpParamDef args[] =
74
{ GIMP_PDB_STRING, "str", "String" },
75
{ GIMP_PDB_FLOAT, "opacity", "Opacity" },
76
{ GIMP_PDB_INT32, "spacing", "Spacing" },
77
{ GIMP_PDB_INT32, "paint mode", "Paint mode" },
78
{ GIMP_PDB_INT32, "mask width", "Brush width" },
79
{ GIMP_PDB_INT32, "mask height" "Brush heigth" },
80
{ GIMP_PDB_INT32, "mask len", "Length of brush mask data" },
81
{ GIMP_PDB_INT8ARRAY, "mask data", "The brush mask data" },
82
{ GIMP_PDB_INT32, "dialog status", "If the dialog was closing "
83
"[0 = No, 1 = Yes]" },
86
gchar *brush_callback = gimp_procedural_db_temp_name ();
88
gimp_install_temp_proc (brush_callback,
89
"Temporary brush popup callback procedure",
97
G_N_ELEMENTS (args), 0,
101
if (gimp_brushes_popup (brush_callback, title, brush_name,
102
opacity, spacing, paint_mode))
104
GimpBrushData *brush_data;
106
gimp_extension_enable (); /* Allow callbacks to be watched */
108
/* Now add to hash table so we can find it again */
109
if (! gimp_brush_select_ht)
110
gimp_brush_select_ht = g_hash_table_new_full (g_str_hash, g_str_equal,
113
brush_data = g_new0 (GimpBrushData, 1);
115
brush_data->brush_callback = brush_callback;
116
brush_data->callback = callback;
117
brush_data->data = data;
119
g_hash_table_insert (gimp_brush_select_ht, brush_callback, brush_data);
121
return brush_callback;
124
gimp_uninstall_temp_proc (brush_callback);
125
g_free (brush_callback);
131
gimp_brush_select_destroy (const gchar *brush_callback)
133
GimpBrushData *brush_data;
135
g_return_if_fail (brush_callback != NULL);
136
g_return_if_fail (gimp_brush_select_ht != NULL);
138
brush_data = g_hash_table_lookup (gimp_brush_select_ht, brush_callback);
142
g_warning ("Can't find internal brush data");
146
if (brush_data->idle_id)
147
g_source_remove (brush_data->idle_id);
149
g_free (brush_data->brush_name);
150
g_free (brush_data->brush_mask_data);
152
if (brush_data->brush_callback)
153
gimp_brushes_close_popup (brush_data->brush_callback);
155
gimp_uninstall_temp_proc (brush_callback);
157
g_hash_table_remove (gimp_brush_select_ht, brush_callback);
161
/* private functions */
164
gimp_temp_brush_run (const gchar *name,
166
const GimpParam *param,
168
GimpParam **return_vals)
170
static GimpParam values[1];
171
GimpBrushData *brush_data;
173
brush_data = g_hash_table_lookup (gimp_brush_select_ht, name);
177
g_warning ("Can't find internal brush data");
181
g_free (brush_data->brush_name);
182
g_free (brush_data->brush_mask_data);
184
brush_data->brush_name = g_strdup (param[0].data.d_string);
185
brush_data->opacity = param[1].data.d_float;
186
brush_data->spacing = param[2].data.d_int32;
187
brush_data->paint_mode = param[3].data.d_int32;
188
brush_data->width = param[4].data.d_int32;
189
brush_data->height = param[5].data.d_int32;
190
brush_data->brush_mask_data = g_memdup (param[7].data.d_int8array,
191
param[6].data.d_int32);
192
brush_data->closing = param[8].data.d_int32;
194
if (! brush_data->idle_id)
195
brush_data->idle_id = g_idle_add ((GSourceFunc) gimp_temp_brush_run_idle,
200
*return_vals = values;
202
values[0].type = GIMP_PDB_STATUS;
203
values[0].data.d_status = GIMP_PDB_SUCCESS;
207
gimp_temp_brush_run_idle (GimpBrushData *brush_data)
209
brush_data->idle_id = 0;
211
if (brush_data->callback)
212
brush_data->callback (brush_data->brush_name,
215
brush_data->paint_mode,
218
brush_data->brush_mask_data,
222
if (brush_data->closing)
224
gchar *brush_callback = brush_data->brush_callback;
226
brush_data->brush_callback = NULL;
227
gimp_brush_select_destroy (brush_callback);