Newbie question

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

 



I've got a problem with GdkRectangle.
 
Why is that if I do not define update_rect and update_rect1
GdkRectangle variables in the code below  I can not see the points drawn
with gdk_draw_point ?
 
What is the difference between gtk_box_pack_start
and gtk_container_add functions ?.
 
How can I redraw the drawing area to be able to display another set of points.
 
I have tried it by adding a for loop of Nops below the gdk_draw_point
for loop and use another for loop of gdk_draw_point  but I haven't been able to do it.
I would like to make the effect of motion by writting different set of points in a fix rate
time intervals.
 
 
Thanks for your help.
 
Aitor
 
 
#include <gtk/gtk.h>
#include <math.h>
#define IMAGE_WIDTH 256
#define IMAGE_HEIGHT 256 
#define OFFSET (IMAGE_HEIGHT/2)
#define N_POINTS_IN_SINE 120
#define N_POINTS_IN_WINDOW  256
#define PERIOD 100
#ifndef PI
#define PI 3.14159265358979323846
#endif
gboolean on_darea_expose (GtkWidget *widget,
     GdkEventExpose *event,
     gpointer user_data);
static gboolean delete_event( GtkWidget *widget,
                              GdkEvent  *event,
                              gpointer   data )
{
    g_print ("delete event occurred\n");
    return FALSE;
}
static void destroy( GtkWidget *widget,
                     gpointer   data )
{
    gtk_main_quit ();
}

int
main (int argc, char *argv[])
{
  GtkWidget *window, *darea;
  gtk_init (&argc, &argv);
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  g_signal_connect (G_OBJECT (window), "delete_event",
                      G_CALLBACK (delete_event), NULL);
  g_signal_connect (G_OBJECT (window), "destroy",
                      G_CALLBACK (destroy), NULL);
  darea = gtk_drawing_area_new ();
  gtk_widget_set_size_request (darea, IMAGE_WIDTH, IMAGE_HEIGHT);
  gtk_container_add (GTK_CONTAINER (window), darea);
  gtk_signal_connect (GTK_OBJECT (darea), "expose-event",
                      GTK_SIGNAL_FUNC (on_darea_expose), NULL);
  gtk_window_set_title (GTK_WINDOW (window), "test");
  gtk_widget_show_all (window);
 
  gtk_main ();
  return 0;
}

gboolean
on_darea_expose (GtkWidget *widget,
   GdkEventExpose *event,
   gpointer user_data)
{
  int i;
  GdkRectangle update_rect;
  GdkRectangle update_rect1;
  GdkPoint point;
  gdk_draw_line(widget->window,
                widget->style->black_gc,
                0,IMAGE_HEIGHT/2,IMAGE_WIDTH,IMAGE_HEIGHT/2);
  for(i=0;i<=N_POINTS_IN_WINDOW;i++){
    point.x = point.x + 1;
    point.y = OFFSET - cos(2*PI/(N_POINTS_IN_SINE)*i)*OFFSET;
    gdk_draw_point(widget->window, widget->style->black_gc,
                   point.x, point.y);
  }
   
  return TRUE;
}

 


Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux