Re: How to use GdkColor?
- From: Aaron Kennedy <aaronk t131 aone net au>
- To: gtk-list redhat com
- Subject: Re: How to use GdkColor?
- Date: Mon, 28 Jun 1999 20:47:57 +1000
Erwin,
I think you'll find the following works...
Note that the variable "color1" is NO LONGER a pointer. How can you
assign red, green and blue values to a pointer that hasn't been set to
point to any memory yet?
That's why it was crashing,
Aaron
#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);
}
--
...Unix, MS-DOS, and Windows NT (also known as the Good, the Bad, and the Ugly).
----==-- _ / / \
---==---(_)__ __ ____ __ / / /\ \
--==---/ / _ \/ // /\ \/ / / /_/\ \ \
-=====/_/_//_/\_,_/ /_/\_\ /______\ \ \
A proud member of TeamLinux \_________\/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]