2001-02-05 23:22:20 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* 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>
|
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"
|
|
|
|
|
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
|
|
|
|
2004-09-28 03:40:12 +08:00
|
|
|
static void gimp_view_renderer_dispose (GObject *object);
|
|
|
|
static void gimp_view_renderer_finalize (GObject *object);
|
2002-02-01 00:47:20 +08:00
|
|
|
|
2004-09-28 03:40:12 +08:00
|
|
|
static gboolean gimp_view_renderer_idle_update (GimpViewRenderer *renderer);
|
|
|
|
static void gimp_view_renderer_real_draw (GimpViewRenderer *renderer,
|
|
|
|
GdkWindow *window,
|
|
|
|
GtkWidget *widget,
|
|
|
|
const GdkRectangle *draw_area,
|
|
|
|
const GdkRectangle *expose_area);
|
|
|
|
static void gimp_view_renderer_real_render (GimpViewRenderer *renderer,
|
|
|
|
GtkWidget *widget);
|
|
|
|
|
|
|
|
static void gimp_view_renderer_size_changed (GimpViewRenderer *renderer,
|
|
|
|
GimpViewable *viewable);
|
|
|
|
static GdkGC * gimp_view_renderer_create_gc (GimpViewRenderer *renderer,
|
|
|
|
GdkWindow *window,
|
|
|
|
GtkWidget *widget);
|
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;
|
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
|
|
|
{
|
2005-12-20 06:37:49 +08:00
|
|
|
renderer->viewable = NULL;
|
2002-11-10 04:01:19 +08:00
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
renderer->width = 8;
|
|
|
|
renderer->height = 8;
|
|
|
|
renderer->border_width = 0;
|
|
|
|
renderer->dot_for_dot = TRUE;
|
|
|
|
renderer->is_popup = FALSE;
|
2001-02-08 12:16:41 +08:00
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
renderer->border_type = GIMP_VIEW_BORDER_BLACK;
|
|
|
|
renderer->border_color = black_color;
|
|
|
|
renderer->gc = NULL;
|
2002-03-22 23:21:18 +08:00
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
renderer->buffer = NULL;
|
|
|
|
renderer->rowstride = 0;
|
|
|
|
renderer->bytes = 3;
|
2003-02-27 00:17:10 +08:00
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
renderer->pixbuf = NULL;
|
|
|
|
renderer->bg_stock_id = NULL;
|
2003-02-27 00:17:10 +08:00
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
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
|
|
|
|
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
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
if (renderer->buffer)
|
2003-02-27 00:17:10 +08:00
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
g_free (renderer->buffer);
|
|
|
|
renderer->buffer = 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (renderer->gc)
|
2002-02-01 00:47:20 +08:00
|
|
|
{
|
2003-04-11 19:18:12 +08:00
|
|
|
g_object_unref (renderer->gc);
|
|
|
|
renderer->gc = NULL;
|
2002-02-01 00:47:20 +08:00
|
|
|
}
|
|
|
|
|
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 *
|
|
|
|
gimp_view_renderer_new_internal (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;
|
|
|
|
|
|
|
|
return renderer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-01 00:47:20 +08:00
|
|
|
/* public functions */
|
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
GimpViewRenderer *
|
|
|
|
gimp_view_renderer_new (GType viewable_type,
|
|
|
|
gint size,
|
|
|
|
gint border_width,
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
renderer = gimp_view_renderer_new_internal (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 *
|
|
|
|
gimp_view_renderer_new_full (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
|
|
|
|
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
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
renderer = gimp_view_renderer_new_internal (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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
if (renderer->buffer)
|
2002-05-10 20:47:42 +08:00
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
g_free (renderer->buffer);
|
|
|
|
renderer->buffer = 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),
|
2004-07-06 21:18:42 +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),
|
2004-07-06 21:18:42 +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
|
|
|
{
|
|
|
|
gint width, height;
|
|
|
|
|
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
|
|
|
|
2003-03-01 20:55:43 +08:00
|
|
|
renderer->rowstride = (renderer->width * renderer->bytes + 3) & ~3;
|
2001-06-18 21:10:03 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
if (renderer->buffer)
|
2002-01-31 01:39:56 +08:00
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
g_free (renderer->buffer);
|
|
|
|
renderer->buffer = 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
|
|
|
|
2003-04-11 19:18:12 +08:00
|
|
|
if (renderer->gc)
|
2003-02-27 00:17:10 +08:00
|
|
|
{
|
|
|
|
GdkColor gdk_color;
|
|
|
|
|
2003-06-11 00:44:44 +08:00
|
|
|
gimp_rgb_get_gdk_color (&renderer->border_color, &gdk_color);
|
2003-04-11 19:18:12 +08:00
|
|
|
gdk_gc_set_rgb_fg_color (renderer->gc, &gdk_color);
|
2003-02-27 00:17:10 +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);
|
|
|
|
|
|
|
|
if (renderer->gc)
|
|
|
|
{
|
|
|
|
g_object_unref (renderer->gc);
|
|
|
|
renderer->gc = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-13 23:04:13 +08:00
|
|
|
void
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_unrealize (GimpViewRenderer *renderer)
|
2003-11-13 23:04:13 +08:00
|
|
|
{
|
2004-08-26 06:31:44 +08:00
|
|
|
g_return_if_fail (GIMP_IS_VIEW_RENDERER (renderer));
|
2003-11-13 23:04:13 +08:00
|
|
|
|
|
|
|
if (renderer->gc)
|
|
|
|
{
|
|
|
|
g_object_unref (renderer->gc);
|
|
|
|
renderer->gc = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
g_source_remove (renderer->idle_id);
|
2002-11-10 04:01:19 +08:00
|
|
|
|
2003-03-03 20:59:03 +08:00
|
|
|
renderer->needs_render = TRUE;
|
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
renderer->idle_id =
|
2002-11-10 04:01:19 +08:00
|
|
|
g_idle_add_full (G_PRIORITY_LOW,
|
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 =
|
|
|
|
g_idle_add_full (G_PRIORITY_LOW,
|
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
|
|
|
{
|
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
|
|
|
|
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
|
|
|
|
2003-11-17 21:34:38 +08:00
|
|
|
if (renderer->viewable)
|
|
|
|
{
|
2004-08-26 06:31:44 +08:00
|
|
|
GIMP_VIEW_RENDERER_GET_CLASS (renderer)->draw (renderer,
|
|
|
|
window, widget,
|
|
|
|
draw_area,
|
|
|
|
expose_area);
|
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);
|
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_real_draw (renderer,
|
|
|
|
window, widget, draw_area, expose_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)
|
|
|
|
{
|
2003-09-30 20:06:58 +08:00
|
|
|
GdkRectangle rect;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
rect.width = renderer->width + 2 * renderer->border_width;
|
|
|
|
rect.height = renderer->height + 2 * renderer->border_width;
|
|
|
|
rect.x = draw_area->x + (draw_area->width - rect.width) / 2;
|
|
|
|
rect.y = draw_area->y + (draw_area->height - rect.height) / 2;
|
2003-09-29 21:35:59 +08:00
|
|
|
|
|
|
|
if (! renderer->gc)
|
2004-08-26 06:31:44 +08:00
|
|
|
renderer->gc = gimp_view_renderer_create_gc (renderer,
|
|
|
|
window, widget);
|
2003-09-29 21:35:59 +08:00
|
|
|
|
|
|
|
for (i = 0; i < renderer->border_width; i++)
|
|
|
|
gdk_draw_rectangle (window,
|
|
|
|
renderer->gc,
|
|
|
|
FALSE,
|
2003-09-30 20:06:58 +08:00
|
|
|
rect.x + i,
|
|
|
|
rect.y + i,
|
|
|
|
rect.width - 2 * i - 1,
|
|
|
|
rect.height - 2 * i - 1);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_real_draw (GimpViewRenderer *renderer,
|
|
|
|
GdkWindow *window,
|
|
|
|
GtkWidget *widget,
|
|
|
|
const GdkRectangle *draw_area,
|
|
|
|
const GdkRectangle *expose_area)
|
2003-09-29 21:35:59 +08:00
|
|
|
{
|
2003-09-30 20:06:58 +08:00
|
|
|
GdkRectangle rect;
|
2003-09-29 21:35:59 +08:00
|
|
|
GdkRectangle render_rect;
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2003-04-11 19:18:12 +08:00
|
|
|
if (renderer->bg_stock_id)
|
|
|
|
{
|
|
|
|
if (!renderer->gc)
|
2004-08-26 06:31:44 +08:00
|
|
|
renderer->gc = gimp_view_renderer_create_gc (renderer,
|
|
|
|
window, widget);
|
2003-04-11 19:18:12 +08:00
|
|
|
|
2003-09-29 21:35:59 +08:00
|
|
|
if (gdk_rectangle_intersect ((GdkRectangle *) draw_area,
|
|
|
|
(GdkRectangle *) expose_area,
|
|
|
|
&render_rect))
|
|
|
|
{
|
|
|
|
gdk_draw_rectangle (GDK_DRAWABLE (window), renderer->gc,
|
|
|
|
TRUE,
|
|
|
|
render_rect.x, render_rect.y,
|
|
|
|
render_rect.width, render_rect.height);
|
|
|
|
}
|
2003-04-11 19:18:12 +08:00
|
|
|
}
|
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
rect.width = gdk_pixbuf_get_width (renderer->pixbuf);
|
|
|
|
rect.height = gdk_pixbuf_get_height (renderer->pixbuf);
|
2003-09-30 20:06:58 +08:00
|
|
|
rect.x = draw_area->x + (draw_area->width - rect.width) / 2;
|
|
|
|
rect.y = draw_area->y + (draw_area->height - rect.height) / 2;
|
2003-03-01 11:53:41 +08:00
|
|
|
|
2003-09-30 20:06:58 +08:00
|
|
|
if (gdk_rectangle_intersect (&rect, (GdkRectangle *) expose_area,
|
2003-04-11 16:37:26 +08:00
|
|
|
&render_rect))
|
2003-03-01 11:53:41 +08:00
|
|
|
{
|
|
|
|
gdk_draw_pixbuf (GDK_DRAWABLE (window),
|
|
|
|
widget->style->bg_gc[widget->state],
|
2004-09-27 07:44:24 +08:00
|
|
|
renderer->pixbuf,
|
2003-09-30 20:06:58 +08:00
|
|
|
render_rect.x - rect.x,
|
|
|
|
render_rect.y - rect.y,
|
2003-03-01 11:53:41 +08:00
|
|
|
render_rect.x,
|
|
|
|
render_rect.y,
|
|
|
|
render_rect.width,
|
|
|
|
render_rect.height,
|
|
|
|
GDK_RGB_DITHER_NORMAL,
|
2003-03-14 00:49:37 +08:00
|
|
|
0, 0);
|
2003-03-01 11:53:41 +08:00
|
|
|
}
|
2003-02-27 21:59:41 +08:00
|
|
|
}
|
2003-03-01 11:53:41 +08:00
|
|
|
else if (renderer->buffer)
|
|
|
|
{
|
2003-09-30 20:06:58 +08:00
|
|
|
rect.width = renderer->width;
|
|
|
|
rect.height = renderer->height;
|
|
|
|
rect.x = draw_area->x + (draw_area->width - rect.width) / 2;
|
|
|
|
rect.y = draw_area->y + (draw_area->height - rect.height) / 2;
|
2002-11-10 04:01:19 +08:00
|
|
|
|
2003-09-30 20:06:58 +08:00
|
|
|
if (gdk_rectangle_intersect (&rect, (GdkRectangle *) expose_area,
|
2003-04-11 16:37:26 +08:00
|
|
|
&render_rect))
|
2003-03-01 11:53:41 +08:00
|
|
|
{
|
|
|
|
guchar *buf;
|
|
|
|
|
|
|
|
buf = (renderer->buffer +
|
2003-09-30 20:06:58 +08:00
|
|
|
(render_rect.y - rect.y) * renderer->rowstride +
|
|
|
|
(render_rect.x - rect.x) * renderer->bytes);
|
2003-03-01 11:53:41 +08:00
|
|
|
|
|
|
|
gdk_draw_rgb_image_dithalign (window,
|
|
|
|
widget->style->black_gc,
|
|
|
|
render_rect.x,
|
|
|
|
render_rect.y,
|
|
|
|
render_rect.width,
|
|
|
|
render_rect.height,
|
|
|
|
GDK_RGB_DITHER_NORMAL,
|
|
|
|
buf,
|
|
|
|
renderer->rowstride,
|
|
|
|
expose_area->x - draw_area->x,
|
|
|
|
expose_area->y - draw_area->y);
|
|
|
|
}
|
|
|
|
}
|
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,
|
|
|
|
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,
|
2004-07-06 21:18:42 +08:00
|
|
|
renderer->width,
|
|
|
|
renderer->height);
|
2003-03-04 01:19:30 +08:00
|
|
|
if (temp_buf)
|
|
|
|
{
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_default_render_buffer (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
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_default_render_buffer (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
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_render_buffer (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
|
|
|
|
|
|
|
if (renderer->buffer)
|
2003-02-27 00:17:10 +08:00
|
|
|
{
|
2003-03-04 01:19:30 +08:00
|
|
|
g_free (renderer->buffer);
|
|
|
|
renderer->buffer = NULL;
|
|
|
|
}
|
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
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_render_buffer (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
|
|
|
}
|
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
if (! renderer->buffer)
|
|
|
|
renderer->buffer = g_new0 (guchar, renderer->height * renderer->rowstride);
|
|
|
|
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_render_to_buffer (temp_buf,
|
|
|
|
channel,
|
|
|
|
inside_bg,
|
|
|
|
outside_bg,
|
|
|
|
renderer->buffer,
|
|
|
|
renderer->width,
|
|
|
|
renderer->height,
|
|
|
|
renderer->rowstride,
|
|
|
|
renderer->bytes);
|
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
|
|
|
|
2001-02-08 04:35:18 +08:00
|
|
|
void
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_render_to_buffer (TempBuf *temp_buf,
|
|
|
|
gint channel,
|
|
|
|
GimpViewBG inside_bg,
|
|
|
|
GimpViewBG outside_bg,
|
|
|
|
guchar *dest_buffer,
|
|
|
|
gint dest_width,
|
|
|
|
gint dest_height,
|
|
|
|
gint dest_rowstride,
|
|
|
|
gint dest_bytes)
|
2001-02-08 04:35:18 +08:00
|
|
|
{
|
|
|
|
guchar *src, *s;
|
|
|
|
guchar *cb;
|
2003-02-27 00:17:10 +08:00
|
|
|
guchar *pad_buf;
|
2001-02-08 04:35:18 +08:00
|
|
|
gint a;
|
|
|
|
gint i, j, b;
|
|
|
|
gint x1, y1, x2, y2;
|
|
|
|
gint rowstride;
|
|
|
|
gboolean color;
|
|
|
|
gboolean has_alpha;
|
2001-08-11 15:47:35 +08:00
|
|
|
gboolean render_composite;
|
2002-02-01 00:47:20 +08:00
|
|
|
gint red_component;
|
|
|
|
gint green_component;
|
|
|
|
gint blue_component;
|
|
|
|
gint alpha_component;
|
2001-02-08 04:35:18 +08:00
|
|
|
gint offset;
|
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
|
|
|
{
|
|
|
|
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
|
|
|
{
|
|
|
|
/* Handle the leading transparency */
|
|
|
|
for (j = 0; j < x1; j++)
|
|
|
|
for (b = 0; b < dest_bytes; b++)
|
2005-07-20 04:42:14 +08:00
|
|
|
gimp_render_temp_buf[j * dest_bytes + b] = cb[j * 3 + b];
|
2004-07-06 21:18:42 +08:00
|
|
|
|
|
|
|
/* The stuff in the middle */
|
|
|
|
s = src;
|
|
|
|
for (j = x1; j < x2; j++)
|
|
|
|
{
|
2002-02-01 00:47:20 +08:00
|
|
|
if (has_alpha && render_composite)
|
|
|
|
{
|
|
|
|
a = s[alpha_component] << 8;
|
|
|
|
|
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)
|
|
|
|
{
|
2005-07-20 04:42:14 +08:00
|
|
|
gimp_render_temp_buf[j * 3 + 0] =
|
|
|
|
gimp_render_blend_dark_check [(a | s[red_component])];
|
|
|
|
gimp_render_temp_buf[j * 3 + 1] =
|
|
|
|
gimp_render_blend_dark_check [(a | s[green_component])];
|
|
|
|
gimp_render_temp_buf[j * 3 + 2] =
|
|
|
|
gimp_render_blend_dark_check [(a | s[blue_component])];
|
2003-02-27 00:17:10 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-07-20 04:42:14 +08:00
|
|
|
gimp_render_temp_buf[j * 3 + 0] =
|
|
|
|
gimp_render_blend_light_check [(a | s[red_component])];
|
|
|
|
gimp_render_temp_buf[j * 3 + 1] =
|
|
|
|
gimp_render_blend_light_check [(a | s[green_component])];
|
|
|
|
gimp_render_temp_buf[j * 3 + 2] =
|
|
|
|
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
|
|
|
{
|
2005-07-20 04:42:14 +08:00
|
|
|
gimp_render_temp_buf[j * 3 + 0] =
|
|
|
|
gimp_render_blend_white [(a | s[red_component])];
|
|
|
|
gimp_render_temp_buf[j * 3 + 1] =
|
|
|
|
gimp_render_blend_white [(a | s[green_component])];
|
|
|
|
gimp_render_temp_buf[j * 3 + 2] =
|
|
|
|
gimp_render_blend_white [(a | s[blue_component])];
|
2002-02-01 00:47:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-07-20 04:42:14 +08:00
|
|
|
gimp_render_temp_buf[j * 3 + 0] = s[red_component];
|
|
|
|
gimp_render_temp_buf[j * 3 + 1] = s[green_component];
|
|
|
|
gimp_render_temp_buf[j * 3 + 2] = s[blue_component];
|
2002-02-01 00:47:20 +08:00
|
|
|
}
|
2001-02-08 04:35:18 +08:00
|
|
|
|
2004-07-06 21:18:42 +08:00
|
|
|
s += temp_buf->bytes;
|
|
|
|
}
|
2001-02-08 04:35:18 +08:00
|
|
|
|
2004-07-06 21:18:42 +08:00
|
|
|
/* Handle the trailing transparency */
|
|
|
|
for (j = x2; j < dest_width; j++)
|
|
|
|
for (b = 0; b < dest_bytes; b++)
|
2005-07-20 04:42:14 +08:00
|
|
|
gimp_render_temp_buf[j * dest_bytes + b] = cb[j * 3 + b];
|
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
|
|
|
{
|
|
|
|
for (j = 0; j < dest_width; j++)
|
|
|
|
for (b = 0; b < dest_bytes; b++)
|
2005-07-20 04:42:14 +08:00
|
|
|
gimp_render_temp_buf[j * dest_bytes + b] = cb[j * 3 + b];
|
2004-07-06 21:18:42 +08:00
|
|
|
}
|
2001-02-08 04:35:18 +08:00
|
|
|
|
2003-02-27 00:17:10 +08:00
|
|
|
memcpy (dest_buffer + i * dest_rowstride,
|
2005-07-20 04:42:14 +08:00
|
|
|
gimp_render_temp_buf,
|
2003-03-01 20:55:43 +08:00
|
|
|
dest_width * dest_bytes);
|
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)
|
|
|
|
{
|
|
|
|
if (renderer->buffer)
|
|
|
|
{
|
|
|
|
g_free (renderer->buffer);
|
|
|
|
renderer->buffer = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_ref (pixbuf);
|
|
|
|
|
|
|
|
if (renderer->pixbuf)
|
|
|
|
g_object_unref (renderer->pixbuf);
|
|
|
|
|
|
|
|
renderer->pixbuf = pixbuf;
|
|
|
|
|
|
|
|
renderer->needs_render = FALSE;
|
|
|
|
}
|
|
|
|
|
2003-04-11 19:18:12 +08:00
|
|
|
static GdkGC *
|
2004-08-26 06:31:44 +08:00
|
|
|
gimp_view_renderer_create_gc (GimpViewRenderer *renderer,
|
|
|
|
GdkWindow *window,
|
|
|
|
GtkWidget *widget)
|
2003-04-11 19:18:12 +08:00
|
|
|
{
|
|
|
|
GdkGC *gc;
|
|
|
|
GdkPixmap *pixmap = NULL;
|
2003-04-11 20:48:54 +08:00
|
|
|
GdkColormap *colormap;
|
2003-04-11 19:18:12 +08:00
|
|
|
GdkGCValues values;
|
|
|
|
GdkGCValuesMask mask;
|
|
|
|
|
2003-06-11 00:44:44 +08:00
|
|
|
gimp_rgb_get_gdk_color (&renderer->border_color, &values.foreground);
|
2003-04-11 19:18:12 +08:00
|
|
|
|
2003-04-11 20:48:54 +08:00
|
|
|
colormap = gdk_drawable_get_colormap (window);
|
|
|
|
gdk_rgb_find_color (colormap, &values.foreground);
|
|
|
|
|
2003-04-11 19:18:12 +08:00
|
|
|
mask = GDK_GC_FOREGROUND;
|
|
|
|
|
|
|
|
if (renderer->bg_stock_id)
|
|
|
|
{
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
|
|
|
|
pixbuf = gtk_widget_render_icon (widget,
|
|
|
|
renderer->bg_stock_id,
|
|
|
|
GTK_ICON_SIZE_DIALOG, NULL);
|
|
|
|
|
|
|
|
if (pixbuf)
|
|
|
|
{
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
|
|
|
|
width = gdk_pixbuf_get_width (pixbuf);
|
|
|
|
height = gdk_pixbuf_get_height (pixbuf);
|
|
|
|
|
|
|
|
pixmap = gdk_pixmap_new (window, width, height,
|
|
|
|
gdk_colormap_get_visual (colormap)->depth);
|
|
|
|
gdk_drawable_set_colormap (pixmap, colormap);
|
|
|
|
|
|
|
|
gdk_draw_rectangle (pixmap, widget->style->white_gc,
|
|
|
|
TRUE,
|
|
|
|
0, 0, width, height);
|
|
|
|
|
|
|
|
gdk_draw_pixbuf (pixmap, widget->style->white_gc,
|
|
|
|
pixbuf, 0, 0,
|
|
|
|
0, 0, width, height,
|
|
|
|
GDK_RGB_DITHER_NORMAL, 0, 0);
|
|
|
|
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pixmap)
|
|
|
|
{
|
|
|
|
values.fill = GDK_TILED;
|
|
|
|
values.tile = pixmap;
|
|
|
|
values.ts_x_origin = 0;
|
|
|
|
values.ts_y_origin = 0;
|
|
|
|
|
|
|
|
mask |= (GDK_GC_FILL |
|
|
|
|
GDK_GC_TILE | GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gc = gdk_gc_new_with_values (GDK_DRAWABLE (window), &values, mask);
|
|
|
|
|
|
|
|
if (pixmap)
|
|
|
|
g_object_unref (pixmap);
|
|
|
|
|
|
|
|
return gc;
|
|
|
|
}
|