2005-09-20 06:58:16 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
|
|
*
|
|
|
|
* gimpzoompreview.c
|
|
|
|
* Copyright (C) 2005 David Odin <dindinx@gimp.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; 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 "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "gimpuitypes.h"
|
|
|
|
|
|
|
|
#include "gimp.h"
|
|
|
|
|
2006-02-07 23:52:53 +08:00
|
|
|
#include "gimpdrawablepreview.h"
|
2005-09-20 06:58:16 +08:00
|
|
|
#include "gimpzoompreview.h"
|
|
|
|
|
2005-11-22 19:50:29 +08:00
|
|
|
|
2006-02-26 08:55:35 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_DRAWABLE
|
|
|
|
};
|
|
|
|
|
2006-01-25 22:40:31 +08:00
|
|
|
typedef struct GimpZoomPreviewPrivate
|
2005-09-21 05:52:54 +08:00
|
|
|
{
|
|
|
|
GimpDrawable *drawable;
|
2005-10-03 02:00:49 +08:00
|
|
|
GimpZoomModel *model;
|
2005-09-21 05:52:54 +08:00
|
|
|
GdkRectangle extents;
|
2006-01-25 22:40:31 +08:00
|
|
|
} GimpZoomPreviewPrivate;
|
|
|
|
|
2006-02-26 08:55:35 +08:00
|
|
|
|
2006-01-25 22:40:31 +08:00
|
|
|
#define GIMP_ZOOM_PREVIEW_GET_PRIVATE(obj) \
|
|
|
|
((GimpZoomPreviewPrivate *) ((GimpZoomPreview *) (obj))->priv)
|
2005-09-21 05:52:54 +08:00
|
|
|
|
2006-02-26 08:55:35 +08:00
|
|
|
static GObject * gimp_zoom_preview_constructor (GType type,
|
2006-03-19 21:35:24 +08:00
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params);
|
2006-02-26 08:55:35 +08:00
|
|
|
|
|
|
|
static void gimp_zoom_preview_get_property (GObject *object,
|
2006-03-19 21:35:24 +08:00
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2006-02-26 08:55:35 +08:00
|
|
|
static void gimp_zoom_preview_set_property (GObject *object,
|
2006-03-19 21:35:24 +08:00
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2005-10-01 23:12:59 +08:00
|
|
|
static void gimp_zoom_preview_set_adjustments (GimpZoomPreview *preview,
|
|
|
|
gdouble old_factor,
|
|
|
|
gdouble new_factor);
|
|
|
|
static void gimp_zoom_preview_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation,
|
|
|
|
GimpZoomPreview *preview);
|
|
|
|
static void gimp_zoom_preview_style_set (GtkWidget *widget,
|
|
|
|
GtkStyle *prev_style);
|
2005-11-22 19:50:29 +08:00
|
|
|
static gboolean gimp_zoom_preview_scroll_event (GtkWidget *widget,
|
|
|
|
GdkEventScroll *event,
|
|
|
|
GimpZoomPreview *preview);
|
2005-10-01 23:12:59 +08:00
|
|
|
static void gimp_zoom_preview_draw (GimpPreview *preview);
|
|
|
|
static void gimp_zoom_preview_draw_buffer (GimpPreview *preview,
|
|
|
|
const guchar *buffer,
|
|
|
|
gint rowstride);
|
|
|
|
static void gimp_zoom_preview_draw_thumb (GimpPreview *preview,
|
|
|
|
GimpPreviewArea *area,
|
|
|
|
gint width,
|
|
|
|
gint height);
|
2006-02-06 19:07:48 +08:00
|
|
|
static void gimp_zoom_preview_set_cursor (GimpPreview *preview);
|
2005-09-20 06:58:16 +08:00
|
|
|
|
2006-02-26 08:55:35 +08:00
|
|
|
static void gimp_zoom_preview_set_drawable (GimpZoomPreview *preview,
|
2006-03-19 21:35:24 +08:00
|
|
|
GimpDrawable *drawable);
|
2006-02-26 08:55:35 +08:00
|
|
|
|
2006-02-06 19:07:48 +08:00
|
|
|
|
2006-01-25 22:40:31 +08:00
|
|
|
G_DEFINE_TYPE (GimpZoomPreview, gimp_zoom_preview, GIMP_TYPE_SCROLLED_PREVIEW)
|
2006-05-15 17:46:31 +08:00
|
|
|
|
2005-09-20 06:58:16 +08:00
|
|
|
#define parent_class gimp_zoom_preview_parent_class
|
|
|
|
|
2006-05-15 17:46:31 +08:00
|
|
|
|
2005-09-20 06:58:16 +08:00
|
|
|
static void
|
|
|
|
gimp_zoom_preview_class_init (GimpZoomPreviewClass *klass)
|
|
|
|
{
|
2005-09-21 05:52:54 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2005-09-20 06:58:16 +08:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
GimpPreviewClass *preview_class = GIMP_PREVIEW_CLASS (klass);
|
|
|
|
|
2006-02-26 08:55:35 +08:00
|
|
|
object_class->constructor = gimp_zoom_preview_constructor;
|
|
|
|
object_class->get_property = gimp_zoom_preview_get_property;
|
|
|
|
object_class->set_property = gimp_zoom_preview_set_property;
|
|
|
|
|
2005-09-20 06:58:16 +08:00
|
|
|
widget_class->style_set = gimp_zoom_preview_style_set;
|
|
|
|
|
|
|
|
preview_class->draw = gimp_zoom_preview_draw;
|
|
|
|
preview_class->draw_buffer = gimp_zoom_preview_draw_buffer;
|
|
|
|
preview_class->draw_thumb = gimp_zoom_preview_draw_thumb;
|
2006-02-06 19:07:48 +08:00
|
|
|
preview_class->set_cursor = gimp_zoom_preview_set_cursor;
|
2005-09-21 05:52:54 +08:00
|
|
|
|
|
|
|
g_type_class_add_private (object_class, sizeof (GimpZoomPreviewPrivate));
|
2006-02-26 08:55:35 +08:00
|
|
|
|
2006-04-06 19:28:02 +08:00
|
|
|
/**
|
|
|
|
* GimpZoomPreview:drawable:
|
|
|
|
*
|
|
|
|
* The drawable the #GimpZoomPreview is currently attached to.
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
*/
|
2006-02-26 08:55:35 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_DRAWABLE,
|
|
|
|
g_param_spec_pointer ("drawable", NULL, NULL,
|
2006-03-19 21:35:24 +08:00
|
|
|
GIMP_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
2005-09-20 06:58:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_zoom_preview_init (GimpZoomPreview *preview)
|
|
|
|
{
|
2006-01-25 22:40:31 +08:00
|
|
|
GimpZoomPreviewPrivate *priv;
|
2005-09-21 05:52:54 +08:00
|
|
|
GtkWidget *button_bar;
|
|
|
|
GtkWidget *button;
|
2005-09-28 10:46:06 +08:00
|
|
|
GtkWidget *box;
|
2006-01-25 22:40:31 +08:00
|
|
|
|
|
|
|
preview->priv = G_TYPE_INSTANCE_GET_PRIVATE (preview,
|
|
|
|
GIMP_TYPE_ZOOM_PREVIEW,
|
|
|
|
GimpZoomPreviewPrivate);
|
|
|
|
|
|
|
|
priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
|
2005-09-21 05:52:54 +08:00
|
|
|
|
2005-10-03 02:00:49 +08:00
|
|
|
priv->model = gimp_zoom_model_new ();
|
|
|
|
gimp_zoom_model_set_range (GIMP_ZOOM_MODEL (priv->model), 1.0, 256.0);
|
|
|
|
g_signal_connect_swapped (priv->model, "zoomed",
|
2005-09-20 06:58:16 +08:00
|
|
|
G_CALLBACK (gimp_zoom_preview_set_adjustments),
|
|
|
|
preview);
|
|
|
|
|
2005-09-28 19:02:02 +08:00
|
|
|
box = gimp_preview_get_controls (GIMP_PREVIEW (preview));
|
2005-09-28 10:46:06 +08:00
|
|
|
g_return_if_fail (GTK_IS_BOX (box));
|
|
|
|
|
|
|
|
button_bar = gtk_hbox_new (FALSE, 2);
|
|
|
|
gtk_box_pack_end (GTK_BOX (box), button_bar, FALSE, FALSE, 0);
|
2005-09-20 06:58:16 +08:00
|
|
|
gtk_widget_show (button_bar);
|
|
|
|
|
|
|
|
/* zoom out */
|
2005-10-03 02:00:49 +08:00
|
|
|
button = gimp_zoom_button_new (priv->model,
|
2005-09-26 05:22:39 +08:00
|
|
|
GIMP_ZOOM_OUT, GTK_ICON_SIZE_SMALL_TOOLBAR);
|
|
|
|
gtk_box_pack_start (GTK_BOX (button_bar), button, FALSE, FALSE, 0);
|
2005-09-20 06:58:16 +08:00
|
|
|
gtk_widget_show (button);
|
|
|
|
|
|
|
|
/* zoom in */
|
2005-10-03 02:00:49 +08:00
|
|
|
button = gimp_zoom_button_new (priv->model,
|
2005-09-26 05:22:39 +08:00
|
|
|
GIMP_ZOOM_IN, GTK_ICON_SIZE_SMALL_TOOLBAR);
|
|
|
|
gtk_box_pack_start (GTK_BOX (button_bar), button, FALSE, FALSE, 0);
|
2005-09-20 06:58:16 +08:00
|
|
|
gtk_widget_show (button);
|
|
|
|
|
|
|
|
g_signal_connect (GIMP_PREVIEW (preview)->area, "size-allocate",
|
|
|
|
G_CALLBACK (gimp_zoom_preview_size_allocate),
|
|
|
|
preview);
|
2005-11-22 19:50:29 +08:00
|
|
|
g_signal_connect (GIMP_PREVIEW (preview)->area, "scroll-event",
|
|
|
|
G_CALLBACK (gimp_zoom_preview_scroll_event),
|
|
|
|
preview);
|
2005-09-20 06:58:16 +08:00
|
|
|
|
|
|
|
g_object_set (GIMP_PREVIEW (preview)->area,
|
|
|
|
"check-size", gimp_check_size (),
|
|
|
|
"check-type", gimp_check_type (),
|
|
|
|
NULL);
|
2005-09-28 10:46:06 +08:00
|
|
|
|
|
|
|
gimp_scrolled_preview_set_policy (GIMP_SCROLLED_PREVIEW (preview),
|
|
|
|
GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS);
|
2005-09-20 06:58:16 +08:00
|
|
|
}
|
|
|
|
|
2006-02-26 08:55:35 +08:00
|
|
|
static GObject *
|
|
|
|
gimp_zoom_preview_constructor (GType type,
|
2006-03-19 21:35:24 +08:00
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params)
|
2006-02-26 08:55:35 +08:00
|
|
|
{
|
|
|
|
GObject *object;
|
|
|
|
|
|
|
|
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
|
|
|
|
|
|
|
|
gimp_zoom_preview_set_adjustments (GIMP_ZOOM_PREVIEW (object), 1.0, 1.0);
|
|
|
|
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_zoom_preview_get_property (GObject *object,
|
2006-03-19 21:35:24 +08:00
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2006-02-26 08:55:35 +08:00
|
|
|
{
|
|
|
|
GimpZoomPreview *preview = GIMP_ZOOM_PREVIEW (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_DRAWABLE:
|
|
|
|
g_value_set_pointer (value, gimp_zoom_preview_get_drawable (preview));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_zoom_preview_set_property (GObject *object,
|
2006-03-19 21:35:24 +08:00
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2006-02-26 08:55:35 +08:00
|
|
|
{
|
|
|
|
GimpZoomPreview *preview = GIMP_ZOOM_PREVIEW (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_DRAWABLE:
|
|
|
|
gimp_zoom_preview_set_drawable (preview,
|
2006-03-19 21:35:24 +08:00
|
|
|
g_value_get_pointer (value));
|
2006-02-26 08:55:35 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-20 06:58:16 +08:00
|
|
|
static void
|
2005-10-01 23:12:59 +08:00
|
|
|
gimp_zoom_preview_set_adjustments (GimpZoomPreview *preview,
|
|
|
|
gdouble old_factor,
|
|
|
|
gdouble new_factor)
|
2005-09-20 06:58:16 +08:00
|
|
|
{
|
2005-10-01 23:12:59 +08:00
|
|
|
GimpScrolledPreview *scrolled_preview = GIMP_SCROLLED_PREVIEW (preview);
|
|
|
|
GtkAdjustment *adj;
|
|
|
|
gdouble width;
|
|
|
|
gdouble height;
|
|
|
|
gdouble ratio;
|
2005-09-20 06:58:16 +08:00
|
|
|
|
2006-01-25 22:35:56 +08:00
|
|
|
gimp_scrolled_preview_freeze (scrolled_preview);
|
2005-11-22 20:09:17 +08:00
|
|
|
|
2005-10-01 23:12:59 +08:00
|
|
|
width = GIMP_PREVIEW (preview)->width;
|
|
|
|
height = GIMP_PREVIEW (preview)->height;
|
2005-11-22 19:50:29 +08:00
|
|
|
|
2005-10-01 23:12:59 +08:00
|
|
|
ratio = new_factor / old_factor;
|
2005-09-20 06:58:16 +08:00
|
|
|
|
2005-09-28 10:46:06 +08:00
|
|
|
adj = gtk_range_get_adjustment (GTK_RANGE (scrolled_preview->hscr));
|
|
|
|
adj->lower = 0;
|
2005-10-01 23:12:59 +08:00
|
|
|
adj->page_size = width;
|
|
|
|
adj->upper = width * new_factor;
|
|
|
|
adj->step_increment = new_factor;
|
|
|
|
adj->page_increment = MAX (width / 2.0, adj->step_increment);
|
2005-11-22 19:50:29 +08:00
|
|
|
adj->value = CLAMP ((adj->value + width / 2.0) * ratio
|
|
|
|
- width / 2.0,
|
|
|
|
adj->lower, adj->upper - width);
|
2005-09-28 10:46:06 +08:00
|
|
|
gtk_adjustment_changed (adj);
|
2005-10-01 20:01:27 +08:00
|
|
|
gtk_adjustment_value_changed (adj);
|
2005-09-28 10:46:06 +08:00
|
|
|
|
|
|
|
adj = gtk_range_get_adjustment (GTK_RANGE (scrolled_preview->vscr));
|
|
|
|
adj->lower = 0;
|
2005-10-01 23:12:59 +08:00
|
|
|
adj->page_size = height;
|
|
|
|
adj->upper = height * new_factor;
|
|
|
|
adj->step_increment = new_factor;
|
|
|
|
adj->page_increment = MAX (height / 2.0, adj->step_increment);
|
2005-11-22 19:50:29 +08:00
|
|
|
adj->value = CLAMP ((adj->value + height / 2.0) * ratio
|
|
|
|
- height / 2.0,
|
|
|
|
adj->lower, adj->upper - height);
|
2005-09-28 10:46:06 +08:00
|
|
|
gtk_adjustment_changed (adj);
|
2005-11-22 20:09:17 +08:00
|
|
|
gtk_adjustment_value_changed (adj);
|
2006-01-25 22:35:56 +08:00
|
|
|
|
|
|
|
gimp_scrolled_preview_thaw (scrolled_preview);
|
2005-09-20 06:58:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_zoom_preview_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation,
|
|
|
|
GimpZoomPreview *preview)
|
|
|
|
{
|
2005-10-01 23:12:59 +08:00
|
|
|
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
|
|
|
|
gdouble zoom_factor;
|
2005-11-22 19:50:29 +08:00
|
|
|
|
2005-09-21 05:52:54 +08:00
|
|
|
gint width = GIMP_PREVIEW (preview)->xmax - GIMP_PREVIEW (preview)->xmin;
|
|
|
|
gint height = GIMP_PREVIEW (preview)->ymax - GIMP_PREVIEW (preview)->ymin;
|
2005-09-20 06:58:16 +08:00
|
|
|
|
|
|
|
GIMP_PREVIEW (preview)->width = MIN (width, allocation->width);
|
|
|
|
GIMP_PREVIEW (preview)->height = MIN (height, allocation->height);
|
|
|
|
|
2005-10-03 02:00:49 +08:00
|
|
|
zoom_factor = gimp_zoom_model_get_factor (priv->model);
|
2005-10-01 23:12:59 +08:00
|
|
|
gimp_zoom_preview_set_adjustments (preview, zoom_factor, zoom_factor);
|
2005-09-20 06:58:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_zoom_preview_style_set (GtkWidget *widget,
|
|
|
|
GtkStyle *prev_style)
|
|
|
|
{
|
2005-09-21 05:52:54 +08:00
|
|
|
GimpPreview *preview = GIMP_PREVIEW (widget);
|
2005-11-22 19:50:29 +08:00
|
|
|
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
|
2005-09-21 05:52:54 +08:00
|
|
|
GimpDrawable *drawable = priv->drawable;
|
|
|
|
gint size;
|
|
|
|
gint width, height;
|
2005-10-09 21:54:03 +08:00
|
|
|
gint x1, y1;
|
|
|
|
gint x2, y2;
|
2005-09-20 06:58:16 +08:00
|
|
|
|
|
|
|
if (GTK_WIDGET_CLASS (parent_class)->style_set)
|
|
|
|
GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style);
|
|
|
|
|
2005-11-22 19:50:29 +08:00
|
|
|
gtk_widget_style_get (widget, "size", &size, NULL);
|
|
|
|
|
2006-02-07 23:36:17 +08:00
|
|
|
if (_gimp_drawable_preview_get_bounds (drawable, &x1, &y1, &x2, &y2))
|
2005-10-09 21:54:03 +08:00
|
|
|
{
|
|
|
|
width = x2 - x1;
|
|
|
|
height = y2 - y1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
width = gimp_drawable_width (drawable->drawable_id);
|
|
|
|
height = gimp_drawable_height (drawable->drawable_id);
|
|
|
|
}
|
2005-09-20 06:58:16 +08:00
|
|
|
|
|
|
|
if (width > height)
|
|
|
|
{
|
|
|
|
preview->width = MIN (width, size);
|
|
|
|
preview->height = (height * preview->width) / width;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
preview->height = MIN (height, size);
|
|
|
|
preview->width = (width * preview->height) / height;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_set_size_request (preview->area,
|
|
|
|
preview->width, preview->height);
|
|
|
|
}
|
|
|
|
|
2005-11-22 19:50:29 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_zoom_preview_scroll_event (GtkWidget *widget,
|
|
|
|
GdkEventScroll *event,
|
|
|
|
GimpZoomPreview *preview)
|
2005-09-20 06:58:16 +08:00
|
|
|
{
|
2005-11-22 19:50:29 +08:00
|
|
|
if (event->state & GDK_CONTROL_MASK)
|
|
|
|
{
|
|
|
|
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
|
2005-09-20 06:58:16 +08:00
|
|
|
|
2006-01-25 22:35:56 +08:00
|
|
|
gimp_scrolled_preview_freeze (GIMP_SCROLLED_PREVIEW (preview));
|
2005-11-22 20:09:17 +08:00
|
|
|
|
2005-11-22 19:50:29 +08:00
|
|
|
switch (event->direction)
|
|
|
|
{
|
|
|
|
case GDK_SCROLL_UP:
|
|
|
|
gimp_zoom_model_zoom (priv->model, GIMP_ZOOM_IN, 0.0);
|
|
|
|
break;
|
2005-09-20 06:58:16 +08:00
|
|
|
|
2005-11-22 19:50:29 +08:00
|
|
|
case GDK_SCROLL_DOWN:
|
|
|
|
gimp_zoom_model_zoom (priv->model, GIMP_ZOOM_OUT, 0.0);
|
|
|
|
break;
|
2005-09-20 06:58:16 +08:00
|
|
|
|
2005-11-22 19:50:29 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2005-11-22 20:09:17 +08:00
|
|
|
|
2006-01-25 22:35:56 +08:00
|
|
|
gimp_scrolled_preview_thaw (GIMP_SCROLLED_PREVIEW (preview));
|
2005-11-22 19:50:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2005-09-20 06:58:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-09-21 05:52:54 +08:00
|
|
|
gimp_zoom_preview_draw (GimpPreview *preview)
|
2005-09-20 06:58:16 +08:00
|
|
|
{
|
2005-11-22 19:50:29 +08:00
|
|
|
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
|
|
|
|
GimpDrawable *drawable;
|
2005-09-21 05:52:54 +08:00
|
|
|
guchar *data;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gint bpp;
|
|
|
|
gint src_x;
|
|
|
|
gint src_y;
|
|
|
|
gint src_width;
|
|
|
|
gint src_height;
|
|
|
|
gdouble zoom_factor;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_ZOOM_PREVIEW (preview));
|
|
|
|
|
|
|
|
drawable = priv->drawable;
|
2005-09-20 06:58:16 +08:00
|
|
|
if (!drawable)
|
|
|
|
return;
|
2005-11-22 19:50:29 +08:00
|
|
|
|
2005-10-03 02:00:49 +08:00
|
|
|
zoom_factor = gimp_zoom_model_get_factor (priv->model);
|
2005-09-20 06:58:16 +08:00
|
|
|
|
2005-09-21 05:52:54 +08:00
|
|
|
width = preview->width;
|
|
|
|
height = preview->height;
|
2005-11-22 20:09:17 +08:00
|
|
|
|
|
|
|
src_x = (priv->extents.x +
|
|
|
|
preview->xoff * priv->extents.width / width / zoom_factor);
|
|
|
|
src_y = (priv->extents.y +
|
|
|
|
preview->yoff * priv->extents.height / height / zoom_factor);
|
2005-09-21 05:52:54 +08:00
|
|
|
src_width = priv->extents.width / zoom_factor;
|
|
|
|
src_height = priv->extents.height / zoom_factor;
|
2005-09-20 06:58:16 +08:00
|
|
|
|
|
|
|
data = gimp_drawable_get_sub_thumbnail_data (drawable->drawable_id,
|
|
|
|
src_x, src_y,
|
|
|
|
src_width, src_height,
|
|
|
|
&width, &height, &bpp);
|
2005-11-22 20:09:17 +08:00
|
|
|
|
2005-09-21 05:52:54 +08:00
|
|
|
gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview->area),
|
2005-09-20 06:58:16 +08:00
|
|
|
0, 0, width, height,
|
|
|
|
gimp_drawable_type (drawable->drawable_id),
|
|
|
|
data, width * bpp);
|
|
|
|
g_free (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_zoom_preview_draw_buffer (GimpPreview *preview,
|
2005-09-21 05:52:54 +08:00
|
|
|
const guchar *buffer,
|
|
|
|
gint rowstride)
|
2005-09-20 06:58:16 +08:00
|
|
|
{
|
2005-09-21 05:52:54 +08:00
|
|
|
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
|
|
|
|
GimpDrawable *drawable = priv->drawable;
|
2005-11-22 19:50:29 +08:00
|
|
|
gint32 image_id;
|
2005-09-20 06:58:16 +08:00
|
|
|
|
|
|
|
image_id = gimp_drawable_get_image (drawable->drawable_id);
|
|
|
|
|
|
|
|
if (gimp_selection_is_empty (image_id))
|
|
|
|
{
|
|
|
|
gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview->area),
|
|
|
|
0, 0,
|
|
|
|
preview->width, preview->height,
|
|
|
|
gimp_drawable_type (drawable->drawable_id),
|
|
|
|
buffer,
|
|
|
|
rowstride);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-10-10 01:07:56 +08:00
|
|
|
guchar *sel;
|
|
|
|
guchar *src;
|
|
|
|
gint selection_id;
|
|
|
|
gint width, height;
|
|
|
|
gint bpp;
|
|
|
|
gint src_x;
|
|
|
|
gint src_y;
|
|
|
|
gint src_width;
|
|
|
|
gint src_height;
|
|
|
|
gdouble zoom_factor;
|
|
|
|
|
|
|
|
zoom_factor = gimp_zoom_model_get_factor (priv->model);
|
2005-09-20 06:58:16 +08:00
|
|
|
selection_id = gimp_image_get_selection (image_id);
|
|
|
|
|
|
|
|
width = preview->width;
|
|
|
|
height = preview->height;
|
|
|
|
|
2005-10-10 01:07:56 +08:00
|
|
|
src_x = priv->extents.x +
|
|
|
|
preview->xoff * priv->extents.width / width / zoom_factor;
|
|
|
|
src_y = priv->extents.y +
|
|
|
|
preview->yoff * priv->extents.height / height / zoom_factor;
|
|
|
|
src_width = priv->extents.width / zoom_factor;
|
|
|
|
src_height = priv->extents.height / zoom_factor;
|
|
|
|
|
|
|
|
src = gimp_drawable_get_sub_thumbnail_data (drawable->drawable_id,
|
|
|
|
src_x, src_y,
|
|
|
|
src_width, src_height,
|
|
|
|
&width, &height, &bpp);
|
|
|
|
sel = gimp_drawable_get_sub_thumbnail_data (selection_id,
|
|
|
|
src_x, src_y,
|
|
|
|
src_width, src_height,
|
|
|
|
&width, &height, &bpp);
|
2005-09-20 06:58:16 +08:00
|
|
|
|
|
|
|
gimp_preview_area_mask (GIMP_PREVIEW_AREA (preview->area),
|
|
|
|
0, 0, preview->width, preview->height,
|
|
|
|
gimp_drawable_type (drawable->drawable_id),
|
|
|
|
src, width * drawable->bpp,
|
|
|
|
buffer, rowstride,
|
|
|
|
sel, width);
|
|
|
|
|
|
|
|
g_free (sel);
|
|
|
|
g_free (src);
|
|
|
|
}
|
2005-10-10 01:07:56 +08:00
|
|
|
|
2005-09-20 06:58:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_zoom_preview_draw_thumb (GimpPreview *preview,
|
|
|
|
GimpPreviewArea *area,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
|
|
|
{
|
2005-09-21 05:52:54 +08:00
|
|
|
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
|
|
|
|
GimpDrawable *drawable = priv->drawable;
|
2005-10-09 21:54:03 +08:00
|
|
|
|
2006-02-07 23:36:17 +08:00
|
|
|
if (drawable)
|
|
|
|
_gimp_drawable_preview_area_draw_thumb (area, drawable, width, height);
|
2005-09-20 06:58:16 +08:00
|
|
|
}
|
|
|
|
|
2006-02-06 19:07:48 +08:00
|
|
|
static void
|
|
|
|
gimp_zoom_preview_set_cursor (GimpPreview *preview)
|
|
|
|
{
|
|
|
|
if (! GTK_WIDGET_REALIZED (preview->area))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (gimp_zoom_preview_get_factor (GIMP_ZOOM_PREVIEW (preview)) > 1.0)
|
|
|
|
{
|
|
|
|
gdk_window_set_cursor (preview->area->window,
|
|
|
|
GIMP_SCROLLED_PREVIEW (preview)->cursor_move);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gdk_window_set_cursor (preview->area->window, preview->default_cursor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-26 08:55:35 +08:00
|
|
|
static void
|
|
|
|
gimp_zoom_preview_set_drawable (GimpZoomPreview *preview,
|
2006-03-19 21:35:24 +08:00
|
|
|
GimpDrawable *drawable)
|
2005-09-20 06:58:16 +08:00
|
|
|
{
|
2006-02-26 08:55:35 +08:00
|
|
|
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
|
2005-09-21 05:52:54 +08:00
|
|
|
gint width, height;
|
|
|
|
gint max_width, max_height;
|
2005-10-09 21:54:03 +08:00
|
|
|
gint x1, y1;
|
|
|
|
gint x2, y2;
|
2005-09-20 06:58:16 +08:00
|
|
|
|
2005-09-21 05:52:54 +08:00
|
|
|
priv->drawable = drawable;
|
2005-10-05 21:50:09 +08:00
|
|
|
|
2006-02-07 23:36:17 +08:00
|
|
|
if (_gimp_drawable_preview_get_bounds (drawable, &x1, &y1, &x2, &y2))
|
2005-10-09 21:54:03 +08:00
|
|
|
{
|
|
|
|
width = x2 - x1;
|
|
|
|
height = y2 - y1;
|
|
|
|
|
|
|
|
priv->extents.x = x1;
|
|
|
|
priv->extents.y = y1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
width = gimp_drawable_width (drawable->drawable_id);
|
|
|
|
height = gimp_drawable_height (drawable->drawable_id);
|
2005-09-20 06:58:16 +08:00
|
|
|
|
2005-10-09 21:54:03 +08:00
|
|
|
priv->extents.x = 0;
|
|
|
|
priv->extents.y = 0;
|
|
|
|
}
|
2005-11-22 19:50:29 +08:00
|
|
|
|
2005-09-21 05:52:54 +08:00
|
|
|
priv->extents.width = width;
|
|
|
|
priv->extents.height = height;
|
2005-11-22 19:50:29 +08:00
|
|
|
|
2005-09-20 06:58:16 +08:00
|
|
|
if (width > height)
|
|
|
|
{
|
|
|
|
max_width = MIN (width, 512);
|
|
|
|
max_height = (height * max_width) / width;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
max_height = MIN (height, 512);
|
|
|
|
max_width = (width * max_height) / height;
|
|
|
|
}
|
2005-11-22 19:50:29 +08:00
|
|
|
|
2005-09-20 06:58:16 +08:00
|
|
|
gimp_preview_set_bounds (GIMP_PREVIEW (preview),
|
|
|
|
0, 0, max_width, max_height);
|
|
|
|
|
|
|
|
g_object_set (GIMP_PREVIEW (preview)->frame,
|
|
|
|
"ratio", (gdouble) width / (gdouble) height,
|
|
|
|
NULL);
|
2006-02-26 08:55:35 +08:00
|
|
|
}
|
2005-09-20 06:58:16 +08:00
|
|
|
|
2006-02-26 08:55:35 +08:00
|
|
|
/**
|
|
|
|
* gimp_zoom_preview_new:
|
|
|
|
* @drawable: a #GimpDrawable
|
|
|
|
*
|
|
|
|
* Creates a new #GimpZoomPreview widget for @drawable.
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
**/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_zoom_preview_new (GimpDrawable *drawable)
|
|
|
|
{
|
|
|
|
return g_object_new (GIMP_TYPE_ZOOM_PREVIEW,
|
2006-03-19 21:35:24 +08:00
|
|
|
"drawable", drawable,
|
|
|
|
NULL);
|
2005-09-20 06:58:16 +08:00
|
|
|
}
|
2005-09-21 05:52:54 +08:00
|
|
|
|
2005-10-05 21:50:09 +08:00
|
|
|
/**
|
|
|
|
* gimp_zoom_get_drawable:
|
|
|
|
* @preview: a #GimpZoomPreview widget
|
|
|
|
*
|
2006-04-06 19:28:02 +08:00
|
|
|
* Returns the #GimpDrawable the #GimpZoomPreview is attached to.
|
|
|
|
*
|
2005-10-05 21:50:09 +08:00
|
|
|
* Return Value: the #GimpDrawable that was passed to gimp_zoom_preview_new().
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
**/
|
2005-09-21 05:52:54 +08:00
|
|
|
GimpDrawable *
|
|
|
|
gimp_zoom_preview_get_drawable (GimpZoomPreview *preview)
|
|
|
|
{
|
|
|
|
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
|
|
|
|
|
|
|
|
return priv->drawable;
|
|
|
|
}
|
2005-10-03 02:00:49 +08:00
|
|
|
|
2005-10-05 21:50:09 +08:00
|
|
|
/**
|
|
|
|
* gimp_zoom_get_factor:
|
|
|
|
* @preview: a #GimpZoomPreview widget
|
|
|
|
*
|
2006-04-06 19:28:02 +08:00
|
|
|
* Returns the zoom factor of the zoom model the preview is currently using.
|
|
|
|
*
|
2005-10-05 21:50:09 +08:00
|
|
|
* Return Value: the current zoom factor
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
**/
|
2005-10-03 02:00:49 +08:00
|
|
|
gdouble
|
|
|
|
gimp_zoom_preview_get_factor (GimpZoomPreview *preview)
|
|
|
|
{
|
|
|
|
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
|
|
|
|
|
|
|
|
return gimp_zoom_model_get_factor (priv->model);
|
|
|
|
}
|
2005-11-22 19:50:29 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_zoom_preview_get_source:
|
2006-04-06 19:28:02 +08:00
|
|
|
* @preview: a #GimpZoomPreview widget
|
|
|
|
* @width: a pointer to an int where the current width of the zoom widget
|
|
|
|
* will be put.
|
|
|
|
* @height: a pointer to an int where the current width of the zoom widget
|
|
|
|
* will be put.
|
|
|
|
* @bpp: a pointer to an int where the bpp of the current drawable the zoom
|
|
|
|
* widget is using will be put.
|
2005-11-22 19:50:29 +08:00
|
|
|
*
|
2006-04-06 19:28:02 +08:00
|
|
|
* Returns the scaled image data of the part of the drawable the
|
|
|
|
* #GimpZoomPreview is currently showing, as a newly allocated array of guchar.
|
|
|
|
* This function also allow to get the current width, height and bpp of the
|
|
|
|
* #GimpZoomPreview.
|
2005-11-22 19:50:29 +08:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
*/
|
|
|
|
guchar *
|
|
|
|
gimp_zoom_preview_get_source (GimpZoomPreview *preview,
|
|
|
|
gint *width,
|
|
|
|
gint *height,
|
|
|
|
gint *bpp)
|
|
|
|
{
|
|
|
|
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
|
|
|
|
GimpPreview *gimp_preview = GIMP_PREVIEW (preview);
|
|
|
|
GimpDrawable *drawable = priv->drawable;
|
|
|
|
guchar *data;
|
|
|
|
gint src_x;
|
|
|
|
gint src_y;
|
|
|
|
gint src_width;
|
|
|
|
gint src_height;
|
|
|
|
gdouble zoom_factor;
|
|
|
|
|
|
|
|
zoom_factor = gimp_zoom_model_get_factor (priv->model);
|
|
|
|
|
|
|
|
*width = gimp_preview->width;
|
|
|
|
*height = gimp_preview->height;
|
|
|
|
|
|
|
|
src_x = priv->extents.x +
|
|
|
|
gimp_preview->xoff * priv->extents.width / *width / zoom_factor;
|
|
|
|
src_y = priv->extents.y +
|
|
|
|
gimp_preview->yoff * priv->extents.height / *height / zoom_factor;
|
|
|
|
|
|
|
|
src_width = priv->extents.width / zoom_factor;
|
|
|
|
src_height = priv->extents.height / zoom_factor;
|
|
|
|
|
|
|
|
data = gimp_drawable_get_sub_thumbnail_data (drawable->drawable_id,
|
|
|
|
src_x, src_y,
|
|
|
|
src_width, src_height,
|
|
|
|
width, height, bpp);
|
|
|
|
return data;
|
|
|
|
}
|