Commit cec74ba8 authored by Nezael's avatar Nezael
Browse files

Bug is now corrected

we can now draw properly where the mouse is.
parent 9a25a312
......@@ -8,18 +8,19 @@
/* Controllers */
root.controller('PaperBoardCtrl', ['$scope', '$stateParams', '$http', '$state', '$paperboardFactory', '$languageFactory', '$utilsFactory', function ($scope, $stateParams, $http, $state, $paperboardFactory, $languageFactory, $utilsFactory) {
var paperBoardCtrl = this;
let paperBoardCtrl = this;
let canvas = document.querySelector('#drawZone');
let ctx = canvas.getContext("2d");
let rect;
let mouseX = 0;
let mouseY = 0;
let lineWidth = 3;
let isDrawing = false;
let style = "#000";
let pen = false;
var canvas = document.querySelector('#drawZone');
var ctx = canvas.getContext("2d");
var rect = canvas.getBoundingClientRect();
var mouseX = 0;
var mouseY = 0;
var lineWidth = 3;
var isDrawing = false;
var style = "#000";
var pen = false;
paperBoardCtrl.getPaperBoardDetails = function (paperBoardDetails) {
if (!paperBoardDetails) var paperBoardDetails = {"id": $stateParams.elementId};
......@@ -29,7 +30,7 @@ root.controller('PaperBoardCtrl', ['$scope', '$stateParams', '$http', '$state',
{
if (data.status == "success")
{
var paperboard = data.details[0];
let paperboard = data.details[0];
paperBoardCtrl.paperboard = JSON.parse(paperboard.params);
paperBoardCtrl.paperboard.id = paperboard.id;
paperBoardCtrl.paperboard.type = 1;
......@@ -62,7 +63,7 @@ root.controller('PaperBoardCtrl', ['$scope', '$stateParams', '$http', '$state',
$scope.leaveBoard = function(){
alert("Vous venez de quitter l'atelier");
alert("Vous venez de quitter l'atelier");
}
paperBoardCtrl.getPaperBoardDetails();
......@@ -74,8 +75,12 @@ root.controller('PaperBoardCtrl', ['$scope', '$stateParams', '$http', '$state',
canvas.addEventListener('mousedown', e=>
{
rect = canvas.getBoundingClientRect();
mouseX = e.clientX - rect.left;
mouseY = e.clientY - rect.top;
console.log("position souris X: " + e.clientX + "position canvas X: " + rect.left);
console.log("position souris Y: " + e.clientY + "position canvas Y: " + rect.top)
console.log("X: " + mouseX + " : Y: " + mouseY);
isDrawing = true;
});
......@@ -85,9 +90,11 @@ root.controller('PaperBoardCtrl', ['$scope', '$stateParams', '$http', '$state',
{
if(pen)
{
console.log("après dessin X: " + mouseX + " : Y: " + mouseY);
paperBoardCtrl.lineDraw(ctx,mouseX,mouseY,e.clientX - rect.left, e.clientY - rect.top, style, lineWidth);
mouseX = e.clientX - rect.left;
mouseY = e.clientY - rect.top;
}
}
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment