#ifndef _MAP_H
#define _MAP_H


#define BACKSTORE

#include <X11/Xlib.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>
#include <X11/cursorfont.h>

#include <X11/xpm.h>

#define PEN_COUNT   13

#define PEN_BLACK   0
#define PEN_WHITE   1
#define PEN_GREEN   2
#define PEN_ORANGE  3
#define PEN_RED     4
#define PEN_BLUE    5
#define PEN_YELLOW  6
#define PEN_GREEN2  7
#define PEN_VIOLET  8
#define PEN_GRAY    9
#define PEN_MAGENTA 10
#define PEN_GREENX  11
#define PEN_CYAN    12

#define FONT "-*-courier-bold-r-normal-*-*-180-*-*-*-*-iso8859-*"
#define xFONT "-*-helvetica-bold-r-normal-*-*-240-*-*-*-*-iso8859-*"

class Map;

class Glyph
{
    friend class Marker;
    friend class Map;
    
    int w,h;    
    Pixmap pm;
    Pixmap clip;
};

class Graphic
{
    friend class Map;
    Graphic *next, *prev;
  protected:
    Map *map;
  public:
    virtual void Draw(void) = 0;
    void SetMap(Map *m) { map = m; };
};

class Marker : public Graphic
{
    Glyph *glyph;
    int x,y;
  public:
    void Draw(void);
    Marker(Glyph *gl, int x0, int y0);
    void MoveTo(int x0, int y0);
    void SetGlyph(Glyph *gl) { glyph = gl; };
};

class Text : public Graphic
{
    int x, y;
    char *text;
    int textl;
    int pen;
  public:
    void Draw(void);
    Text(char *s, int p, int x0, int y0);
    void MoveTo(int x0, int y0);
    void Set(char *s);
    void Color(int p);
    int Width(void);
};
    
class Line : public Graphic
{
    int x0, x1, y0, y1;
    int pen;
  public:
    Line(int p, int xx0, int yy0, int xx1, int yy1);
    void MoveTo(int xx0, int yy0, int xx1, int yy1);    
    void Draw(void);
};


class Map
{
    friend class Text;
    friend class Line;
    friend class Marker;

#ifdef BACKSTORE
    Pixmap canvas;
#endif    
    int w,h;

    int font_b, font_h;
    XFontStruct *font;
    
    Window win;
    Display *display;
    int screen;
    
    GC gc[PEN_COUNT];
    Pixel pens[PEN_COUNT];

    Graphic *gr_first, *gr_last;
    
  public:
    Glyph *RegisterGlyph(char **data, int pen);
    Map(int ww, int hh, int in_root = 0);
    void HandleIO(void);
    int FD(void) { return ConnectionNumber(display); };        
    void AddGraphic(Graphic *gr, int bottom = 0);
    void DelGraphic(Graphic *gr);
    void Refresh(void);
    int GetFD(void);
};

#endif /* _MAP_H */

