#include "display.h"
#include "displays.h"
#include "graph.h"
#include "player.h"
#include "pixmaps.h"

displayData::~displayData() {;}

WDisplay::~WDisplay() {
  if (data != NULL)
    delete data;
  data = NULL;
}

void WDisplay::WriteInt(int x, int y, int n, int width, int color)
{
  char str[20];
  sprintf(str, "%*d", width, n);
  WriteStr(x, y, str, color);
}

void WDisplay::WriteChar(int x, int y, int ch, int color)
{
  char str[2];
  str[0] = ch;
  str[1] = '\0';
  WriteStr(x, y, str, color);
}

void WDisplay::DrawCity(ScreenCoord c, Player *owner, int size, int hasWalls, int isDisordered)
{
  DrawPixmap(c.x, c.y, &city_pic, owner->id);
  if (size < 10)
    WriteInt(c.x+4, c.y+4, size, 1, black);
  else
    WriteInt(c.x, c.y, size, 2, black);
  if (hasWalls) {
    int w, h;
    city_pic.GetInfo(w,h);
    Rect(c.x+1, c.y+1, w-2, h-2, gray);
    Rect(c.x, c.y, w, h, gray);
  }
  if (isDisordered)
    DrawPixmap(c.x,c.y, &disorder_pic);
}

void WDisplay::DrawBlankSquare(ScreenCoord coord)
{
  FillRect(coord.x, coord.y, SquareWidth, SquareHeight, black);
}

void WDisplay::DrawPixmap(MapCoord c, CPixmap *handle, int owner, double xoffset, double yoffset) {
  DrawPixmap(TranslateScreen(c),handle, owner, int(xoffset*SquareWidth), int(yoffset*SquareHeight));
}

void WDisplay::GetEvent(EventType event, int x, int /*y*/, char */*data*/)
{
  // I've made these things available all the time, rather than in the city
  // turn only

  if (state == IN_SELECT)
    return;

  if (event == KEYBOARD) {
    if (x == 't')
      player->ChooseTaxRate();
    else if (x == 'l')
      player->ChooseLuxRate();
    else if (x == 'r')
      Update();
    else if (x == 'g' && player->govt != ANARCHY) {
      if (player->HasWonder(PYRAMIDS) && !Objects[PYRAMIDS].isObsolete)
	player->ChooseGovernment();
      else
	player->ChooseRevolution();
    }
  }
}
