~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/widgets/gimpviewrendererbrush.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2008-10-06 13:30:41 UTC
  • mto: This revision was merged to the branch mainline in revision 35.
  • Revision ID: james.westby@ubuntu.com-20081006133041-3panbkcanaymfsmp
Tags: upstream-2.6.0
ImportĀ upstreamĀ versionĀ 2.6.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include "gimpviewrendererbrush.h"
34
34
 
35
35
 
36
 
static void   gimp_view_renderer_brush_finalize   (GObject          *object);
37
 
static void   gimp_view_renderer_brush_render     (GimpViewRenderer *renderer,
38
 
                                                   GtkWidget        *widget);
 
36
static void   gimp_view_renderer_brush_finalize (GObject            *object);
 
37
static void   gimp_view_renderer_brush_render   (GimpViewRenderer   *renderer,
 
38
                                                 GtkWidget          *widget);
 
39
static void   gimp_view_renderer_brush_draw     (GimpViewRenderer   *renderer,
 
40
                                                 GtkWidget          *widget,
 
41
                                                 cairo_t            *cr,
 
42
                                                 const GdkRectangle *area);
39
43
 
40
 
static gboolean gimp_view_renderer_brush_render_timeout (gpointer  data);
 
44
static gboolean gimp_view_renderer_brush_render_timeout (gpointer    data);
41
45
 
42
46
 
43
47
G_DEFINE_TYPE (GimpViewRendererBrush, gimp_view_renderer_brush,
55
59
  object_class->finalize = gimp_view_renderer_brush_finalize;
56
60
 
57
61
  renderer_class->render = gimp_view_renderer_brush_render;
 
62
  renderer_class->draw   = gimp_view_renderer_brush_draw;
58
63
}
59
64
 
