How can I solve this problem of Gdk
- From: =?iso-8859-15?b?QW5hIEd1dGnpcnJl?=z Pascual <al004180 alumail uji es>
- To: gtk-list gnome org
- Subject: How can I solve this problem of Gdk
- Date: Fri, 14 Feb 2003 11:27:25 +0100
hi,
i'm new with gtk/gdk. i create a program to design some differents objects, in
this case a simple line. but i supose i don't use correctly the pointers
'cause i obtain these errors.
Gdk-CRITICAL **: file gdkgc.c: line 51 (gdk_gc_new_with_values): assertion
`window != NULL' failed.
Gdk-CRITICAL **: file gdkgc.c: line 456 (gdk_gc_set_foreground): assertion `gc
!= NULL' failed.
Gdk-CRITICAL **: file gdkgc.c: line 766 (gdk_gc_set_line_attributes):
assertion `gc != NULL' failed.
Gdk-CRITICAL **: file gdkdraw.c: line 65 (gdk_draw_line): assertion `drawable
!= NULL' failed.
Gdk-CRITICAL **: file gdkdraw.c: line 212 (gdk_draw_string): assertion
`drawable != NULL' failed.
my code see above.
// --------------------------------------------------------------
#include <gtk/gtk.h>
typedef struct
{
GtkWidget *window;
gchar *nom;
GtkWidget *drawingarea;
GdkDrawable *drawable;
GdkColormap *gdkcolormap;
GdkGC *gdkgc;
} e_app;
typedef struct {
gdouble lx1, lx2, ly1, ly2;
double lgrosor;
GdkColor lcolor;
GdkFont *lfont;
gchar *lnombre;
} e_linea;
void InicializarLinea(e_linea *l);
void DibujarLinea(e_linea *l, e_app *a);
gboolean EventoExponer(GtkWidget *widget,
GdkEventButton *event,
gpointer client_data);
gint main (gint argc,gchar *argv[])
{
e_app app;
e_linea lin;
GtkWidget *vbox;
gtk_init (&argc, &argv);
InicializarLinea(&lin);
app.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_name(app.window, "Ventanita");
vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER (app.window), vbox);
gtk_widget_show(vbox);
gtk_signal_connect(GTK_OBJECT (app.window), "destroy",
GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
app.drawingarea = gtk_drawing_area_new();
gtk_drawing_area_size(GTK_DRAWING_AREA(app.drawingarea), 300, 300);
gtk_box_pack_start(GTK_BOX(vbox), app.drawingarea, TRUE, TRUE, 0);
gtk_widget_show(app.drawingarea);
gtk_widget_set_events(app.drawingarea, GDK_EXPOSURE_MASK);
gtk_signal_connect(GTK_OBJECT(app.drawingarea),
"event",
GTK_SIGNAL_FUNC(EventoExponer),
&app);
gtk_widget_realize(app.window);
app.drawable = app.drawingarea -> window;
app.gdkgc= gdk_gc_new(app.drawable);
app.gdkcolormap= gdk_colormap_get_system();
gtk_widget_show(app.window);
gtk_main();
return 0;
}
void InicializarLinea(e_linea *l)
{
l->lx1= 50;
l->lx2= 100;
l->ly1= 80;
l->ly2= 80;
l->lgrosor= 1;
l->lcolor.red= 0xffff;
l->lcolor.green= 0;
l->lcolor.blue= 0;
l->lfont= gdk_font_load
("-Adobe-Helvetica-Bold-R-Normal--*-140-*-*-*-*-*-*");
l->lnombre= "l- 0 0";
}
void DibujarLinea(e_linea *l, e_app *a)
{
gdk_colormap_alloc_color(a->gdkcolormap, &l->lcolor, TRUE, TRUE);
gdk_gc_set_foreground(a->gdkgc, &l->lcolor);
gdk_gc_set_line_attributes(a->gdkgc,
l->lgrosor,
GDK_LINE_SOLID,
GDK_CAP_BUTT,
GDK_JOIN_MITER);
gdk_draw_line(a->drawable, a->gdkgc, l->lx1, l->ly1, l->lx2, l->ly2);
if (l->lfont == NULL)
g_print("font is NULL\n");
else
gdk_draw_string (a->drawable, l->lfont, a->gdkgc, l->lx1, l->ly1-10,
l->lnombre);
}
gboolean EventoExponer(GtkWidget *widget,
GdkEventButton *event,
gpointer client_data)
{
if (event->type == GDK_EXPOSE)
DibujarLinea((e_linea *)client_data, (e_app *)client_data);
return FALSE;
}
// --------------------------------------------------------------
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]