// -*- c++ -*-
#ifndef _DISPLAY_H
#define _DISPLAY_H

#include "mytypes.h"
#include "coord.h"

class Player;
class CPixmap;
struct MenuItem;

class displayData {
public:
  virtual ~displayData();
  virtual void Raise() = 0;
  virtual void Flush() = 0;
  virtual void Map() = 0;

  virtual void Clear() = 0;

  virtual void FillRect(int x, int y, int width, int ht, int col) = 0; 
  virtual void Rect(int x, int y, int width, int ht, int col)  = 0;
  virtual void DrawPixmap(int x, int y, CPixmap *handle, int owner) = 0;
  virtual void WriteStr(int x, int y, char *str, int color) = 0;

  virtual void ExposeNotify(int x, int y, int width, int height) = 0;

  virtual void CreateDrawingArea(int width, int height, WDisplay *window) = 0;
  virtual void AddButton(char *name, void (*callback)(void *), void *call_data) = 0; 
  virtual void AddMenu(char *name, MenuItem *list, void (*callback)(void *, void *), void *call_data) = 0;
};

class WDisplay
{
public:
  WDisplay(Player *p) {player = p;}
  virtual ~WDisplay();

  void Raise() {data->Raise();}
  void Flush() {data->Flush();}

  virtual void Update() = 0;

  virtual void GetEvent(EventType event, int x, int y, char *data); 

  Player *GetPlayer() {return player;}

  void Clear() {data->Clear();}
  void DrawPixmap(ScreenCoord c, CPixmap *handle, int owner = -1, int xoffset = 0, int yoffset = 0)
       {DrawPixmap(c.x+xoffset,c.y+yoffset,handle, owner);}
  void DrawCity(MapCoord c,Player *owner,int size,int hasWalls,int disordered) 
       {DrawCity(TranslateScreen(c), owner, size, hasWalls, disordered);}
  void DrawPixmap(MapCoord c, CPixmap *handle, int owner = -1) 
       {DrawPixmap(TranslateScreen(c),handle, owner);}
  void DrawPixmap(MapCoord c, CPixmap *handle, int owner, double xoffset, double yoffset);

  void DrawBlankSquare(ScreenCoord c);
  void DrawBlankSquare(MapCoord c)  {DrawBlankSquare(TranslateScreen(c));}
  void Rect(ScreenCoord c, int width, int ht, int col) {Rect(c.x,c.y,width,ht,col);}
  void Rect(MapCoord c, int width, int ht, int col) {Rect(TranslateScreen(c),width,ht,col);}
  
  void ExposeNotify(int x, int y, int width, int ht) {data->ExposeNotify(x,y,width,ht);}
  friend void AllocColors(class Graphics *screen);

protected:
  virtual void Setup() = 0;

  void FillRect(int x, int y, int width, int ht, int col) 
    { data->FillRect(x, y, width, ht, col); }
  void Rect(int x, int y, int width, int ht, int col) 
    { data->Rect(x, y, width, ht, col); }
  void DrawPixmap(int x, int y, CPixmap *handle, int owner = -1)
    { data->DrawPixmap(x, y, handle, owner); }
  void WriteStr(int x, int y, char *str, int color)
    { data->WriteStr(x, y, str, color); }
  void WriteChar(int x, int y, int ch, int color);
  void WriteInt(int x, int y, int n, int width, int color);
  void DrawCity(ScreenCoord c, Player *owner, int size, int hasWalls, int isDisordered);
  virtual ScreenCoord TranslateScreen(MapCoord coord) = 0;

  void CreateDrawingArea(int width, int height, WDisplay *window)
    { data->CreateDrawingArea(width, height, window); }
  void AddButton(char *name, void (*callback)(void *), void *call_data)
    { data->AddButton(name, callback, call_data); }
  void AddMenu(char *name, MenuItem *list, void (*callback)(void *, void *), void *call_data)
    { data->AddMenu(name, list, callback, call_data); }

  static int white, black, gray; // colors
  Player *player;

  displayData *data;
};

#endif
