2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-02-05 23:22:20 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2004-08-26 06:31:44 +08:00
|
|
|
* gimpviewrenderer.c
|
2003-03-01 11:53:41 +08:00
|
|
|
* Copyright (C) 2003 Michael Natterer <mitch@gimp.org>
|
2007-11-02 07:37:00 +08:00
|
|
|
* Copyright (C) 2007 Sven Neumann <sven@gimp.org>
|
2001-02-05 23:22:20 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (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
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2001-03-12 01:24:47 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
2001-05-03 20:26:05 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2001-05-22 04:30:16 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2001-02-05 23:22:20 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2001-05-08 11:48:54 +08:00
|
|
|
#include "widgets-types.h"
|
2001-02-05 23:22:20 +08:00
|
|
|
|
2001-05-15 19:25:25 +08:00
|
|
|
#include "base/temp-buf.h"
|
|
|
|
|
2006-08-30 05:44:51 +08:00
|
|
|
#include "core/gimpcontext.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpmarshal.h"
|
2002-03-22 23:47:59 +08:00
|
|
|
#include "core/gimpviewable.h"
|
2001-02-23 11:29:53 +08:00
|
|
|
|
2005-07-20 04:42:14 +08:00
|
|
|
#include "gimprender.h"
|
2004-08-26 06:31:44 +08:00
|
|
|
#include "gimpviewrenderer.h"
|
2004-08-26 22:20:30 +08:00
|
|
|
#include "gimpviewrenderer-utils.h"
|
2003-03-13 21:08:37 +08:00
|
|
|
#include "gimpwidgets-utils.h"
|
2001-05-08 11:48:54 +08:00
|
|
|
|
2001-02-05 23:22:20 +08:00
|
|
|
|
2001-02-07 05:43:59 +08:00
|
|
|
enum
|
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
UPDATE,
|
2001-02-07 05:43:59 +08:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2001-02-05 23:22:20 +08:00
|
|
|
|
2007-12-29 01:54:01 +08:00
|
|
|
static void gimp_view_renderer_dispose (GObject *object);
|
|
|
|
static void gimp_view_renderer_finalize (GObject *object);
|
|
|
|
|
|
|
|
static gboolean gimp_view_renderer_idle_update (GimpViewRenderer *renderer);
|
|
|
|
static void gimp_view_renderer_real_set_context (GimpViewRenderer *renderer,
|
|
|
|
GimpContext *context);
|
|
|
|
static void gimp_view_renderer_real_invalidate (GimpViewRenderer *renderer);
|
|
|
|
static void gimp_view_renderer_real_draw (GimpViewRenderer *renderer,
|
|
|
|
GtkWidget *widget,
|
|
|
|
cairo_t *cr,
|
|
|
|
const GdkRectangle *draw_area);
|
|
|
|
static void gimp_view_renderer_real_render (GimpViewRenderer *renderer,
|
|
|
|
GtkWidget *widget);
|
|
|
|
|
|
|
|
static void gimp_view_renderer_size_changed (GimpViewRenderer *renderer,
|
|
|
|
GimpViewable *viewable);
|
2007-11-05 03:14:32 +08:00
|
|
|
|
2007-11-02 07:37:00 +08:00
|
|
|
static cairo_pattern_t *
|
2007-12-29 01:54:01 +08:00
|
|
|
gimp_view_renderer_create_background (GimpViewRenderer *renderer,
|
|
|
|
GtkWidget *widget);
|
2001-02-05 23:22:20 +08:00
|
|
|
|
2007-12-29 01:54:01 +08:00
|
|
|
static void gimp_view_render_to_surface (TempBuf *temp_buf,
|
|
|
|
gint channel,
|
|
|
|
GimpViewBG inside_bg,
|
|
|
|
GimpViewBG outside_bg,
|
|
|
|
cairo_surface_t *surface,
|
|
|
|
gint dest_width,
|
|
|
|
gint dest_height);
|
2007-11-02 07:37:00 +08:00
|
|
|
|
|
|
|
|
2001-02-05 23:22:20 +08:00
|
|
|
|
2006-05-15 17:46:31 +08:00
|
|
|
G_DEFINE_TYPE (GimpViewRenderer, gimp_view_renderer, G_TYPE_OBJECT)
|
2005-12-20 06:37:49 +08:00
|
|
|
|
|
|
|
#define parent_class gimp_view_renderer_parent_class
|
2001-02-07 05:43:59 +08:00
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
static guint renderer_signals[LAST_SIGNAL] = { 0 };
|
2001-02-05 23:22:20 +08:00
|
|
|
|
2004-03-14 00:54:35 +08:00
|
|
|
static GimpRGB black_color;
|
|
|
|
static GimpRGB white_color;
|
|
|
|
static GimpRGB green_color;
|
|
|
|
static GimpRGB red_color;
|
|
|
|
|
2001-02-05 23:22:20 +08:00
|
|
|
|
|
|
|
static void
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_class_init (GimpViewRendererClass *klass)
|
2001-02-05 23:22:20 +08:00
|
|
|
{
|
2004-07-06 21:18:42 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2001-02-05 23:22:20 +08:00
|
|
|
|
2003-09-29 21:35:59 +08:00
|
|
|
renderer_signals[UPDATE] =
|
2003-03-01 11:53:41 +08:00
|
|
|
g_signal_new ("update",
|
2004-07-06 21:18:42 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
2004-08-26 06:31:44 +08:00
|
|
|
G_STRUCT_OFFSET (GimpViewRendererClass, update),
|
2004-07-06 21:18:42 +08:00
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
object_class->dispose = gimp_view_renderer_dispose;
|
|
|
|
object_class->finalize = gimp_view_renderer_finalize;
|
2001-02-08 02:01:54 +08:00
|
|
|
|
2006-01-17 18:08:50 +08:00
|
|
|
klass->update = NULL;
|
2006-09-01 02:47:13 +08:00
|
|
|
klass->set_context = gimp_view_renderer_real_set_context;
|
|
|
|
klass->invalidate = gimp_view_renderer_real_invalidate;
|
2004-08-26 06:31:44 +08:00
|
|
|
klass->draw = gimp_view_renderer_real_draw;
|
|
|
|
klass->render = gimp_view_renderer_real_render;
|
2004-03-14 00:54:35 +08:00
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
klass->frame = NULL;
|
|
|
|
klass->frame_left = 0;
|
|
|
|
klass->frame_right = 0;
|
|
|
|
klass->frame_top = 0;
|
|
|
|
klass->frame_bottom = 0;
|
|
|
|
|
2004-03-14 00:54:35 +08:00
|
|
|
gimp_rgba_set (&black_color, 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE);
|
|
|
|
gimp_rgba_set (&white_color, 1.0, 1.0, 1.0, GIMP_OPACITY_OPAQUE);
|
|
|
|
gimp_rgba_set (&green_color, 0.0, 0.94, 0.0, GIMP_OPACITY_OPAQUE);
|
|
|
|
gimp_rgba_set (&red_color, 1.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE);
|
2001-02-05 23:22:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_init (GimpViewRenderer *renderer)
|
2001-02-05 23:22:20 +08:00
|
|
|
{
|
2006-08-30 05:44:51 +08:00
|
|
|
renderer->context = NULL;
|
2002-11-10 04:01:19 +08:00
|
|
|
|
2006-08-30 05:44:51 +08:00
|
|
|
renderer->viewable_type = G_TYPE_NONE;
|
|
|
|
renderer->viewable = NULL;
|
2001-02-08 12:16:41 +08:00
|
|
|
|
2007-06-12 04:01:54 +08:00
|
|
|
renderer->width = 0;
|
|
|
|
renderer->height = 0;
|
2006-08-30 05:44:51 +08:00
|
|
|
renderer->border_width = 0;
|
|
|
|
renderer->dot_for_dot = TRUE;
|
|
|
|
renderer->is_popup = FALSE;
|
2002-03-22 23:21:18 +08:00
|
|
|
|
2006-08-30 05:44:51 +08:00
|
|
|
renderer->border_type = GIMP_VIEW_BORDER_BLACK;
|
|
|
|
renderer->border_color = black_color;
|
2007-11-02 07:37:00 +08:00
|
|
|
|
2007-11-05 03:14:32 +08:00
|
|
|
renderer->surface = NULL;
|
2007-11-02 07:37:00 +08:00
|
|
|
renderer->pattern = NULL;
|
2006-08-30 05:44:51 +08:00
|
|
|
renderer->pixbuf = NULL;
|
|
|
|
renderer->bg_stock_id = NULL;
|
|
|
|
|
|
|
|
renderer->size = -1;
|
|
|
|
renderer->needs_render = TRUE;
|
|
|
|
renderer->idle_id = 0;
|
2001-02-05 23:22:20 +08:00
|
|
|
}
|
|
|
|
|
2002-02-01 00:47:20 +08:00
|
|
|
static void
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_dispose (GObject *object)
|
2002-02-01 00:47:20 +08:00
|
|
|
{
|
2004-08-26 06:31:44 +08:00
|
|
|
GimpViewRenderer *renderer = GIMP_VIEW_RENDERER (object);
|
2003-02-27 21:59:41 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
if (renderer->viewable)
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_set_viewable (renderer, NULL);
|
2002-02-01 00:47:20 +08:00
|
|
|
|
2006-09-01 02:47:13 +08:00
|
|
|
if (renderer->context)
|
|
|
|
gimp_view_renderer_set_context (renderer, NULL);
|
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_remove_idle (renderer);
|
2004-07-06 21:18:42 +08:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_finalize (GObject *object)
|
2004-07-06 21:18:42 +08:00
|
|
|
{
|
2004-08-26 06:31:44 +08:00
|
|
|
GimpViewRenderer *renderer = GIMP_VIEW_RENDERER (object);
|
2004-07-06 21:18:42 +08:00
|
|
|
|
2007-11-05 03:14:32 +08:00
|
|
|
if (renderer->pattern)
|
|
|
|
{
|
|
|
|
cairo_pattern_destroy (renderer->pattern);
|
|
|
|
renderer->pattern = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (renderer->surface)
|
2003-02-27 00:17:10 +08:00
|
|
|
{
|
2007-11-05 03:14:32 +08:00
|
|
|
cairo_surface_destroy (renderer->surface);
|
|
|
|
renderer->surface = NULL;
|
2003-02-27 00:17:10 +08:00
|
|
|
}
|
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
if (renderer->pixbuf)
|
2002-02-01 00:47:20 +08:00
|
|
|
{
|
2004-09-27 07:44:24 +08:00
|
|
|
g_object_unref (renderer->pixbuf);
|
|
|
|
renderer->pixbuf = NULL;
|
2002-02-01 00:47:20 +08:00
|
|
|
}
|
|
|
|
|
2003-04-11 19:18:12 +08:00
|
|
|
if (renderer->bg_stock_id)
|
|
|
|
{
|
|
|
|
g_free (renderer->bg_stock_id);
|
|
|
|
renderer->bg_stock_id = NULL;
|
|
|
|
}
|
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2002-02-01 00:47:20 +08:00
|
|
|
}
|
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
static GimpViewRenderer *
|
2006-08-30 05:44:51 +08:00
|
|
|
gimp_view_renderer_new_internal (GimpContext *context,
|
|
|
|
GType viewable_type,
|
|
|
|
gboolean is_popup)
|
2003-11-17 21:34:38 +08:00
|
|
|
{
|
2004-08-26 06:31:44 +08:00
|
|
|
GimpViewRenderer *renderer;
|
2003-11-17 21:34:38 +08:00
|
|
|
|
2004-08-26 22:20:30 +08:00
|
|
|
renderer = g_object_new (gimp_view_renderer_type_from_viewable_type (viewable_type),
|
2003-11-17 21:34:38 +08:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
renderer->viewable_type = viewable_type;
|
|
|
|
renderer->is_popup = is_popup ? TRUE : FALSE;
|
|
|
|
|
2006-09-01 02:47:13 +08:00
|
|
|
if (context)
|
|
|
|
gimp_view_renderer_set_context (renderer, context);
|
|
|
|
|
2003-11-17 21:34:38 +08:00
|
|
|
return renderer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-01 00:47:20 +08:00
|
|
|
/* public functions */
|
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
GimpViewRenderer *
|
2006-08-30 05:44:51 +08:00
|
|
|
gimp_view_renderer_new (GimpContext *context,
|
|
|
|
GType viewable_type,
|
|
|
|
gint size,
|
|
|
|
gint border_width,
|
2007-11-02 07:37:00 +08:00
|
|
|
gboolean is_popup)
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
2004-08-26 06:31:44 +08:00
|
|
|
GimpViewRenderer *renderer;
|
2001-02-20 06:54:12 +08:00
|
|
|
|
2006-08-30 05:44:51 +08:00
|
|
|
g_return_val_if_fail (context == NULL || GIMP_IS_CONTEXT (context), NULL);
|
2003-03-03 20:59:03 +08:00
|
|
|
g_return_val_if_fail (g_type_is_a (viewable_type, GIMP_TYPE_VIEWABLE), NULL);
|
2003-04-01 21:53:47 +08:00
|
|
|
g_return_val_if_fail (size > 0 &&
|
|
|
|
size <= GIMP_VIEWABLE_MAX_PREVIEW_SIZE, NULL);
|
2002-08-27 23:31:24 +08:00
|
|
|
g_return_val_if_fail (border_width >= 0 &&
|
2004-08-26 06:31:44 +08:00
|
|
|
border_width <= GIMP_VIEW_MAX_BORDER_WIDTH, NULL);
|
2001-02-13 08:12:15 +08:00
|
|
|
|
2006-08-30 05:44:51 +08:00
|
|
|
renderer = gimp_view_renderer_new_internal (context, viewable_type,
|
|
|
|
is_popup);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_set_size (renderer, size, border_width);
|
|
|
|
gimp_view_renderer_remove_idle (renderer);
|
2001-02-13 08:12:15 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
return renderer;
|
2001-02-09 23:12:01 +08:00
|
|
|
}
|
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
GimpViewRenderer *
|
2006-08-30 05:44:51 +08:00
|
|
|
gimp_view_renderer_new_full (GimpContext *context,
|
|
|
|
GType viewable_type,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gint border_width,
|
|
|
|
gboolean is_popup)
|
2001-02-05 23:22:20 +08:00
|
|
|
{
|
2004-08-26 06:31:44 +08:00
|
|
|
GimpViewRenderer *renderer;
|
2001-02-05 23:22:20 +08:00
|
|
|
|
2006-08-30 05:44:51 +08:00
|
|
|
g_return_val_if_fail (context == NULL || GIMP_IS_CONTEXT (context), NULL);
|
2003-03-03 20:59:03 +08:00
|
|
|
g_return_val_if_fail (g_type_is_a (viewable_type, GIMP_TYPE_VIEWABLE), NULL);
|
2003-04-01 21:53:47 +08:00
|
|
|
g_return_val_if_fail (width > 0 &&
|
|
|
|
width <= GIMP_VIEWABLE_MAX_PREVIEW_SIZE, NULL);
|
|
|
|
g_return_val_if_fail (height > 0 &&
|
|
|
|
height <= GIMP_VIEWABLE_MAX_PREVIEW_SIZE, NULL);
|
2002-08-27 23:31:24 +08:00
|
|
|
g_return_val_if_fail (border_width >= 0 &&
|
2004-08-26 06:31:44 +08:00
|
|
|
border_width <= GIMP_VIEW_MAX_BORDER_WIDTH, NULL);
|
2001-02-05 23:22:20 +08:00
|
|
|
|
2006-08-30 05:44:51 +08:00
|
|
|
renderer = gimp_view_renderer_new_internal (context, viewable_type,
|
|
|
|
is_popup);
|
2001-02-05 23:22:20 +08:00
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_set_size_full (renderer, width, height, border_width);
|
|
|
|
gimp_view_renderer_remove_idle (renderer);
|
2002-08-22 20:49:01 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
return renderer;
|
2002-08-22 20:49:01 +08:00
|
|
|
}
|
|
|
|
|
2006-08-30 05:44:51 +08:00
|
|
|
void
|
|
|
|
gimp_view_renderer_set_context (GimpViewRenderer *renderer,
|
|
|
|
GimpContext *context)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_VIEW_RENDERER (renderer));
|
|
|
|
g_return_if_fail (context == NULL || GIMP_IS_CONTEXT (context));
|
|
|
|
|
|
|
|
if (context != renderer->context)
|
|
|
|
{
|
2006-09-01 02:47:13 +08:00
|
|
|
GIMP_VIEW_RENDERER_GET_CLASS (renderer)->set_context (renderer,
|
|
|
|
context);
|
2006-08-30 05:44:51 +08:00
|
|
|
|
|
|
|
if (renderer->viewable)
|
|
|
|
gimp_view_renderer_invalidate (renderer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-08 12:16:41 +08:00
|
|
|
void
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_set_viewable (GimpViewRenderer *renderer,
|
|
|
|
GimpViewable *viewable)
|
2001-02-08 12:16:41 +08:00
|
|
|
{
|
2004-08-26 06:31:44 +08:00
|
|
|
g_return_if_fail (GIMP_IS_VIEW_RENDERER (renderer));
|
2006-01-17 18:08:50 +08:00
|
|
|
g_return_if_fail (viewable == NULL || GIMP_IS_VIEWABLE (viewable));
|
2002-08-22 20:49:01 +08:00
|
|
|
|
|
|
|
if (viewable)
|
2003-11-17 21:34:38 +08:00
|
|
|
g_return_if_fail (g_type_is_a (G_TYPE_FROM_INSTANCE (viewable),
|
|
|
|
renderer->viewable_type));
|
2001-02-08 12:16:41 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
if (viewable == renderer->viewable)
|
2002-05-10 20:47:42 +08:00
|
|
|
return;
|
|
|
|
|
2007-11-05 03:14:32 +08:00
|
|
|
if (renderer->surface)
|
2002-05-10 20:47:42 +08:00
|
|
|
{
|
2007-11-05 03:14:32 +08:00
|
|
|
cairo_surface_destroy (renderer->surface);
|
|
|
|
renderer->surface = NULL;
|
2002-05-10 20:47:42 +08:00
|
|
|
}
|
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
if (renderer->pixbuf)
|
2001-02-08 12:16:41 +08:00
|
|
|
{
|
2004-09-27 07:44:24 +08:00
|
|
|
g_object_unref (renderer->pixbuf);
|
|
|
|
renderer->pixbuf = NULL;
|
2003-03-01 11:53:41 +08:00
|
|
|
}
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
if (renderer->viewable)
|
|
|
|
{
|
|
|
|
g_object_remove_weak_pointer (G_OBJECT (renderer->viewable),
|
2006-06-20 01:50:40 +08:00
|
|
|
(gpointer) &renderer->viewable);
|
2001-02-08 12:16:41 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
g_signal_handlers_disconnect_by_func (renderer->viewable,
|
2004-08-26 06:31:44 +08:00
|
|
|
G_CALLBACK (gimp_view_renderer_invalidate),
|
2003-03-01 11:53:41 +08:00
|
|
|
renderer);
|
2003-02-20 20:47:42 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
g_signal_handlers_disconnect_by_func (renderer->viewable,
|
2004-08-26 06:31:44 +08:00
|
|
|
G_CALLBACK (gimp_view_renderer_size_changed),
|
2003-03-01 11:53:41 +08:00
|
|
|
renderer);
|
2002-03-22 23:47:59 +08:00
|
|
|
}
|
2001-02-08 12:16:41 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
renderer->viewable = viewable;
|
2001-02-08 12:16:41 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
if (renderer->viewable)
|
2001-02-08 12:16:41 +08:00
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
g_object_add_weak_pointer (G_OBJECT (renderer->viewable),
|
2006-06-20 01:50:40 +08:00
|
|
|
(gpointer) &renderer->viewable);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
g_signal_connect_swapped (renderer->viewable,
|
2005-05-27 21:05:26 +08:00
|
|
|
"invalidate-preview",
|
2004-08-26 06:31:44 +08:00
|
|
|
G_CALLBACK (gimp_view_renderer_invalidate),
|
2003-03-01 11:53:41 +08:00
|
|
|
renderer);
|
2001-02-08 12:16:41 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
g_signal_connect_swapped (renderer->viewable,
|
2005-05-27 21:05:26 +08:00
|
|
|
"size-changed",
|
2004-08-26 06:31:44 +08:00
|
|
|
G_CALLBACK (gimp_view_renderer_size_changed),
|
2003-03-01 11:53:41 +08:00
|
|
|
renderer);
|
2001-02-08 12:16:41 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
if (renderer->size != -1)
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_set_size (renderer, renderer->size,
|
|
|
|
renderer->border_width);
|
2003-03-22 01:22:04 +08:00
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_invalidate (renderer);
|
2001-02-08 12:16:41 +08:00
|
|
|
}
|
2004-07-06 21:18:42 +08:00
|
|
|
else
|
|
|
|
{
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_update_idle (renderer);
|
2004-07-06 21:18:42 +08:00
|
|
|
}
|
2001-02-08 12:16:41 +08:00
|
|
|
}
|
|
|
|
|
2001-03-12 01:24:47 +08:00
|
|
|
void
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_set_size (GimpViewRenderer *renderer,
|
2006-01-17 18:08:50 +08:00
|
|
|
gint view_size,
|
2004-08-26 06:31:44 +08:00
|
|
|
gint border_width)
|
2001-03-12 01:24:47 +08:00
|
|
|
{
|
2007-11-05 03:14:32 +08:00
|
|
|
gint width;
|
|
|
|
gint height;
|
2001-03-12 01:24:47 +08:00
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
g_return_if_fail (GIMP_IS_VIEW_RENDERER (renderer));
|
2006-01-17 18:08:50 +08:00
|
|
|
g_return_if_fail (view_size > 0 &&
|
|
|
|
view_size <= GIMP_VIEWABLE_MAX_PREVIEW_SIZE);
|
2002-08-27 23:31:24 +08:00
|
|
|
g_return_if_fail (border_width >= 0 &&
|
2004-08-26 06:31:44 +08:00
|
|
|
border_width <= GIMP_VIEW_MAX_BORDER_WIDTH);
|
2001-03-12 01:24:47 +08:00
|
|
|
|
2006-01-17 18:08:50 +08:00
|
|
|
renderer->size = view_size;
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
if (renderer->viewable)
|
2003-02-22 03:03:19 +08:00
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
gimp_viewable_get_preview_size (renderer->viewable,
|
2006-01-17 18:08:50 +08:00
|
|
|
view_size,
|
2003-03-01 11:53:41 +08:00
|
|
|
renderer->is_popup,
|
|
|
|
renderer->dot_for_dot,
|
2003-02-22 03:03:19 +08:00
|
|
|
&width, &height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-01-17 18:08:50 +08:00
|
|
|
width = view_size;
|
|
|
|
height = view_size;
|
2003-02-22 03:03:19 +08:00
|
|
|
}
|
2001-03-12 01:24:47 +08:00
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_set_size_full (renderer, width, height, border_width);
|
2001-03-12 01:24:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_set_size_full (GimpViewRenderer *renderer,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gint border_width)
|
2001-03-12 01:24:47 +08:00
|
|
|
{
|
2004-08-26 06:31:44 +08:00
|
|
|
g_return_if_fail (GIMP_IS_VIEW_RENDERER (renderer));
|
2003-04-01 21:53:47 +08:00
|
|
|
g_return_if_fail (width > 0 &&
|
|
|
|
width <= GIMP_VIEWABLE_MAX_PREVIEW_SIZE);
|
|
|
|
g_return_if_fail (height > 0 &&
|
|
|
|
height <= GIMP_VIEWABLE_MAX_PREVIEW_SIZE);
|
2002-08-27 23:31:24 +08:00
|
|
|
g_return_if_fail (border_width >= 0 &&
|
2004-08-26 06:31:44 +08:00
|
|
|
border_width <= GIMP_VIEW_MAX_BORDER_WIDTH);
|
2001-03-12 01:24:47 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
if (width != renderer->width ||
|
|
|
|
height != renderer->height ||
|
|
|
|
border_width != renderer->border_width)
|
2002-01-31 01:39:56 +08:00
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
renderer->width = width;
|
|
|
|
renderer->height = height;
|
|
|
|
renderer->border_width = border_width;
|
2002-01-31 01:39:56 +08:00
|
|
|
|
2007-11-05 03:14:32 +08:00
|
|
|
if (renderer->surface)
|
2002-01-31 01:39:56 +08:00
|
|
|
{
|
2007-11-05 03:14:32 +08:00
|
|
|
cairo_surface_destroy (renderer->surface);
|
|
|
|
renderer->surface = NULL;
|
2002-01-31 01:39:56 +08:00
|
|
|
}
|
|
|
|
|
2003-03-03 20:59:03 +08:00
|
|
|
if (renderer->viewable)
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_invalidate (renderer);
|
2002-01-31 01:39:56 +08:00
|
|
|
}
|
2001-06-18 21:10:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_set_dot_for_dot (GimpViewRenderer *renderer,
|
|
|
|
gboolean dot_for_dot)
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
2004-08-26 06:31:44 +08:00
|
|
|
g_return_if_fail (GIMP_IS_VIEW_RENDERER (renderer));
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
if (dot_for_dot != renderer->dot_for_dot)
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
renderer->dot_for_dot = dot_for_dot ? TRUE: FALSE;
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
if (renderer->size != -1)
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_set_size (renderer, renderer->size,
|
|
|
|
renderer->border_width);
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_invalidate (renderer);
|
2001-06-18 21:10:03 +08:00
|
|
|
}
|
2001-03-12 01:24:47 +08:00
|
|
|
}
|
|
|
|
|
2004-03-14 00:54:35 +08:00
|
|
|
void
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_set_border_type (GimpViewRenderer *renderer,
|
|
|
|
GimpViewBorderType border_type)
|
2004-03-14 00:54:35 +08:00
|
|
|
{
|
|
|
|
GimpRGB *border_color = &black_color;
|
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
g_return_if_fail (GIMP_IS_VIEW_RENDERER (renderer));
|
2004-03-14 00:54:35 +08:00
|
|
|
|
|
|
|
renderer->border_type = border_type;
|
|
|
|
|
|
|
|
switch (border_type)
|
|
|
|
{
|
2006-01-17 18:08:50 +08:00
|
|
|
case GIMP_VIEW_BORDER_BLACK:
|
|
|
|
border_color = &black_color;
|
|
|
|
break;
|
|
|
|
case GIMP_VIEW_BORDER_WHITE:
|
|
|
|
border_color = &white_color;
|
|
|
|
break;
|
|
|
|
case GIMP_VIEW_BORDER_GREEN:
|
|
|
|
border_color = &green_color;
|
|
|
|
break;
|
|
|
|
case GIMP_VIEW_BORDER_RED:
|
|
|
|
border_color = &red_color;
|
|
|
|
break;
|
2004-03-14 00:54:35 +08:00
|
|
|
}
|
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_set_border_color (renderer, border_color);
|
2004-03-14 00:54:35 +08:00
|
|
|
}
|
|
|
|
|
2001-03-12 01:24:47 +08:00
|
|
|
void
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_set_border_color (GimpViewRenderer *renderer,
|
|
|
|
const GimpRGB *color)
|
2001-03-12 01:24:47 +08:00
|
|
|
{
|
2004-08-26 06:31:44 +08:00
|
|
|
g_return_if_fail (GIMP_IS_VIEW_RENDERER (renderer));
|
2001-03-12 01:24:47 +08:00
|
|
|
g_return_if_fail (color != NULL);
|
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
if (gimp_rgb_distance (&renderer->border_color, color))
|
2001-03-12 01:24:47 +08:00
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
renderer->border_color = *color;
|
2001-03-12 01:24:47 +08:00
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_update_idle (renderer);
|
2001-03-12 01:24:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-11 19:18:12 +08:00
|
|
|
void
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_set_background (GimpViewRenderer *renderer,
|
|
|
|
const gchar *stock_id)
|
2003-04-11 19:18:12 +08:00
|
|
|
{
|
2004-08-26 06:31:44 +08:00
|
|
|
g_return_if_fail (GIMP_IS_VIEW_RENDERER (renderer));
|
2003-04-11 19:18:12 +08:00
|
|
|
|
|
|
|
if (renderer->bg_stock_id)
|
|
|
|
g_free (renderer->bg_stock_id);
|
|
|
|
|
|
|
|
renderer->bg_stock_id = g_strdup (stock_id);
|
|
|
|
|
2007-11-02 07:37:00 +08:00
|
|
|
if (renderer->pattern)
|
2003-04-11 19:18:12 +08:00
|
|
|
{
|
2007-11-02 07:37:00 +08:00
|
|
|
g_object_unref (renderer->pattern);
|
|
|
|
renderer->pattern = NULL;
|
2003-11-13 23:04:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-24 10:42:09 +08:00
|
|
|
void
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_invalidate (GimpViewRenderer *renderer)
|
2001-02-24 10:42:09 +08:00
|
|
|
{
|
2004-08-26 06:31:44 +08:00
|
|
|
g_return_if_fail (GIMP_IS_VIEW_RENDERER (renderer));
|
2001-08-07 20:42:23 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
if (renderer->idle_id)
|
2006-09-01 02:47:13 +08:00
|
|
|
{
|
|
|
|
g_source_remove (renderer->idle_id);
|
|
|
|
renderer->idle_id = 0;
|
|
|
|
}
|
2002-11-10 04:01:19 +08:00
|
|
|
|
2006-09-01 02:47:13 +08:00
|
|
|
GIMP_VIEW_RENDERER_GET_CLASS (renderer)->invalidate (renderer);
|
2003-03-03 20:59:03 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
renderer->idle_id =
|
2007-06-08 07:05:02 +08:00
|
|
|
g_idle_add_full (GIMP_VIEWABLE_PRIORITY_IDLE,
|
2004-08-26 06:31:44 +08:00
|
|
|
(GSourceFunc) gimp_view_renderer_idle_update,
|
2003-03-03 20:59:03 +08:00
|
|
|
renderer, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_update (GimpViewRenderer *renderer)
|
2003-03-03 20:59:03 +08:00
|
|
|
{
|
2004-08-26 06:31:44 +08:00
|
|
|
g_return_if_fail (GIMP_IS_VIEW_RENDERER (renderer));
|
2003-03-03 20:59:03 +08:00
|
|
|
|
|
|
|
if (renderer->idle_id)
|
|
|
|
{
|
|
|
|
g_source_remove (renderer->idle_id);
|
|
|
|
renderer->idle_id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_signal_emit (renderer, renderer_signals[UPDATE], 0);
|
|
|
|
}
|
|
|
|
|
2003-03-16 19:14:29 +08:00
|
|
|
void
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_update_idle (GimpViewRenderer *renderer)
|
2003-03-16 19:14:29 +08:00
|
|
|
{
|
2004-08-26 06:31:44 +08:00
|
|
|
g_return_if_fail (GIMP_IS_VIEW_RENDERER (renderer));
|
2003-03-16 19:14:29 +08:00
|
|
|
|
|
|
|
if (renderer->idle_id)
|
|
|
|
g_source_remove (renderer->idle_id);
|
|
|
|
|
|
|
|
renderer->idle_id =
|
2007-06-08 07:05:02 +08:00
|
|
|
g_idle_add_full (GIMP_VIEWABLE_PRIORITY_IDLE,
|
2004-08-26 06:31:44 +08:00
|
|
|
(GSourceFunc) gimp_view_renderer_idle_update,
|
2003-03-16 19:14:29 +08:00
|
|
|
renderer, NULL);
|
|
|
|
}
|
|
|
|
|
2003-03-03 20:59:03 +08:00
|
|
|
void
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_remove_idle (GimpViewRenderer *renderer)
|
2003-03-03 20:59:03 +08:00
|
|
|
{
|
2004-08-26 06:31:44 +08:00
|
|
|
g_return_if_fail (GIMP_IS_VIEW_RENDERER (renderer));
|
2003-03-03 20:59:03 +08:00
|
|
|
|
|
|
|
if (renderer->idle_id)
|
|
|
|
{
|
|
|
|
g_source_remove (renderer->idle_id);
|
|
|
|
renderer->idle_id = 0;
|
|
|
|
}
|
2001-02-24 10:42:09 +08:00
|
|
|
}
|
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
void
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_draw (GimpViewRenderer *renderer,
|
|
|
|
GdkWindow *window,
|
|
|
|
GtkWidget *widget,
|
|
|
|
const GdkRectangle *draw_area,
|
|
|
|
const GdkRectangle *expose_area)
|
2003-03-01 11:53:41 +08:00
|
|
|
{
|
2007-11-05 03:14:32 +08:00
|
|
|
cairo_t *cr;
|
|
|
|
GdkRectangle render_rect;
|
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
g_return_if_fail (GIMP_IS_VIEW_RENDERER (renderer));
|
2003-03-01 11:53:41 +08:00
|
|
|
g_return_if_fail (GDK_IS_WINDOW (window));
|
|
|
|
g_return_if_fail (GTK_IS_WIDGET (widget));
|
|
|
|
g_return_if_fail (draw_area != NULL);
|
|
|
|
g_return_if_fail (expose_area != NULL);
|
2002-01-31 00:14:26 +08:00
|
|
|
|
2007-11-05 03:14:32 +08:00
|
|
|
if (G_UNLIKELY (renderer->context == NULL))
|
|
|
|
g_warning ("%s: renderer->context is NULL", G_STRFUNC);
|
|
|
|
|
2003-11-17 21:34:38 +08:00
|
|
|
if (! GTK_WIDGET_DRAWABLE (widget))
|
2003-03-01 11:53:41 +08:00
|
|
|
return;
|
2001-02-07 05:43:59 +08:00
|
|
|
|
2007-11-05 03:14:32 +08:00
|
|
|
if (! gdk_rectangle_intersect ((GdkRectangle *) draw_area,
|
|
|
|
(GdkRectangle *) expose_area,
|
|
|
|
&render_rect))
|
|
|
|
return;
|
|
|
|
|
|
|
|
cr = gdk_cairo_create (window);
|
|
|
|
|
|
|
|
gdk_cairo_rectangle (cr, &render_rect);
|
|
|
|
cairo_clip (cr);
|
2007-11-02 04:24:02 +08:00
|
|
|
|
2003-11-17 21:34:38 +08:00
|
|
|
if (renderer->viewable)
|
|
|
|
{
|
2007-11-14 00:00:13 +08:00
|
|
|
cairo_save (cr);
|
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
GIMP_VIEW_RENDERER_GET_CLASS (renderer)->draw (renderer,
|
2007-11-05 03:14:32 +08:00
|
|
|
widget, cr, draw_area);
|
2007-11-14 00:00:13 +08:00
|
|
|
|
|
|
|
cairo_restore (cr);
|
2003-11-17 21:34:38 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GimpViewableClass *viewable_class;
|
|
|
|
|
|
|
|
viewable_class = g_type_class_ref (renderer->viewable_type);
|
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_default_render_stock (renderer,
|
|
|
|
widget,
|
|
|
|
viewable_class->default_stock_id);
|
2003-11-17 21:34:38 +08:00
|
|
|
|
|
|
|
g_type_class_unref (viewable_class);
|
|
|
|
|
2007-11-05 03:14:32 +08:00
|
|
|
gimp_view_renderer_real_draw (renderer, widget, cr, draw_area);
|
2003-11-17 21:34:38 +08:00
|
|
|
}
|
2002-11-10 04:01:19 +08:00
|
|
|
|
2003-09-29 21:35:59 +08:00
|
|
|
if (renderer->border_width > 0)
|
|
|
|
{
|
2007-11-05 03:14:32 +08:00
|
|
|
gint width = renderer->width + renderer->border_width;
|
|
|
|
gint height = renderer->height + renderer->border_width;
|
|
|
|
gdouble x, y;
|
2003-09-30 20:06:58 +08:00
|
|
|
|
2007-11-02 07:37:00 +08:00
|
|
|
cairo_set_line_width (cr, renderer->border_width);
|
|
|
|
cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
|
2007-12-13 00:14:49 +08:00
|
|
|
gimp_cairo_set_source_rgb (cr, &renderer->border_color);
|
2003-09-29 21:35:59 +08:00
|
|
|
|
2007-11-05 03:14:32 +08:00
|
|
|
x = draw_area->x + (draw_area->width - width) / 2.0;
|
|
|
|
y = draw_area->y + (draw_area->height - height) / 2.0;
|
2007-11-02 07:37:00 +08:00
|
|
|
|
2007-11-05 03:14:32 +08:00
|
|
|
cairo_rectangle (cr, x, y, width, height);
|
|
|
|
cairo_stroke (cr);
|
2003-09-29 21:35:59 +08:00
|
|
|
}
|
2007-11-05 03:14:32 +08:00
|
|
|
|
|
|
|
cairo_destroy (cr);
|
2003-09-29 21:35:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static gboolean
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_idle_update (GimpViewRenderer *renderer)
|
2003-09-29 21:35:59 +08:00
|
|
|
{
|
|
|
|
renderer->idle_id = 0;
|
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_update (renderer);
|
2003-09-29 21:35:59 +08:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-09-01 02:47:13 +08:00
|
|
|
static void
|
|
|
|
gimp_view_renderer_real_set_context (GimpViewRenderer *renderer,
|
|
|
|
GimpContext *context)
|
|
|
|
{
|
2006-09-01 16:59:24 +08:00
|
|
|
if (renderer->context)
|
|
|
|
g_object_unref (renderer->context);
|
|
|
|
|
2006-09-01 02:47:13 +08:00
|
|
|
renderer->context = context;
|
2006-09-01 16:59:24 +08:00
|
|
|
|
|
|
|
if (renderer->context)
|
|
|
|
g_object_ref (renderer->context);
|
2006-09-01 02:47:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_view_renderer_real_invalidate (GimpViewRenderer *renderer)
|
|
|
|
{
|
|
|
|
renderer->needs_render = TRUE;
|
|
|
|
}
|
|
|
|
|
2003-09-29 21:35:59 +08:00
|
|
|
static void
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_real_draw (GimpViewRenderer *renderer,
|
|
|
|
GtkWidget *widget,
|
2007-11-05 03:14:32 +08:00
|
|
|
cairo_t *cr,
|
2007-11-05 04:30:38 +08:00
|
|
|
const GdkRectangle *area)
|
2003-09-29 21:35:59 +08:00
|
|
|
{
|
|
|
|
if (renderer->needs_render)
|
2004-08-26 06:31:44 +08:00
|
|
|
GIMP_VIEW_RENDERER_GET_CLASS (renderer)->render (renderer, widget);
|
2003-09-29 21:35:59 +08:00
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
if (renderer->pixbuf)
|
2003-02-27 21:59:41 +08:00
|
|
|
{
|
2007-11-05 03:14:32 +08:00
|
|
|
gint width = gdk_pixbuf_get_width (renderer->pixbuf);
|
|
|
|
gint height = gdk_pixbuf_get_height (renderer->pixbuf);
|
|
|
|
gint x, y;
|
2007-11-02 07:37:00 +08:00
|
|
|
|
2007-11-05 03:14:32 +08:00
|
|
|
if (renderer->bg_stock_id)
|
|
|
|
{
|
|
|
|
if (! renderer->pattern)
|
2007-12-29 01:54:01 +08:00
|
|
|
renderer->pattern = gimp_view_renderer_create_background (renderer,
|
|
|
|
widget);
|
2003-04-11 19:18:12 +08:00
|
|
|
|
2007-11-05 03:14:32 +08:00
|
|
|
cairo_set_source (cr, renderer->pattern);
|
|
|
|
cairo_paint (cr);
|
|
|
|
}
|
2003-03-01 11:53:41 +08:00
|
|
|
|
2007-11-05 04:30:38 +08:00
|
|
|
x = area->x + (area->width - width) / 2;
|
|
|
|
y = area->y + (area->height - height) / 2;
|
2007-11-02 07:37:00 +08:00
|
|
|
|
2007-11-05 03:14:32 +08:00
|
|
|
gdk_cairo_set_source_pixbuf (cr, renderer->pixbuf, x, y);
|
|
|
|
cairo_rectangle (cr, x, y, width, height);
|
|
|
|
cairo_fill (cr);
|
2003-02-27 21:59:41 +08:00
|
|
|
}
|
2007-11-05 03:14:32 +08:00
|
|
|
else if (renderer->surface)
|
2003-03-01 11:53:41 +08:00
|
|
|
{
|
2007-12-29 01:17:10 +08:00
|
|
|
cairo_content_t content = cairo_surface_get_content (renderer->surface);
|
|
|
|
gint width = renderer->width;
|
|
|
|
gint height = renderer->height;
|
2007-11-02 07:37:00 +08:00
|
|
|
|
2007-12-29 01:17:10 +08:00
|
|
|
cairo_translate (cr,
|
|
|
|
area->x + (area->width - width) / 2,
|
|
|
|
area->y + (area->height - height) / 2);
|
2002-11-10 04:01:19 +08:00
|
|
|
|
2007-12-29 01:17:10 +08:00
|
|
|
cairo_rectangle (cr, 0, 0, width, height);
|
|
|
|
|
|
|
|
if (content == CAIRO_CONTENT_COLOR_ALPHA)
|
|
|
|
{
|
2007-12-29 01:54:01 +08:00
|
|
|
if (! renderer->pattern)
|
2007-12-29 02:44:32 +08:00
|
|
|
{
|
|
|
|
renderer->pattern =
|
2007-12-29 03:14:36 +08:00
|
|
|
gimp_cairo_checkerboard_create (cr, GIMP_CHECK_SIZE_SM,
|
|
|
|
gimp_render_light_check_color (),
|
|
|
|
gimp_render_dark_check_color ());
|
2007-12-29 02:44:32 +08:00
|
|
|
}
|
2007-12-29 01:17:10 +08:00
|
|
|
|
2007-12-29 01:54:01 +08:00
|
|
|
cairo_set_source (cr, renderer->pattern);
|
2007-12-29 01:17:10 +08:00
|
|
|
cairo_fill_preserve (cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_set_source_surface (cr, renderer->surface, 0, 0);
|
2007-11-05 03:14:32 +08:00
|
|
|
cairo_fill (cr);
|
2003-03-01 11:53:41 +08:00
|
|
|
}
|
2002-11-04 20:15:29 +08:00
|
|
|
}
|
|
|
|
|
2001-02-08 04:35:18 +08:00
|
|
|
static void
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_real_render (GimpViewRenderer *renderer,
|
|
|
|
GtkWidget *widget)
|
2001-02-07 08:06:58 +08:00
|
|
|
{
|
2004-09-27 07:44:24 +08:00
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
TempBuf *temp_buf;
|
|
|
|
const gchar *stock_id;
|
|
|
|
|
|
|
|
pixbuf = gimp_viewable_get_pixbuf (renderer->viewable,
|
2006-08-30 05:44:51 +08:00
|
|
|
renderer->context,
|
2004-09-27 07:44:24 +08:00
|
|
|
renderer->width,
|
|
|
|
renderer->height);
|
|
|
|
if (pixbuf)
|
|
|
|
{
|
|
|
|
gimp_view_renderer_render_pixbuf (renderer, pixbuf);
|
|
|
|
return;
|
|
|
|
}
|
2001-02-08 04:35:18 +08:00
|
|
|
|
2003-03-04 01:19:30 +08:00
|
|
|
temp_buf = gimp_viewable_get_preview (renderer->viewable,
|
2006-08-30 05:44:51 +08:00
|
|
|
renderer->context,
|
2004-07-06 21:18:42 +08:00
|
|
|
renderer->width,
|
|
|
|
renderer->height);
|
2003-03-04 01:19:30 +08:00
|
|
|
if (temp_buf)
|
|
|
|
{
|
2007-11-05 03:14:32 +08:00
|
|
|
gimp_view_renderer_default_render_surface (renderer, widget, temp_buf);
|
2004-09-27 07:44:24 +08:00
|
|
|
return;
|
2003-03-04 01:19:30 +08:00
|
|
|
}
|
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
stock_id = gimp_viewable_get_stock_id (renderer->viewable);
|
|
|
|
gimp_view_renderer_default_render_stock (renderer, widget, stock_id);
|
2003-03-04 01:19:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_size_changed (GimpViewRenderer *renderer,
|
|
|
|
GimpViewable *viewable)
|
2003-03-04 01:19:30 +08:00
|
|
|
{
|
|
|
|
if (renderer->size != -1)
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_set_size (renderer, renderer->size,
|
|
|
|
renderer->border_width);
|
2003-03-22 01:22:04 +08:00
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_invalidate (renderer);
|
2003-03-04 01:19:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* protected functions */
|
|
|
|
|
|
|
|
void
|
2007-11-05 03:14:32 +08:00
|
|
|
gimp_view_renderer_default_render_surface (GimpViewRenderer *renderer,
|
|
|
|
GtkWidget *widget,
|
|
|
|
TempBuf *temp_buf)
|
2003-03-04 01:19:30 +08:00
|
|
|
{
|
2004-08-26 06:31:44 +08:00
|
|
|
g_return_if_fail (GIMP_IS_VIEW_RENDERER (renderer));
|
2003-03-04 01:19:30 +08:00
|
|
|
g_return_if_fail (GTK_IS_WIDGET (widget));
|
|
|
|
g_return_if_fail (temp_buf != NULL);
|
|
|
|
|
|
|
|
if (temp_buf->width < renderer->width)
|
|
|
|
temp_buf->x = (renderer->width - temp_buf->width) / 2;
|
2001-02-08 04:35:18 +08:00
|
|
|
|
2003-03-04 01:19:30 +08:00
|
|
|
if (temp_buf->height < renderer->height)
|
|
|
|
temp_buf->y = (renderer->height - temp_buf->height) / 2;
|
2003-02-27 00:17:10 +08:00
|
|
|
|
2007-11-05 03:14:32 +08:00
|
|
|
gimp_view_renderer_render_surface (renderer, temp_buf, -1,
|
|
|
|
GIMP_VIEW_BG_CHECKS,
|
|
|
|
GIMP_VIEW_BG_WHITE);
|
2003-03-04 01:19:30 +08:00
|
|
|
}
|
2003-02-27 00:17:10 +08:00
|
|
|
|
2003-03-04 01:19:30 +08:00
|
|
|
void
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_default_render_stock (GimpViewRenderer *renderer,
|
|
|
|
GtkWidget *widget,
|
|
|
|
const gchar *stock_id)
|
2003-03-04 01:19:30 +08:00
|
|
|
{
|
2003-04-12 05:23:34 +08:00
|
|
|
GdkPixbuf *pixbuf = NULL;
|
2003-03-13 21:08:37 +08:00
|
|
|
GtkIconSize icon_size;
|
2003-03-04 01:19:30 +08:00
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
g_return_if_fail (GIMP_IS_VIEW_RENDERER (renderer));
|
2003-03-04 01:19:30 +08:00
|
|
|
g_return_if_fail (GTK_IS_WIDGET (widget));
|
|
|
|
g_return_if_fail (stock_id != NULL);
|
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
if (renderer->pixbuf)
|
2003-03-04 01:19:30 +08:00
|
|
|
{
|
2004-09-27 07:44:24 +08:00
|
|
|
g_object_unref (renderer->pixbuf);
|
|
|
|
renderer->pixbuf = NULL;
|
2003-02-27 00:17:10 +08:00
|
|
|
}
|
2003-03-04 01:19:30 +08:00
|
|
|
|
2007-11-05 03:14:32 +08:00
|
|
|
if (renderer->surface)
|
2003-02-27 00:17:10 +08:00
|
|
|
{
|
2007-11-05 03:14:32 +08:00
|
|
|
cairo_surface_destroy (renderer->surface);
|
|
|
|
renderer->surface = NULL;
|
2003-03-04 01:19:30 +08:00
|
|
|
}
|
2003-03-01 11:53:41 +08:00
|
|
|
|
2003-03-13 21:08:37 +08:00
|
|
|
icon_size = gimp_get_icon_size (widget, stock_id, GTK_ICON_SIZE_INVALID,
|
2004-07-06 21:18:42 +08:00
|
|
|
renderer->width, renderer->height);
|
2003-03-01 11:53:41 +08:00
|
|
|
|
2003-04-12 05:23:34 +08:00
|
|
|
if (icon_size)
|
|
|
|
pixbuf = gtk_widget_render_icon (widget, stock_id, icon_size, NULL);
|
2003-09-29 21:35:59 +08:00
|
|
|
|
2003-03-04 01:19:30 +08:00
|
|
|
if (pixbuf)
|
|
|
|
{
|
2003-11-17 21:34:38 +08:00
|
|
|
gint width = gdk_pixbuf_get_width (pixbuf);
|
|
|
|
gint height = gdk_pixbuf_get_height (pixbuf);
|
|
|
|
|
|
|
|
if (width > renderer->width || height > renderer->height)
|
2003-02-27 00:17:10 +08:00
|
|
|
{
|
2003-03-04 01:19:30 +08:00
|
|
|
GdkPixbuf *scaled_pixbuf;
|
2003-11-17 21:34:38 +08:00
|
|
|
|
|
|
|
gimp_viewable_calc_preview_size (width, height,
|
|
|
|
renderer->width, renderer->height,
|
2003-03-04 01:19:30 +08:00
|
|
|
TRUE, 1.0, 1.0,
|
2003-11-17 21:34:38 +08:00
|
|
|
&width, &height,
|
2003-03-04 01:19:30 +08:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf,
|
2003-11-17 21:34:38 +08:00
|
|
|
width, height,
|
2003-03-04 01:19:30 +08:00
|
|
|
GDK_INTERP_BILINEAR);
|
|
|
|
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
pixbuf = scaled_pixbuf;
|
2003-02-27 00:17:10 +08:00
|
|
|
}
|
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
renderer->pixbuf = pixbuf;
|
2001-06-18 21:10:03 +08:00
|
|
|
}
|
2003-03-04 01:19:30 +08:00
|
|
|
|
|
|
|
renderer->needs_render = FALSE;
|
2001-02-07 08:06:58 +08:00
|
|
|
}
|
|
|
|
|
2003-03-04 01:19:30 +08:00
|
|
|
void
|
2007-11-05 03:14:32 +08:00
|
|
|
gimp_view_renderer_render_surface (GimpViewRenderer *renderer,
|
|
|
|
TempBuf *temp_buf,
|
|
|
|
gint channel,
|
|
|
|
GimpViewBG inside_bg,
|
|
|
|
GimpViewBG outside_bg)
|
2001-06-18 21:10:03 +08:00
|
|
|
{
|
2004-09-27 07:44:24 +08:00
|
|
|
if (renderer->pixbuf)
|
2003-03-07 00:47:34 +08:00
|
|
|
{
|
2004-09-27 07:44:24 +08:00
|
|
|
g_object_unref (renderer->pixbuf);
|
|
|
|
renderer->pixbuf = NULL;
|
2003-03-07 00:47:34 +08:00
|
|
|
}
|
|
|
|
|
2007-11-05 03:14:32 +08:00
|
|
|
if (! renderer->surface)
|
|
|
|
renderer->surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
|
|
|
|
renderer->width,
|
|
|
|
renderer->height);
|
2004-09-27 07:44:24 +08:00
|
|
|
|
2007-11-05 03:14:32 +08:00
|
|
|
gimp_view_render_to_surface (temp_buf,
|
|
|
|
channel,
|
|
|
|
inside_bg,
|
|
|
|
outside_bg,
|
|
|
|
renderer->surface,
|
|
|
|
renderer->width,
|
|
|
|
renderer->height);
|
2002-02-01 00:47:20 +08:00
|
|
|
|
2003-03-04 01:19:30 +08:00
|
|
|
renderer->needs_render = FALSE;
|
|
|
|
}
|
2002-02-01 00:47:20 +08:00
|
|
|
|
2007-11-02 07:37:00 +08:00
|
|
|
static void
|
2007-11-05 03:14:32 +08:00
|
|
|
gimp_view_render_to_surface (TempBuf *temp_buf,
|
|
|
|
gint channel,
|
|
|
|
GimpViewBG inside_bg,
|
|
|
|
GimpViewBG outside_bg,
|
|
|
|
cairo_surface_t *surface,
|
|
|
|
gint dest_width,
|
|
|
|
gint dest_height)
|
2001-02-08 04:35:18 +08:00
|
|
|
{
|
2007-11-05 03:14:32 +08:00
|
|
|
const guchar *src;
|
|
|
|
const guchar *pad_buf;
|
|
|
|
guchar *dest;
|
|
|
|
gint i, j;
|
|
|
|
gint x1, y1;
|
|
|
|
gint x2, y2;
|
2007-06-12 04:01:54 +08:00
|
|
|
gint rowstride;
|
2007-11-05 03:14:32 +08:00
|
|
|
gint dest_stride;
|
2007-06-12 04:01:54 +08:00
|
|
|
gboolean color;
|
|
|
|
gboolean has_alpha;
|
|
|
|
gboolean render_composite;
|
|
|
|
gint red_component;
|
|
|
|
gint green_component;
|
|
|
|
gint blue_component;
|
|
|
|
gint alpha_component;
|
|
|
|
|
|
|
|
g_return_if_fail (temp_buf != NULL);
|
2007-11-05 03:14:32 +08:00
|
|
|
g_return_if_fail (surface != NULL);
|
|
|
|
|
|
|
|
dest = cairo_image_surface_get_data (surface);
|
|
|
|
dest_stride = cairo_image_surface_get_stride (surface);
|
2001-03-12 01:24:47 +08:00
|
|
|
|
2001-02-08 04:35:18 +08:00
|
|
|
/* Here are the different cases this functions handles correctly:
|
|
|
|
* 1) Offset temp_buf which does not necessarily cover full image area
|
|
|
|
* 2) Color conversion of temp_buf if it is gray and image is color
|
|
|
|
* 3) Background check buffer for transparent temp_bufs
|
|
|
|
* 4) Using the optional "channel" argument, one channel can be extracted
|
|
|
|
* from a multi-channel temp_buf and composited as a grayscale
|
|
|
|
* Prereqs:
|
|
|
|
* 1) Grayscale temp_bufs have bytes == {1, 2}
|
|
|
|
* 2) Color temp_bufs have bytes == {3, 4}
|
|
|
|
* 3) If image is gray, then temp_buf should have bytes == {1, 2}
|
|
|
|
*/
|
2002-02-01 00:47:20 +08:00
|
|
|
|
|
|
|
color = (temp_buf->bytes == 3 || temp_buf->bytes == 4);
|
|
|
|
has_alpha = (temp_buf->bytes == 2 || temp_buf->bytes == 4);
|
|
|
|
render_composite = (channel == -1);
|
|
|
|
rowstride = temp_buf->width * temp_buf->bytes;
|
2001-02-08 04:35:18 +08:00
|
|
|
|
2001-08-10 22:41:39 +08:00
|
|
|
/* render the checkerboard only if the temp_buf has alpha *and*
|
2004-08-26 06:31:44 +08:00
|
|
|
* we render a composite view
|
2001-08-10 22:41:39 +08:00
|
|
|
*/
|
2004-08-26 06:31:44 +08:00
|
|
|
if (has_alpha && render_composite && outside_bg == GIMP_VIEW_BG_CHECKS)
|
2005-07-20 04:42:14 +08:00
|
|
|
pad_buf = gimp_render_check_buf;
|
2004-08-26 06:31:44 +08:00
|
|
|
else if (outside_bg == GIMP_VIEW_BG_WHITE)
|
2005-07-20 04:42:14 +08:00
|
|
|
pad_buf = gimp_render_white_buf;
|
2002-02-01 00:47:20 +08:00
|
|
|
else
|
2005-07-20 04:42:14 +08:00
|
|
|
pad_buf = gimp_render_empty_buf;
|
2002-02-01 00:47:20 +08:00
|
|
|
|
|
|
|
if (render_composite)
|
2001-02-08 04:35:18 +08:00
|
|
|
{
|
2002-02-01 00:47:20 +08:00
|
|
|
if (color)
|
|
|
|
{
|
|
|
|
red_component = RED_PIX;
|
|
|
|
green_component = GREEN_PIX;
|
|
|
|
blue_component = BLUE_PIX;
|
|
|
|
alpha_component = ALPHA_PIX;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
red_component = GRAY_PIX;
|
|
|
|
green_component = GRAY_PIX;
|
|
|
|
blue_component = GRAY_PIX;
|
|
|
|
alpha_component = ALPHA_G_PIX;
|
|
|
|
}
|
2001-02-08 04:35:18 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-02-01 00:47:20 +08:00
|
|
|
red_component = channel;
|
|
|
|
green_component = channel;
|
|
|
|
blue_component = channel;
|
|
|
|
alpha_component = 0;
|
2001-02-08 04:35:18 +08:00
|
|
|
}
|
2001-02-05 23:22:20 +08:00
|
|
|
|
2003-02-27 00:17:10 +08:00
|
|
|
x1 = CLAMP (temp_buf->x, 0, dest_width);
|
|
|
|
y1 = CLAMP (temp_buf->y, 0, dest_height);
|
|
|
|
x2 = CLAMP (temp_buf->x + temp_buf->width, 0, dest_width);
|
|
|
|
y2 = CLAMP (temp_buf->y + temp_buf->height, 0, dest_height);
|
2001-02-05 23:22:20 +08:00
|
|
|
|
2001-02-08 04:35:18 +08:00
|
|
|
src = temp_buf_data (temp_buf) + ((y1 - temp_buf->y) * rowstride +
|
2004-07-06 21:18:42 +08:00
|
|
|
(x1 - temp_buf->x) * temp_buf->bytes);
|
2001-02-05 23:22:20 +08:00
|
|
|
|
2003-02-27 00:17:10 +08:00
|
|
|
for (i = 0; i < dest_height; i++)
|
2001-02-08 04:35:18 +08:00
|
|
|
{
|
2007-11-05 03:14:32 +08:00
|
|
|
guchar *d = dest;
|
|
|
|
const guchar *cb;
|
|
|
|
gint offset;
|
|
|
|
|
2001-02-08 04:35:18 +08:00
|
|
|
if (i & 0x4)
|
2004-07-06 21:18:42 +08:00
|
|
|
{
|
|
|
|
offset = 4;
|
|
|
|
cb = pad_buf + offset * 3;
|
|
|
|
}
|
2001-02-08 04:35:18 +08:00
|
|
|
else
|
2004-07-06 21:18:42 +08:00
|
|
|
{
|
|
|
|
offset = 0;
|
|
|
|
cb = pad_buf;
|
|
|
|
}
|
2001-02-08 04:35:18 +08:00
|
|
|
|
2003-09-29 21:35:59 +08:00
|
|
|
/* The interesting stuff between leading & trailing
|
2001-02-08 04:35:18 +08:00
|
|
|
* vertical transparency
|
|
|
|
*/
|
|
|
|
if (i >= y1 && i < y2)
|
2004-07-06 21:18:42 +08:00
|
|
|
{
|
2007-11-05 03:14:32 +08:00
|
|
|
const guchar *s = src;
|
|
|
|
|
2004-07-06 21:18:42 +08:00
|
|
|
/* Handle the leading transparency */
|
2007-11-05 03:14:32 +08:00
|
|
|
for (j = 0; j < x1; j++, d += 4, cb += 3)
|
|
|
|
{
|
2007-11-05 23:54:15 +08:00
|
|
|
GIMP_CAIRO_RGB24_SET_PIXEL (d, cb[0], cb[1], cb[2]);
|
2007-11-05 03:14:32 +08:00
|
|
|
}
|
2004-07-06 21:18:42 +08:00
|
|
|
|
|
|
|
/* The stuff in the middle */
|
2007-11-05 03:14:32 +08:00
|
|
|
for (j = x1; j < x2; j++, d += 4, s += temp_buf->bytes)
|
2004-07-06 21:18:42 +08:00
|
|
|
{
|
2002-02-01 00:47:20 +08:00
|
|
|
if (has_alpha && render_composite)
|
|
|
|
{
|
2007-11-05 03:14:32 +08:00
|
|
|
const guint a = s[alpha_component] << 8;
|
2002-02-01 00:47:20 +08:00
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
if (inside_bg == GIMP_VIEW_BG_CHECKS)
|
2002-02-01 00:47:20 +08:00
|
|
|
{
|
2003-02-27 00:17:10 +08:00
|
|
|
if ((j + offset) & 0x4)
|
|
|
|
{
|
2007-11-05 23:54:15 +08:00
|
|
|
GIMP_CAIRO_RGB24_SET_PIXEL (d,
|
|
|
|
gimp_render_blend_dark_check [a | s[red_component]],
|
|
|
|
gimp_render_blend_dark_check [a | s[green_component]],
|
|
|
|
gimp_render_blend_dark_check [a | s[blue_component]]);
|
2003-02-27 00:17:10 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-11-05 23:54:15 +08:00
|
|
|
GIMP_CAIRO_RGB24_SET_PIXEL (d,
|
|
|
|
gimp_render_blend_light_check [a | s[red_component]],
|
|
|
|
gimp_render_blend_light_check [a | s[green_component]],
|
|
|
|
gimp_render_blend_light_check [a | s[blue_component]]);
|
2003-02-27 00:17:10 +08:00
|
|
|
}
|
2002-02-01 00:47:20 +08:00
|
|
|
}
|
2004-08-26 06:31:44 +08:00
|
|
|
else /* GIMP_VIEW_BG_WHITE */
|
2002-02-01 00:47:20 +08:00
|
|
|
{
|
2007-11-05 23:54:15 +08:00
|
|
|
GIMP_CAIRO_RGB24_SET_PIXEL (d,
|
|
|
|
gimp_render_blend_white [a | s[red_component]],
|
|
|
|
gimp_render_blend_white [a | s[green_component]],
|
|
|
|
gimp_render_blend_white [a | s[blue_component]]);
|
2002-02-01 00:47:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-11-05 23:54:15 +08:00
|
|
|
GIMP_CAIRO_RGB24_SET_PIXEL (d,
|
|
|
|
s[red_component],
|
|
|
|
s[green_component],
|
|
|
|
s[blue_component]);
|
2002-02-01 00:47:20 +08:00
|
|
|
}
|
2004-07-06 21:18:42 +08:00
|
|
|
}
|
2001-02-08 04:35:18 +08:00
|
|
|
|
2004-07-06 21:18:42 +08:00
|
|
|
/* Handle the trailing transparency */
|
2007-11-05 03:14:32 +08:00
|
|
|
for (j = x2; j < dest_width; j++, d+= 4, cb += 3)
|
|
|
|
{
|
2007-11-05 23:54:15 +08:00
|
|
|
GIMP_CAIRO_RGB24_SET_PIXEL (d, cb[0], cb[1], cb[2]);
|
2007-11-05 03:14:32 +08:00
|
|
|
}
|
2001-02-08 04:35:18 +08:00
|
|
|
|
2004-07-06 21:18:42 +08:00
|
|
|
src += rowstride;
|
|
|
|
}
|
2001-02-08 04:35:18 +08:00
|
|
|
else
|
2004-07-06 21:18:42 +08:00
|
|
|
{
|
2007-11-05 03:14:32 +08:00
|
|
|
for (j = 0; j < dest_width; j++, d+= 4, cb += 3)
|
|
|
|
{
|
2007-11-05 23:54:15 +08:00
|
|
|
GIMP_CAIRO_RGB24_SET_PIXEL (d, cb[0], cb[1], cb[2]);
|
2007-11-05 03:14:32 +08:00
|
|
|
}
|
2004-07-06 21:18:42 +08:00
|
|
|
}
|
2001-02-08 04:35:18 +08:00
|
|
|
|
2007-11-05 03:14:32 +08:00
|
|
|
dest += dest_stride;
|
2001-02-08 04:35:18 +08:00
|
|
|
}
|
2003-02-27 00:17:10 +08:00
|
|
|
}
|
2003-04-11 19:18:12 +08:00
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
void
|
|
|
|
gimp_view_renderer_render_pixbuf (GimpViewRenderer *renderer,
|
|
|
|
GdkPixbuf *pixbuf)
|
|
|
|
{
|
2007-11-05 03:14:32 +08:00
|
|
|
if (renderer->surface)
|
2004-09-27 07:44:24 +08:00
|
|
|
{
|
2007-11-05 03:14:32 +08:00
|
|
|
cairo_surface_destroy (renderer->surface);
|
|
|
|
renderer->surface = NULL;
|
2004-09-27 07:44:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g_object_ref (pixbuf);
|
|
|
|
|
|
|
|
if (renderer->pixbuf)
|
|
|
|
g_object_unref (renderer->pixbuf);
|
|
|
|
|
|
|
|
renderer->pixbuf = pixbuf;
|
|
|
|
|
|
|
|
renderer->needs_render = FALSE;
|
|
|
|
}
|
|
|
|
|
2007-12-29 01:54:01 +08:00
|
|
|
/* This function creates a background pattern from a stock icon
|
|
|
|
* if renderer->bg_stock_id is set.
|
|
|
|
*/
|
2007-11-02 07:37:00 +08:00
|
|
|
static cairo_pattern_t *
|
2007-12-29 01:54:01 +08:00
|
|
|
gimp_view_renderer_create_background (GimpViewRenderer *renderer,
|
|
|
|
GtkWidget *widget)
|
2003-04-11 19:18:12 +08:00
|
|
|
{
|
2007-11-02 07:37:00 +08:00
|
|
|
cairo_pattern_t *pattern = NULL;
|
2003-04-11 19:18:12 +08:00
|
|
|
|
|
|
|
if (renderer->bg_stock_id)
|
|
|
|
{
|
2007-11-02 07:37:00 +08:00
|
|
|
GdkPixbuf *pixbuf = gtk_widget_render_icon (widget,
|
|
|
|
renderer->bg_stock_id,
|
|
|
|
GTK_ICON_SIZE_DIALOG, NULL);
|
2003-04-11 19:18:12 +08:00
|
|
|
|
|
|
|
if (pixbuf)
|
|
|
|
{
|
2007-11-02 07:37:00 +08:00
|
|
|
cairo_surface_t *surface;
|
|
|
|
|
2007-12-12 22:41:25 +08:00
|
|
|
surface = gimp_cairo_surface_create_from_pixbuf (pixbuf);
|
2003-04-11 19:18:12 +08:00
|
|
|
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
|
2007-11-02 07:37:00 +08:00
|
|
|
pattern = cairo_pattern_create_for_surface (surface);
|
|
|
|
cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
|
2003-04-11 19:18:12 +08:00
|
|
|
|
2007-11-02 07:37:00 +08:00
|
|
|
cairo_surface_destroy (surface);
|
2003-04-11 19:18:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-02 07:37:00 +08:00
|
|
|
return pattern;
|
2003-04-11 19:18:12 +08:00
|
|
|
}
|