mirror of
https://gitlab.gnome.org/GNOME/gimp
synced 2024-10-22 20:41:43 +00:00
0614aa5329
2003-02-27 Michael Natterer <mitch@gimp.org> * app/core/gimpviewable.[ch]: added virtual function get_popup_size() which returns a boolean indicating if a popup is needed and its size. * app/core/gimpbrush.c * app/core/gimpbrushpipe.c * app/core/gimpbuffer.c * app/core/gimpdrawable-preview.[ch] * app/core/gimpdrawable.c * app/core/gimpgradient.c * app/core/gimpimage.c * app/core/gimppalette.c * app/core/gimppattern.c * app/core/gimpundo.c: implement it. * app/widgets/gimppreview.[ch]: removed virtual functions needs_popup() and create_popup(). Removed the code which creates the popup and the popup members of the GimpPreview struct. * app/widgets/gimppreview-popup.[ch]: new files providing the utility function gimp_preview_popup_show() which can show popups from any widget, not just from a GimpPreview. Checks if a popup is needed using gimp_viewable_get_popup_size(). * app/widgets/gimpcellrendererviewable.c: show popups here too. * app/widgets/gimpbrushpreview.c * app/widgets/gimpbufferpreview.c * app/widgets/gimpdrawablepreview.c * app/widgets/gimpimagepreview.c: removed needs_popup() and create_popup() implementations. * app/widgets/gimpnavigationpreview.c: removed empty render() implementation. * app/widgets/gimpundoeditor.c: use a tree instead of a list view. * app/widgets/gimpgradientpreview.[ch] * app/widgets/gimppalettepreview.[ch] * app/widgets/gimppatternpreview.[ch]: removed because they only implemented the removed popup functions. * app/widgets/Makefile.am * app/widgets/widgets-types.h * app/widgets/gimpmenuitem.c * app/widgets/gimppreview-utils.c: changed accordingly
157 lines
4.4 KiB
C
157 lines
4.4 KiB
C
/* The GIMP -- an image manipulation program
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
*
|
|
* GimpImagePreview Widget
|
|
* Copyright (C) 2001 Michael Natterer <mitch@gimp.org>
|
|
*
|
|
* 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>
|
|
|
|
#include "widgets-types.h"
|
|
|
|
#include "base/temp-buf.h"
|
|
|
|
#include "core/gimpimage.h"
|
|
|
|
#include "gimpimagepreview.h"
|
|
|
|
|
|
static void gimp_image_preview_class_init (GimpImagePreviewClass *klass);
|
|
static void gimp_image_preview_init (GimpImagePreview *preview);
|
|
|
|
static void gimp_image_preview_render (GimpPreview *preview);
|
|
|
|
|
|
static GimpPreviewClass *parent_class = NULL;
|
|
|
|
|
|
GType
|
|
gimp_image_preview_get_type (void)
|
|
{
|
|
static GType preview_type = 0;
|
|
|
|
if (! preview_type)
|
|
{
|
|
static const GTypeInfo preview_info =
|
|
{
|
|
sizeof (GimpImagePreviewClass),
|
|
NULL, /* base_init */
|
|
NULL, /* base_finalize */
|
|
(GClassInitFunc) gimp_image_preview_class_init,
|
|
NULL, /* class_finalize */
|
|
NULL, /* class_data */
|
|
sizeof (GimpImagePreview),
|
|
0, /* n_preallocs */
|
|
(GInstanceInitFunc) gimp_image_preview_init,
|
|
};
|
|
|
|
preview_type = g_type_register_static (GIMP_TYPE_PREVIEW,
|
|
"GimpImagePreview",
|
|
&preview_info, 0);
|
|
}
|
|
|
|
return preview_type;
|
|
}
|
|
|
|
static void
|
|
gimp_image_preview_class_init (GimpImagePreviewClass *klass)
|
|
{
|
|
GimpPreviewClass *preview_class;
|
|
|
|
preview_class = GIMP_PREVIEW_CLASS (klass);
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
preview_class->render = gimp_image_preview_render;
|
|
}
|
|
|
|
static void
|
|
gimp_image_preview_init (GimpImagePreview *preview)
|
|
{
|
|
preview->channel = -1;
|
|
}
|
|
|
|
static void
|
|
gimp_image_preview_render (GimpPreview *preview)
|
|
{
|
|
GimpImage *gimage;
|
|
gint width;
|
|
gint height;
|
|
gint preview_width;
|
|
gint preview_height;
|
|
gboolean scaling_up;
|
|
TempBuf *render_buf;
|
|
|
|
gimage = GIMP_IMAGE (preview->viewable);
|
|
|
|
width = preview->width;
|
|
height = preview->height;
|
|
|
|
gimp_viewable_calc_preview_size (preview->viewable,
|
|
gimage->width,
|
|
gimage->height,
|
|
width,
|
|
height,
|
|
preview->dot_for_dot,
|
|
gimage->xresolution,
|
|
gimage->yresolution,
|
|
&preview_width,
|
|
&preview_height,
|
|
&scaling_up);
|
|
|
|
if (scaling_up)
|
|
{
|
|
TempBuf *temp_buf;
|
|
|
|
temp_buf = gimp_viewable_get_new_preview (preview->viewable,
|
|
gimage->width,
|
|
gimage->height);
|
|
render_buf = temp_buf_scale (temp_buf, preview_width, preview_height);
|
|
|
|
temp_buf_free (temp_buf);
|
|
}
|
|
else
|
|
{
|
|
render_buf = gimp_viewable_get_new_preview (preview->viewable,
|
|
preview_width,
|
|
preview_height);
|
|
}
|
|
|
|
/* xresolution != yresolution */
|
|
if (preview_width > width || preview_height > height)
|
|
{
|
|
TempBuf *temp_buf;
|
|
|
|
temp_buf = temp_buf_scale (render_buf, width, height);
|
|
|
|
temp_buf_free (render_buf);
|
|
render_buf = temp_buf;
|
|
}
|
|
|
|
if (preview_width < width) render_buf->x = (width - preview_width) / 2;
|
|
if (preview_height < height) render_buf->y = (height - preview_height) / 2;
|
|
|
|
gimp_preview_render_preview (preview, render_buf,
|
|
GIMP_IMAGE_PREVIEW (preview)->channel,
|
|
GIMP_PREVIEW_BG_CHECKS,
|
|
GIMP_PREVIEW_BG_WHITE);
|
|
|
|
temp_buf_free (render_buf);
|
|
}
|