libgimpwidgets/Makefile.am libgimpwidgets/gimpwidgets.h

2001-05-06  Sven Neumann  <sven@gimp.org>

	* libgimpwidgets/Makefile.am
	* libgimpwidgets/gimpwidgets.h
	* libgimpwidgets/gimpwidgetstypes.h
	* libgimpwidgets/gimpoffsetarea.c
	* libgimpwidgets/gimpoffsetarea.h: new widget GimpOffsetArea cut
	of the resize dialog, allows to interactively specify offsets when
	resizing images or drawables.

	* libgimpwidgets/gimppixmap.c: removed empty destroy method.

	* app/resize.c: use new GimpOffsetArea.
This commit is contained in:
Sven Neumann 2001-05-06 21:51:20 +00:00 committed by Sven Neumann
parent 10afaf8d1c
commit 163b18cda3
10 changed files with 679 additions and 642 deletions

View File

@ -1,3 +1,17 @@
2001-05-06 Sven Neumann <sven@gimp.org>
* libgimpwidgets/Makefile.am
* libgimpwidgets/gimpwidgets.h
* libgimpwidgets/gimpwidgetstypes.h
* libgimpwidgets/gimpoffsetarea.c
* libgimpwidgets/gimpoffsetarea.h: new widget GimpOffsetArea cut
of the resize dialog, allows to interactively specify offsets when
resizing images or drawables.
* libgimpwidgets/gimppixmap.c: removed empty destroy method.
* app/resize.c: use new GimpOffsetArea.
2001-05-06 Michael Natterer <mitch@gimp.org>
* libgimpwidgets/Makefile.am

View File

@ -38,9 +38,8 @@
#include "libgimp/gimpintl.h"
#define EVENT_MASK GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK
#define DRAWING_AREA_SIZE 200
#define TEXT_WIDTH 35
#define TEXT_WIDTH 35
typedef struct _ResizePrivate ResizePrivate;
@ -58,7 +57,7 @@ struct _ResizePrivate
/* offset frame */
GtkWidget *offset_se;
GtkWidget *drawing_area;
GtkWidget *offset_area;
/* resolution frame */
GtkWidget *printsize_se;
@ -73,7 +72,6 @@ struct _ResizePrivate
gint orig_x, orig_y;
};
static void resize_draw (Resize *resize);
static void unit_update (GtkWidget *widget,
gpointer data);
static gint resize_bound_off_x (Resize *resize,
@ -93,10 +91,12 @@ static void size_update (Resize *widget,
gdouble height,
gdouble ratio_x,
gdouble ratio_y);
static void offset_area_offsets_changed (GtkWidget *offset_area,
gint offset_x,
gint offset_y,
gpointer data);
static void offset_update (GtkWidget *widget,
gpointer data);
static gint resize_events (GtkWidget *widget,
GdkEvent *event);
static void printsize_update (GtkWidget *widget,
gpointer data);
static void resolution_callback (GtkWidget *widget,
@ -159,15 +159,6 @@ resize_widget_new (ResizeType type,
resize->offset_x = 0;
resize->offset_y = 0;
/* Get the image width and height variables, based on the gimage */
if (width > height)
private->ratio = (gdouble) DRAWING_AREA_SIZE / (gdouble) width;
else
private->ratio = (gdouble) DRAWING_AREA_SIZE / (gdouble) height;
private->area_width = (gint) (private->ratio * width);
private->area_height = (gint) (private->ratio * height);
/* dialog box */
{
const gchar *wmclass = NULL;
@ -493,7 +484,7 @@ resize_widget_new (ResizeType type,
gtk_widget_show (abox);
/* frame to hold drawing area */
/* frame to hold GimpOffsetArea */
abox = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
gtk_box_pack_start (GTK_BOX (vbox), abox, FALSE, FALSE, 0);
@ -501,18 +492,14 @@ resize_widget_new (ResizeType type,
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_container_add (GTK_CONTAINER (abox), frame);
private->drawing_area = gtk_drawing_area_new ();
gtk_drawing_area_size (GTK_DRAWING_AREA (private->drawing_area),
private->area_width, private->area_height);
gtk_widget_set_events (private->drawing_area, EVENT_MASK);
gtk_signal_connect (GTK_OBJECT (private->drawing_area), "event",
GTK_SIGNAL_FUNC (resize_events),
NULL);
gtk_object_set_user_data (GTK_OBJECT (private->drawing_area), resize);
gtk_container_add (GTK_CONTAINER (frame), private->drawing_area);
gtk_widget_show (private->drawing_area);
private->offset_area = gimp_offset_area_new (private->old_width,
private->old_height);
gtk_signal_connect (GTK_OBJECT (private->offset_area), "offsets_changed",
GTK_SIGNAL_FUNC (offset_area_offsets_changed),
resize);
gtk_container_add (GTK_CONTAINER (frame), private->offset_area);
gtk_widget_show (private->offset_area);
gtk_widget_show (frame);
gtk_widget_show (abox);
gtk_widget_show (vbox);
}
@ -669,98 +656,6 @@ resize_widget_new (ResizeType type,
return resize;
}
static void
resize_draw (Resize *resize)
{
GtkWidget *widget;
ResizePrivate *private;
gint aw, ah;
gint x, y;
gint w, h;
/* Only need to draw if it's a resize widget */
if (resize->type != ResizeWidget)
return;
private = (ResizePrivate *) resize->private_part;
widget = private->drawing_area;
/* If we're making the size larger */
if (private->old_width <= resize->width)
w = resize->width;
/* otherwise, if we're making the size smaller */
else
w = private->old_width * 2 - resize->width;
/* If we're making the size larger */
if (private->old_height <= resize->height)
h = resize->height;
/* otherwise, if we're making the size smaller */
else
h = private->old_height * 2 - resize->height;
if (w > h)
private->ratio = (gdouble) DRAWING_AREA_SIZE / (gdouble) w;
else
private->ratio = (gdouble) DRAWING_AREA_SIZE / (gdouble) h;
aw = (gint) (private->ratio * w);
ah = (gint) (private->ratio * h);
if (aw != private->area_width || ah != private->area_height)
{
private->area_width = aw;
private->area_height = ah;
gtk_drawing_area_size (GTK_DRAWING_AREA (private->drawing_area), aw, ah);
}
if (private->old_width <= resize->width)
x = private->ratio * resize->offset_x;
else
x = private->ratio * (resize->offset_x + private->old_width - resize->width);
if (private->old_height <= resize->height)
y = private->ratio * resize->offset_y;
else
y = private->ratio * (resize->offset_y + private->old_height - resize->height);
w = private->ratio * private->old_width;
h = private->ratio * private->old_height;
gdk_window_clear (private->drawing_area->window);
gtk_draw_shadow (widget->style, widget->window,
GTK_STATE_NORMAL, GTK_SHADOW_OUT,
x, y, w, h);
/* If we're making the size smaller */
if (private->old_width > resize->width ||
private->old_height > resize->height)
{
if (private->old_width > resize->width)
{
x = private->ratio * (private->old_width - resize->width);
w = private->ratio * resize->width;
}
else
{
x = -1;
w = aw + 2;
}
if (private->old_height > resize->height)
{
y = private->ratio * (private->old_height - resize->height);
h = private->ratio * resize->height;
}
else
{
y = -1;
h = ah + 2;
}
gdk_draw_rectangle (private->drawing_area->window,
widget->style->black_gc, 0,
x, y, w, h);
}
}
static gint
resize_bound_off_x (Resize *resize,
gint off_x)
@ -852,27 +747,18 @@ offset_update (GtkWidget *widget,
{
Resize *resize;
ResizePrivate *private;
gint offset_x;
gint offset_y;
resize = (Resize *) data;
private = (ResizePrivate *) resize->private_part;
offset_x =
RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (private->offset_se), 0));
offset_x = resize_bound_off_x (resize, offset_x);
resize->offset_x = resize_bound_off_x (resize,
RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (private->offset_se), 0)));
offset_y =
RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (private->offset_se), 1));
offset_y = resize_bound_off_y (resize, offset_y);
resize->offset_y = resize_bound_off_y (resize,
RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (private->offset_se), 1)));
if ((offset_x != resize->offset_x) ||
(offset_y != resize->offset_y))
{
resize->offset_x = offset_x;
resize->offset_y = offset_y;
resize_draw (resize);
}
gimp_offset_area_set_offsets (GIMP_OFFSET_AREA (private->offset_area),
resize->offset_x, resize->offset_y);
}
/*
@ -990,12 +876,15 @@ size_update (Resize *resize,
private = (ResizePrivate *) resize->private_part;
resize->width = (gint) (width + 0.5);
resize->width = (gint) (width + 0.5);
resize->height = (gint) (height + 0.5);
resize->ratio_x = ratio_x;
resize->ratio_y = ratio_y;
gimp_offset_area_set_size (GIMP_OFFSET_AREA (private->offset_area),
resize->width, resize->height);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->size_se), resize);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (private->size_se),
0, width);
@ -1009,25 +898,17 @@ size_update (Resize *resize,
gtk_adjustment_set_value (GTK_ADJUSTMENT (private->ratio_y_adj), ratio_y);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->ratio_x_adj), resize);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->ratio_y_adj), resize);
if (resize->type == ResizeWidget)
{
resize->offset_x = resize_bound_off_x (resize, resize->offset_x);
resize->offset_y = resize_bound_off_y (resize, resize->offset_y);
gimp_size_entry_set_refval_boundaries
(GIMP_SIZE_ENTRY (private->offset_se), 0,
MIN (0, resize->width - private->old_width),
MAX (0, resize->width - private->old_width));
(GIMP_SIZE_ENTRY (private->offset_se), 0,
MIN (0, resize->width - private->old_width),
MAX (0, resize->width - private->old_width));
gimp_size_entry_set_refval_boundaries
(GIMP_SIZE_ENTRY (private->offset_se), 1,
MIN (0, resize->height - private->old_height),
MAX (0, resize->height - private->old_height));
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (private->offset_se),
0, resize->offset_x);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (private->offset_se),
1, resize->offset_y);
(GIMP_SIZE_ENTRY (private->offset_se), 1,
MIN (0, resize->height - private->old_height),
MAX (0, resize->height - private->old_height));
}
if ((resize->type == ScaleWidget) && (resize->target == ResizeImage))
@ -1041,10 +922,30 @@ size_update (Resize *resize,
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->printsize_se),
resize);
}
resize_draw (resize);
}
static void
offset_area_offsets_changed (GtkWidget *offset_area,
gint offset_x,
gint offset_y,
gpointer data)
{
Resize *resize;
ResizePrivate *private;
resize = (Resize *) data;
private = (ResizePrivate *) resize->private_part;
resize->offset_x = offset_x;
resize->offset_y = offset_y;
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (private->offset_se),
0, resize->offset_x);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (private->offset_se),
1, resize->offset_y);
}
static void
printsize_update (GtkWidget *widget,
gpointer data)
@ -1195,62 +1096,6 @@ resolution_update (Resize *resize,
resize);
}
static gint
resize_events (GtkWidget *widget,
GdkEvent *event)
{
Resize *resize;
ResizePrivate *private;
gint dx, dy;
gint off_x, off_y;
resize = (Resize *) gtk_object_get_user_data (GTK_OBJECT (widget));
private = (ResizePrivate *) resize->private_part;
switch (event->type)
{
case GDK_EXPOSE:
resize_draw (resize);
break;
case GDK_BUTTON_PRESS:
gdk_pointer_grab (private->drawing_area->window, FALSE,
(GDK_BUTTON1_MOTION_MASK |
GDK_BUTTON_RELEASE_MASK),
NULL, NULL, event->button.time);
private->orig_x = resize->offset_x;
private->orig_y = resize->offset_y;
private->start_x = event->button.x;
private->start_y = event->button.y;
break;
case GDK_MOTION_NOTIFY:
/* X offset */
dx = event->motion.x - private->start_x;
off_x = private->orig_x + dx / private->ratio;
off_x = resize_bound_off_x (resize, off_x);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (private->offset_se),
0, off_x);
/* Y offset */
dy = event->motion.y - private->start_y;
off_y = private->orig_y + dy / private->ratio;
off_y = resize_bound_off_y (resize, off_y);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (private->offset_se),
1, off_y);
gtk_signal_emit_by_name (GTK_OBJECT (private->offset_se), "value_changed",
resize);
break;
case GDK_BUTTON_RELEASE:
gdk_pointer_ungrab (event->button.time);
break;
default:
break;
}
return FALSE;
}
/*** Resize sanity checks ***/
void
resize_scale_implement (ImageResize *image_scale)

View File

