Many questions when I drew a line

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

 



/***************************************************************************
I'm new to GTK+, please help me with following simple questions.
Thanks for your patience.

I wrote a simple programme to draw a line, the whole file is below these questions:
1. I use gtk_widget_set_size_request() to resize the drawing_area,
   but it's useless. The size of the drawing_area will resize to it's
   parent's size automatically.How to make it's size fixed?
2. The bg_color I set in redraw() is useless too. Each time I run the application,
   the background color is different. Looks like random color.
3. Where can find introduction of GrStyle? It's too simple in GTK+ Manual Page.
4. How to set the line color and line width?
5. How to use color? The common RGB color is like (255, 255, 255),
   but in GTK+ this can be (0xffff, 0xffff, 0xffff). 
   I was confused, how to set a right RGB color? Is there a bunch of build in
   color I can use?
 ***************************************************************************/
#include <gtk/gtk.h>

gboolean redraw(GtkWidget *widget, GdkEvent *event, gpointer data)
{
	GdkGC *gc = gdk_gc_new(widget->window);
	GdkColor bg_color;

	// Draw background
	bg_color.red = 0xffff;
	bg_color.green = 0;
	bg_color.blue = 0;
	gdk_gc_set_foreground(gc, &bg_color);
	gdk_draw_rectangle(widget->window, gc, TRUE,
			0, 0, widget->allocation.width, widget->allocation.height);
	gdk_draw_line(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
			0, 0, 120, 100);

	return TRUE;
}

int main(int argc, char *argv[])
{
	GtkWidget *w;
	GtkWidget *drawing_area;

	gtk_init(&argc, &argv);

	w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_default_size(GTK_WINDOW(w), 300, 200);
	g_signal_connect(GTK_OBJECT(w), "destroy", G_CALLBACK(gtk_main_quit), NULL);

	drawing_area = gtk_drawing_area_new();
	gtk_widget_set_size_request(GTK_WIDGET(drawing_area), 100, 100);
	g_signal_connect(G_OBJECT(drawing_area), "expose-event", G_CALLBACK(redraw), NULL);
	gtk_container_add(GTK_CONTAINER(w), drawing_area);

	gtk_widget_show_all(w);
	gtk_main();
	return 0; 
}

_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux