#ifndef PRIMITIVEWINDOW_H
#define PRIMITIVEWINDOW_H

#include <string>
#include <vector>
#include <ostream>
using namespace std;


#include <GL/glut.h>
#include <GL/gl.h>

#include <gobj.h>
#include <graphmisc.h>
#include <point.h>


/*!
\brief Write text to the screen with a primitive window.

This is a primitive state machine with a font and a current
 position. 
*/
class primitiveWindow : public gobjContainer, public ostream
{
  /** Interpret and write the strings into this classes container. */
  void eval(string const & s);
public:

  /** Initial Position */
  point3<double> X0;
  /** Current Position */
  point3<double> X;
  /** Line height change.*/
  double columnchange;
  /** GLUT font */
  void * font;

  /** Construct with an initial position, height and font. */
  primitiveWindow
  (
    point3<double> const & X0_,
    doublec columnchange_,
    void * font_ = GLUT_BITMAP_HELVETICA_10
  ); 

  /** Clear the graphics and return to the cursor to the initial 
      position. */
  void reset()
    { nuke(); X=X0; }

  /** Set a 10 point font size. */
  void setfont10()
    { font=GLUT_BITMAP_HELVETICA_10; }
  /** Set a 12 point font size. */
  void setfont12()
    { font=GLUT_BITMAP_HELVETICA_12; }

  /** Interpret the string as a paragraph with minimum len character width. */
  void addparagraph(string const & s, uintc len);

  /** Reads the object into a stream and interprets it. */
  template< typename T >
  void eval(T & x)
  {
    stringstream ss;
    ss << x;

    eval(ss.str());
//    return *this;  //--problem with bad cast.
  }

  /** Expecting a string from stringstream.str() where the
      return characters delimet the string s. */
  static void interpretString
  (
    vector<string> & v, 
    string const & s
  );

  /** Write a line to the screen. */
  void addline(string const & s)
  {
    push( new gobjMyBitmapCharacter(s,X,font) );
    X.y -= columnchange;
  }

};

//! WARNING:  I am having difficulty getting streams to work so 
//! a reference to the stream has not been returned.
//!
//! Further use named variables in the x argument.
//!   eg String tmp("The cat");  pw << tmp;  
template< typename T >
void operator << ( primitiveWindow & pw, T & x)
{
  pw.eval(x);
}


#endif