@ -38,9 +38,8 @@
#include "libgimp/gimpintl.h"
#define EVENT_MASK GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK
#define DRAWING_AREA_SIZE 200
#define TEXT_WIDTH 35
#define TEXT_WIDTH 35
typedef struct _ResizePrivate ResizePrivate;
@ -58,7 +57,7 @@ struct _ResizePrivate
/* offset frame */
GtkWidget *offset_se;
GtkWidget *drawing_area;
GtkWidget *offset_area;
/* resolution frame */
GtkWidget *printsize_se;
@ -73,7 +72,6 @@ struct _ResizePrivate
gint orig_x, orig_y;
};
static void resize_draw (Resize *resize);
static void unit_update (GtkWidget *widget,
gpointer data);
static gint resize_bound_off_x (Resize *resize,
@ -93,10 +91,12 @@ static void size_update (Resize *widget,
gdouble height,
gdouble ratio_x,
gdouble ratio_y);
static void offset_area_offsets_changed (GtkWidget *offset_area,
gint offset_x,
gint offset_y,
gpointer data);
static void offset_update (GtkWidget *widget,
gpointer data);
static gint resize_events (GtkWidget *widget,
GdkEvent *event);
static void printsize_update (GtkWidget *widget,
gpointer data);
static void resolution_callback (GtkWidget *widget,
@ -159,15 +159,6 @@ resize_widget_new (ResizeType type,
resize->offset_x = 0;
resize->offset_y = 0;
/* Get the image width and height variables, based on the gimage */
if (width > height)
private->ratio = (gdouble) DRAWING_AREA_SIZE / (gdouble) width;
else
private->ratio = (gdouble) DRAWING_AREA_SIZE / (gdouble) height;
private->area_width = (gint) (private->ratio * width);
private->area_height = (gint) (private->ratio * height);
/* dialog box */
{
const gchar *wmclass = NULL;
@ -493,7 +484,7 @@ resize_widget_new (ResizeType type,
gtk_widget_show (abox);
/* frame to hold drawing area */
/* frame to hold GimpOffsetArea */
abox = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
gtk_box_pack_start (GTK_BOX (vbox), abox, FALSE, FALSE, 0);
@ -501,18 +492,14 @@ resize_widget_new (ResizeType type,
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_container_add (GTK_CONTAINER (abox), frame);
private->drawing_area = gtk_drawing_area_new ();
gtk_drawing_area_size (GTK_DRAWING_AREA (private->drawing_area),
private->area_width, private->area_height);
gtk_widget_set_events (private->drawing_area, EVENT_MASK);
gtk_signal_connect (GTK_OBJECT (private->drawing_area), "event",
GTK_SIGNAL_FUNC (resize_events),
NULL);
gtk_object_set_user_data (GTK_OBJECT (private->drawing_area), resize);
gtk_container_add (GTK_CONTAINER (frame), private->drawing_area);
gtk_widget_show (private->drawing_area);
private->offset_area = gimp_offset_area_new (private->old_width,
private->old_height);
gtk_signal_connect (GTK_OBJECT (private->offset_area), "offsets_changed",
GTK_SIGNAL_FUNC (offset_area_offsets_changed),
resize);
gtk_container_add (GTK_CONTAINER (frame), private->offset_area);
gtk_widget_show (private->offset_area);
gtk_widget_show (frame);
gtk_widget_show (abox);
gtk_widget_show (vbox);
}
@ -669,98 +656,6 @@ resize_widget_new (ResizeType type,
return resize;
}
static void
resize_draw (Resize *resize)
{
GtkWidget *widget;
ResizePrivate *private;
gint aw, ah;
gint x, y;
gint w, h;
/* Only need to draw if it's a resize widget */
if (resize->type != ResizeWidget)
return;
private = (ResizePrivate *) resize->private_part;
widget = private->drawing_area;
/* If we're making the size larger */
if (private->old_width <= resize->width)
w = resize->width;
/* otherwise, if we're making the size smaller */
else
w = private->old_width * 2 - resize->width;
/* If we're making the size larger */
if (private->old_height <= resize->height)
h = resize->height;
/* otherwise, if we're making the size smaller */
else
h = private->old_height * 2 - resize->height;
if (w > h)
private->ratio = (gdouble) DRAWING_AREA_SIZE / (gdouble) w;
else
private->ratio = (gdouble) DRAWING_AREA_SIZE / (gdouble) h;
aw = (gint) (private->ratio * w);
ah = (gint) (private->ratio * h);
if (aw != private->area_width || ah != private->area_height)
{
private->area_width = aw;
private->area_height = ah;
gtk_drawing_area_size (GTK_DRAWING_AREA (private->drawing_area), aw, ah);
}
if (private->old_width <= resize->width)
x = private->ratio * resize->offset_x;
else
x = private->ratio * (resize->offset_x + private->old_width - resize->width);
if (private->old_height <= resize->height)
y = private->ratio * resize->offset_y;
else
y = private->ratio * (resize->offset_y + private->old_height - resize->height);
w = private->ratio * private->old_width;
h = private->ratio * private->old_height;
gdk_window_clear (private->drawing_area->window);
gtk_draw_shadow (widget->style, widget->window,
GTK_STATE_NORMAL, GTK_SHADOW_OUT,
x, y, w, h);
/* If we're making the size smaller */
if (private->old_width > resize->width ||
private->old_height > resize->height)
{
if (private->old_width > resize->width)
{
x = private->ratio * (private->old_width - resize->width);
w = private->ratio * resize->width;
}
else
{
x = -1;
w = aw + 2;
}
if (private->old_height > resize->height)
{
y = private->ratio * (private->old_height - resize->height);
h = private->ratio * resize->height;
}
else
{
y = -1;
h = ah + 2;
}
gdk_draw_rectangle (private->drawing_area->window,
widget->style->black_gc, 0,
x, y, w, h);
}
}
static gint
resize_bound_off_x (Resize *resize,
gint off_x)
@ -852,27 +747,18 @@ offset_update (GtkWidget *widget,
{
Resize *resize;
ResizePrivate *private;
gint offset_x;
gint offset_y;
resize = (Resize *) data;
private = (ResizePrivate *) resize->private_part;
offset_x =
RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (private->offset_se), 0));
offset_x = resize_bound_off_x (resize, offset_x);
resize->offset_x = resize_bound_off_x (resize,
RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (private->offset_se), 0)));
offset_y =
RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (private->offset_se), 1));
offset_y = resize_bound_off_y (resize, offset_y);
resize->offset_y = resize_bound_off_y (resize,
RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (private->offset_se), 1)));
if ((offset_x != resize->offset_x) ||
(offset_y != resize->offset_y))
{
resize->offset_x = offset_x;
resize->offset_y = offset_y;
resize_draw (resize);
}
gimp_offset_area_set_offsets (GIMP_OFFSET_AREA (private->offset_area),
resize->offset_x, resize->offset_y);
}
/*
@ -990,12 +876,15 @@ size_update (Resize *resize,
private = (ResizePrivate *) resize->private_part;
resize->width = (gint) (width + 0.5);
resize->width = (gint) (width + 0.5);
resize->height = (gint) (height + 0.5);
resize->ratio_x = ratio_x;
resize->ratio_y = ratio_y;
gimp_offset_area_set_size (GIMP_OFFSET_AREA (private->offset_area),
resize->width, resize->height);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->size_se), resize);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (private->size_se),
0, width);
@ -1009,25 +898,17 @@ size_update (Resize *resize,
gtk_adjustment_set_value (GTK_ADJUSTMENT (private->ratio_y_adj), ratio_y);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->ratio_x_adj), resize);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->ratio_y_adj), resize);
if (resize->type == ResizeWidget)
{
resize->offset_x = resize_bound_off_x (resize, resize->offset_x);
resize->offset_y = resize_bound_off_y (resize, resize->offset_y);
gimp_size_entry_set_refval_boundaries
(GIMP_SIZE_ENTRY (private->offset_se), 0,
MIN (0, resize->width - private->old_width),
MAX (0, resize->width - private->old_width));
(GIMP_SIZE_ENTRY (private->offset_se), 0,
MIN (0, resize->width - private->old_width),
MAX (0, resize->width - private->old_width));
gimp_size_entry_set_refval_boundaries
(GIMP_SIZE_ENTRY (private->offset_se), 1,
MIN (0, resize->height - private->old_height),
MAX (0, resize->height - private->old_height));
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (private->offset_se),
0, resize->offset_x);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (private->offset_se),
1, resize->offset_y);
(GIMP_SIZE_ENTRY (private->offset_se), 1,
MIN (0, resize->height - private->old_height),
MAX (0, resize->height - private->old_height));
}
if ((resize->type == ScaleWidget) && (resize->target == ResizeImage))
@ -1041,10 +922,30 @@ size_update (Resize *resize,
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->printsize_se),
resize);
}
resize_draw (resize);
}
static void
offset_area_offsets_changed (GtkWidget *offset_area,
gint offset_x,
gint offset_y,
gpointer data)
{
Resize *resize;
ResizePrivate *private;
resize = (Resize *) data;
private = (ResizePrivate *) resize->private_part;
resize->offset_x = offset_x;
resize->offset_y = offset_y;
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (private->offset_se),
0, resize->offset_x);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (private->offset_se),
1, resize->offset_y);
}
static void
printsize_update (GtkWidget *widget,
gpointer data)
@ -1195,62 +1096,6 @@ resolution_update (Resize *resize,
resize);
}
static gint
resize_events (GtkWidget *widget,
GdkEvent *event)
{
Resize *resize;
ResizePrivate *private;
gint dx, dy;
gint off_x, off_y;
resize = (Resize *) gtk_object_get_user_data (GTK_OBJECT (widget));
private = (ResizePrivate *) resize->private_part;
switch (event->type)
{
case GDK_EXPOSE:
resize_draw (resize);
break;
case GDK_BUTTON_PRESS:
gdk_pointer_grab (private->drawing_area->window, FALSE,
(GDK_BUTTON1_MOTION_MASK |
GDK_BUTTON_RELEASE_MASK),
NULL, NULL, event->button.time);
private->orig_x = resize->offset_x;
private->orig_y = resize->offset_y;
private->start_x = event->button.x;
private->start_y = event->button.y;
break;
case GDK_MOTION_NOTIFY:
/* X offset */
dx = event->motion.x - private->start_x;
off_x = private->orig_x + dx / private->ratio;
off_x = resize_bound_off_x (resize, off_x);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (private->offset_se),
0, off_x);
/* Y offset */
dy = event->motion.y - private->start_y;
off_y = private->orig_y + dy / private->ratio;
off_y = resize_bound_off_y (resize, off_y);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (private->offset_se),
1, off_y);
gtk_signal_emit_by_name (GTK_OBJECT (private->offset_se), "value_changed",
resize);
break;
case GDK_BUTTON_RELEASE:
gdk_pointer_ungrab (event->button.time);
break;
default:
break;
}
return FALSE;
}
/*** Resize sanity checks ***/
void
resize_scale_implement (ImageResize *image_scale)

