Skip to content

Commit 158cc8b

Browse files
committed
prevent saving when saving, brush one point fix
1 parent 6ecba80 commit 158cc8b

4 files changed

Lines changed: 35 additions & 21 deletions

File tree

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,4 +318,3 @@ ToDo list
318318
- Add recent image sizes in resize tool
319319
- Blur region
320320
- Ability to save loacaly
321-
- API for load file by URL

build/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
Painterro({
4848
// hiddenTools: ['save']
49-
}).show().save();
49+
}).show();
5050
</script>
5151
</body>
5252
</html>

js/main.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ class PainterroProc {
330330
this.ratioRelation = undefined;
331331
this.id = this.params.id;
332332
this.bgColor = this.params.backgroundFillColor;
333+
this.saving = false;
333334

334335
if (this.id === undefined) {
335336
this.id = genId();
@@ -501,6 +502,10 @@ class PainterroProc {
501502
}
502503

503504
save () {
505+
if (this.saving) {
506+
return
507+
}
508+
this.saving = true;
504509
const btn = document.getElementById(this.toolByName.save.buttonId);
505510
const icon = document.querySelector(`#${this.toolByName.save.buttonId} > i`);
506511
btn && (btn.setAttribute('disabled', 'true'));
@@ -512,12 +517,12 @@ class PainterroProc {
512517
this.hide()
513518
}
514519
icon && (icon.className = 'ptro-icon ptro-icon-save');
515-
//btn && (btn.removeAttribute('disabled'));
520+
this.saving = false;
516521
})
517522
} else {
518523
console.error("No saveHandler defined, please check documentation")
519524
icon && (icon.className = 'ptro-icon ptro-icon-save');
520-
//btn && (btn.removeAttribute('disabled'))
525+
this.saving = false;
521526
}
522527
return this;
523528
}

js/primitive.js

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,34 @@ export class PrimitiveTool {
5959
drawBrushPath () {
6060
const smPoints = this.points;
6161

62-
this.ctx.beginPath();
63-
this.ctx.lineWidth = this.lineWidth;
64-
this.ctx.strokeStyle = this.main.colorWidgetState.line.alphaColor;
65-
this.ctx.fillStyle = this.main.colorWidgetState.fill.alphaColor;
66-
67-
this.ctx.moveTo(this.points[0].x, this.points[0].y);
68-
let last;
69-
for (let p of smPoints.slice(1)) {
70-
this.ctx.lineTo(p.x, p.y);
71-
last = p;
72-
}
73-
if (last) {
74-
this.ctx.moveTo(last.x, last.y);
62+
if (smPoints.length === 1) {
63+
this.ctx.beginPath();
64+
this.ctx.lineWidth = 0;
65+
this.ctx.fillStyle = this.main.colorWidgetState.line.alphaColor;
66+
this.ctx.ellipse(
67+
this.points[0].x, this.points[0].y,
68+
this.lineWidth / 2, this.lineWidth / 2,
69+
0, 2 * Math.PI, false);
70+
this.ctx.fill();
71+
this.ctx.closePath();
72+
} else {
73+
this.ctx.beginPath();
74+
this.ctx.lineWidth = this.lineWidth;
75+
this.ctx.strokeStyle = this.main.colorWidgetState.line.alphaColor;
76+
this.ctx.fillStyle = this.main.colorWidgetState.fill.alphaColor;
77+
78+
this.ctx.moveTo(this.points[0].x, this.points[0].y);
79+
let last;
80+
for (let p of smPoints.slice(1)) {
81+
this.ctx.lineTo(p.x, p.y);
82+
last = p;
83+
}
84+
if (last) {
85+
this.ctx.moveTo(last.x, last.y);
86+
}
87+
this.ctx.stroke();
88+
this.ctx.closePath();
7589
}
76-
77-
this.ctx.stroke();
78-
79-
this.ctx.closePath();
8090
}
8191

8292
handleMouseMove(event) {

0 commit comments

Comments
 (0)