clear fix

This commit is contained in:
Mahdi Dibaiee 2014-02-05 20:08:28 +03:30
parent cfe3bb7e99
commit 3f17f819d4
3 changed files with 23 additions and 13 deletions

View File

@ -9,7 +9,7 @@ function save() {
}
c.fillStyle = 'white';
c.globalCompositeOperation = 'destination-over';
c.fillRect(0, 0, $c.width(), $c.height());
c.fillRect(0, 0, width(), height());
c.fillStyle = cache.fillStyle;
c.globalCompositeOperation = cache.composite;
break;
@ -21,7 +21,7 @@ function save() {
}
c.fillStyle = settings.strokeStyle;
c.globalCompositeOperation = 'destination-over';
c.fillRect(0, 0, $c.width(), $c.height());
c.fillRect(0, 0, width(), height());
c.fillStyle = cache.fillStyle;
c.globalCompositeOperation = cache.composite;
break;
@ -59,7 +59,7 @@ function save() {
}
window.points.history.push({
data: c.getImageData(0, 0, $c.width(), $c.height()),
data: c.getImageData(0, 0, width(), height()),
points: window.points.slice(0)
})
window.points.history.last = window.points.history.length-1;
@ -168,13 +168,14 @@ function save() {
// Bottom
$('#clear').click(function() {
c.clearRect(0, 0, $c.width(), $c.height());
c.clearRect(0, 0, width(), height());
window.points = [];
if(window.points.history.last < window.points.history.length-1) {
window.points.history.splice(window.points.history.last+1);
}
window.points.history.push({
data: c.getImageData(0, 0, $c.width(), $c.height()),
data: c.getImageData(0, 0, width(), height()),
points: []
})
window.points.history.last = window.points.history.length-1;

View File

@ -7,19 +7,19 @@ function sizeAndPos() {
var w = $(window).width(),
h = $(window).height();
$c.attr('width', w * window.devicePixelRatio);
$c.attr('height',h * window.devicePixelRatio - 53 * window.devicePixelRatio);
$c.attr('height',(h - 53) * window.devicePixelRatio);
$c.css({
'width' : w,
'height' : h - 53
});
c.clearRect(0,0, $c.width(), $c.height());
c.clearRect(0,0, width(), height());
c.putImageData(data, 0, 0);
}
function relative(x,y) {
return {
x : x*window.devicePixelRatio,
y : y*window.devicePixelRatio - 53 * window.devicePixelRatio
y : (y - 53) * window.devicePixelRatio
}
}
@ -79,6 +79,14 @@ function redo() {
}
}
function width() {
return $c.width() * window.devicePixelRatio;
}
function height() {
return ($c.height() - 53) * window.devicePixelRatio;
}
function dataToBlob(data) {
var binary = atob(data.split(',')[1]), array = [];
var type = data.split(',')[0].split(':')[1].split(';')[0];

View File

@ -9,7 +9,7 @@ function save() {
}
c.fillStyle = 'white';
c.globalCompositeOperation = 'destination-over';
c.fillRect(0, 0, $c.width(), $c.height());
c.fillRect(0, 0, width(), height());
c.fillStyle = cache.fillStyle;
c.globalCompositeOperation = cache.composite;
break;
@ -21,7 +21,7 @@ function save() {
}
c.fillStyle = settings.strokeStyle;
c.globalCompositeOperation = 'destination-over';
c.fillRect(0, 0, $c.width(), $c.height());
c.fillRect(0, 0, width(), height());
c.fillStyle = cache.fillStyle;
c.globalCompositeOperation = cache.composite;
break;
@ -66,7 +66,7 @@ function save() {
}
window.points.history.push({
data: c.getImageData(0, 0, $c.width(), $c.height()),
data: c.getImageData(0, 0, width(), height()),
points: window.points.slice(0)
})
window.points.history.last = window.points.history.length-1;
@ -173,13 +173,14 @@ function save() {
// Bottom
$('#clear').on('tap', function() {
c.clearRect(0, 0, $c.width(), $c.height());
c.clearRect(0, 0, width(), height());
window.points = [];
if(window.points.history.last < window.points.history.length-1) {
window.points.history.splice(window.points.history.last+1);
}
window.points.history.push({
data: c.getImageData(0, 0, $c.width(), $c.height()),
data: c.getImageData(0, 0, width(), height()),
points: []
})
window.points.history.last = window.points.history.length-1;