Emit signal




I have just started working with Gtk, and am facing a pretty simple
problem. I have included a small piece of code below. Only relavent
portion is included.

The changeit function as called whenever the scale value is changed. It
make some changes to the (gpointer)im sent to it. I want this to be
reflected on the screen. How do I force the "expose_event" of "darea" to
occur while still inside the changeit function. This is prettu easy
using qt, as it involves emiting the corresponding signal, which will
fall in the correct slot automatically.

Is my approach correct? Or am i fundamentally wrong somewhere?

Thanking you in advance,


-- 
Ankit Mohan
ankit@mail.com
ankit@ieee.org





typedef struct _image {
	unsigned char *data;
	int width, height;
} image;

gboolean expose_event(GtkWidget *widget, GdkEvent *event, gpointer im)
{
	gdk_draw_rgb_image(widget->window,
widget->style->fg_gc[GTK_STATE_NORMAL],
					0, 0, ((image*)im)->width, ((image*)im)->height,
					GDK_RGB_DITHER_MAX, ((image*)im)->data, ((image*)im)->width*3);
	return TRUE;
}

void changeit(GtkAdjustment *adj, gpointer im)
{
	//Do some manipulation on im and return it thru (gpointer)im
}

int main(int argc, char *argv[])

	GtkWidget *window, *darea, *scale;
	GtkObject *adj;
	image *img;
	
	gtk_init(&argc, &argv);
	gdk_rgb_init();
	
	gtk_widget_push_visual(gdk_imlib_get_visual());
	gtk_widget_push_colormap(gdk_imlib_get_colormap());
	
	gtk_signal_connect(GTK_OBJECT(darea), "expose-event",
					GTK_SIGNAL_FUNC(expose_event), (gpointer)img);
	
	//Adjustment stuff
	adj=gtk_adjustment_new(0, -127, 127, 1, 10, 0);
	scale=gtk_hscale_new(GTK_ADJUSTMENT(adj));
	gtk_signal_connect(GTK_OBJECT(adj), "value-changed",
GTK_SIGNAL_FUNC(changeit), (gpointer)img);
	
	//Show all

	gtk_main();
	return 0;
}



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