How to use GdkColor?
- From: erwin verhulst philips com
- To: <gtk-list redhat com>
- Subject: How to use GdkColor?
- Date: Mon, 28 Jun 1999 11:42:55 +0200
Hi
I've attached a simple program that draws a rectangle when you click with the mouse in the window. It worked fine until I wanted to chance the color of the rectangle. The program compiles OK, but when I try to run it the following message appears.
* ERROR * sigsegv caught
What is wrong with the program?
Can somebody get me on track?
Thanks,
Erwin , NL
P.S. I've got this program from the GTK-list. I've lost the GOOD man's name, but who ever it was, THANKS A MILLION.
#include <glib.h>
#include <gdk/gdk.h>
#include <gtk/gtk.h>
GtkWidget *drawingarea = NULL;
void destroy_window (GtkWidget *widget, gpointer client_data)
{
gtk_main_quit ();
}
gint area_event (GtkWidget *widget, GdkEvent *event, gpointer *data)
{
gint x, y;
GdkModifierType state;
GdkColor *color1;
color1->red = 65;
color1->green = 0;
color1->blue = 0;
gdk_gc_set_foreground (widget->style->fg_gc[1], color1);
/* Check if we've received a button pressed event */
if (event->type == GDK_BUTTON_PRESS )
{
gdk_window_get_pointer (drawingarea->window, &x, &y, &state);
gdk_draw_rectangle (drawingarea->window,widget->style->fg_gc[1],1,(gint)x,(gint)y,30,5);
}
return(0);
}
gint main (gint argc, gchar *argv[])
{
GtkWidget *window, *window2;
gtk_init (&argc,&argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW(window), "Dessine-moi un point");
gtk_window_set_policy (GTK_WINDOW(window), TRUE, TRUE, TRUE);
gtk_signal_connect (GTK_OBJECT(window), "delete_event",
(GtkSignalFunc)destroy_window, (gpointer)window);
gtk_signal_connect (GTK_OBJECT(window), "destroy",
(GtkSignalFunc)destroy_window, (gpointer)window);
window2 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW(window2), "21 rectangles");
gtk_window_set_policy (GTK_WINDOW(window2), TRUE, TRUE, TRUE);
gtk_signal_connect (GTK_OBJECT(window2), "delete_event",
(GtkSignalFunc)destroy_window, (gpointer)window2);
gtk_signal_connect (GTK_OBJECT(window2), "destroy",
(GtkSignalFunc)destroy_window, (gpointer)window2);
drawingarea = gtk_drawing_area_new ();
gtk_drawing_area_size (GTK_DRAWING_AREA(drawingarea), 300, 300);
gtk_widget_set_events (drawingarea, GDK_BUTTON_PRESS_MASK |
GDK_POINTER_MOTION_MASK |
GDK_POINTER_MOTION_HINT_MASK);
gtk_signal_connect (GTK_OBJECT(drawingarea), "event",
(GtkSignalFunc)area_event, NULL);
gtk_container_add (GTK_CONTAINER(window), drawingarea);
gtk_widget_show (drawingarea);
gtk_widget_show (window);
gtk_main ();
return(0);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]