2001-01-29 21:51:23 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2003-03-04 01:19:30 +08:00
|
|
|
* gimppreviewrendererdrawable.c
|
|
|
|
* Copyright (C) 2003 Michael Natterer <mitch@gimp.org>
|
2001-02-07 08:06:58 +08:00
|
|
|
*
|
2001-01-29 21:51:23 +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 <gtk/gtk.h>
|
|
|
|
|
2001-02-20 06:54:12 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
2001-05-08 11:48:54 +08:00
|
|
|
#include "widgets-types.h"
|
2001-01-29 21:51:23 +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/gimpdrawable.h"
|
|
|
|
#include "core/gimpimage.h"
|
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
#include "gimppreviewrendererdrawable.h"
|
2001-05-08 11:48:54 +08:00
|
|
|
|
2001-01-29 21:51:23 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
static void gimp_preview_renderer_drawable_class_init (GimpPreviewRendererDrawableClass *klass);
|
2003-03-04 01:19:30 +08:00
|
|
|
static void gimp_preview_renderer_drawable_init (GimpPreviewRendererDrawable *renderer);
|
2001-01-29 21:51:23 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
static void gimp_preview_renderer_drawable_render (GimpPreviewRenderer *renderer,
|
|
|
|
GtkWidget *widget);
|
2001-02-07 10:37:49 +08:00
|
|
|
|
2001-01-29 21:51:23 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
static GimpPreviewRendererClass *parent_class = NULL;
|
2001-01-29 21:51:23 +08:00
|
|
|
|
|
|
|
|
2001-10-17 19:33:43 +08:00
|
|
|
GType
|
2003-03-01 11:53:41 +08:00
|
|
|
gimp_preview_renderer_drawable_get_type (void)
|
2001-01-29 21:51:23 +08:00
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
static GType renderer_type = 0;
|
2001-01-29 21:51:23 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
if (! renderer_type)
|
2001-01-29 21:51:23 +08:00
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
static const GTypeInfo renderer_info =
|
2001-02-07 08:06:58 +08:00
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
sizeof (GimpPreviewRendererDrawableClass),
|
2001-10-17 19:33:43 +08:00
|
|
|
NULL, /* base_init */
|
|
|
|
NULL, /* base_finalize */
|
2003-03-01 11:53:41 +08:00
|
|
|
(GClassInitFunc) gimp_preview_renderer_drawable_class_init,
|
2001-10-17 19:33:43 +08:00
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
2003-03-01 11:53:41 +08:00
|
|
|
sizeof (GimpPreviewRendererDrawable),
|
2001-10-17 19:33:43 +08:00
|
|
|
0, /* n_preallocs */
|
2003-03-01 11:53:41 +08:00
|
|
|
(GInstanceInitFunc) gimp_preview_renderer_drawable_init,
|
2001-02-07 08:06:58 +08:00
|
|
|
};
|
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
renderer_type = g_type_register_static (GIMP_TYPE_PREVIEW_RENDERER,
|
|
|
|
"GimpPreviewRendererDrawable",
|
|
|
|
&renderer_info, 0);
|
2001-01-29 21:51:23 +08:00
|
|
|
}
|
2003-03-01 11:53:41 +08:00
|
|
|
|
|
|
|
return renderer_type;
|
2001-01-29 21:51:23 +08:00
|
|
|
}
|
|
|
|
|
2001-02-07 08:06:58 +08:00
|
|
|
static void
|
2003-03-01 11:53:41 +08:00
|
|
|
gimp_preview_renderer_drawable_class_init (GimpPreviewRendererDrawableClass *klass)
|
2001-01-29 21:51:23 +08:00
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
GimpPreviewRendererClass *renderer_class;
|
2001-01-30 01:54:02 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
renderer_class = GIMP_PREVIEW_RENDERER_CLASS (klass);
|
2001-01-29 21:51:23 +08:00
|
|
|
|
2001-10-17 19:33:43 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2001-02-20 06:54:12 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
renderer_class->render = gimp_preview_renderer_drawable_render;
|
2001-01-29 21:51:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-03-04 01:19:30 +08:00
|
|
|
gimp_preview_renderer_drawable_init (GimpPreviewRendererDrawable *renderer)
|
2001-01-29 21:51:23 +08:00
|
|
|
{
|
|
|
|
}
|
2001-02-07 10:37:49 +08:00
|
|
|
|
2001-02-08 04:35:18 +08:00
|
|
|
static void
|
2003-03-01 11:53:41 +08:00
|
|
|
gimp_preview_renderer_drawable_render (GimpPreviewRenderer *renderer,
|
|
|
|
GtkWidget *widget)
|
2001-02-07 10:37:49 +08:00
|
|
|
{
|
2001-02-20 06:54:12 +08:00
|
|
|
GimpDrawable *drawable;
|
2003-05-08 19:52:31 +08:00
|
|
|
GimpItem *item;
|
2001-02-20 06:54:12 +08:00
|
|
|
GimpImage *gimage;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gint preview_width;
|
|
|
|
gint preview_height;
|
|
|
|
gboolean scaling_up;
|
2003-03-07 00:47:34 +08:00
|
|
|
TempBuf *render_buf = NULL;
|
2001-02-20 06:54:12 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
drawable = GIMP_DRAWABLE (renderer->viewable);
|
2003-05-08 19:52:31 +08:00
|
|
|
item = GIMP_ITEM (drawable);
|
|
|
|
gimage = gimp_item_get_image (item);
|
2001-02-20 06:54:12 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
width = renderer->width;
|
|
|
|
height = renderer->height;
|
2001-02-20 06:54:12 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
if (gimage && ! renderer->is_popup)
|
2001-02-20 06:54:12 +08:00
|
|
|
{
|
|
|
|
width = MAX (1, ROUND ((((gdouble) width / (gdouble) gimage->width) *
|
2003-05-08 19:52:31 +08:00
|
|
|
(gdouble) item->width)));
|
2001-02-20 06:54:12 +08:00
|
|
|
height = MAX (1, ROUND ((((gdouble) height / (gdouble) gimage->height) *
|
2003-05-08 19:52:31 +08:00
|
|
|
(gdouble) item->height)));
|
2001-02-20 06:54:12 +08:00
|
|
|
|
2003-11-17 21:34:38 +08:00
|
|
|
gimp_viewable_calc_preview_size (item->width,
|
2003-05-08 19:52:31 +08:00
|
|
|
item->height,
|
2003-02-22 03:03:19 +08:00
|
|
|
width,
|
|
|
|
height,
|
2003-03-01 11:53:41 +08:00
|
|
|
renderer->dot_for_dot,
|
2003-02-22 03:03:19 +08:00
|
|
|
gimage->xresolution,
|
|
|
|
gimage->yresolution,
|
|
|
|
&preview_width,
|
|
|
|
&preview_height,
|
|
|
|
&scaling_up);
|
2001-02-20 06:54:12 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-11-17 21:34:38 +08:00
|
|
|
gimp_viewable_calc_preview_size (item->width,
|
2003-05-08 19:52:31 +08:00
|
|
|
item->height,
|
2003-02-22 03:03:19 +08:00
|
|
|
width,
|
|
|
|
height,
|
2003-03-01 11:53:41 +08:00
|
|
|
renderer->dot_for_dot,
|
2003-02-22 03:03:19 +08:00
|
|
|
gimage ? gimage->xresolution : 1.0,
|
|
|
|
gimage ? gimage->yresolution : 1.0,
|
|
|
|
&preview_width,
|
|
|
|
&preview_height,
|
|
|
|
&scaling_up);
|
2001-02-20 06:54:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (scaling_up)
|
|
|
|
{
|
|
|
|
TempBuf *temp_buf;
|
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
temp_buf = gimp_viewable_get_new_preview (renderer->viewable,
|
2003-05-08 19:52:31 +08:00
|
|
|
item->width,
|
|
|
|
item->height);
|
2001-02-20 06:54:12 +08:00
|
|
|
|
2003-03-07 00:47:34 +08:00
|
|
|
if (temp_buf)
|
|
|
|
{
|
|
|
|
render_buf = temp_buf_scale (temp_buf, preview_width, preview_height);
|
|
|
|
|
|
|
|
temp_buf_free (temp_buf);
|
|
|
|
}
|
2001-02-20 06:54:12 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
render_buf = gimp_viewable_get_new_preview (renderer->viewable,
|
2001-02-20 06:54:12 +08:00
|
|
|
preview_width,
|
|
|
|
preview_height);
|
|
|
|
}
|
|
|
|
|
2003-03-07 00:47:34 +08:00
|
|
|
if (render_buf)
|
2001-02-20 06:54:12 +08:00
|
|
|
{
|
2003-03-07 00:47:34 +08:00
|
|
|
if (gimage && ! renderer->is_popup)
|
|
|
|
{
|
2003-05-08 19:52:31 +08:00
|
|
|
if (item->offset_x != 0)
|
2003-03-07 00:47:34 +08:00
|
|
|
render_buf->x =
|
|
|
|
ROUND ((((gdouble) renderer->width / (gdouble) gimage->width) *
|
2003-05-08 19:52:31 +08:00
|
|
|
(gdouble) item->offset_x));
|
2003-03-07 00:47:34 +08:00
|
|
|
|
2003-05-08 19:52:31 +08:00
|
|
|
if (item->offset_y != 0)
|
2003-03-07 00:47:34 +08:00
|
|
|
render_buf->y =
|
|
|
|
ROUND ((((gdouble) renderer->height / (gdouble) gimage->height) *
|
2003-05-08 19:52:31 +08:00
|
|
|
(gdouble) item->offset_y));
|
2003-03-07 00:47:34 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (preview_width < width)
|
|
|
|
render_buf->x = (width - preview_width) / 2;
|
|
|
|
|
|
|
|
if (preview_height < height)
|
|
|
|
render_buf->y = (height - preview_height) / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_preview_renderer_render_buffer (renderer, render_buf, -1,
|
|
|
|
GIMP_PREVIEW_BG_CHECKS,
|
|
|
|
GIMP_PREVIEW_BG_CHECKS);
|
|
|
|
|
|
|
|
temp_buf_free (render_buf);
|
2001-02-20 06:54:12 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-03-07 00:47:34 +08:00
|
|
|
const gchar *stock_id;
|
2001-02-20 06:54:12 +08:00
|
|
|
|
2003-03-07 00:47:34 +08:00
|
|
|
stock_id = gimp_viewable_get_stock_id (renderer->viewable);
|
2001-02-20 06:54:12 +08:00
|
|
|
|
2003-03-07 00:47:34 +08:00
|
|
|
gimp_preview_renderer_default_render_stock (renderer, widget, stock_id);
|
|
|
|
}
|
2001-02-07 10:37:49 +08:00
|
|
|
}
|