GDK drawing problem
- From: "cowboy cowboy" <yong_zhy hotmail com>
- To: gtk-list gnome org
- Subject: GDK drawing problem
- Date: Wed, 31 Dec 2003 11:59:47 +0000
HI, all
I am design a little program using GTK. I am new to GTK so I don't know how
to do it. The requirements of the project are given below:
a gtkwindow splited into two parts (left and right), several toggle buttons
on the right cell. When I click one button, some basic primitives will be
drawn on the left cell; if I click it again, those primitives drawn by this
button will be hidden.
I have generated the GUI using glade and modified something in interface.c,
but it doesn't do what I want. ( I haven't added any event handler to those
buttons.)
eg:
I only want the background of left cell be green, right cell remains. But I
don't know when and how to get a GdkGC only for left part.
Can anyone give a suggestion on how to remove the primitives already drawn
on screen?
thanks
the source of interface.c:
//////////////////////////////////////////////////////////////////////////////
GtkWidget*
create_window1 (void)
{
GtkWidget *window1;
GtkWidget *hbox1;
GtkWidget *drawingarea1;
GtkWidget *frame1;
GtkWidget *vbox1;
GtkWidget *togglebutton7;
GtkWidget *togglebutton8;
GtkWidget *togglebutton9;
GtkWidget *togglebutton10;
GtkWidget *togglebutton11;
GtkWidget *togglebutton12;
GtkWidget *togglebutton13;
/*
* User defined variables
*/
GdkColor* color;
GdkPixmap *background,*source,*dist,*ff;
GdkGC *gc,*gcc,*gccc;
int sizeX = 400;
int sizeY = 400;
GdkColor red,white,black;
window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_object_set_data (GTK_OBJECT (window1), "window1", window1);
gtk_window_set_title (GTK_WINDOW (window1), "My Window");
gtk_window_set_default_size (GTK_WINDOW (window1), -1, 400);
gtk_widget_show(window1);
hbox1 = gtk_hbox_new (FALSE, 10);
gtk_widget_ref (hbox1);
gtk_object_set_data_full (GTK_OBJECT (window1), "hbox1", hbox1,
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (hbox1);
gtk_container_add (GTK_CONTAINER (window1), hbox1);
/*
drawingarea1 = gtk_drawing_area_new ();
gtk_widget_ref (drawingarea1);
gtk_object_set_data_full (GTK_OBJECT (window1), "drawingarea1",
drawingarea1,
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (drawingarea1);
gtk_box_pack_start (GTK_BOX (hbox1), drawingarea1, TRUE, TRUE, 0);
*/
/*//////////////////////////////////////////////////*/
gc = gdk_gc_new(window1->window);
g_assert(gc!= NULL);
color = (GdkColor*)malloc(sizeof(GdkColor));
color->red=0;
color->green = 0xffff;
color->blue = 0;
color->pixel = (gulong)(0);
gdk_color_alloc(gtk_widget_get_colormap(window1),color);
background = gdk_pixmap_new(window1->window,sizeX,sizeY,-1);
g_assert(background != NULL);
gdk_gc_set_foreground(gc,color);
gdk_draw_rectangle(background,gc,TRUE,0,0,sizeX,sizeY);
gtk_widget_set_app_paintable(window1,TRUE);
gdk_window_set_back_pixmap(window1->window,background,0);
gdk_color_parse("red",&red);
gdk_color_alloc(gtk_widget_get_colormap(window1),&red);
gdk_color_parse("red",&white);
gdk_color_alloc(gtk_widget_get_colormap(window1),&white);
gdk_color_parse("red",&black);
gdk_color_alloc(gtk_widget_get_colormap(window1),&black);
source = gdk_pixmap_new(window1->window,sizeX,sizeY,-1);
dist = gdk_pixmap_new(NULL,sizeX,sizeY,1);
gcc = gdk_gc_new(dist);
gdk_gc_set_foreground(gcc,&black);
gdk_draw_rectangle(dist,gcc,TRUE,0,0,sizeX,sizeY);
gdk_gc_set_foreground(gcc,&white);
gccc = gdk_gc_new(source);
gdk_gc_set_background(gccc,&white);
gdk_draw_rectangle(source,gccc,TRUE,0,0,sizeX,sizeY);
gdk_gc_set_foreground(gccc,&white);
gdk_draw_rectangle(source,gccc,TRUE,20,20,100,100);
gdk_draw_rectangle(dist,gcc,TRUE,20,20,100,100);
gdk_gc_set_foreground(gccc,&black);
gdk_draw_rectangle(source,gccc,FALSE,0,0,10,10);
gdk_draw_rectangle(dist,gcc,FALSE,0,0,10,10);
gdk_gc_set_foreground(gccc,&red);
gdk_draw_rectangle(source,gccc,TRUE,70,50,100,100);
gdk_draw_rectangle(dist,gcc,TRUE,70,50,100,100);
drawingarea1= gtk_pixmap_new(source,dist);
// gdk_pixmap_unref(source);
// gdk_pixmap_unref(dist);
// gtk_widget_ref (drawingarea1);
// gtk_object_set_data_full (GTK_OBJECT (window1), "drawingarea1",
drawingarea1,
// (GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (drawingarea1);
gtk_box_pack_start (GTK_BOX (hbox1), drawingarea1, TRUE, TRUE, 0);
/*//////////////////////////////////////////////////*/
frame1 = gtk_frame_new ("Controls");
gtk_widget_ref (frame1);
gtk_object_set_data_full (GTK_OBJECT (window1), "frame1", frame1,
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (frame1);
gtk_box_pack_start (GTK_BOX (hbox1), frame1, FALSE, TRUE, 0);
gtk_frame_set_shadow_type (GTK_FRAME (frame1), GTK_SHADOW_ETCHED_OUT);
vbox1 = gtk_vbox_new (FALSE, 20);
gtk_widget_ref (vbox1);
gtk_object_set_data_full (GTK_OBJECT (window1), "vbox1", vbox1,
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (vbox1);
gtk_container_add (GTK_CONTAINER (frame1), vbox1);
togglebutton7 = gtk_toggle_button_new_with_label ("togglebutton7");
gtk_widget_ref (togglebutton7);
gtk_object_set_data_full (GTK_OBJECT (window1), "togglebutton7",
togglebutton7,
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (togglebutton7);
gtk_box_pack_start (GTK_BOX (vbox1), togglebutton7, FALSE, FALSE, 0);
togglebutton8 = gtk_toggle_button_new_with_label ("togglebutton8");
gtk_widget_ref (togglebutton8);
gtk_object_set_data_full (GTK_OBJECT (window1), "togglebutton8",
togglebutton8,
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (togglebutton8);
gtk_box_pack_start (GTK_BOX (vbox1), togglebutton8, FALSE, FALSE, 0);
togglebutton9 = gtk_toggle_button_new_with_label ("togglebutton9");
gtk_widget_ref (togglebutton9);
gtk_object_set_data_full (GTK_OBJECT (window1), "togglebutton9",
togglebutton9,
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (togglebutton9);
gtk_box_pack_start (GTK_BOX (vbox1), togglebutton9, FALSE, FALSE, 0);
togglebutton10 = gtk_toggle_button_new_with_label ("togglebutton10");
gtk_widget_ref (togglebutton10);
gtk_object_set_data_full (GTK_OBJECT (window1), "togglebutton10",
togglebutton10,
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (togglebutton10);
gtk_box_pack_start (GTK_BOX (vbox1), togglebutton10, FALSE, FALSE, 0);
togglebutton11 = gtk_toggle_button_new_with_label ("togglebutton11");
gtk_widget_ref (togglebutton11);
gtk_object_set_data_full (GTK_OBJECT (window1), "togglebutton11",
togglebutton11,
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (togglebutton11);
gtk_box_pack_start (GTK_BOX (vbox1), togglebutton11, FALSE, FALSE, 0);
togglebutton12 = gtk_toggle_button_new_with_label ("togglebutton12");
gtk_widget_ref (togglebutton12);
gtk_object_set_data_full (GTK_OBJECT (window1), "togglebutton12",
togglebutton12,
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (togglebutton12);
gtk_box_pack_start (GTK_BOX (vbox1), togglebutton12, FALSE, FALSE, 0);
togglebutton13 = gtk_toggle_button_new_with_label ("togglebutton13");
gtk_widget_ref (togglebutton13);
gtk_object_set_data_full (GTK_OBJECT (window1), "togglebutton13",
togglebutton13,
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (togglebutton13);
gtk_box_pack_start (GTK_BOX (vbox1), togglebutton13, FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT (window1), "destroy",
GTK_SIGNAL_FUNC (gtk_main_quit),
NULL);
return window1;
}
_________________________________________________________________
Find it on the web with MSN Search. http://search.msn.com.sg/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]