mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-24 02:27:19 +00:00
Slight improvements to bitmap editor
This commit is contained in:
parent
3126a15758
commit
cab5c88d3a
@ -17,7 +17,9 @@ function BitmapEditor(macroNode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BitmapEditor.prototype.getContent = function() {
|
BitmapEditor.prototype.getContent = function() {
|
||||||
return [Renderer.ElementNode("canvas",{},[])];
|
return [Renderer.ElementNode("canvas",{
|
||||||
|
"class": ["tw-edit-field"]
|
||||||
|
},[])];
|
||||||
};
|
};
|
||||||
|
|
||||||
BitmapEditor.prototype.renderInDom = function() {
|
BitmapEditor.prototype.renderInDom = function() {
|
||||||
@ -36,13 +38,14 @@ BitmapEditor.prototype.addEventHandlers = function() {
|
|||||||
var self = this;
|
var self = this;
|
||||||
this.macroNode.domNode.addEventListener("touchstart",function(event) {
|
this.macroNode.domNode.addEventListener("touchstart",function(event) {
|
||||||
self.brushDown = true;
|
self.brushDown = true;
|
||||||
|
self.strokeStart(event.touches[0].clientX,event.touches[0].clientY);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
return false;
|
return false;
|
||||||
},false);
|
},false);
|
||||||
this.macroNode.domNode.addEventListener("touchmove",function(event) {
|
this.macroNode.domNode.addEventListener("touchmove",function(event) {
|
||||||
if(self.brushDown) {
|
if(self.brushDown) {
|
||||||
self.moveTo(event.touches[0].clientX,event.touches[0].clientY);
|
self.strokeMove(event.touches[0].clientX,event.touches[0].clientY);
|
||||||
}
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
@ -51,6 +54,7 @@ BitmapEditor.prototype.addEventHandlers = function() {
|
|||||||
this.macroNode.domNode.addEventListener("touchend",function(event) {
|
this.macroNode.domNode.addEventListener("touchend",function(event) {
|
||||||
if(self.brushDown) {
|
if(self.brushDown) {
|
||||||
self.brushDown = false;
|
self.brushDown = false;
|
||||||
|
self.strokeEnd();
|
||||||
self.saveChanges();
|
self.saveChanges();
|
||||||
}
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@ -58,13 +62,16 @@ BitmapEditor.prototype.addEventHandlers = function() {
|
|||||||
return false;
|
return false;
|
||||||
},false);
|
},false);
|
||||||
this.macroNode.domNode.addEventListener("mousedown",function(event) {
|
this.macroNode.domNode.addEventListener("mousedown",function(event) {
|
||||||
|
self.strokeStart(event.clientX,event.clientY);
|
||||||
self.brushDown = true;
|
self.brushDown = true;
|
||||||
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
return false;
|
return false;
|
||||||
},false);
|
},false);
|
||||||
this.macroNode.domNode.addEventListener("mousemove",function(event) {
|
this.macroNode.domNode.addEventListener("mousemove",function(event) {
|
||||||
if(self.brushDown) {
|
if(self.brushDown) {
|
||||||
self.moveTo(event.clientX,event.clientY);
|
self.strokeMove(event.clientX,event.clientY);
|
||||||
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -72,7 +79,9 @@ BitmapEditor.prototype.addEventHandlers = function() {
|
|||||||
this.macroNode.domNode.addEventListener("mouseup",function(event) {
|
this.macroNode.domNode.addEventListener("mouseup",function(event) {
|
||||||
if(self.brushDown) {
|
if(self.brushDown) {
|
||||||
self.brushDown = false;
|
self.brushDown = false;
|
||||||
|
self.strokeEnd();
|
||||||
self.saveChanges();
|
self.saveChanges();
|
||||||
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -80,14 +89,31 @@ BitmapEditor.prototype.addEventHandlers = function() {
|
|||||||
},false);
|
},false);
|
||||||
};
|
};
|
||||||
|
|
||||||
BitmapEditor.prototype.moveTo = function(x,y) {
|
BitmapEditor.prototype.strokeStart = function(x,y) {
|
||||||
var canvas = this.macroNode.content[0].domNode,
|
var canvas = this.macroNode.content[0].domNode,
|
||||||
canvasRect = canvas.getBoundingClientRect(),
|
canvasRect = canvas.getBoundingClientRect(),
|
||||||
ctx = canvas.getContext("2d");
|
ctx = canvas.getContext("2d");
|
||||||
ctx.beginPath();
|
this.startX = x - canvasRect.left;
|
||||||
ctx.arc(x - canvasRect.left,y - canvasRect.top,10,0,Math.PI*2,false);
|
this.startY = y - canvasRect.top;
|
||||||
ctx.fill();
|
// ctx.beginPath();
|
||||||
ctx.closePath();
|
ctx.moveTo(this.startX,this.startY);
|
||||||
|
};
|
||||||
|
|
||||||
|
BitmapEditor.prototype.strokeMove = function(x,y) {
|
||||||
|
var canvas = this.macroNode.content[0].domNode,
|
||||||
|
canvasRect = canvas.getBoundingClientRect(),
|
||||||
|
ctx = canvas.getContext("2d");
|
||||||
|
ctx.lineWidth = 2;
|
||||||
|
ctx.lineCap = "round";
|
||||||
|
ctx.lineJoin = "round";
|
||||||
|
this.startX = x - canvasRect.left;
|
||||||
|
this.startY = y - canvasRect.top;
|
||||||
|
ctx.lineTo(this.startX,this.startY);
|
||||||
|
ctx.stroke();
|
||||||
|
};
|
||||||
|
|
||||||
|
BitmapEditor.prototype.strokeEnd = function() {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
BitmapEditor.prototype.saveChanges = function() {
|
BitmapEditor.prototype.saveChanges = function() {
|
||||||
|
@ -17,6 +17,13 @@ body {
|
|||||||
border: 1px dotted #888;
|
border: 1px dotted #888;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
canvas.tw-edit-field {
|
||||||
|
cursor: crosshair;
|
||||||
|
-moz-user-select: none;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
-ms-user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
img {
|
img {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user