From 043cd3b51d58dbf1160c7217b472c5ab46745444 Mon Sep 17 00:00:00 2001 From: Nathan Kunicki Date: Sat, 18 Nov 2017 00:18:54 +0000 Subject: [PATCH] Added accessors for width and height --- src/bittmappeditor.ts | 26 +++++++++++++++++++------- src/main.ts | 2 +- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/bittmappeditor.ts b/src/bittmappeditor.ts index 5621035..855c004 100644 --- a/src/bittmappeditor.ts +++ b/src/bittmappeditor.ts @@ -104,21 +104,21 @@ class BittMappEditor { } - setPixel (x: number, y: number) { + setPixel (x: number, y: number): void { const byte: number = ((y * (this._width / 8)) + Math.floor(x / 8)), mask: number = 1 << (x % 8); this._data[byte] = this._data[byte] |= mask; } - unsetPixel (x: number, y: number) { + unsetPixel (x: number, y: number): void { const byte: number = ((y * (this._width / 8)) + Math.floor(x / 8)), mask: number = 1 << (x % 8); this._data[byte] = this._data[byte] &= ~mask; } - resize (width: number = this._width, height: number = this._height) { + resize (width: number = this._width, height: number = this._height): void { this._data = new Uint8Array((width / 8) * height); this._pixelWidth = this.canvasWidth / this._width; this._pixelHeight = this.canvasHeight / this._height; @@ -126,17 +126,27 @@ class BittMappEditor { } + get height (): number { + return this._height; + } + + set height (height: number) { this.resize(this._width, height); } + get width (): number { + return this._width; + } + + set width (width: number) { this.resize(width, this._height); } - _handleMouseEvent (event: MouseEvent, button: number) { + _handleMouseEvent (event: MouseEvent, button: number): void { const pixelX: number = Math.floor(event.offsetX / this._pixelWidth), pixelY: number = Math.floor(event.offsetY / this._pixelHeight); @@ -152,13 +162,13 @@ class BittMappEditor { } - _redraw () { + _redraw (): void { this._drawGrid(); this._drawPixels(); } - _drawGrid () { + _drawGrid (): void { this._context.fillStyle = "#FFFFFF"; this._context.strokeStyle = "#CCCCCC"; @@ -199,7 +209,9 @@ class BittMappEditor { } - _drawPixels () { + _drawPixels (): void { + + console.log(this.width); this._context.fillStyle = "#000000"; this._context.strokeStyle = "#FFFFFFF"; diff --git a/src/main.ts b/src/main.ts index 74695d1..1c0105a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,4 @@ -window.onload = function () { +window.onload = function (): void { let editor: BittMappEditor = new BittMappEditor({ canvas: document.getElementById("editor"),