/* Outputwindow.h
 * 
 * Modified to avoid the use of <strstream.h>
 */


#include "arcballWindow.h"
#include "main.h"
#include "section.h"
#include "station.h"
#include "train.h"
#include "platform.h"
#include "font.h"
#include <stdio.h>

void runWindow( void (*idleFunc)(void) );


class perspWindow : public arcballWindow {

public:

  void (*idleFunc)(void);

  perspWindow( int x, int y, int width, int height, char *title, void (*func)(void) )
    : arcballWindow( x, y, width, height, title )

  {
    idleFunc = func;
    projection = ORTHOGRAPHIC;
    horizUnits = 2000;
    centreX = 0; centreY = 0;
    mode = TRANSLATE;
    setCursor();
  }

  void reshape( int width, int height ) {
    window::reshape( width, height );
  }

  void keyAction( unsigned char key, int x, int y ) {
#ifdef GL
    arcballWindow::keyAction( key, x, y );

    switch (key) {
    case '+':
    case '=':
      horizUnits /= 2;		/* zoom IN */
      glutPostRedisplay();
      break;
    case '-':
    case '_':
      horizUnits *= 2;		/* zoom OUT */
      glutPostRedisplay();
      break;
    }
#endif    
  };

  void draw() {
#ifdef GL
    char message[100];

    if (outputGraphics) {
      glClearColor( 0, 0, 0, 0 );
      glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
      glDisable( GL_DEPTH_TEST );

      for (int i=0; i<allSections.size(); i++)
	allSections[i]->draw();
      for (int i=0; i<allStations.size(); i++)
	allStations[i]->draw();
      for (int i=0; i<allPlatforms.size(); i++)
	allPlatforms[i]->draw();
      for (int i=0; i<allTrains.size(); i++)
	allTrains[i]->draw();

      // Print the time

      sprintf( message, "time %g", currentTime );

      glColor3f( 1, 0, 0 );
      printString( message, 0, 0, viewport[2], viewport[3] );
    }
#endif
  }

  void idle() {
    if (idleFunc != NULL)
      idleFunc();
  }
};


extern perspWindow *window;

