#include <X11/Xlib.h>
#include <X11/Xutil.h>

#define FONT_NAME "-adobe-helvetica-medium-r-*-*-18-*-*-*-*-*-*-*"
#define BLACK 0
#define WHITE 1

class Win {
 private:
  Display *d;
  int screen;
  GC gc;
  XFontStruct *font;
  Colormap cmap;
 public:
  /* Window dimensions */
  int width;
  int height;
  Pixmap buf;
  Window w;

  Win(int width, int height, char *title);
  ~Win() {
    XCloseDisplay(d);
  };
  void set_size(char *title, int new_w, int new_h);
  int button_click(Point *point);
  void update(void);
  void blit(Drawable src, Drawable dest, int x, int y, int w, int h);
  /* Defaults to drawing on buffer */
  void blit(Drawable src, int x, int y, int w, int h) {
    blit(src, buf, x, y, w, h);
  };
  void clear_area(Drawable drwbl, int x, int y, int w, int h, int c);
  void clear_area(int x, int y, int w, int h, int c) {
       clear_area(buf, x, y, w, h, c);
  };
  void clear() {
       clear_area(buf, 0, 0, width, height, WHITE);
  };
  void print(char *msg, int x,int y, int color);
  void print(char *msg, int x,int y) {
    print(msg, x, y, 0);
  };
  void draw_line(Drawable dest, int sx, int sy, int dx, int dy, int w, int c);
  void draw_line(int sx, int sy, int dx, int dy) {
    draw_line(buf, sx, sy, dx, dy, 2, BLACK);
  };
  void draw_line(int sx, int sy, int dx, int dy, int w) {
    draw_line(buf, sx, sy, dx, dy, w, BLACK);
  };
  int text_width(char *str) {
       return XTextWidth(font, str, strlen(str));
  };
};
