/*
 * LineDevice.C - simple line device driver.
 *
 * Copyright (C) 1992, Christoph Streit (streit@iam.unibe.ch)
 *                     University of Berne, Switzerland
 * All rights reserved.
 *
 * This software may be freely copied, modified, and redistributed
 * provided that this copyright notice is preserved on all copies.
 *
 * You may not distribute this software, in whole or in part, as part of
 * any commercial product without the express consent of the authors.
 *
 * There is no warranty or other guarantee of fitness of this software
 * for any purpose.  It is provided solely "as is".
 *
 */

#include "LineDevice.h"
#include "Polygon.h"

//___________________________________________________________ LineDevice

LineDevice::LineDevice(BaseWindow* window, Options* options)
: DeviceDriver(options), w(window)
{}

LineDevice::~LineDevice()
{
  delete w;
}

void LineDevice::begin()
{
  if (!theOptions->autoscale) {
    w->disableBuffering();
    w->setView(theOptions->eye, theOptions->lookat, theOptions->up, 
	       theOptions->fov);
  }
  w->open(theOptions->resX, theOptions->resY, "L-System " + LSystemName);

  if (theOptions->autoscale)
    w->writeText("Please wait ...", 
		 theOptions->resX/2-40, theOptions->resY/2-5);
}

void LineDevice::end(const BoundingBox& b)
{
  char key;

  if (theOptions->verbose)
    cerr << "primitives: "<< primitives << '\n';
  if (theOptions->autoscale) {
    w->setView(b, theOptions->up, theOptions->fov);
    w->clear();
  }

  w->flush();
  do {
    key = w->waitForKey();
  } while(key != 'q' && key != 'Q');
  w->close();
}

void LineDevice::cylinder(const Vector& p1, const Vector& p2, real)
{
  if (definingMacro)
    return;

  primitives++;
  w->line(p1, p2);
}

void LineDevice::cone(const Vector& p1, real, const Vector& p2, real)
{
  if (definingMacro)
    return;

  primitives++;
  w->line(p1, p2);
}

void LineDevice::polygon(Polygon* p)
{
  if (definingMacro)
    return;

  primitives++;
  w->polygon(p);
}

void LineDevice::sphere(const Vector&, real){}
