Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ############################################################
- // YOUR IMPLEMENTATION
- // ############################################################
- namespace tui {
- class color {
- private:
- byte code = 0;
- color(byte code) //constructor
- {
- this->code = code;
- }
- public:
- byte getCode() const
- {
- return code;
- }
- static const color black;
- static const color red;
- static const color green;
- static const color yellow;
- static const color blue;
- static const color magenta;
- static const color white;
- static const color system_default;
- };
- /* predefine some colors */
- const color color::black(0);
- const color color::red(1);
- const color color::green(2);
- const color color::yellow(3);
- const color color::blue(4);
- const color color::magenta(5);
- const color color::white(7);
- const color color::system_default(9);
- class pen {
- private:
- color _foreground, _background;
- char _c;
- bool _bright;
- public:
- pen(color foreground_code, color background_code, char ch, bool bright) //constructor
- :_foreground(foreground_code),_background(background_code),_c(ch),_bright(bright)
- {}
- point pen_to_point() const //convert a pen to a point
- {
- point pt;
- pt._ch = _c;
- pt._color_code = _foreground.getCode();
- pt._bg_color_code = _background.getCode();
- pt._bright = _bright;
- return pt;
- }
- };
- class shape {
- public:
- virtual ~shape() {}; // the virtual destructor of base class
- virtual void draw(screen &scr, const pen &p) const = 0;
- };
- class rectangle : public shape {
- private:
- int height;
- int width;
- int top_left_x;
- int top_left_y;
- int bottom_x ;
- int bottom_y ;
- public:
- rectangle(int x, int y, int height, int width) // the constructor of rectangle
- :top_left_x(x),top_left_y(y),height(height),width(width),bottom_x(top_left_x + height),bottom_y(top_left_y + width)
- {}
- ~rectangle() {}; //the destructor of the derived class ( 1) delete the rectangle(Derived class) 2) delete the shape (base class))
- /* Public Helpers for private members*/
- int getHeight()
- {
- return height;
- }
- int getWidth()
- {
- return width;
- }
- int getTop_left_corner_x()
- {
- return top_left_x;
- }
- int getTop_left_corner_y()
- {
- return top_left_y;
- }
- void draw(screen &scr, const pen &p) const
- {
- scr.set_rect(top_left_x, top_left_y, bottom_x, bottom_y, p.pen_to_point());
- }
- };
- class circle : public shape {
- private:
- int center_x;
- int center_y;
- int radius;
- public:
- circle(int x, int y, int rad) //constructor of the circle
- :center_x(x), center_y(y), radius(rad)
- {}
- ~circle() {}; ////the destructor of the derived class ( 1) delete the circle(Derived class) 2) delete the shape (base class))
- /* Public Helpers for private members*/
- int getCenter_x()
- {
- return center_x;
- }
- int getCenter_y()
- {
- return center_y;
- }
- int getRadius()
- {
- return radius;
- }
- void draw(screen &scr, const pen &p) const
- {
- scr.set_circle(center_x, center_y, radius, p.pen_to_point());
- }
- };
- class canvas {
- private:
- screen& _scr; //an screen obj
- std::vector<std::pair < shape*, pen > > list;
- public:
- canvas(screen &scr) //constructor
- :_scr(scr)
- {}
- /* The 3 methods of the class*/
- void add(shape* obj, pen obj1)
- {
- list.push_back(std::make_pair(obj, obj1));
- }
- void clear()
- {
- list.clear();
- _scr.clear();
- }
- void show()
- {
- _scr.clear();
- int i;
- for (i = 0; i < list.size(); i++)
- list[i].first->draw(_scr, list[i].second);
- _scr.render();
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement