~ubuntu-branches/ubuntu/maverick/gimp/maverick-updates

« back to all changes in this revision

Viewing changes to libgimp/gimpbrushselect.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2005-12-09 19:44:52 UTC
  • Revision ID: james.westby@ubuntu.com-20051209194452-yggpemjlofpjqyf4
Tags: upstream-2.2.9
ImportĀ upstreamĀ versionĀ 2.2.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* LIBGIMP - The GIMP Library
 
2
 * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
 
3
 *
 
4
 * gimpbrushselect.c
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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.
 
20
 */
 
21
 
 
22
#include "config.h"
 
23
 
 
24
#include "gimp.h"
 
25
 
 
26
 
 
27
typedef struct _GimpBrushData GimpBrushData;
 
28
 
 
29
struct _GimpBrushData
 
30
{
 
31
  gchar                *brush_callback;
 
32
  guint                 idle_id;
 
33
  gchar                *brush_name;
 
34
  gdouble               opacity;
 
35
  gint                  spacing;
 
36
  gint                  paint_mode;
 
37
  gint                  width;
 
38
  gint                  height;
 
39
  guchar               *brush_mask_data;
 
40
  GimpRunBrushCallback  callback;
 
41
  gboolean              closing;
 
42
  gpointer              data;
 
43
};
 
44
 
 
45
 
 
46
/*  local function prototypes  */
 
47
 
 
48
static void      gimp_temp_brush_run      (const gchar      *name,
 
49
                                           gint              nparams,
 
50
                                           const GimpParam  *param,
 
51
                                           gint             *nreturn_vals,
 
52
                                           GimpParam       **return_vals);
 
53
static gboolean  gimp_temp_brush_run_idle (GimpBrushData    *brush_data);
 
54
 
 
55
 
 
56
/*  private variables  */
 
57
 
 
58
static GHashTable *gimp_brush_select_ht = NULL;
 
59
 
 
60
 
 
61
/*  public functions  */
 
62
 
 
63
const gchar *
 
64
gimp_brush_select_new (const gchar          *title,
 
65
                       const gchar          *brush_name,
 
66
                       gdouble               opacity,
 
67
                       gint                  spacing,
 
68
                       GimpLayerModeEffects  paint_mode,
 
69
                       GimpRunBrushCallback  callback,
 
70
                       gpointer              data)
 
71
{
 
72
  static GimpParamDef args[] =
 
73
  {
 
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]" },
 
84
  };
 
85
 
 
86
  gchar *brush_callback = gimp_procedural_db_temp_name ();
 
87
 
 
88
  gimp_install_temp_proc (brush_callback,
 
89
                          "Temporary brush popup callback procedure",
 
90
                          "",
 
91
                          "Andy Thomas",
 
92
                          "Andy Thomas",
 
93
                          "1997",
 
94
                          NULL,
 
95
                          "RGB*, GRAY*",
 
96
                          GIMP_TEMPORARY,
 
97
                          G_N_ELEMENTS (args), 0,
 
98
                          args, NULL,
 
99
                          gimp_temp_brush_run);
 
100
 
 
101
  if (gimp_brushes_popup (brush_callback, title, brush_name,
 
102
                          opacity, spacing, paint_mode))
 
103
    {
 
104
      GimpBrushData *brush_data;
 
105
 
 
106
      gimp_extension_enable (); /* Allow callbacks to be watched */
 
107
 
 
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,
 
111
                                                      g_free, g_free);
 
112
 
 
113
      brush_data = g_new0 (GimpBrushData, 1);
 
114
 
 
115
      brush_data->brush_callback = brush_callback;
 
116
      brush_data->callback       = callback;
 
117
      brush_data->data           = data;
 
118
 
 
119
      g_hash_table_insert (gimp_brush_select_ht, brush_callback, brush_data);
 
120
 
 
121
      return brush_callback;
 
122
    }
 
123
 
 
124
  gimp_uninstall_temp_proc (brush_callback);
 
125
  g_free (brush_callback);
 
126
 
 
127
  return NULL;
 
128
}
 
129
 
 
130
void
 
131
gimp_brush_select_destroy (const gchar *brush_callback)
 
132
{
 
133
  GimpBrushData *brush_data;
 
134
 
 
135
  g_return_if_fail (brush_callback != NULL);
 
136
  g_return_if_fail (gimp_brush_select_ht != NULL);
 
137
 
 
138
  brush_data = g_hash_table_lookup (gimp_brush_select_ht, brush_callback);
 
139
 
 
140
  if (! brush_data)
 
141
    {
 
142
      g_warning ("Can't find internal brush data");
 
143
      return;
 
144
    }
 
145
 
 
146
  if (brush_data->idle_id)
 
147
    g_source_remove (brush_data->idle_id);
 
148
 
 
149
  g_free (brush_data->brush_name);
 
150
  g_free (brush_data->brush_mask_data);
 
151
 
 
152
  if (brush_data->brush_callback)
 
153
    gimp_brushes_close_popup (brush_data->brush_callback);
 
154
 
 
155
  gimp_uninstall_temp_proc (brush_callback);
 
156
 
 
157
  g_hash_table_remove (gimp_brush_select_ht, brush_callback);
 
158
}
 
159
 
 
160
 
 
161
/*  private functions  */
 
162
 
 
163
static void
 
164
gimp_temp_brush_run (const gchar      *name,
 
165
                     gint              nparams,
 
166
                     const GimpParam  *param,
 
167
                     gint             *nreturn_vals,
 
168
                     GimpParam       **return_vals)
 
169
{
 
170
  static GimpParam  values[1];
 
171
  GimpBrushData    *brush_data;
 
172
 
 
173
  brush_data = g_hash_table_lookup (gimp_brush_select_ht, name);
 
174
 
 
175
  if (! brush_data)
 
176
    {
 
177
      g_warning ("Can't find internal brush data");
 
178
    }
 
179
  else
 
180
    {
 
181
      g_free (brush_data->brush_name);
 
182
      g_free (brush_data->brush_mask_data);
 
183
 
 
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;
 
193
 
 
194
      if (! brush_data->idle_id)
 
195
        brush_data->idle_id = g_idle_add ((GSourceFunc) gimp_temp_brush_run_idle,
 
196
                                          brush_data);
 
197
    }
 
198
 
 
199
  *nreturn_vals = 1;
 
200
  *return_vals  = values;
 
201
 
 
202
  values[0].type          = GIMP_PDB_STATUS;
 
203
  values[0].data.d_status = GIMP_PDB_SUCCESS;
 
204
}
 
205
 
 
206
static gboolean
 
207
gimp_temp_brush_run_idle (GimpBrushData *brush_data)
 
208
{
 
209
  brush_data->idle_id = 0;
 
210
 
 
211
  if (brush_data->callback)
 
212
    brush_data->callback (brush_data->brush_name,
 
213
                          brush_data->opacity,
 
214
                          brush_data->spacing,
 
215
                          brush_data->paint_mode,
 
216
                          brush_data->width,
 
217
                          brush_data->height,
 
218
                          brush_data->brush_mask_data,
 
219
                          brush_data->closing,
 
220
                          brush_data->data);
 
221
 
 
222
  if (brush_data->closing)
 
223
    {
 
224
      gchar *brush_callback = brush_data->brush_callback;
 
225
 
 
226
      brush_data->brush_callback = NULL;
 
227
      gimp_brush_select_destroy (brush_callback);
 
228
    }
 
229
 
 
230
  return FALSE;
 
231
}