/* LICENSE:
  =========================================================================
    CMPack'04 Source Code Release for OPEN-R SDK 1.1.5-r2 for ERS7
    Copyright (C) 2004 Multirobot Lab [Project Head: Manuela Veloso]
    School of Computer Science, Carnegie Mellon University
    All rights reserved.
  ========================================================================= */

#ifndef INCLUDED_GuiState_h
#define INCLUDED_GuiState_h

#include <gtk/gtk.h>

#include "../../../agent/headers/field.h"
#include "../../../agent/headers/gvector.h"

typedef GVector::vector2d<double> vector2d;

extern GtkWidget *ChokeChainWin;
extern GtkWidget *WorldViewWin;
extern GtkWidget *EgoViewWin;
extern GtkWidget *VisRLEWin;
extern GdkColor *Colors;

class UI;

/*------------------------------------------------------------------
CLASS
  WorldViewState

DESCRIPTION
  State associated with the GUI's World View window.
------------------------------------------------------------------*/
class WorldViewState {
public:
  static const double halfFieldViewLength=halfLength+goalDepth;
  static const double halfFieldViewWidth =halfWidth+markerOffset;
  static const double viewSize = 1.2; // factor larger than field size

  WorldViewState();

  void setSize(int new_xsize,int new_ysize);
  int getXSize() {
    return xSize;
  }
  int getYSize() {
    return ySize;
  }
  
  int xWorldToScreen(float world_x);
  int yWorldToScreen(float world_y);
  GdkPoint worldToScreen(vector2d world);
  GdkPoint worldToScreen(float x,float y);
  
  int xWorldDiffToScreen(float world_x_diff);
  int yWorldDiffToScreen(float world_y_diff);

  GdkPoint *getFieldPoints();

private:
  void initFieldPoints();

  int xSize,ySize;
  float xScale,yScale; // amount of pixels/mm

  GdkPoint fspts[17]; // field surface points
};

/*------------------------------------------------------------------
CLASS
  EgoViewState

DESCRIPTION
  State associated with the GUI's Ego View window.
------------------------------------------------------------------*/
class EgoViewState {
public:
  static const double RobotLength = 200.0;
  static const double RobotWidth  = 150.0;

  EgoViewState();

  void setSize(int new_xsize,int new_ysize);
  int getXSize() {
    return xSize;
  }
  int getYSize() {
    return ySize;
  }
  int getMinSize() {
    return minSize;
  }
  GVector::vector2d<int> getCenter() {
    return center;
  }
  // return a value from 0 to 1
  double distScale(double dist);
  GVector::vector2d<int> egoToScreen(vector2d ego);

  GdkPoint *getRobotPoints();

private:
  void initRobotPoints();

  int xSize,ySize;
  int minSize;
  GVector::vector2d<int> center;

  GdkPoint rpts[4]; // robot points
};

/*------------------------------------------------------------------
CLASS
  VisRLEState

DESCRIPTION
  State associated with the GUI's Vision RLE window.
------------------------------------------------------------------*/
class VisRLEState {
public:
  VisRLEState();

  void setSize(int new_xsize,int new_ysize);
  int getXSize() {
    return xSize;
  }
  int getYSize() {
    return ySize;
  }

  int getXScale() {
    return xScale;
  }
  int getYScale() {
    return yScale;
  }
  int getXOffset() {
    return xOffset;
  }
  int getYOffset() {
    return yOffset;
  }
  
private:
  int xSize,ySize;
  int xOffset,yOffset;
  int xScale,yScale; // amount of screen pixels/dog pixel
};

extern UI *ui;

#endif
