Drawing with gdk (gtk) tutorial, examples?



<--------------------------------------------------------------------->
I know this question have been up some months ago, but I do not think
that thread pointed to any examples og tutorial, and I can not find any
good documentation of this topic. I'm trying to draw a simple line in
window. If someone could explain this to me, I guess I can work out the
rest by myself.

Thanks,
Øystein
(gtk-newbee)

(Attaching a source-code here, hope you not annoyed)

----8<-----
/* Øystein's testprogram for tegning */

#include <gtk/gtk.h>

/* callback */
void destroy( GtkWidget *widget,
           gpointer   data )
{
  gtk_main_quit();
}

int main( int   argc,
       char *argv[] )
{
  /* GtkWidget is the storage type for widgets */
  GtkWidget *window;
  GtkWidget *drawing;

  /* This is called in all GTK applications. Arguments are parsed
   * from the command line and are returned to the application. */
  gtk_init(&argc, &argv);

  /* create a new window */
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  /* Here we connect the "destroy" event to a signal handler.
   * This event occurs when we call gtk_widget_destroy() on the window,
   * or if we return FALSE in the "delete_event" callback. */
  gtk_signal_connect (GTK_OBJECT (window), "destroy",
                GTK_SIGNAL_FUNC (destroy), NULL);

  /* Create drawing widget */
  drawing = gtk_drawing_area_new();
  /* Set the size */
  gtk_drawing_area_size (GTK_DRAWING_AREA (drawing), 300,300);

  /* Draw a line */
    gdk_draw_line(drawing->window, drawing->style->white_gc ,
          0 ,0 ,300 ,300);

  /* gtk_widget_draw(drawing, ?????); Do I need something like this?*/

  /* Get the drawing in the window */
  gtk_container_add (GTK_CONTAINER (window), drawing);

  /* Show the stuff */
  gtk_widget_show (drawing);
  gtk_widget_show (window);

  gtk_main();
  return 0;
}




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