View File

@ -38,9 +38,8 @@
#include "libgimp/gimpintl.h"
#define EVENT_MASK GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK
#define DRAWING_AREA_SIZE 200
#define TEXT_WIDTH 35
#define TEXT_WIDTH 35
typedef struct _ResizePrivate ResizePrivate;
@ -58,7 +57,7 @@ struct _ResizePrivate
/* offset frame */
GtkWidget *offset_se;
GtkWidget *drawing_area;
GtkWidget *offset_area;
/* resolution frame */
GtkWidget *printsize_se;
@ -73,7 +72,6 @@ struct _ResizePrivate
gint orig_x, orig_y;
};
static void resize_draw (Resize *resize);
static void unit_update (GtkWidget *widget,
gpointer data);
static gint resize_bound_off_x (Resize *resize,
@ -93,10 +91,12 @@ static void size_update (Resize *widget,
gdouble height,
gdouble ratio_x,
gdouble ratio_y);
static void offset_area_offsets_changed (GtkWidget *offset_area,
gint offset_x,
gint offset_y,
gpointer data);
static void offset_update (GtkWidget *widget,
gpointer data);
static gint resize_events (GtkWidget *widget,
GdkEvent *event);
static void printsize_update (GtkWidget *widget,
gpointer data);
static void resolution_callback (GtkWidget *widget,
@ -159,15 +159,6 @@ resize_widget_new (ResizeType type,
resize->offset_x = 0;
resize->offset_y = 0;
/* Get the image width and height variables, based on the gimage */
if (width > height)
private->ratio = (gdouble) DRAWING_AREA_SIZE / (gdouble) width;
else
private->ratio = (gdouble) DRAWING_AREA_SIZE / (gdouble) height;
private->area_width = (gint) (private->ratio * width);
private->area_height = (gint) (private->ratio * height);
/* dialog box */
{
const gchar *wmclass = NULL;
@ -493,7 +484,7 @@ resize_widget_new (ResizeType type,
gtk_widget_show (abox);
/* frame to hold drawing area */
/* frame to hold GimpOffsetArea */
abox = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
gtk_box_pack_start (GTK_BOX (vbox), abox, FALSE, FALSE, 0);
@ -501,18 +492,14 @@ resize_widget_new (ResizeType type,
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_container_add (GTK_CONTAINER (abox), frame);
private->drawing_area = gtk_drawing_area_new ();
gtk_drawing_area_size (GTK_DRAWING_AREA (private->drawing_area),
private->area_width, private->area_height);
gtk_widget_set_events (private->drawing_area, EVENT_MASK);
gtk_signal_connect (GTK_OBJECT (private->drawing_area), "event",
GTK_SIGNAL_FUNC (resize_events),
NULL);
gtk_object_set_user_data (GTK_OBJECT (private->drawing_area), resize);
gtk_container_add (GTK_CONTAINER (frame), private->drawing_area);
gtk_widget_show (private->drawing_area);
private->offset_area = gimp_offset_area_new (private->old_width,
private->old_height);
gtk_signal_connect (GTK_OBJECT (private->offset_area), "offsets_changed",
GTK_SIGNAL_FUNC (offset_area_offsets_changed),
resize);
gtk_container_add (GTK_CONTAINER (frame), private->offset_area);
gtk_widget_show (private->offset_area);
gtk_widget_show (frame);
gtk_widget_show (abox);
gtk_widget_show (vbox);
}
@ -669,98 +656,6 @@ resize_widget_new (ResizeType type,
return resize;
}
static void
resize_draw (Resize *resize)
{
GtkWidget *widget;
ResizePrivate *private;
gint aw, ah;
gint x, y;
gint w, h;
/* Only need to draw if it's a resize widget */
if (resize->type != ResizeWidget)
return;
private = (ResizePrivate *) resize->private_part;
widget = private->drawing_area;
/* If we're making the size larger */
if (private->old_width <= resize->width)
w = resize->width;
/* otherwise, if we're making the size smaller */
else
w = private->old_width * 2 - resize->width;
/* If we're making the size larger */
if (private->old_height <= resize->height)
h = resize->height;
/* otherwise, if we're making the size smaller */
else
h = private->old_height * 2 - resize->height;
if (w > h)
private->ratio = (gdouble) DRAWING_AREA_SIZE / (gdouble) w;
else
private->ratio = (gdouble) DRAWING_AREA_SIZE / (gdouble) h;
aw = (gint) (private->ratio * w);
ah = (gint) (private->ratio * h);
if (aw != private->area_width || ah != private->area_height)
{
private->area_width = aw;
private->area_height = ah;
gtk_drawing_area_size (GTK_DRAWING_AREA (private->drawing_area), aw, ah);
}
if (private->old_width <= resize->width)
x = private->ratio * resize->offset_x;
else
x = private->ratio * (resize->offset_x + private->old_width - resize->width);
if (private->old_height <= resize->height)
y = private->ratio * resize->offset_y;
else
y = private->ratio * (resize->offset_y + private->old_height - resize->height);
w = private->ratio * private->old_width;
h = private->ratio * private->old_height;
gdk_window_clear (private->drawing_area->window);
gtk_draw_shadow (widget->style, widget->window,
GTK_STATE_NORMAL, GTK_SHADOW_OUT,
x, y, w, h);
/* If we're making the size smaller */
if (private->old_width > resize->width ||
private->old_height > resize->height)
{
if (private->old_width > resize->width)
{
x = private->ratio * (private->old_width - resize->width);
w = private->ratio * resize->width;
}
else
{
x = -1;
w = aw + 2;
}
if (private->old_height > resize->height)
{
y = private->ratio * (private->old_height - resize->height);
h = private->ratio * resize->height;
}
else
{
y = -1;
h = ah + 2;
}
gdk_draw_rectangle (private->drawing_area->window,
widget->style->black_gc, 0,
x, y, w, h);
}
}
static gint
resize_bound_off_x (Resize *resize,
gint off_x)
@ -852,27 +747,18 @@ offset_update (GtkWidget *widget,
{
Resize *resize;
ResizePrivate *private;
gint offset_x;
gint offset_y;
resize = (Resize *) data;
private = (ResizePrivate *) resize->private_part;
offset_x =
RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (private->offset_se), 0));
offset_x = resize_bound_off_x (resize, offset_x);
resize->offset_x = resize_bound_off_x (resize,
RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (private->offset_se), 0)));
offset_y =
RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (private->offset_se), 1));
offset_y = resize_bound_off_y (resize, offset_y);
resize->offset_y = resize_bound_off_y (resize,
RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (private->offset_se), 1)));
if ((offset_x != resize->offset_x) ||
(offset_y != resize->offset_y))
{
resize->offset_x = offset_x;
resize->offset_y = offset_y;
resize_draw (resize);
}
gimp_offset_area_set_offsets (GIMP_OFFSET_AREA (private->offset_area),
resize->offset_x, resize->offset_y);
}
/*
@ -990,12 +876,15 @@ size_update (Resize *resize,
private = (ResizePrivate *) resize->private_part;
resize->width = (gint) (width + 0.5);
resize->width = (gint) (width + 0.5);
resize->height = (gint) (height + 0.5);
resize->ratio_x = ratio_x;
resize->ratio_y = ratio_y;
gimp_offset_area_set_size (GIMP_OFFSET_AREA (private->offset_area),
resize->width, resize->height);
gtk_signal_handler_block_by_data (GTK_OBJECT (private->size_se), resize);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (private->size_se),
0, width);
@ -1009,25 +898,17 @@ size_update (Resize *resize,
gtk_adjustment_set_value (GTK_ADJUSTMENT (private->ratio_y_adj), ratio_y);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->ratio_x_adj), resize);
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->ratio_y_adj), resize);
if (resize->type == ResizeWidget)
{
resize->offset_x = resize_bound_off_x (resize, resize->offset_x);
resize->offset_y = resize_bound_off_y (resize, resize->offset_y);
gimp_size_entry_set_refval_boundaries
(GIMP_SIZE_ENTRY (private->offset_se), 0,
MIN (0, resize->width - private->old_width),
MAX (0, resize->width - private->old_width));
(GIMP_SIZE_ENTRY (private->offset_se), 0,
MIN (0, resize->width - private->old_width),
MAX (0, resize->width - private->old_width));
gimp_size_entry_set_refval_boundaries
(GIMP_SIZE_ENTRY (private->offset_se), 1,
MIN (0, resize->height - private->old_height),
MAX (0, resize->height - private->old_height));
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (private->offset_se),
0, resize->offset_x);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (private->offset_se),
1, resize->offset_y);
(GIMP_SIZE_ENTRY (private->offset_se), 1,
MIN (0, resize->height - private->old_height),
MAX (0, resize->height - private->old_height));
}
if ((resize->type == ScaleWidget) && (resize->target == ResizeImage))
@ -1041,10 +922,30 @@ size_update (Resize *resize,
gtk_signal_handler_unblock_by_data (GTK_OBJECT (private->printsize_se),
resize);
}
resize_draw (resize);
}
static void
offset_area_offsets_changed (GtkWidget *offset_area,
gint offset_x,
gint offset_y,
gpointer data)
{
Resize *resize;
ResizePrivate *private;
resize = (Resize *) data;
private = (ResizePrivate *) resize->private_part;
resize->offset_x = offset_x;
resize->offset_y = offset_y;
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (private->offset_se),
0, resize->offset_x);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (private->offset_se),
1, resize->offset_y);
}
static void
printsize_update (GtkWidget *widget,
gpointer data)
@ -1195,62 +1096,6 @@ resolution_update (Resize *resize,
resize);
}
static gint
resize_events (GtkWidget *widget,
GdkEvent *event)
{
Resize *resize;
ResizePrivate *private;
gint dx, dy;
gint off_x, off_y;
resize = (Resize *) gtk_object_get_user_data (GTK_OBJECT (widget));
private = (ResizePrivate *) resize->private_part;
switch (event->type)
{
case GDK_EXPOSE:
resize_draw (resize);
break;
case GDK_BUTTON_PRESS:
gdk_pointer_grab (private->drawing_area->window, FALSE,
(GDK_BUTTON1_MOTION_MASK |
GDK_BUTTON_RELEASE_MASK),
NULL, NULL, event->button.time);
private->orig_x = resize->offset_x;
private->orig_y = resize->offset_y;
private->start_x = event->button.x;
private->start_y = event->button.y;
break;
case GDK_MOTION_NOTIFY:
/* X offset */
dx = event->motion.x - private->start_x;
off_x = private->orig_x + dx / private->ratio;
off_x = resize_bound_off_x (resize, off_x);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (private->offset_se),
0, off_x);
/* Y offset */
dy = event->motion.y - private->start_y;
off_y = private->orig_y + dy / private->ratio;
off_y = resize_bound_off_y (resize, off_y);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (private->offset_se),
1, off_y);
gtk_signal_emit_by_name (GTK_OBJECT (private->offset_se), "value_changed",
resize);
break;
case GDK_BUTTON_RELEASE:
gdk_pointer_ungrab (event->button.time);
break;
default:
break;
}
return FALSE;
}
/*** Resize sanity checks ***/
void
resize_scale_implement (ImageResize *image_scale)

