#include <gtk/gtk.h>

typedef struct{
  GtkWidget *win;
  GtkWidget *vbox;
  GtkWidget *bt_refresh;
  GtkWidget *draw_area;
}UserData;


void refresh_btn(GtkWidget *widget, gpointer data){
  UserData* uwData = data;
  gtk_widget_queue_draw(uwData->draw_area);
}


gboolean refresh_draw (GtkWidget *widget, cairo_t *cr, gpointer dataColor){
  guint width, height;
  GtkStyleContext *context;

  context = gtk_widget_get_style_context (widget);
  width = gtk_widget_get_allocated_width (widget);
  height = gtk_widget_get_allocated_height (widget);

  gtk_render_background (context, cr, 0, 0, width, height);

  cairo_arc (cr,
             width / 2.0, height / 2.0,
             MIN (width, height) / 2.0,
             0, 2 * G_PI);

  cairo_set_source_rgb (cr,0,0,0);
  cairo_fill (cr);
  return FALSE;
}


int main(int argc, char* argv[]){
  UserData uData;
   
  gtk_init(&argc, &argv);
  //Création de la window
  uData.win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_container_set_border_width (GTK_CONTAINER (uData.win), 10);
  g_signal_connect (G_OBJECT(uData.win),"delete_event",G_CALLBACK(gtk_main_quit) ,NULL);
  //box verticale 
  uData.vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL,10);
  gtk_container_add(GTK_CONTAINER(uData.win),uData.vbox);


  
  //Bouton refresh
  uData.bt_refresh = gtk_button_new_with_label("Refresh");
  gtk_box_pack_start (GTK_BOX(uData.vbox), uData.bt_refresh, FALSE, FALSE, 5);
  g_signal_connect (G_OBJECT (uData.bt_refresh), "clicked", G_CALLBACK (refresh_btn), &uData);

 
  //Zone couleur
  uData.draw_area = gtk_drawing_area_new ();
  gtk_widget_set_size_request (uData.draw_area, 400, 400);
  gtk_box_pack_start (GTK_BOX(uData.vbox), uData.draw_area, FALSE, FALSE, 5);

  g_signal_connect (G_OBJECT (uData.draw_area), "draw", G_CALLBACK (refresh_draw), NULL);

  gtk_widget_show_all(uData.win);
  gtk_main();
  return 0;
}
