muaz-khan / Canvas-Designer

Collaborative, extendable, JavaScript Canvas2D drawing tool, supports dozens of builtin tools, as well as generates JavaScript code for 2D animations.
https://www.webrtc-experiment.com/Canvas-Designer/
MIT License
368 stars 171 forks source link

How to drag and drop an image to canvas #76

Open tabishmirza opened 3 years ago

tabishmirza commented 3 years ago

Hi Muaz,

First of all, thanks for the great library. I have been trying to drag and drop images on the canvas but canvas behavior is weird. Here is what i am doing. i make the image dragable and then on "temp-canvas" drop event i execute the following code

        ev.preventDefault();

        var data = ev.dataTransfer.getData("icon-id");

        var x = ev.pageX;
        var y = ev.pageY;

        var image = document.getElementById(data);

        var points = [
            ['image', [image.src, x, y, image.width, image.height, 1],
                ['2', '#6c96c8', 'rgba(0,0,0,0)', '1', 'source-over', 'round', 'round', '15px "Arial"']
            ]
        ];

        designer.syncData({
            startIndex: designer.pointsLength,
            points: points
        });

this does not trigger my designer.addSyncListener callback. please help me with this

tabishmirza commented 3 years ago

@muaz-khan please help me with this

Thanks