View File

@ -42,6 +42,8 @@ libgimpwidgets_1_3_la_SOURCES = \
gimpfileselection.h \
gimphelpui.c \
gimphelpui.h \
gimpoffsetarea.c \
gimpoffsetarea.h \
gimppatheditor.c \
gimppatheditor.h \
gimppixmap.c \
@ -62,6 +64,7 @@ libgimpwidgetsinclude_HEADERS = \
gimpdialog.h \
gimpfileselection.h \
gimphelpui.h \
gimpoffsetarea.h \
gimppatheditor.h \
gimppixmap.h \
gimpquerybox.h \

View File

@ -0,0 +1,418 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpoffsetarea.c
* Copyright (C) 2001 Sven Neumann <sven@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 <stdio.h>
#include <gtk/gtk.h>
#include "gimpwidgetstypes.h"
#include "gimpoffsetarea.h"
#define DRAWING_AREA_SIZE 200
enum
{
OFFSETS_CHANGED,
LAST_SIGNAL
};
static void gimp_offset_area_destroy (GtkObject *object);
static void gimp_offset_area_resize (GimpOffsetArea *offset_area);
static gboolean gimp_offset_area_event (GtkWidget *widget,
GdkEvent *event);
static void gimp_offset_area_draw (GimpOffsetArea *offset_area);
static guint gimp_offset_area_signals[LAST_SIGNAL] = { 0 };
static GtkDrawingAreaClass *parent_class = NULL;
static void
gimp_offset_area_destroy (GtkObject *object)
{
GimpOffsetArea *offset_area = GIMP_OFFSET_AREA (object);
g_return_if_fail (offset_area != NULL);
if (GTK_OBJECT_CLASS (parent_class)->destroy)
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
static void
gimp_offset_area_class_init (GimpOffsetAreaClass *class)
{
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
object_class = (GtkObjectClass *) class;
widget_class = (GtkWidgetClass *) class;
parent_class = gtk_type_class (gtk_drawing_area_get_type ());
gimp_offset_area_signals[OFFSETS_CHANGED] =
gtk_signal_new ("offsets_changed",
GTK_RUN_FIRST,
object_class->type,
GTK_SIGNAL_OFFSET (GimpOffsetAreaClass,
offsets_changed),
gtk_marshal_NONE__INT_INT,
GTK_TYPE_NONE, 2,
GTK_TYPE_INT, GTK_TYPE_INT);
gtk_object_class_add_signals (object_class, gimp_offset_area_signals,
LAST_SIGNAL);
object_class->destroy = gimp_offset_area_destroy;
widget_class->event = gimp_offset_area_event;
}
static void
gimp_offset_area_init (GimpOffsetArea *offset_area)
{
offset_area->orig_width = 0;
offset_area->orig_height = 0;
offset_area->width = 0;
offset_area->height = 0;
offset_area->offset_x = 0;
offset_area->offset_y = 0;
offset_area->display_ratio_x = 1.0;
offset_area->display_ratio_y = 1.0;
gtk_widget_add_events (GTK_WIDGET (offset_area),
GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK);
}
GtkType
gimp_offset_area_get_type (void)
{
static guint offset_area_type = 0;
if (!offset_area_type)
{
GtkTypeInfo offset_area_info =
{
"GimpOffsetArea",
sizeof (GimpOffsetArea),
sizeof (GimpOffsetAreaClass),
(GtkClassInitFunc) gimp_offset_area_class_init,
(GtkObjectInitFunc) gimp_offset_area_init,
/* reserved_1 */ NULL,
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL
};
offset_area_type = gtk_type_unique (gtk_drawing_area_get_type (),
&offset_area_info);
}
return offset_area_type;
}
/**
* gimp_offset_area_new:
* @orig_width: the original width
* @orig_height: the original height
*
* Creates a new #GimpOffsetArea widget. A #GimpOffsetArea can be used
* when resizing an image or a drawable to allow the user to interactively
* specify the new offsets.
*
* Return value: the new #GimpOffsetArea widget.
**/
GtkWidget *
gimp_offset_area_new (gint orig_width,
gint orig_height)
{
GimpOffsetArea *offset_area;
g_return_val_if_fail (orig_width > 0, NULL);
g_return_val_if_fail (orig_height > 0, NULL);
offset_area = gtk_type_new (gimp_offset_area_get_type ());
offset_area->orig_width = offset_area->width = orig_width;
offset_area->orig_height = offset_area->height = orig_height;
gimp_offset_area_resize (offset_area);
return GTK_WIDGET (offset_area);
}
/**
* gimp_offset_area_set_size:
* @offset_area: a #GimpOffsetArea.
* @width: the new width
* @height: the new height
*
* Sets the size of the image/drawable displayed by the #GimpOffsetArea.
* If the offsets change as a result of this change, the %offsets_changed
* signal is emitted.
**/
void
gimp_offset_area_set_size (GimpOffsetArea *offset_area,
gint width,
gint height)
{
gint offset_x;
gint offset_y;
g_return_if_fail (offset_area != NULL);
g_return_if_fail (GIMP_IS_OFFSET_AREA (offset_area));
g_return_if_fail (width > 0 && height > 0);
if (offset_area->width != width || offset_area->height != height)
{
offset_area->width = width;
offset_area->height = height;
if (offset_area->orig_width <= offset_area->width)
offset_x = CLAMP (offset_area->offset_x,
0, offset_area->width - offset_area->orig_width);
else
offset_x = CLAMP (offset_area->offset_x,
offset_area->width - offset_area->orig_width, 0);
if (offset_area->orig_height <= offset_area->height)
offset_y = CLAMP (offset_area->offset_y,
0, offset_area->height - offset_area->orig_height);
else
offset_y = CLAMP (offset_area->offset_y,
offset_area->height - offset_area->orig_height, 0);
offset_area->offset_x = offset_x;
offset_area->offset_y = offset_y;
gimp_offset_area_resize (offset_area);
gtk_widget_queue_draw (GTK_WIDGET (offset_area));
if (offset_x != offset_area->offset_x ||
offset_y != offset_area->offset_y)
{
gtk_signal_emit (GTK_OBJECT (offset_area),
gimp_offset_area_signals[OFFSETS_CHANGED],
offset_area->offset_x, offset_area->offset_y);
}
}
}
/**
* gimp_offset_area_set_size:
* @offset_area: a #GimpOffsetArea.
* @width: the X offset
* @height: the Y offset
*
* Sets the offsets of the image/drawable displayed by the #GimpOffsetArea.
* It does not emit the %offsets_changed signal.
**/
void
gimp_offset_area_set_offsets (GimpOffsetArea *offset_area,
gint offset_x,
gint offset_y)
{
g_return_if_fail (offset_area != NULL);
g_return_if_fail (GIMP_IS_OFFSET_AREA (offset_area));
if (offset_area->offset_x != offset_x || offset_area->offset_y != offset_y)
{
if (offset_area->orig_width <= offset_area->width)
offset_area->offset_x =
CLAMP (offset_x, 0, offset_area->width - offset_area->orig_width);
else
offset_area->offset_x =
CLAMP (offset_x, offset_area->width - offset_area->orig_width, 0);
if (offset_area->orig_height <= offset_area->height)
offset_area->offset_y =
CLAMP (offset_y, 0, offset_area->height - offset_area->orig_height);
else
offset_area->offset_y =
CLAMP (offset_y, offset_area->height - offset_area->orig_height, 0);
gtk_widget_queue_draw (GTK_WIDGET (offset_area));
}
}
static void
gimp_offset_area_resize (GimpOffsetArea *offset_area)
{
gint width;
gint height;
gdouble ratio;
if (offset_area->orig_width == 0 || offset_area->orig_height == 0)
return;
if (offset_area->orig_width <= offset_area->width)
width = offset_area->width;
else
width = offset_area->orig_width * 2 - offset_area->width;
if (offset_area->orig_height <= offset_area->height)
height = offset_area->height;
else
height = offset_area->orig_height * 2 - offset_area->height;
ratio = (gdouble) DRAWING_AREA_SIZE / (gdouble) MAX (width, height);
width = ratio * (gdouble) width;
height = ratio * (gdouble) height;
gtk_drawing_area_size (GTK_DRAWING_AREA (offset_area), width, height);
}
static gboolean
gimp_offset_area_event (GtkWidget *widget,
GdkEvent *event)
{
static gint orig_offset_x = 0;
static gint orig_offset_y = 0;
static gint start_x = 0;
static gint start_y = 0;
GimpOffsetArea *offset_area = GIMP_OFFSET_AREA (widget);
GdkEventConfigure *conf_event;
gint offset_x;
gint offset_y;
if (offset_area->orig_width == 0 || offset_area->orig_height == 0)
return FALSE;
switch (event->type)
{
case GDK_CONFIGURE:
conf_event = (GdkEventConfigure *) event;
offset_area->display_ratio_x = (gdouble) conf_event->width /
((offset_area->orig_width <= offset_area->width) ?
offset_area->width :
offset_area->orig_width * 2 - offset_area->width);
offset_area->display_ratio_y = (gdouble) conf_event->height /
((offset_area->orig_height <= offset_area->height) ?
offset_area->height :
offset_area->orig_height * 2 - offset_area->height);
break;
case GDK_EXPOSE:
gimp_offset_area_draw (offset_area);
break;
case GDK_BUTTON_PRESS:
gdk_pointer_grab (widget->window, FALSE,
(GDK_BUTTON1_MOTION_MASK |
GDK_BUTTON_RELEASE_MASK),
NULL, NULL, event->button.time);
orig_offset_x = offset_area->offset_x;
orig_offset_y = offset_area->offset_y;
start_x = event->button.x;
start_y = event->button.y;
break;
case GDK_MOTION_NOTIFY:
offset_x = orig_offset_x +
(event->motion.x - start_x) / offset_area->display_ratio_x;
offset_y = orig_offset_y +
(event->motion.y - start_y) / offset_area->display_ratio_y;
if (offset_area->offset_x != offset_x ||
offset_area->offset_y != offset_y)
{
gimp_offset_area_set_offsets (offset_area, offset_x, offset_y);
gtk_signal_emit (GTK_OBJECT (offset_area),
gimp_offset_area_signals[OFFSETS_CHANGED],
offset_area->offset_x, offset_area->offset_y);
}
break;
case GDK_BUTTON_RELEASE:
gdk_pointer_ungrab (event->button.time);
start_x = start_y = 0;
break;
default:
break;
}
return FALSE;
}
static void
gimp_offset_area_draw (GimpOffsetArea *offset_area)
{
GtkWidget *widget = GTK_WIDGET (offset_area);
gint w, h;
gint x, y;
gdk_window_clear (widget->window);
x = offset_area->display_ratio_x *
((offset_area->orig_width <= offset_area->width) ?
offset_area->offset_x :
offset_area->offset_x + offset_area->orig_width - offset_area->width);
y = offset_area->display_ratio_y *
((offset_area->orig_height <= offset_area->height) ?
offset_area->offset_y :
offset_area->offset_y + offset_area->orig_height - offset_area->height);
w = offset_area->display_ratio_x * offset_area->orig_width;
h = offset_area->display_ratio_y * offset_area->orig_height;
gtk_draw_shadow (widget->style, widget->window,
GTK_STATE_NORMAL, GTK_SHADOW_OUT,
x, y, w, h);
if (offset_area->orig_width > offset_area->width ||
offset_area->orig_height > offset_area->height)
{
if (offset_area->orig_width > offset_area->width)
{
x = offset_area->display_ratio_x *
(offset_area->orig_width - offset_area->width);
w = offset_area->display_ratio_x * offset_area->width;
}
else
{
x = -1;
w = widget->allocation.width + 2;
}
if (offset_area->orig_height > offset_area->height)
{
y = offset_area->display_ratio_y *
(offset_area->orig_height - offset_area->height);
h = offset_area->display_ratio_y * offset_area->height;
}
else
{
y = -1;
h = widget->allocation.height + 2;
}
gdk_draw_rectangle (widget->window, widget->style->black_gc, 0,
x, y, w, h);
}
}

View File

@ -0,0 +1,80 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpoffsetarea.h
* Copyright (C) 2001 Sven Neumann <sven@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.
*/
#ifndef __GIMP_OFFSET_AREA_H__
#define __GIMP_OFFSET_AREA_H__
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* For information look into the C source or the html documentation */
#define GIMP_TYPE_OFFSET_AREA (gimp_offset_area_get_type ())
#define GIMP_OFFSET_AREA(obj) (GTK_CHECK_CAST ((obj), GIMP_TYPE_OFFSET_AREA, GimpOffsetArea))
#define GIMP_OFFSET_AREA_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GIMP_TYPE_OFFSET_AREA, GimpOffsetAreaClass))
#define GIMP_IS_OFFSET_AREA(obj) (GTK_CHECK_TYPE ((obj), GIMP_TYPE_OFFSET_AREA))
#define GIMP_IS_OFFSET_AREA_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_OFFSET_AREA))
typedef struct _GimpOffsetAreaClass GimpOffsetAreaClass;
struct _GimpOffsetArea
{
GtkDrawingArea parent_instance;
gint orig_width;
gint orig_height;
gint width;
gint height;
gint offset_x;
gint offset_y;
gdouble display_ratio_x;
gdouble display_ratio_y;
};
struct _GimpOffsetAreaClass
{
GtkDrawingAreaClass parent_class;
void (* offsets_changed) (GimpOffsetArea *offset_area,
gint offset_x,
gint offset_y);
};
GtkType gimp_offset_area_get_type (void);
GtkWidget * gimp_offset_area_new (gint orig_width,
gint orig_height);
void gimp_offset_area_set_size (GimpOffsetArea *offset_area,
gint width,
gint height);
void gimp_offset_area_set_offsets (GimpOffsetArea *offset_area,
gint offset_x,
gint offset_y);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __GIMP_OFFSET_AREA_H__ */

View File

@ -29,7 +29,6 @@
#include "gimppixmap.h"
static void gimp_pixmap_destroy (GtkObject *object);
static void gimp_pixmap_realize (GtkWidget *widget);
static void gimp_pixmap_create_from_xpm_d (GimpPixmap *pixmap);
@ -37,29 +36,15 @@ static void gimp_pixmap_create_from_xpm_d (GimpPixmap *pixmap);
static GtkPixmapClass *parent_class = NULL;
static void
gimp_pixmap_destroy (GtkObject *object)
{
GimpPixmap *pixmap = GIMP_PIXMAP (object);
g_return_if_fail (pixmap != NULL);
if (GTK_OBJECT_CLASS (parent_class)->destroy)
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
static void
gimp_pixmap_class_init (GimpPixmapClass *class)
{
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
object_class = (GtkObjectClass *) class;
widget_class = (GtkWidgetClass *) class;
parent_class = gtk_type_class (gtk_pixmap_get_type ());
object_class->destroy = gimp_pixmap_destroy;
widget_class->realize = gimp_pixmap_realize;
}

View File

@ -33,6 +33,7 @@
#include <libgimpwidgets/gimpdialog.h>
#include <libgimpwidgets/gimpfileselection.h>
#include <libgimpwidgets/gimphelpui.h>
#include <libgimpwidgets/gimpoffsetarea.h>
#include <libgimpwidgets/gimppatheditor.h>
#include <libgimpwidgets/gimppixmap.h>
#include <libgimpwidgets/gimpquerybox.h>

View File

@ -48,6 +48,7 @@ typedef struct _GimpButton GimpButton;
typedef struct _GimpChainButton GimpChainButton;
typedef struct _GimpColorArea GimpColorArea;
typedef struct _GimpColorButton GimpColorButton;
typedef struct _GimpOffsetArea GimpOffsetArea;
typedef struct _GimpPathEditor GimpPathEditor;
typedef struct _GimpPixmap GimpPixmap;
typedef struct _GimpSizeEntry GimpSizeEntry;