// window.h // // Defines a simple graphics interface around the Watcom graphics // library. Intended to make it easy to port programs with graphics, // since you'll only have to port this module. // // by Dave Hershberger #ifndef WINDOW_H #define WINDOW_H #include #include #include // The Watcom graphics library header #define NUM_COLORS 256 class Color { private: static int next_avail_index; static long colors[NUM_COLORS]; int index; int closest(long color); public: // The conversion from Color to short allows you to do things like // blue = Color(_BLUE); // _setcolor(blue); operator short () { return index; } // The "long color" below is of the form 0x00bbggrr, where each of // bb, gg, and rr are in the range 0 - 63. Notice the seemingly // reversed order of Blue, Green, Red. Color(long color = 0); Color(int red, int green, int blue); Color(short palette_index) { index = palette_index; } char red() { return colors[index] & 0xff; } char green() { return (colors[index] >> 8) & 0xff; } char blue() { return colors[index] >> 16; } }; // Image should eventually be a class, I suppose. typedef char *Image; enum GraphMode {GRAPHICS, TEXT, UNKNOWN}; class Window { private: static GraphMode mode; int left, top, right, bottom; Color cur_color; public: Window(int x1, int y1, int x2, int y2); int maxx() { return right - left; } int maxy() { return bottom - top; } friend void set_graphics_mode(); friend void set_text_mode(); void set_color(Color color); void clear(); void fill_ellipse(int x1, int y1, int x2, int y2); void fill_rectangle(int x1, int y1, int x2, int y2); void linestyle(unsigned short style); void line(int x1, int y1, int x2, int y2); void set_pixel(int x, int y); Color get_pixel(int x, int y); Image get_image(int x1, int y1, int x2, int y2); void put_image(Image image, int x, int y); }; #endif // WINDOW_H