Commit 9af9bae0 authored by David Odin's avatar David Odin

added VOID__DOUBLE_DOUBLE marshaller.

* libgimpwidgets/gimpwidgetsmarshal.list: added VOID__DOUBLE_DOUBLE
 marshaller.

* libgimpwidgets/gimpzoommodel.[ch]: new signal: "zoomed", emitted
  when the zoom factor changes.  This signal have the old factor and the
  new factor as argument.

* libgimp/gimpzoompreview.c: use the "zoomed" signal instead of the
  "notify::value" one. This allow to use the old and new factors to keep
  the preview centered on the same point.
parent 95f8702d
2005-10-01 DindinX <dindinx@gimp.org>
* libgimpwidgets/gimpwidgetsmarshal.list: added VOID__DOUBLE_DOUBLE
marshaller.
* libgimpwidgets/gimpzoommodel.[ch]: new signal: "zoomed", emitted
when the zoom factor changes. This signal have the old factor and the
new factor as argument.
* libgimp/gimpzoompreview.c: use the "zoomed" signal instead of the
"notify::value" one. This allow to use the old and new factors to keep
the preview centered on the same point.
2005-10-01 DindinX <dindinx@gimp.org>
* libgimp/gimpzoompreview.c: call gtk_adjustment_value_changed in
......
......@@ -23,6 +23,15 @@ GimpZoomModel
</para>
<!-- ##### SIGNAL GimpZoomModel::zoomed ##### -->
<para>
</para>
@gimpzoommodel: the object which received the signal.
@arg1:
@arg2:
<!-- ##### ARG GimpZoomModel:fraction ##### -->
<para>
......
......@@ -47,25 +47,27 @@ struct _GimpZoomPreviewPrivate
#define GIMP_ZOOM_PREVIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GIMP_TYPE_ZOOM_PREVIEW, GimpZoomPreviewPrivate))
static void gimp_zoom_preview_set_adjustments (GimpZoomPreview *preview);
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);
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);
static gboolean gimp_zoom_preview_get_bounds (GimpDrawable *drawable,
gint *xmin,
gint *ymin,
gint *xmax,
gint *ymax);
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);
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);
static gboolean gimp_zoom_preview_get_bounds (GimpDrawable *drawable,
gint *xmin,
gint *ymin,
gint *xmax,
gint *ymax);
G_DEFINE_TYPE (GimpZoomPreview, gimp_zoom_preview,
GIMP_TYPE_SCROLLED_PREVIEW)
......@@ -99,7 +101,7 @@ gimp_zoom_preview_init (GimpZoomPreview *preview)
priv->zoom = gimp_zoom_model_new ();
gimp_zoom_model_set_range (GIMP_ZOOM_MODEL (priv->zoom), 1.0, 256.0);
g_signal_connect_swapped (priv->zoom, "notify::value",
g_signal_connect_swapped (priv->zoom, "zoomed",
G_CALLBACK (gimp_zoom_preview_set_adjustments),
preview);
......@@ -148,37 +150,41 @@ gimp_zoom_preview_init (GimpZoomPreview *preview)
}
static void
gimp_zoom_preview_set_adjustments (GimpZoomPreview *preview)
gimp_zoom_preview_set_adjustments (GimpZoomPreview *preview,
gdouble old_factor,
gdouble new_factor)
{
GimpScrolledPreview *scrolled_preview;
GtkAdjustment *adj;
gdouble zoom_factor;
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
GimpScrolledPreview *scrolled_preview = GIMP_SCROLLED_PREVIEW (preview);
GtkAdjustment *adj;
gdouble width;
gdouble height;
gdouble ratio;
scrolled_preview = GIMP_SCROLLED_PREVIEW (preview);
zoom_factor = gimp_zoom_model_get_factor (priv->zoom);
width = GIMP_PREVIEW (preview)->width;
height = GIMP_PREVIEW (preview)->height;
ratio = new_factor / old_factor;
adj = gtk_range_get_adjustment (GTK_RANGE (scrolled_preview->hscr));
adj->lower = 0;
adj->page_size = GIMP_PREVIEW (preview)->width;
adj->upper = GIMP_PREVIEW (preview)->width * zoom_factor;
adj->step_increment = 1.0;
adj->page_increment = MAX (adj->page_size / 2.0, adj->step_increment);
adj->value = CLAMP (adj->value,
adj->page_size = width;
adj->upper = width * new_factor;
adj->step_increment = new_factor;
adj->page_increment = MAX (width / 2.0, adj->step_increment);
adj->value = CLAMP ((adj->value + width / 2.0) * ratio - width / 2.0,
adj->lower,
adj->upper - adj->page_size);
adj->upper - width);
gtk_adjustment_changed (adj);
gtk_adjustment_value_changed (adj);
adj = gtk_range_get_adjustment (GTK_RANGE (scrolled_preview->vscr));
adj->lower = 0;
adj->page_size = GIMP_PREVIEW (preview)->height;
adj->upper = GIMP_PREVIEW (preview)->height * zoom_factor;
adj->step_increment = 1.0;
adj->page_increment = MAX (adj->page_size / 2.0, adj->step_increment);
adj->value = CLAMP (adj->value,
adj->page_size = height;
adj->upper = height * new_factor;
adj->step_increment = new_factor;
adj->page_increment = MAX (height / 2.0, adj->step_increment);
adj->value = CLAMP ((adj->value + height / 2.0) *ratio - height / 2.0,
adj->lower,
adj->upper - adj->page_size);
adj->upper - height);
gtk_adjustment_changed (adj);
gtk_adjustment_value_changed (adj);
......@@ -190,13 +196,16 @@ gimp_zoom_preview_size_allocate (GtkWidget *widget,
GtkAllocation *allocation,
GimpZoomPreview *preview)
{
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
gdouble zoom_factor;
gint width = GIMP_PREVIEW (preview)->xmax - GIMP_PREVIEW (preview)->xmin;
gint height = GIMP_PREVIEW (preview)->ymax - GIMP_PREVIEW (preview)->ymin;
GIMP_PREVIEW (preview)->width = MIN (width, allocation->width);
GIMP_PREVIEW (preview)->height = MIN (height, allocation->height);
gimp_zoom_preview_set_adjustments (preview);
zoom_factor = gimp_zoom_model_get_factor (priv->zoom);
gimp_zoom_preview_set_adjustments (preview, zoom_factor, zoom_factor);
}
static void
......@@ -483,7 +492,7 @@ gimp_zoom_preview_new (GimpDrawable *drawable)
"ratio", (gdouble) width / (gdouble) height,
NULL);
gimp_zoom_preview_set_adjustments (preview);
gimp_zoom_preview_set_adjustments (preview, 1.0, 1.0);
return GTK_WIDGET (preview);
}
......
......@@ -29,5 +29,6 @@ VOID: OBJECT, INT
VOID: POINTER, POINTER
VOID: STRING, FLAGS
VOID: STRING, INT
VOID: DOUBLE, DOUBLE
BOOLEAN: POINTER
......@@ -30,12 +30,19 @@
#include "libgimpmath/gimpmath.h"
#include "gimphelpui.h"
#include "gimpwidgetsmarshal.h"
#include "gimpzoommodel.h"
#define ZOOM_MIN (1.0 / 256.0)
#define ZOOM_MAX (256.0)
enum
{
ZOOMED,
LAST_SIGNAL
};
enum
{
PROP_0,
......@@ -66,15 +73,34 @@ static void gimp_zoom_model_get_property (GObject *object,
GValue *value,
GParamSpec *pspec);
static guint zoom_model_signals[LAST_SIGNAL] = { 0, };
G_DEFINE_TYPE (GimpZoomModel, gimp_zoom_model, G_TYPE_OBJECT);
#define parent_class gimp_zoom_model_parent_class
static void
gimp_zoom_model_class_init (GimpZoomModelClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
/**
* GimpZoomModel::zoomed:
* @model: the object that received the signal
* @old_factor: the zoom factor before it changes
* @new_factor: the zoom factor after it has changed.
*
* Emitted the zoom factor of the zoom model changes.
*/
zoom_model_signals[ZOOMED] =
g_signal_new ("zoomed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GimpZoomModelClass,
zoomed),
NULL, NULL,
_gimp_widgets_marshal_VOID__DOUBLE_DOUBLE,
G_TYPE_NONE, 2,
G_TYPE_DOUBLE, G_TYPE_DOUBLE);
object_class->set_property = gimp_zoom_model_set_property;
object_class->get_property = gimp_zoom_model_get_property;
......@@ -129,7 +155,9 @@ gimp_zoom_model_set_property (GObject *object,
GParamSpec *pspec)
{
GimpZoomModelPrivate *priv = GIMP_ZOOM_MODEL_GET_PRIVATE (object);
gdouble previous_value;
previous_value = priv->value;
g_object_freeze_notify (object);
switch (property_id)
......@@ -137,6 +165,7 @@ gimp_zoom_model_set_property (GObject *object,
case PROP_VALUE:
priv->value = g_value_get_double (value);
g_object_notify (object, "value");
g_object_notify (object, "fraction");
g_object_notify (object, "percentage");
break;
......@@ -164,6 +193,11 @@ gimp_zoom_model_set_property (GObject *object,
}
g_object_thaw_notify (object);
if (priv->value != previous_value)
{
g_signal_emit (object, zoom_model_signals[ZOOMED],
0, previous_value, priv->value);
}
}
static void
......
......@@ -45,6 +45,10 @@ struct _GimpZoomModelClass
{
GObjectClass parent_class;
void (* zoomed) (GimpZoomModel *model,
gdouble old_factor,
gdouble new_factor);
/* Padding for future expansion */
void (* _gimp_reserved1) (void);
void (* _gimp_reserved2) (void);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment