drawing pixels on screen



I am trying to figure out how to draw lines and circles and stuff like
that.  I have written a little test program, and I can get some grapihcs
on screen using the gtk_timeout_add() function.  Unfortunately, this
isn't exactly what I want.  I want the pixels be drawn once in the
GdkDrawable, and just be able to enjoy the view without needing to
update (=recall Draw()) the screen every x seconds.  I only want to call
the Draw() once and put is't output in a GdkDrawable.
Can someone correct my code, or give me another very simple program that
just draws a window with a line in it?
Thanks a lot!
This is my testprogram:

/*
 * drawtest.c
 * 
 * Program to test drawing with GTK+
 */
#include <gtk/gtk.h>
#include <stdlib.h>

gint destroyapp (GtkWidget *widget, gpointer gdata)
{
 gtk_main_quit ();
 return (FALSE);
}

gint Draw (gpointer data)
{
 gint i;
 gint intensity = 0;
 GtkWidget* drawing_area = (GtkWidget *) data;
 GdkDrawable *drawable;
 
 drawable = drawing_area->window;
 
 gdk_draw_rectangle (drawable,
  		     drawing_area->style->black_gc,
		     TRUE,
		     5,
		     5,
		     drawing_area->allocation.width-10,
		     drawing_area->allocation.height-10);
		     
 for (i=0; i<=drawing_area->allocation.width-11; i++) {
   intensity =
(((float)rand())/RAND_MAX)*(drawing_area->allocation.height-10);
   g_print("%d\n", intensity);
   gdk_draw_point (	drawable,
   			drawing_area->style->white_gc, 
			i+5,
			drawing_area->allocation.height-intensity-5);
 }
 
 return (TRUE);
}
 

int main (int argc, char *argv[])
{
  GtkWidget *window;
  GtkWidget *drawing_area;
  GtkWidget *vbox;
  
  gtk_init (&argc, &argv);
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  vbox = gtk_hbox_new (FALSE, 0);
  gtk_container_add (GTK_CONTAINER (window), vbox);
  gtk_widget_show (vbox);
  gtk_signal_connect (GTK_OBJECT (window), "destroy",
  			GTK_SIGNAL_FUNC (destroyapp), NULL);
  drawing_area = gtk_drawing_area_new();
  gtk_drawing_area_size (GTK_DRAWING_AREA (drawing_area), 600, 400);
  gtk_box_pack_start (GTK_BOX (vbox), drawing_area, TRUE, TRUE, 0); 
  gtk_widget_show (drawing_area);
  gtk_widget_show (window);
  
  gtk_timeout_add(1000, Draw, (gpointer) drawing_area);

  /* How can I change this so that the pixels are once put on the screen
and
  let them stay on the screen without having to update my screen with 
  gtk_timeout_add ???
  Can't I just call the Draw() function and 'freeze' the screen or
something
  like that so that the things I have drawn stay on screen? */
  
  gtk_main();
  return 0;
}

--
Bart Vandewoestyne		http://hello.to/MC303		
Hugo Verrieststraat 48		Bart.Vandewoestyne@skynet.be
8550 ZWEVEGEM			ICQ# 21275340
BELGIUM - EUROPE		nick: MC303
Phone: +32(0)56/75.48.11
-------------------------------------------------------------------
If carpenters made buildings the way programmers make programs, the 
first woodpecker to come along would destroy all of civilization.
				- Weinberg's Second Law -




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