#include "forms.h"
#include "pieinthesky.h"

extern int timeout_id;
extern void *stupid;

void update_pie(int id, void *vptr)
{
  //printf("Im doing nothing.\n");
  timeout_id = fl_add_timeout(10, update_pie, stupid);
}


void updatechart(FD_pieinthesky *form, double value, int position)
{
  static double itemvalue[5] = {50, 50, 50, 50, 50};
  itemvalue [position] = value;  
  fl_freeze_form (form->pieinthesky);
  fl_clear_chart (form->piechart);
  fl_add_chart_value (form->piechart, itemvalue[0], "item 1",FL_RED);
  fl_add_chart_value (form->piechart, itemvalue[1], "item 2",FL_GREEN);
  fl_add_chart_value (form->piechart, itemvalue[2], "item 3",FL_YELLOW);
  fl_add_chart_value (form->piechart, itemvalue[3], "item 4",FL_BLUE);
  fl_add_chart_value (form->piechart, itemvalue[4], "item 5",FL_CYAN);
  fl_unfreeze_form (form->pieinthesky);
}


/* callbacks and freeobj handles for form pieinthesky */
void item1(FL_OBJECT *ob, long data)
{
  double itemvalue;
  itemvalue = fl_get_slider_value (ob);
  printf ("item 1 has a value of %E\n", itemvalue);
  updatechart (ob->form->fdui, itemvalue, 0);
  
}

void item2(FL_OBJECT *ob, long data)
{
  /* fill-in code for callback */  
  double itemvalue;
  itemvalue = fl_get_slider_value (ob);
  printf ("item 2 has a value of %E\n", itemvalue);
  updatechart (ob->form->fdui, itemvalue, 1);
}

void item3(FL_OBJECT *ob, long data)
{
  /* fill-in code for callback */
  double itemvalue;
  itemvalue = fl_get_slider_value (ob);
  printf ("item 3 has a value of %E\n", itemvalue);
  updatechart (ob->form->fdui, itemvalue, 2);  
}

void item4(FL_OBJECT *ob, long data)
{
  /* fill-in code for callback */
  double itemvalue;
  itemvalue = fl_get_slider_value (ob);
  printf ("item 4 has a value of %E\n", itemvalue);
  updatechart (ob->form->fdui, itemvalue, 3);  
}

void item5(FL_OBJECT *ob, long data)
{
  /* fill-in code for callback */
  double itemvalue;
  itemvalue = fl_get_slider_value (ob);
  printf ("item 5 has a value of %E\n", itemvalue);
  updatechart (ob->form->fdui, itemvalue, 4);  
}


void quit(FL_OBJECT *ob, long data)
{
  /* fill-in code for callback */
  printf ("click to button was pressed\n");
  fl_finish();
  exit(0);
}

