#include <Fl/fl_draw.H>
#include "DrawObjectWidget.h"
#include <iostream>
using namespace std;

// Constructor
DrawObjectWidget::DrawObjectWidget(int x, 
				   int y, 
				   int w, 
				   int h,
				   float min_x, 
				   float min_y, 
				   float max_x, 
				   float max_y,
				   const char * s) : 
  DrawWidget(x,y,w,h,min_x,min_y,max_x,max_y,s) {}

// Constructor
DrawObjectWidget::DrawObjectWidget(int x, 
				   int y, 
				   int w, 
				   int h,
				   const char * s) :
  DrawWidget(x,y,w,h,s) {}

// Destructor
DrawObjectWidget::~DrawObjectWidget() {
  clear();
}

// Clear the objects from the pointer
void DrawObjectWidget::clear() {
  for (list<DrawObject*>::iterator i=objects.begin();
       i!=objects.end();
       i++) {
    delete (*i);
  }
  objects.clear();
}

// Add an object pointer to the list
void DrawObjectWidget::addDrawObject(DrawObject * o) {
  objects.push_back(o);
  redraw();
}

// Draw the objects
void DrawObjectWidget::draw() {
  // Push a clipping region so that only what needs to be shown is shown
   fl_push_clip(0,0,w(),h());

  // Draw the objects
  for (list<DrawObject*>::iterator i = objects.begin();
       i != objects.end();
       i++) {
    //    cout << "Drawing object... " << endl;
    (*i)->draw(this);
  }

  // Pop the clipping region
  fl_pop_clip();
}

