a question of gtk/gdk structures



hi,
I'm new in gtk programming and I've got an error when I compile
the easy program, any expert could tell me a solution?
thanks in advance,
Ana.

the code is:

//--------------------------------------------------------------

#include <gtk/gtk.h>

typedef struct {
  gdouble lx1;
  gdouble lx2;
  gdouble ly1;
  gdouble ly2;
  double lgrosor;
  GdkColor lcolor;
  GdkFont *lfont;
  gchar *lnombre;
} e_linea;

typedef struct
{
  GtkWidget *window;
  gchar *nom;
  GtkWidget *drawingarea;
  GdkDrawable *drawable;
  GdkColormap *gdkcolormap;
  GdkGC *gdkgc;
} e_app;

typedef struct {
  e_linea *linea;
  e_app *app;
} e_objeto;

void InicializarLinea(e_objeto *o);
void DibujarLinea(e_objeto *o);

gboolean EventoExponer(GtkWidget *widget,
                        GdkEventButton *event,
                        gpointer client_data);
gint main (gint argc,gchar *argv[])
{

  e_objeto obj;
  GtkWidget *vbox;

  gtk_init (&argc, &argv);
  InicializarLinea(&obj);

  obj.app->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_widget_set_name(obj.app->window, "Ventanita");

  vbox = gtk_vbox_new(FALSE, 0);
  gtk_container_add(GTK_CONTAINER (obj.app->window), vbox);

  gtk_widget_realize(obj.app->window);
  gtk_widget_show(vbox);

  obj.app->drawingarea = gtk_drawing_area_new();
  gtk_drawing_area_size(GTK_DRAWING_AREA(obj.app->drawingarea), 300,
300);

  gtk_box_pack_start(GTK_BOX(vbox), obj.app->drawingarea, TRUE, TRUE,
0);
  gtk_widget_show(obj.app->drawingarea);

  obj.app->drawable = obj.app->drawingarea -> window;
  obj.app->gdkgc= gdk_gc_new(obj.app->drawable);
  obj.app->gdkcolormap= gdk_colormap_get_system();

  gtk_widget_set_events(obj.app->drawingarea, GDK_EXPOSURE_MASK);

  gtk_signal_connect(GTK_OBJECT (obj.app->window), "destroy",
		GTK_SIGNAL_FUNC (gtk_main_quit), NULL);

  gtk_signal_connect(GTK_OBJECT(obj.app->drawingarea),
			"event",
			GTK_SIGNAL_FUNC(EventoExponer),
			&obj);

  gtk_widget_show(obj.app->window);
  gtk_main();
  return 0;
}

void InicializarLinea(e_objeto *o)
{
  o->linea->lx1= 50;
  o->linea->lx2= 100;
  o->linea->ly1= 80;
  o->linea->ly2= 80;

  o->linea->lgrosor= 1;

  o->linea->lcolor.red= 0xffff;
  o->linea->lcolor.green= 0;
  o->linea->lcolor.blue= 0;

  o->linea->lfont=
gdk_font_load("-Adobe-Helvetica-Bold-R-Normal--*-140-*-*-*-*-*-*");
  o->linea->lnombre= "l- 0 0";
}

void DibujarLinea(e_objeto *o)
{
  gdk_colormap_alloc_color(o->app->gdkcolormap, &o->linea->lcolor, TRUE,
TRUE);
  gdk_gc_set_foreground(o->app->gdkgc, &o->linea->lcolor);
  gdk_gc_set_line_attributes(o->app->gdkgc,
			o->linea->lgrosor,
			GDK_LINE_SOLID,
			GDK_CAP_BUTT,
			GDK_JOIN_MITER);
  gdk_draw_line(o->app->drawable, o->app->gdkgc, o->linea->lx1,
o->linea->ly1, o->linea->lx2, o->linea->ly2);
  if (o->linea->lfont == NULL)
    g_print("font is NULL\n");
  else
    gdk_draw_string(o->app->drawable, o->linea->lfont, o->app->gdkgc,
o->linea->lx1, o->linea->ly1-10, o->linea->lnombre);
}

gboolean EventoExponer(GtkWidget *widget,
                        GdkEventButton *event,
                        gpointer client_data)
{
  if (event->type == GDK_EXPOSE)
    DibujarLinea((e_objeto *)client_data);
  return FALSE;
}
//----------------------------------------------------------------




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