Skip to content

Commit

Permalink
prevent saving when saving, brush one point fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ivictbor committed Jun 30, 2017
1 parent 6ecba80 commit 158cc8b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,3 @@ ToDo list
- Add recent image sizes in resize tool
- Blur region
- Ability to save loacaly
- API for load file by URL
2 changes: 1 addition & 1 deletion build/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

Painterro({
// hiddenTools: ['save']
}).show().save();
}).show();
</script>
</body>
</html>
9 changes: 7 additions & 2 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ class PainterroProc {
this.ratioRelation = undefined;
this.id = this.params.id;
this.bgColor = this.params.backgroundFillColor;
this.saving = false;

if (this.id === undefined) {
this.id = genId();
Expand Down Expand Up @@ -501,6 +502,10 @@ class PainterroProc {
}

save () {
if (this.saving) {
return
}
this.saving = true;
const btn = document.getElementById(this.toolByName.save.buttonId);
const icon = document.querySelector(`#${this.toolByName.save.buttonId} > i`);
btn && (btn.setAttribute('disabled', 'true'));
Expand All @@ -512,12 +517,12 @@ class PainterroProc {
this.hide()
}
icon && (icon.className = 'ptro-icon ptro-icon-save');
//btn && (btn.removeAttribute('disabled'));
this.saving = false;
})
} else {
console.error("No saveHandler defined, please check documentation")
icon && (icon.className = 'ptro-icon ptro-icon-save');
//btn && (btn.removeAttribute('disabled'))
this.saving = false;
}
return this;
}
Expand Down
44 changes: 27 additions & 17 deletions js/primitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,34 @@ export class PrimitiveTool {
drawBrushPath () {
const smPoints = this.points;

this.ctx.beginPath();
this.ctx.lineWidth = this.lineWidth;
this.ctx.strokeStyle = this.main.colorWidgetState.line.alphaColor;
this.ctx.fillStyle = this.main.colorWidgetState.fill.alphaColor;

this.ctx.moveTo(this.points[0].x, this.points[0].y);
let last;
for (let p of smPoints.slice(1)) {
this.ctx.lineTo(p.x, p.y);
last = p;
}
if (last) {
this.ctx.moveTo(last.x, last.y);
if (smPoints.length === 1) {
this.ctx.beginPath();
this.ctx.lineWidth = 0;
this.ctx.fillStyle = this.main.colorWidgetState.line.alphaColor;
this.ctx.ellipse(
this.points[0].x, this.points[0].y,
this.lineWidth / 2, this.lineWidth / 2,
0, 2 * Math.PI, false);
this.ctx.fill();
this.ctx.closePath();
} else {
this.ctx.beginPath();
this.ctx.lineWidth = this.lineWidth;
this.ctx.strokeStyle = this.main.colorWidgetState.line.alphaColor;
this.ctx.fillStyle = this.main.colorWidgetState.fill.alphaColor;

this.ctx.moveTo(this.points[0].x, this.points[0].y);
let last;
for (let p of smPoints.slice(1)) {
this.ctx.lineTo(p.x, p.y);
last = p;
}
if (last) {
this.ctx.moveTo(last.x, last.y);
}
this.ctx.stroke();
this.ctx.closePath();
}

this.ctx.stroke();

this.ctx.closePath();
}

handleMouseMove(event) {
Expand Down

0 comments on commit 158cc8b

Please sign in to comment.