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

View File

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

View File

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