60
65
static void
84
89
{
85
90
  GimpViewRendererBrush *renderbrush = GIMP_VIEW_RENDERER_BRUSH (renderer);
86
91
  TempBuf               *temp_buf;
87
 
  gint                   brush_width;
88
 
  gint                   brush_height;
89
92
 
90
93
  if (renderbrush->pipe_timeout_id)
91
94
    {
93
96
      renderbrush->pipe_timeout_id = 0;
94
97
    }
95
98
 
96
 
  gimp_viewable_get_size (renderer->viewable, &brush_width, &brush_height);
97
 
 
98
99
  temp_buf = gimp_viewable_get_new_preview (renderer->viewable,
99
100
                                            renderer->context,
100
101
                                            renderer->width,
108
109
 
109
110
  if (renderer->is_popup)
110
111
    {
111
 
      gimp_view_renderer_render_buffer (renderer, temp_buf, -1,
112
 
                                        GIMP_VIEW_BG_WHITE,
113
 
                                        GIMP_VIEW_BG_WHITE);
 
112
      gimp_view_renderer_render_surface (renderer, temp_buf, -1,
 
113
                                         GIMP_VIEW_BG_WHITE,
 
114
                                         GIMP_VIEW_BG_WHITE);
114
115
 
115
116
      temp_buf_free (temp_buf);
116
117
 
125
126
      return;
126
127
    }
127
128
 
128
 
  gimp_view_renderer_render_buffer (renderer, temp_buf, -1,
129
 
                                    GIMP_VIEW_BG_WHITE,
130
 
                                    GIMP_VIEW_BG_WHITE);
 
129
  gimp_view_renderer_render_surface (renderer, temp_buf, -1,
 
130
                                     GIMP_VIEW_BG_WHITE,
 
131
                                     GIMP_VIEW_BG_WHITE);
131
132
 
132
133
  temp_buf_free (temp_buf);
133
 
 
134
 
#define INDICATOR_WIDTH  7
135
 
#define INDICATOR_HEIGHT 7
136
 
 
137
 
  if (renderer->width  >= INDICATOR_WIDTH  * 2 &&
138
 
      renderer->height >= INDICATOR_HEIGHT * 2 &&
139
 
      (renderer->width  < brush_width          ||
140
 
       renderer->height < brush_height         ||
141
 
       GIMP_IS_BRUSH_PIPE (renderer->viewable) ||
142
 
       GIMP_IS_BRUSH_GENERATED (renderer->viewable)))
143
 
    {
144
 
#define WHT { 255, 255, 255 }
145
 
#define BLK {   0,   0,   0 }
146
 
#define RED { 255, 127, 127 }
147
 
#define BLU { 127, 150, 255 }
148
 
 
149
 
      static const guchar scale_indicator_bits[7][7][3] =
150
 
      {
151
 
        { WHT, WHT, WHT, WHT, WHT, WHT, WHT },
152
 
        { WHT, WHT, WHT, BLK, WHT, WHT, WHT },
153
 
        { WHT, WHT, WHT, BLK, WHT, WHT, WHT },
154
 
        { WHT, BLK, BLK, BLK, BLK, BLK, WHT },
155
 
        { WHT, WHT, WHT, BLK, WHT, WHT, WHT },
156
 
        { WHT, WHT, WHT, BLK, WHT, WHT, WHT },
157
 
        { WHT, WHT, WHT, WHT, WHT, WHT, WHT }
158
 
      };
159
 
 
160
 
      static const guchar scale_pipe_indicator_bits[7][7][3] =
161
 
      {
162
 
        { WHT, WHT, WHT, WHT, WHT, WHT, WHT },
163
 
        { WHT, WHT, WHT, BLK, WHT, WHT, RED },
164
 
        { WHT, WHT, WHT, BLK, WHT, RED, RED },
165
 
        { WHT, BLK, BLK, BLK, BLK, BLK, RED },
166
 
        { WHT, WHT, WHT, BLK, RED, RED, RED },
167
 
        { WHT, WHT, RED, BLK, RED, RED, RED },
168
 
        { WHT, RED, RED, RED, RED, RED, RED }
169
 
      };
170
 
 
171
 
      static const guchar pipe_indicator_bits[7][7][3] =
172
 
      {
173
 
        { WHT, WHT, WHT, WHT, WHT, WHT, WHT },
174
 
        { WHT, WHT, WHT, WHT, WHT, WHT, RED },
175
 
        { WHT, WHT, WHT, WHT, WHT, RED, RED },
176
 
        { WHT, WHT, WHT, WHT, RED, RED, RED },
177
 
        { WHT, WHT, WHT, RED, RED, RED, RED },
178
 
        { WHT, WHT, RED, RED, RED, RED, RED },
179
 
        { WHT, RED, RED, RED, RED, RED, RED }
180
 
      };
181
 
 
182
 
      static const guchar scale_genbrush_indicator_bits[7][7][3] =
183
 
      {
184
 
        { WHT, WHT, WHT, WHT, WHT, WHT, WHT },
185
 
        { WHT, WHT, WHT, BLK, WHT, WHT, BLU },
186
 
        { WHT, WHT, WHT, BLK, WHT, BLU, BLU },
187
 
        { WHT, BLK, BLK, BLK, BLK, BLK, BLU },
188
 
        { WHT, WHT, WHT, BLK, WHT, BLU, BLU },
189
 
        { WHT, WHT, BLU, BLK, BLU, BLU, BLU },
190
 
        { WHT, WHT, BLU, BLU, BLU, BLU, BLU }
191
 
      };
192
 
 
193
 
      static const guchar genbrush_indicator_bits[7][7][3] =
194
 
      {
195
 
        { WHT, WHT, WHT, WHT, WHT, WHT, WHT },
196
 
        { WHT, WHT, WHT, WHT, WHT, WHT, BLU },
197
 
        { WHT, WHT, WHT, WHT, WHT, BLU, BLU },
198
 
        { WHT, WHT, WHT, WHT, BLU, BLU, BLU },
199
 
        { WHT, WHT, WHT, BLU, BLU, BLU, BLU },
200
 
        { WHT, WHT, BLU, BLU, BLU, BLU, BLU },
201
 
        { WHT, BLU, BLU, BLU, BLU, BLU, BLU }
202
 
      };
203
 
 
204
 
#undef WHT
205
 
#undef BLK
206
 
#undef RED
207
 
#undef BLU
208
 
 
209
 
      guchar   *buf;
210
 
      guchar   *b;
211
 
      gint      x, y;
212
 
      gint      offset_x;
213
 
      gint      offset_y;
214
 
      gboolean  alpha;
215
 
      gboolean  pipe;
216
 
      gboolean  genbrush;
217
 
      gboolean  scale;
218
 
 
219
 
      offset_x = renderer->width  - INDICATOR_WIDTH;
220
 
      offset_y = renderer->height - INDICATOR_HEIGHT;
221
 
 
222
 
      buf = renderer->buffer + (offset_y * renderer->rowstride +
223
 
                                offset_x * renderer->bytes);
224
 
 
225
 
      pipe     = GIMP_IS_BRUSH_PIPE (renderer->viewable);
226
 
      genbrush = GIMP_IS_BRUSH_GENERATED (renderer->viewable);
227
 
      scale    = (renderer->width  < brush_width ||
228
 
                  renderer->height < brush_height);
229
 
      alpha    = (renderer->bytes == 4);
230
 
 
231
 
      for (y = 0; y < INDICATOR_HEIGHT; y++)
232
 
        {
233
 
          b = buf;
234
 
 
235
 
          for (x = 0; x < INDICATOR_WIDTH; x++)
236
 
            {
237
 
              if (scale)
238
 
                {
239
 
                  if (pipe)
240
 
                    {
241
 
                      *b++ = scale_pipe_indicator_bits[y][x][0];
242
 
                      *b++ = scale_pipe_indicator_bits[y][x][1];
243
 
                      *b++ = scale_pipe_indicator_bits[y][x][2];
244
 
                    }
245
 
                  else if (genbrush)
246
 
                    {
247
 
                      *b++ = scale_genbrush_indicator_bits[y][x][0];
248
 
                      *b++ = scale_genbrush_indicator_bits[y][x][1];
249
 
                      *b++ = scale_genbrush_indicator_bits[y][x][2];
250
 
                    }
251
 
                  else
252
 
                    {
253
 
                      *b++ = scale_indicator_bits[y][x][0];
254
 
                      *b++ = scale_indicator_bits[y][x][1];
255
 
                      *b++ = scale_indicator_bits[y][x][2];
256
 
                    }
257
 
                }
258
 
              else if (pipe)
259
 
                {
260
 
                  *b++ = pipe_indicator_bits[y][x][0];
261
 
                  *b++ = pipe_indicator_bits[y][x][1];
262
 
                  *b++ = pipe_indicator_bits[y][x][2];
263
 
                }
264
 
              else if (genbrush)
265
 
                {
266
 
                  *b++ = genbrush_indicator_bits[y][x][0];
267
 
                  *b++ = genbrush_indicator_bits[y][x][1];
268
 
                  *b++ = genbrush_indicator_bits[y][x][2];
269
 
                }
270
 
 
271
 
              if (alpha)
272
 
                *b++ = 255;
273
 
            }
274
 
 
275
 
          buf += renderer->rowstride;
276
 
        }
277
 
    }
278
 
 
279
 
#undef INDICATOR_WIDTH
280
 
#undef INDICATOR_HEIGHT
281
134
}
282
135
 
283
136
static gboolean
318
171
  if (temp_buf->height < renderer->height)
319
172
    temp_buf->y = (renderer->height - temp_buf->height) / 2;
320
173
 
321
 
  gimp_view_renderer_render_buffer (renderer, temp_buf, -1,
322
 
                                    GIMP_VIEW_BG_WHITE,
323
 
                                    GIMP_VIEW_BG_WHITE);
 
174
  gimp_view_renderer_render_surface (renderer, temp_buf, -1,
 
175
                                     GIMP_VIEW_BG_WHITE,
 
176
                                     GIMP_VIEW_BG_WHITE);
324
177
 
325
178
  temp_buf_free (temp_buf);
326
179
 
328
181
 
329
182
  return TRUE;
330
183
}
 
184
 
 
185
static void
 
186
gimp_view_renderer_brush_draw (GimpViewRenderer   *renderer,
 
187
                               GtkWidget          *widget,
 
188
                               cairo_t            *cr,
 
189
                               const GdkRectangle *area)
 
190
{
 
191
  GIMP_VIEW_RENDERER_CLASS (parent_class)->draw (renderer, widget, cr, area);
 
192
 
 
193
#define INDICATOR_WIDTH  7
 
194
#define INDICATOR_HEIGHT 7
 
195
 
 
196
  if (renderer->width  > 2 * INDICATOR_WIDTH &&
 
197
      renderer->height > 2 * INDICATOR_HEIGHT)
 
198
    {
 
199
      gboolean  pipe      = GIMP_IS_BRUSH_PIPE (renderer->viewable);
 
200
      gboolean  generated = GIMP_IS_BRUSH_GENERATED (renderer->viewable);
 
201
      gint      brush_width;
 
202
      gint      brush_height;
 
203
 
 
204
      if (generated || pipe)
 
205
        {
 
206
          cairo_move_to (cr, area->x + area->width, area->y + area->height);
 
207
          cairo_rel_line_to (cr, - INDICATOR_WIDTH, 0);
 
208
          cairo_rel_line_to (cr, INDICATOR_WIDTH, - INDICATOR_HEIGHT);
 
209
          cairo_rel_line_to (cr, 0, INDICATOR_HEIGHT);
 
210
 
 
211
          if (pipe)
 
212
            cairo_set_source_rgb (cr, 1.0, 0.5, 0.5);
 
213
          else
 
214
            cairo_set_source_rgb (cr, 0.5, 0.6, 1.0);
 
215
 
 
216
          cairo_fill (cr);
 
217
        }
 
218
 
 
219
      gimp_viewable_get_size (renderer->viewable, &brush_width, &brush_height);
 
220
 
 
221
      if (renderer->width < brush_width || renderer->height < brush_height)
 
222
        {
 
223
          cairo_move_to (cr,
 
224
                         area->x + area->width  - INDICATOR_WIDTH + 1,
 
225
                         area->y + area->height - INDICATOR_HEIGHT / 2.0);
 
226
          cairo_rel_line_to (cr, INDICATOR_WIDTH - 2, 0);
 
227
 
 
228
          cairo_move_to (cr,
 
229
                         area->x + area->width  - INDICATOR_WIDTH / 2.0,
 
230
                         area->y + area->height - INDICATOR_HEIGHT + 1);
 
231
          cairo_rel_line_to (cr, 0, INDICATOR_WIDTH - 2);
 
232
 
 
233
          cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
 
234
          cairo_set_line_width (cr, 1);
 
235
          cairo_stroke (cr);
 
236
        }
 
237
    }
 
238
 
 
239
#undef INDICATOR_WIDTH
 
240
#undef INDICATOR_HEIGHT
 
241
}