drawing a line
- From: Shiraz Baig <shiraz_baig yahoo com>
- To: gtk-list gnome org
- Subject: drawing a line
- Date: Thu, 31 Jan 2002 04:47:01 -0800 (PST)
Hi,
I want to draw a line when I push a button. I have
written the following code. It draws line thru two
alternative signal commands.
a. Thru the timer function.
b. Thru the push button.
It works with the timer function. But it does not work
with the push button.
Question:
Can anyone suggest how can it draw the line when I
click the button?
#include <gtk/gtk.h>
/************ Draw line function *******************/
gint Repaint (gpointer data)
{
GtkWidget * drawing_area = (GtkWidget *) data;
GdkDrawable *drawable;
drawable = drawing_area->window;
gdk_draw_line(drawable,
drawing_area->style->black_gc,
100,100,150,150);
}//end of Repaint
/**********************************************/
void quit()
{
gtk_exit(0);
}
/***************** main *********************/
int main(int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *drawing_area;
GtkWidget *vbox;
GtkWidget *button;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), vbox);
gtk_widget_show(vbox);
gtk_signal_connect(GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC (quit), NULL);
button = gtk_button_new_with_label("Draw Line");
//ceate button
gtk_container_add (GTK_CONTAINER(vbox), button);
//contaier for button
gtk_widget_show(button);
drawing_area = gtk_drawing_area_new();
gtk_drawing_area_size(GTK_DRAWING_AREA
(drawing_area), 200, 200);
gtk_box_pack_start(GTK_BOX(vbox), drawing_area, TRUE,
TRUE, 0);
gtk_widget_show(drawing_area);
gtk_widget_show(window);
/********** timer signal ************/
// gtk_timeout_add(1000, Repaint, (gpointer)
drawing_area);
/********* button signal ************/
gtk_signal_connect(GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC (Repaint), (gpointer)
drawing_area);
gtk_main();
} //end of main
__________________________________________________
Do You Yahoo!?
Great stuff seeking new owners in Yahoo! Auctions!
http://auctions.yahoo.com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]