Re: why i can't draw the graphic??
- From: =?gb2312?b?6Zkg6IM=?= <bdragon2001 hotmail com>
- To: james daa com au
- Cc: gnome-devel-list gnome org
- Subject: Re: why i can't draw the graphic??
- Date: Wed, 10 Jul 2002 22:38:32 +0800
hi,james
There are two programmes which represent my confusion.My last
description is
too simple.
1)
gint
expose(GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
gdk_draw_line (widget->window,
widget->style->black_gc,
100, 50, 50, 100);
return TRUE;
}
gint
configure(GtkWidget *widget,GdkEventConfigure *event,gpointer data)
{
gdk_draw_line (widget->window,
widget->style->black_gc,
100, 50, 50, 100);
return TRUE;
}
void quit(){
gtk_exit(0);
}
int
main(int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *drawing_area;
GtkWidget *vbox;
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);
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_signal_connect (GTK_OBJECT (window), "expose_event",
GTK_SIGNAL_FUNC(expose), NULL);
gtk_signal_connect (GTK_OBJECT (window), "configure_event",
GTK_SIGNAL_FUNC(configure), NULL);
gtk_widget_show (window);
gtk_main ();
return 0;
}
In this code,the configure event only happen when i hit the window,but it
should
happen when "the gtk_widget_show(window)" is executed.whether my idea is
right?
2)
gint repaint(gpointer data)
{
GtkWidget * drawing_area=(GtkWidget *)data;
gdk_draw_rectangle(drawing_area->window,
drawing_area->style->white_gc,
TRUE,
0,0,
drawing_area->allocation.width,
drawing_area->allocation.height);
gdk_draw_line (drawing_area->window,
drawing_area->style->black_gc,
100, 50, 50, 100);
gdk_draw_arc(drawing_area->window,
drawing_area->style->black_gc,
FALSE,
0,0,
30,30,0,(360*64));
return TRUE;
}
void quit(){
gtk_exit(0);
}
int
main(int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *drawing_area;
GtkWidget *vbox;
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);
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);
gtk_timeout_add(100,repaint,(gpointer)drawing_area);
gtk_main ();
return 0;
}
Use the timer to draw the graphic,from it i think why the result is
different
between the way of using "gdk_draw_XXX" function in "main",and the way of
using
timer to draw it.Now the timer drawing is ok,but the directly drawing in
main is
failed.I don't understand why,can hardly tell the reason?
Best regards
thanks for your help
ps the directly drawing:
int
main(int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *drawing_area;
GtkWidget *vbox;
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);
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);
/*directly drawing*/
gdk_draw_line (drawing_area->window,
drawing_area->style->black_gc,
100, 50, 50, 100);
gtk_main ();
return 0;
}
in this code,i can't view the line in the drawing_area,
_________________________________________________________________
享用世界上最大的电子邮件系统— MSN Hotmail。http://www.hotmail.com/cn
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]