gtk/demos/testpixbuf-scale.c
Havoc Pennington 7a4c689387 Some updates
2000-10-18  Havoc Pennington  <hp@redhat.com>

	* gtk/gtk-sections.txt: Some updates

	* gdk/gdk-sections.txt: remove GdkPixbufAlphaMode

	* gdk-pixbuf/gdk-pixbuf-sections.txt: Add new API, remove
	GdkPixbufClass/GdkAnimationClass since those are private

	* gdk-pixbuf/Makefile.am (IGNORE_HFILES): ignore more headers

2000-10-18  Havoc Pennington  <hp@redhat.com>

	* gtk/gtktextiter.c (gtk_text_iter_forward_to_newline): Fix a bug
	where any number of empty lines would get skipped

	* gtk/gtktextiter.h: Remove padding from GtkTextIter; live on the
	edge.

	* gtk/gtktextiter.c (gtk_text_iter_make_surreal): enhance the
	warning about invalid iterators (explain more thoroughly)
	(gtk_text_iter_in_region): rename gtk_text_iter_in_range

	* gtk/gtktextview.c (FOCUS_EDGE_WIDTH): Make focus rectangle less
	big

	* demos/*.c: Add error handling

	* gtk/gtktextbuffer.c: don't modify const iterators

	* gtk/gdk-pixbuf-loader.c: Add full error handling here

	* gtk/gtkimage.c (gtk_image_set_from_file): ignore errors
	on file load

	* gtk/gtkiconfactory.c: Update to reflect addition of error
	handling to gdk-pixbuf loaders

2000-10-16  Havoc Pennington  <hp@redhat.com>

	* gdk-pixbuf-io.c (gdk_pixbuf_get_module)
	(gdk_pixbuf_get_named_module) (gdk_pixbuf_load_module):
	add error reporting here also

	* make-inline-pixbuf.c (main): use GError

	* io-xpm.c: include unistd.h

	* gdk-pixbuf-util.c: include string.h

	* io-*.c: add error reporting

	* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file): add
	error reporting

	* gdk-pixbuf-io.c (gdk_pixbuf_new_from_file): Add error reporting

	* gdk-pixbuf-io.h: Add GError** to load_increment and load
	methods

	* gdk-pixbuf-io.c (gdk_pixbuf_save) (gdk_pixbuf_savev): return
	a G_FILE_ERROR if we fail to write or close the file.

	* gdk-pixbuf.h: remove GDK_PIXBUF_ERROR_IO, instead we'll use
	G_FILE_ERROR_*. Rename enum to GdkPixbufError, properly following
	the GError naming rules. Add GError** to load functions.
2000-10-18 18:42:54 +00:00

164 lines
4.8 KiB
C

#include <gtk/gtk.h>
#include <stdio.h>
GdkInterpType interp_type = GDK_INTERP_BILINEAR;
int overall_alpha = 255;
GdkPixbuf *pixbuf;
GtkWidget *darea;
void
set_interp_type (GtkWidget *widget, gpointer data)
{
interp_type = GPOINTER_TO_UINT (data);
gtk_widget_queue_draw (darea);
}
void
overall_changed_cb (GtkAdjustment *adjustment, gpointer data)
{
if (adjustment->value != overall_alpha)
{
overall_alpha = adjustment->value;
gtk_widget_queue_draw (darea);
}
}
gboolean
expose_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
GdkPixbuf *dest;
gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, event->area.width, event->area.height);
gdk_pixbuf_composite_color (pixbuf, dest,
0, 0, event->area.width, event->area.height,
-event->area.x, -event->area.y,
(double) widget->allocation.width / gdk_pixbuf_get_width (pixbuf),
(double) widget->allocation.height / gdk_pixbuf_get_height (pixbuf),
interp_type, overall_alpha,
event->area.x, event->area.y, 16, 0xaaaaaa, 0x555555);
gdk_pixbuf_render_to_drawable (dest, widget->window, widget->style->fg_gc[GTK_STATE_NORMAL],
0, 0, event->area.x, event->area.y,
event->area.width, event->area.height,
GDK_RGB_DITHER_NORMAL, event->area.x, event->area.y);
gdk_pixbuf_unref (dest);
return TRUE;
}
extern void pixbuf_init();
int
main(int argc, char **argv)
{
GtkWidget *window, *vbox;
GtkWidget *menuitem, *optionmenu, *menu;
GtkWidget *alignment;
GtkWidget *hbox, *label, *hscale;
GtkAdjustment *adjustment;
GtkRequisition scratch_requisition;
GError *error;
pixbuf_init ();
gtk_init (&argc, &argv);
gdk_rgb_init ();
if (argc != 2) {
fprintf (stderr, "Usage: testpixbuf-scale FILE\n");
exit (1);
}
error = NULL;
pixbuf = gdk_pixbuf_new_from_file (argv[1], &error);
if (!pixbuf) {
fprintf (stderr, "Cannot load image: %s\n",
error->message);
g_error_free (error);
exit(1);
}
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), vbox);
menu = gtk_menu_new ();
menuitem = gtk_menu_item_new_with_label ("NEAREST");
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
GTK_SIGNAL_FUNC (set_interp_type),
GUINT_TO_POINTER (GDK_INTERP_NEAREST));
gtk_widget_show (menuitem);
gtk_container_add (GTK_CONTAINER (menu), menuitem);
menuitem = gtk_menu_item_new_with_label ("BILINEAR");
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
GTK_SIGNAL_FUNC (set_interp_type),
GUINT_TO_POINTER (GDK_INTERP_BILINEAR));
gtk_widget_show (menuitem);
gtk_container_add (GTK_CONTAINER (menu), menuitem);
menuitem = gtk_menu_item_new_with_label ("TILES");
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
GTK_SIGNAL_FUNC (set_interp_type),
GUINT_TO_POINTER (GDK_INTERP_TILES));
gtk_container_add (GTK_CONTAINER (menu), menuitem);
menuitem = gtk_menu_item_new_with_label ("HYPER");
gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
GTK_SIGNAL_FUNC (set_interp_type),
GUINT_TO_POINTER (GDK_INTERP_HYPER));
gtk_container_add (GTK_CONTAINER (menu), menuitem);
optionmenu = gtk_option_menu_new ();
gtk_option_menu_set_menu (GTK_OPTION_MENU (optionmenu), menu);
gtk_option_menu_set_history (GTK_OPTION_MENU (optionmenu), 1);
alignment = gtk_alignment_new (0.0, 0.0, 0.0, 0.5);
gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, FALSE, 0);
hbox = gtk_hbox_new (FALSE, 4);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
label = gtk_label_new ("Overall Alpha:");
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
adjustment = GTK_ADJUSTMENT (gtk_adjustment_new (overall_alpha, 0, 255, 1, 10, 0));
gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed",
GTK_SIGNAL_FUNC (overall_changed_cb), NULL);
hscale = gtk_hscale_new (adjustment);
gtk_scale_set_digits (GTK_SCALE (hscale), 0);
gtk_box_pack_start (GTK_BOX (hbox), hscale, TRUE, TRUE, 0);
gtk_container_add (GTK_CONTAINER (alignment), optionmenu);
gtk_widget_show_all (vbox);
/* Compute the size without the drawing area, so we know how big to make the default size */
gtk_widget_size_request (vbox, &scratch_requisition);
darea = gtk_drawing_area_new ();
gtk_box_pack_start (GTK_BOX (vbox), darea, TRUE, TRUE, 0);
gtk_signal_connect (GTK_OBJECT (darea), "expose_event",
GTK_SIGNAL_FUNC (expose_cb), NULL);
gtk_window_set_default_size (GTK_WINDOW (window),
gdk_pixbuf_get_width (pixbuf),
scratch_requisition.height + gdk_pixbuf_get_height (pixbuf));
gtk_widget_show_all (window);
gtk_main ();
return 0;
}