Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

erase function is creating problem with undo button #41

Open
sanjaysamant opened this issue Aug 7, 2020 · 0 comments
Open

erase function is creating problem with undo button #41

sanjaysamant opened this issue Aug 7, 2020 · 0 comments

Comments

@sanjaysamant
Copy link

sanjaysamant commented Aug 7, 2020

I have implemented the eraser button, but getting issue while doing undo after erase. If I am erasing only one time on that time undo is working fine if I am erasing more than once then the last erased stroke works fine with undo but other are working as a line stroke.

Please see the below code

`Sketchpad.prototype._stroke = function(start, end, color, size) {
this.context.save();
if(bErasing){
this.context.globalCompositeOperation = "destination-out";
}else{
this.context.globalCompositeOperation = "source-over";
}
// if(size === 7 || size === 13){
// console.log(size)
// this.context.lineJoin = 'square';
// this.context.lineCap = 'square';
// }
// else{
this.context.lineJoin = 'round';
this.context.lineCap = 'round';
// }
this.context.strokeStyle = color;
this.context.lineWidth = size;
// switch(size){

//     case 2:
//     this.context.globalAlpha = 1;
//     break;
//     case 7:
//     this.context.globalAlpha = 0.7;
//     break;
//     case 13:
//     this.context.globalAlpha = 0.4;
//     break;
//     default:
//     this.context.globalAlpha = 0.2;
// }
this.context.beginPath();
this.context.moveTo(start.x, start.y);
this.context.lineTo(end.x, end.y);
this.context.closePath();
this.context.stroke();

this.context.restore();

};
`

and function call is here:-

` var x = "#CB7342",
y = 2;
var bErasing = false;
var canvas, canvasWidth, canvasHeight;
var ctx;
var lastPt=null;
var pathsry = [];
var points = [];
var state;
var colour;
// past states
function ySize(size) {

    y = size;
    sketchpad.penSize = y;
}
var sketchpad;
function undo(){
    bErasing = false;
    sketchpad.undo();
}

function init() {
    canvas = document.getElementById('sheet');
    ctx = canvas.getContext('2d');
    var canvasOffset = $('#sheet').offset();
    var parent = canvas.parentNode;
    canvas.width = parent.clientWidth;
    canvas.height = parent.clientHeight;
    // alert(bErasing)
    sketchpad = new Sketchpad({
        element: '#sheet',
        width: canvas.width,
        height: canvas.height,
        color: null,
        penSize: 2,
        globalAlpha: 0.1
    });
}
// function erase(){
//     sketchpad.erase();
// }
$(document).on('click', "#erase", function () {
    bErasing = true;
});

`

Please help me on this I am trying from last 3 days, but did not get resolution
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant