[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

gdk_pixbuf_scale_simple problem when scaling to large sizes



I am new to gtk+ and I am having a problem with
gdk_pixbuf_scale_simple(). I can successfully scale a
pixbuf from file (calcpic_pixbuf) to a small size (say
100x200 pixels). However, when I scale this pixbuf to
a large size (one with more than 63900 pixels) my
pixbuf simply disappears. I have included my code
below. I think my problem is with in my
"configure_event()" function.

If you need any more information please let me know.

Thanks,
Andy

include <gtk/gtk.h>

static GdkPixmap *calcwnd_pixmap = NULL; //offscreen
calculator window buffer
static GdkPixbuf *calcpic_pixbuf = NULL; //offscreen
large calculator picture

gint delete_event( GtkWidget *widget, GdkEvent *event,
gpointer data ) {
	//return FALSE; calls destroy event
	//return TRUE; no call to destroy
	return FALSE;
}

void destroy( GtkWidget *widget, gpointer data ) {
    gtk_main_quit ();
}

/* called when window size changes (including window
creation) */
static gboolean configure_event( GtkWidget *widget,
GdkEventConfigure *event )
{
	GdkPixbuf *pixbufsm;

	if (calcwnd_pixmap)
		gdk_pixmap_unref(calcwnd_pixmap); //destroy old
pixmap

	calcwnd_pixmap = gdk_pixmap_new(widget->window,
//create new pixmap of proper size
		widget->allocation.width, widget->allocation.height,
-1);
	
	gdk_draw_rectangle (calcwnd_pixmap,
widget->style->white_gc, TRUE, 0, 0,
		widget->allocation.width,
widget->allocation.height); //"clean" pixmap to white

	//display resized calculator
	pixbufsm = gdk_pixbuf_scale_simple(calcpic_pixbuf,
widget->allocation.width,
		widget->allocation.height, GDK_INTERP_HYPER);
	gdk_draw_pixbuf (calcwnd_pixmap,
widget->style->fg_gc[GTK_STATE_NORMAL], 
		pixbufsm, 0, 0, 0, 0, -1, -1, GDK_RGB_DITHER_MAX, 0,
0);
	
	return TRUE;
}

/* Redraw the screen from the backing pixmap (window
was covered) */
static gboolean expose_event( GtkWidget *widget,
GdkEventExpose *event )
{
  gdk_draw_pixmap(widget->window,
		  widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
		  calcwnd_pixmap,
		  event->area.x, event->area.y,
		  event->area.x, event->area.y,
		  event->area.width, event->area.height);

  return FALSE;
}

/* Draw a rectangle on the screen */
static void draw_brush (GtkWidget *widget, gdouble x,
gdouble y)
{
  GdkRectangle update_rect;
	
  update_rect.x = x - 5;
  update_rect.y = y - 5;
  update_rect.width = 10;
  update_rect.height = 10;
  gdk_draw_rectangle (calcwnd_pixmap,
		      widget->style->black_gc,
		      TRUE,
		      update_rect.x, update_rect.y,
		      update_rect.width, update_rect.height);
  gtk_widget_draw (widget, &update_rect);
}


static gint button_press_event( GtkWidget *widget,
GdkEventButton *event )
{
  if (event->button == 1 && calcwnd_pixmap != NULL)
    draw_brush (widget, event->x, event->y);
  return TRUE;
}

int main( int   argc, char *argv[] ) {
	GtkWidget *window, *screen;
	GdkGeometry ar;
	
	ar.min_aspect = .5;
	ar.max_aspect = .5;
	
	gtk_init (&argc, &argv);

	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title (GTK_WINDOW (window), "Main Calc
Window");
	gtk_container_set_border_width (GTK_CONTAINER
(window), 0);
	//gtk_window_set_decorated(GTK_WINDOW (window),
FALSE);
	//gtk_window_set_geometry_hints(GTK_WINDOW (window),
GTK_WIDGET (window),
	//					&ar, GDK_HINT_ASPECT);
	
	/*Window Manager close*/
	g_signal_connect (G_OBJECT (window), "delete_event",
			G_CALLBACK (delete_event), NULL);

	/* gtk_widget_destroy() on window or FALSE return
from "delete_event"*/
	g_signal_connect (G_OBJECT (window), "destroy",
			G_CALLBACK (destroy), NULL);

	//load calc picture from file
	calcpic_pixbuf =
gdk_pixbuf_new_from_file("ti862.png", NULL);

	screen = gtk_drawing_area_new();
	gtk_widget_set_size_request (screen, 100, 100);
	gtk_widget_show(screen);
	
	g_signal_connect (G_OBJECT (screen), "expose_event",
		    G_CALLBACK (expose_event), NULL);
	g_signal_connect (G_OBJECT
(screen),"configure_event",
		    G_CALLBACK (configure_event), NULL);
	g_signal_connect (G_OBJECT (screen),
"button_press_event",
		    G_CALLBACK (button_press_event), NULL);

	gtk_widget_set_events (screen, GDK_EXPOSURE_MASK
			 | GDK_LEAVE_NOTIFY_MASK
			 | GDK_BUTTON_PRESS_MASK
			 | GDK_POINTER_MOTION_MASK
			 | GDK_POINTER_MOTION_HINT_MASK);

	gtk_container_add (GTK_CONTAINER (window), screen);

	gtk_widget_show (window);

	gtk_main ();

	return 0;
}


__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]