~ubuntu-branches/ubuntu/vivid/gimp/vivid

« back to all changes in this revision

Viewing changes to libgimpwidgets/gimppreviewarea.c

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach
  • Date: 2012-05-08 18:50:03 UTC
  • mto: (1.1.26) (0.5.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 71.
  • Revision ID: package-import@ubuntu.com-20120508185003-tltkvbaysf8d2426
ImportĀ upstreamĀ versionĀ 2.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* LIBGIMP - The GIMP Library
2
2
 * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
3
3
 *
4
 
 * This library is free software; you can redistribute it and/or
 
4
 * This library is free software: you can redistribute it and/or
5
5
 * modify it under the terms of the GNU Lesser General Public
6
6
 * License as published by the Free Software Foundation; either
7
 
 * version 2 of the License, or (at your option) any later version.
 
7
 * version 3 of the License, or (at your option) any later version.
8
8
 *
9
9
 * This library is distributed in the hope that it will be useful,
10
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
12
 * Lesser General Public License for more details.
13
13
 *
14
14
 * You should have received a copy of the GNU Lesser General Public
15
 
 * License along with this library; if not, write to the
16
 
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
 
 * Boston, MA 02111-1307, USA.
 
15
 * License along with this library.  If not, see
 
16
 * <http://www.gnu.org/licenses/>.
18
17
 */
19
18
 
20
19
#include "config.h"
32
31
#include "libgimp/libgimp-intl.h"
33
32
 
34
33
 
 
34
/**
 
35
 * SECTION: gimppreviewarea
 
36
 * @title: GimpPreviewArea
 
37
 * @short_description: A general purpose preview widget which caches
 
38
 *                     its pixel data.
 
39
 *
 
40
 * A general purpose preview widget which caches its pixel data.
 
41
 **/
 
42
 
 
43
 
35
44
enum
36
45
{
37
46
  PROP_0,
221
230
                          GdkEventExpose *event)
222
231
{
223
232
  GimpPreviewArea *area = GIMP_PREVIEW_AREA (widget);
 
233
  GtkAllocation    allocation;
 
234
  GdkPixbuf       *pixbuf;
224
235
  GdkRectangle     rect;
225
 
  GdkRectangle     render;
 
236
  cairo_t         *cr;
226
237
 
227
238
  if (! area->buf)
228
239
    return FALSE;
229
240
 
230
 
  rect.x      = (widget->allocation.width  - area->width)  / 2;
231
 
  rect.y      = (widget->allocation.height - area->height) / 2;
 
241
  gtk_widget_get_allocation (widget, &allocation);
 
242
 
 
243
  rect.x      = (allocation.width  - area->width)  / 2;
 
244
  rect.y      = (allocation.height - area->height) / 2;
232
245
  rect.width  = area->width;
233
246
  rect.height = area->height;
234
247
 
235
 
  if (gdk_rectangle_intersect (&rect, &event->area, &render))
236
 
    {
237
 
      GtkStyle *style = gtk_widget_get_style (widget);
238
 
      gint      x     = render.x - rect.x;
239
 
      gint      y     = render.y - rect.y;
240
 
      guchar   *buf   = area->buf + x * 3 + y * area->rowstride;
241
 
 
242
 
      gdk_draw_rgb_image_dithalign (widget->window,
243
 
                                    style->fg_gc[widget->state],
244
 
                                    render.x,
245
 
                                    render.y,
246
 
                                    render.width,
247
 
                                    render.height,
248
 
                                    GDK_RGB_DITHER_MAX,
249
 
                                    buf,
250
 
                                    area->rowstride,
251
 
                                    area->offset_x - render.x,
252
 
                                    area->offset_y - render.y);
253
 
    }
 
248
  pixbuf = gdk_pixbuf_new_from_data (area->buf,
 
249
                                     GDK_COLORSPACE_RGB,
 
250
                                     FALSE,
 
251
                                     8,
 
252
                                     rect.width,
 
253
                                     rect.height,
 
254
                                     area->rowstride,
 
255
                                     NULL, NULL);
 
256
  cr = gdk_cairo_create (gtk_widget_get_window (widget));
 
257
 
 
258
  gdk_cairo_region (cr, event->region);
 
259
  cairo_clip (cr);
 
260
 
 
261
  gdk_cairo_set_source_pixbuf (cr, pixbuf, rect.x, rect.y);
 
262
  cairo_paint (cr);
 
263
 
 
264
  cairo_destroy (cr);
 
265
  g_object_unref (pixbuf);
254
266
 
255
267
  return FALSE;
256
268
}
262
274
                              gint             width,
263
275
                              gint             height)
264
276
{
265
 
  GtkWidget *widget = GTK_WIDGET (area);
266
 
 
267
 
  x += (widget->allocation.width  - area->width)  / 2;
268
 
  y += (widget->allocation.height - area->height) / 2;
 
277
  GtkWidget     *widget = GTK_WIDGET (area);
 
278
  GtkAllocation  allocation;
 
279
 
 
280
  gtk_widget_get_allocation (widget, &allocation);
 
281
 
 
282
  x += (allocation.width  - area->width)  / 2;
 
283
  y += (allocation.height - area->height) / 2;
269
284
 
270
285
  gtk_widget_queue_draw_area (widget, x, y, width, height);
271
286
}