// FILE: canvas.h // written for the course 2172, 1999 // #if !defined(_CANVAS_H_) #define _CANVAS_H_ #include "color.h" #include "pixel.h" // for the definition of ostream& #include /* canvas class * * logically an x by y matrix of pixels * * internally it has a replica matrix to backup * the previous depth * */ class canvas { protected: pixel** _bottom; // used for saving the // image of a lower depth pixel** _top; // image of current depth int x,y; // resolution // The following two constructors are protected // so a canvas cannot be assigned to another // and it cannot be passed and returned by value // (it would be grossly inefficient) canvas(const canvas&) {} canvas& operator=(const canvas&) { return *this; } public: // canvas(x,y) // constructor, creates an x by y top and bottom grids canvas(int,int); // C.draw_point(x,y,c,id) // assigns the color c to the grid position _top[y][x] or // if c == (-1,-1,-1) then _top[y][x] = _bottom[y][x] // id designates the identity of figure the pixel belongs to void draw_point(int,int,const color&,long); // C.fill_area(x,y,id,c2) // fills a bounded area // the boundary is a pixel with identity id void fill_area(int,int,long,const color&); // properties int width() const; // returns the width, ie x int height() const; // returns the height, ie y // C.save_canvas() // copies all entries of _top to _bottom // (used when jumping depths) void save_canvas(); // properly deallocates the two grids virtual ~canvas(); // writes an ASCII PPM file to the output stream ostream& dump_text_PPM(ostream&) const; // writes a binary PPM file to the output stream ostream& dump_binary_PPM(ostream&) const; // C.get_color(i,j) // returns a copy of the color at _top[i][j] color get_color(int,int) const; // C.draw_line(x_1,y_1,x_2,y_2,c,id) draws a line // from (x_1,y_1) to (x_2,y_2) and performs // proper "clipping" and "cropping", in other words // it works even if the coordinates are outside the // range. color c, id id void draw_line(int,int,int,int,const color&,long); }; #endif