-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
90 lines (72 loc) · 1.99 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
'use strict';
/**
* @ngdoc function
* @name arheadosApp.controller:MainCtrl
* @description
* # MainCtrl
* Controller of the arheadosApp
*/
angular.module('arheadosApp')
.controller('MainCtrl', function ($scope, drawManager) {
var colors = {
transparent: 'rgba(0, 0, 0, 0)',
black: 'rgba(0, 0, 0, 1)',
gray: 'rgba(180, 180, 180, 1)'
};
//Internal
var
//Variables
canvas,
resizeCanvas = function () {
var container = document.getElementById('canvasContainer');
var w = container.clientWidth;
var h = window.innerHeight * 0.70;
canvas.width = w;
canvas.height = h;
drawManager.setCanvasSize(canvas.width, canvas.height);
drawManager.resetDraw();
}
;
//Bindings
$scope.shape = {
tool : 'pencil',
lineColor : colors.black,
lineWidth : 1,
lineCap : 'round',
fillStyle : colors.transparent,
filled : true,
stroked : true
};
//Funcions
$scope.init = function () {
canvas = document.getElementById('canvas');
drawManager.setContext(canvas.getContext('2d'));
canvas.ontouchstart =
canvas.onmousedown = function () {
drawManager.startDrawing($scope.shape);
};
canvas.ontouchmove = function () {
event.preventDefault();
drawManager.continueDrawing ();
};
canvas.onmousemove = function () {
drawManager.continueDrawing ();
};
canvas.ontouchend =
canvas.ontouchcancel =
canvas.onmouseup = function () {
drawManager.endDrawing();
};
window.addEventListener('resize', resizeCanvas);
window.addEventListener('load', resizeCanvas());
};
$scope.resetDraw = function (){
drawManager.resetDraw();
};
$scope.undo = function () {
drawManager.undo();
};
$scope.$watch('shape.tool', function () {
$scope.shape.filled = $scope.shape.tool !== 'pencil';
});
});