This commit is contained in:
Claudio Maggioni 2019-10-07 12:17:28 +02:00
parent e27b27e935
commit a1288af118
3 changed files with 26 additions and 21 deletions

View file

@ -38,7 +38,6 @@ class App {
if (this.buttons.camera)
this.buttons.camera.addEventListener('click', () => {
player.srcObject.getVideoTracks().forEach(track => track.stop());
const base64 = this.canvas.toDataURL();
const img = document.createElement('img');
img.src = base64;
@ -83,6 +82,7 @@ class App {
this.brush = "PenBrush";
const brushToolbar = document.querySelector('#brush-toolbar');
if (brushToolbar) {
for (const name in App.BRUSHES) {
const b = document.createElement('button');
b.innerText = name;
@ -95,9 +95,11 @@ class App {
const color = document.createElement('input');
color.type = 'color';
color.name = 'color';
color.value = this.constructor.defaultStrokeStyle;
color.addEventListener('change', () => this.strokeStyle = color.value);
brushToolbar.appendChild(label);
brushToolbar.appendChild(color);
}
this.canvas.addEventListener('mousedown', this.startPath.bind(this));
this.canvas.addEventListener('mousemove', this.draw.bind(this));
@ -110,6 +112,9 @@ class App {
}
get strokeStyle() {
if (this.ctx.strokeStyle == '#000000') {
return 'black';
}
return this.ctx.strokeStyle;
}

View file

@ -4,10 +4,9 @@ const history = {
paths: []
}
history.pop = (app) => {
history.pop = () => {
if (history.paths.length == 0) return;
history.paths.pop();
app.redrawAll();
return history.paths.pop();
};
history.initializeNewPath = () => {
@ -15,10 +14,11 @@ history.initializeNewPath = () => {
};
history.push = (stroke) => {
if (!stroke instanceof Stroke) {
if (!stroke || !stroke instanceof Stroke) {
throw new Error(JSON.stringify(stroke) + ' is not a Stroke instance');
}
history.paths[history.paths.length - 1].push(stroke);
return history.paths[history.paths.length - 1];
}
history.clear = () => {

View file

@ -117,13 +117,13 @@ body{
color: white;
}
#favourites div.gallery {
#favourites {
margin: 5px;
float: left;
width: 200px;
}
#favourites div.gallery img {
#favourites img {
width: 90%;
height: 100px;
box-shadow: 1px 1px 3px 1px rgba(0, 0, 0, 0.42);