From f4c4376d6a5f59968745625013068499a1e84f83 Mon Sep 17 00:00:00 2001 From: ghaiklor Date: Thu, 12 Nov 2015 10:37:32 +0200 Subject: [PATCH] feat(shape): Implements Rectangle shape --- src/shapes/Rectangle.js | 43 +++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/shapes/Rectangle.js b/src/shapes/Rectangle.js index 3f9a6f1..ed79d3d 100644 --- a/src/shapes/Rectangle.js +++ b/src/shapes/Rectangle.js @@ -1,22 +1,35 @@ -import Shape from './../Shape'; -import { COLORS } from '../Cursor'; +import { Shape } from '../Shape'; -export default class Rectangle extends Shape { - constructor() { - super(); +export class Rectangle extends Shape { + /** + * Creates new Rectangle instance + * @constructor + */ + constructor(...args) { + super(...args); } + /** + * Renders the shape + * @param {Cursor} cursor + * @returns {Rectangle} + */ render(cursor) { - let text = ' '; + let position = this.getPosition(); + let width = this.getWidth(); + let height = this.getHeight(); + let background = this.getBackground(); + let foreground = this.getForeground(); - cursor - .reset() - .background(COLORS.YELLOW) - .setPosition(this.getPosition().x, this.getPosition().y) - .write(text) - .move(-text.length, 1) - .write(text) - .move(-text.length, 1) - .write(text); + cursor.fill({ + x1: position.x, + y1: position.y, + x2: width + position.x, + y2: height + position.y, + background, + foreground + }); + + return this; } }