-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
216 lines (189 loc) · 10.3 KB
/
index.html
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp"
crossorigin="anonymous">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN"
crossorigin="anonymous">
</head>
<body>
<div id="canvas-container">
<canvas id="canvas-real" class="canvas" width='1366px' height='768px'></canvas>
<canvas id="canvas-draft" class="canvas" width='1366px' height='768px'></canvas>
</div>
<div class="buttons">
<span class="btn btn-primary fa fa-square" id="drawing-rectangle">Drawing Rectangle</span>
<span class="btn btn-info fa fa-paint-brush" id="drawing-line">Drawing Line</span>
<span class="btn btn-info fa fa-paint-brush" id="drawing-ellipse">Drawing Ellipse</span>
<span class="btn btn-danger fa fa-paint-brush" id="drawing-strokerectangle">Drawing StrokeRectangle</span>
<span class="btn btn-danger fa fa-paint-brush" id="drawing-straight-line">Drawing Straight Line</span>
<span class="btn btn-danger fa fa-paint-brush" id="drawing-curve">Drawing Curve</span>
<span class="btn btn-danger fa fa-paint-brush" id="drawing-polygon">Drawing Polygon</span>
<span class="btn btn-danger fa fa-paint-brush" id="eraser">Eraser</span>
<span class="btn btn-danger fa fa-paint-brush" id="clear">Clear</span>
<span class="btn btn-primary fa fa-square" id="undo">Undo</span>
<span class="btn btn-primary fa fa-paint-brush" id="redo">Redo</span>
<button><input type='text' id="strokestyle" />For strokeStyle</button>
<button><input type='text' id="fillstyle" />For fillStyle</button>
<button><input type='text' id="background" />For background</button>
<span class="btn btn-danger fa fa-paint-brush" id="eyedropper">Eyedropper</span>
<input id="linewidth" type="range" orient="vertical" name="linewidth" min="1" max="100">
<select name="LineType" id="linetype">
<option value="butt">butt</option>
<option value="round">round</option>
<option value="square">square</option>
</select>
<select name="LineJoin" id="linejoin">
<option value="butt">miter</option>
<option value="round">round</option>
<option value="square">bevel</option>
</select>
<!--<select name="linedash" id="linedash">
<option value="[0]">No Dash</option>
<option value="[5]">Dash</option>
</select>-->
<span class="btn btn-danger fa fa-font" id="text-tool">Text Tool</span>
<div id="text-panel">
<form id="add-text">
<label for="text">Text:</label>
<input type="text" name="text" id="text">
<label for="size">Size:</label>
<select id="size" name="size">
<option value = "9" selected>9px</option>
<option value = "12">12px</option>
<option value = "14">14px</option>
<option value = "16">16px</option>
<option value = "20">20px</option>
<option value = "48">48px</option>
<option value = "72">72px</option>
<option value = "96">96px</option>
<option value = "144">144px</option>
<option value = "200">200px</option>
</select>
<label for="fillOrStroke">Fill Or Stroke:</label>
<select id="fillOrStroke" name="fillOrStroke">
<option value = "fill" selected>fill</option>
<option value = "stroke">stroke</option>
</select>
<label for="font-family">Font Family:</label>
<select id="font-family" name="fontFamily">
<option value = "Arial" selected>Arial</option>
<option value = "Times New Roman">Times New Roman</option>
</select>
<label for="style">Style:</label>
<select id="style" name="style">
<option value = "normal" selected>Normal</option>
<option value = "bold">Bold</option>
<option value = "italic">Italic</option>
<option value = "both">Both</option>
</select>
<button type="submit">Add Text</button>
<label for="xpos">X-position: <span id="xpos"></span></label>
<label for="xpos">Y-position: <span id="ypos"></span></label>
</form>
</div>
</div>
<script type='text/javascript' src="https://code.jquery.com/jquery-3.2.1.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous"></script>
<script src='scripts/spectrum.js'></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.8/hammer.js"></script>
<link rel='stylesheet' href='css/spectrum.css' />
<script type='text/javascript' src="scripts/canvas-common.js"></script>
<script type='text/javascript' src="scripts/drawing-line.js"></script>
<script type='text/javascript' src="scripts/drawing-ellipse.js"></script>
<script type='text/javascript' src="scripts/drawing-rectangle.js"></script>
<script type='text/javascript' src="scripts/drawing-strokerectangle.js"></script>
<script type='text/javascript' src="scripts/drawing-straight-line.js"></script>
<script type='text/javascript' src="scripts/drawing-curve.js"></script>
<script type='text/javascript' src="scripts/drawing-polygon.js"></script>
<script type='text/javascript' src="scripts/eraser.js"></script>
<script type='text/javascript' src="scripts/setstrokestyle.js"></script>
<script type='text/javascript' src="scripts/setfillstyle.js"></script>
<script type='text/javascript' src="scripts/setbackground.js"></script>
<script type='text/javascript' src="scripts/eyedropper.js"></script>
<script type='text/javascript' src="scripts/setlinewidth.js"></script>
<script type='text/javascript' src="scripts/setlinetype.js"></script>
<script type='text/javascript' src="scripts/setlinejoin.js"></script>
<!--<script type='text/javascript' src="scripts/setlinedash.js"></script>-->
<script type='text/javascript' src="scripts/add-text.js"></script>
<link href="css/style.css" rel="stylesheet" type='text/css'>
<script type='text/javascript'>
$('#drawing-rectangle').click(() => {
currentFunction = new DrawingRectangle(contextReal, contextDraft);
});
$('#drawing-line').click(() => {
currentFunction = new DrawingLine(contextReal, contextDraft);
});
$('#drawing-ellipse').click(() => {
currentFunction = new DrawingEllipse(contextReal, contextDraft);
});
$('#drawing-strokerectangle').click(() => {
currentFunction = new DrawingStrokeRectangle(contextReal, contextDraft);
});
$('#drawing-straight-line').click(() => {
currentFunction = new DrawingStraightLine(contextReal, contextDraft);
});
$('#drawing-curve').click(() => {
currentFunction = new DrawingCurve(contextReal, contextDraft);
});
$('#drawing-polygon').click(() => {
currentFunction = new DrawingPolygon(contextReal, contextDraft);
});
$('#eraser').click(function () {
currentFunction = new Eraser(contextReal, contextDraft);
});
$('#clear').click(() => {
contextDraft.clearRect(0, 0, canvasDraft.width, canvasDraft.height);
contextReal.clearRect(0, 0, canvasReal.width, canvasReal.height);
});
let undoClicked = false; //first click of Undo
$('#undo').click(() => {
var canvasPic = new Image();
if (undoClicked === false) { //if firstclick needs extra pop
undoList.pop();
undoClicked = true; // if not firstclick only needs to pop once so returns true
}
if (undoList.length == 0) { // to clear the canvas when there is no more image stored
contextReal.clearRect(0, 0, canvasReal.width, canvasReal.height);
return;
}
canvasPic.src = undoList.pop();
canvasPic.onload = function () {
contextReal.clearRect(0, 0, canvasReal.width, canvasReal.height);
contextReal.drawImage(canvasPic, 0, 0);
}
});
$("#eyedropper").click(function () {
currentFunction = new EyeDropper(contextReal);
});
$("#text-tool").click(function () {
currentFunction = new AddText(contextReal, contextDraft);
});
//Listen the input fields change
$('select[name="fontFamily"]').change(function (e) {
currentFunction.onChangeFontFamily(contextDraft, e.target.value);
})
$('input[name="text"]').change(function (e) {
currentFunction.onChangeText(contextDraft, e.target.value);
})
$('select[name="fillOrStroke"]').change(function (e) {
currentFunction.onChangeFillOrStroke(contextDraft, e.target.value);
})
$('select[name="style"]').change(function (e) {
currentFunction.onChangeStyle(contextDraft, e.target.value);
})
$('select[name="size"]').change(function (e) {
currentFunction.onChangeSize(contextDraft, e.target.value);
})
$('#add-text').submit(function (e) {
e.preventDefault();
currentFunction.onSubmit();
this.reset();
});
currentFunction = new DrawingLine(contextReal, contextDraft);
</script>
</body>
</html>