gboolean redraw(GtkWidget *widget, GdkEvent *event, gpointer data)
{
GdkColor myColor;
GdkGC *GCA=NULL;//for arrival line color
GdkGC *GCD=NULL;//for departure line color
//arrival line config 線顏色的設定
GCA=gdk_gc_new(widget->window);
myColor.red = 30000;
myColor.green = 0;
myColor.blue =30000;
gdk_gc_set_rgb_fg_color (GCA,&myColor);
//departure line config
GCD=gdk_gc_new(widget->window);
myColor.red = 0;
myColor.green = 0 ;
myColor.blue = 0;
gdk_gc_set_rgb_fg_color (GCD,&myColor);
gdk_draw_rectangle (widget->window,
widget->style->white_gc,
TRUE,
0, 0,
(gint)DRAW_AREA_WIDTH,
(gint)DRAW_AREA_HEIGHT);
#ifdef DEBUGMSG
printf("white width%d",(3/4*DRAW_AREA_WIDTH));
printf("white height%d",(3/4*DRAW_AREA_WIDTH));
#endif
//gdk_gc_set_rgb_bg_color (GC,&myColor);
//gdk_gc_set_background(GC,&myColor);
//gdk_gc_set_line_attributes (GC,12,2,1,1);
float fHeightRatio = DRAW_AREA_HEIGHT/iTotalCustomer;
float fWidthRatio = DRAW_AREA_WIDTH/iSimTotalPeriod;
int iCount;
for(iCount=0;iCount<iTotalCustomer;iCount++)
{
#if 1
//arrival draw 畫線的函數
gdk_draw_line (widget->window,
GCA,
(gint)fArrival_Time[iCount]*fWidthRatio,
(gint)(DRAW_AREA_HEIGHT- iCount*fHeightRatio),
(gint)fArrival_Time[iCount]*fWidthRatio,
(gint)(DRAW_AREA_HEIGHT- (iCount+1)*fHeightRatio) );
gdk_draw_line (widget->window,
GCA,
(gint)fArrival_Time[iCount]*fWidthRatio,
(gint)(DRAW_AREA_HEIGHT- (iCount+1)*fHeightRatio),
(gint)fArrival_Time[iCount+1]*fWidthRatio,
(gint)(DRAW_AREA_HEIGHT - (iCount+1)*fHeightRatio) );
#endif
//departure draw
gdk_draw_line (widget->window,
GCD,
(gint)fDeparture_Time[iCount]*fWidthRatio+2,
(gint)(DRAW_AREA_HEIGHT - iCount*fHeightRatio)+2,
(gint)fDeparture_Time[iCount]*fWidthRatio+2,
(gint)(DRAW_AREA_HEIGHT - (iCount+1)*fHeightRatio)+2 );
gdk_draw_line (widget->window,
GCD,
(gint)fDeparture_Time[iCount]*fWidthRatio+2,
(gint)(DRAW_AREA_HEIGHT - (iCount+1)*fHeightRatio)+2,
(gint)fDeparture_Time[iCount+1]*fWidthRatio+2,
(gint)(DRAW_AREA_HEIGHT - (iCount+1)*fHeightRatio)+2 );
}
g_object_unref (GCA);
g_object_unref (GCD);
return TRUE;
}
當然還要有一些前製作業,會有一個GtkWidget * GtkMainDraw(){} 裏面要宣告widget和signal 大致上概念是這樣。
請額外參考
http://caterpillar.onlyfun.net/Gossip/G ... ossip.html
和
http://debian.linux.org.tw/~kevpeng/
另外就是到http://library.gnome.org/devel/gtk/stable/ 參考function用法