1
1
<template >
2
- <body style =" background-image : url (' https://png.pngtree.com/thumb_back/fh260/background/20190331/pngtree-vector-white-abstract-background-design-templates-collection-wit-image_94438.jpg' ); background-repeat : repeat ;" >
3
- <div class = " mt-5 orgs" >
4
- <h1 style =" font-family : georgia ; font-size : 45px ;" >
5
- <center >
6
- <b >Create a New Badge!</b >
7
- </center >
8
- </h1 >
9
- <h2 style =" margin-bottom : 30px ; font-family : georgia ; font-size : 25px ;" >
10
- <center >
2
+ <body style =" background-image : url (' https://png.pngtree.com/thumb_back/fh260/background/20190331/pngtree-vector-white-abstract-background-design-templates-collection-wit-image_94438.jpg' ); background-repeat : repeat ; padding-top : 48px ; padding-bottom : 25px ;" >
3
+ <div >
4
+ <h1 style =" font-family : georgia ; font-size : 45px ; text-align : center ;" >
5
+ <b >Create a New Badge!</b >
6
+ </h1 >
7
+ <h2 style =" margin-bottom : 30px ; font-family : georgia ; font-size : 25px ; text-align : center ;" >
11
8
<b >Design your own badge for your organization.</b >
12
- </center >
13
- </ h2 >
14
- < Buttons />
15
- < v-layout style = " margin : 10 px ; " justify-center = " " >
16
- < canvas id = " canvas " width = " 900 " height = " 600 " >
17
- </ canvas >
18
- </ v-layout >
19
- </div >
20
- </body >
9
+ </h2 >
10
+ < div >
11
+ < DrawButtons />
12
+ < canvas id = " canvas " width = " 900 " height = " 600 " >
13
+ </ canvas >
14
+ </ div >
15
+ < ToolButtons / >
16
+ </div >
17
+ </body >
21
18
</template >
22
19
20
+ <style >
21
+
22
+ canvas {
23
+ background-color : white ;
24
+ border : 2px solid gray ;
25
+ border-radius : 2px ;
26
+ margin-bottom : 10px ;
27
+ }
28
+
29
+
30
+ </style >
31
+
23
32
<script >
24
- import Buttons from ' ../components/newBadge/Buttons' ;
33
+ import ToolButtons from ' ../components/newBadge/ToolButtons' ;
34
+ import DrawButtons from ' ../components/newBadge/DrawButtons' ;
25
35
26
36
export default {
27
37
name: ' NewBadge' ,
28
38
components: {
29
- Buttons
39
+ DrawButtons,
40
+ ToolButtons,
30
41
}
31
42
}
32
-
33
- function draw () {
34
- var canvas = document .getElementById (' canvas' );
35
- if (canvas .getContext ) {
36
- var ctx = newCanvas .getContext (' 2d' );
43
+
44
+
45
+
46
+ window .addEventListener (" load" , () => {
47
+ const canvas = document .getElementById (" canvas" );
48
+
49
+ const ctx = canvas .getContext (" 2d" );
50
+
51
+ function getMousePos (canvas , event ) {
52
+ var rect = canvas .getBoundingClientRect ();
53
+ return {
54
+ x: (event .clientX - rect .left ) / (rect .right - rect .left ) * canvas .width ,
55
+ y: (event .clientY - rect .top ) / (rect .bottom - rect .top ) * canvas .height
56
+ };
37
57
}
58
+
59
+ ctx .strokeStyle = " #000000" ;
60
+ ctx .lineWidth = 10 ;
61
+ ctx .lineCap = " round" ;
62
+
63
+ let shouldPaint = false ;
64
+
65
+ function startDrawing () {
66
+ shouldPaint = true ;
67
+ var mousePos = getMousePos (canvas, event );
68
+ ctx .moveTo (mousePos .x , mousePos .y );
69
+ ctx .beginPath ()
70
+ continueDrawing (event );
38
71
}
39
- </script >
40
72
41
- <style >
42
- canvas {
43
- background-color : white ;
44
- margin : auto ;
45
- display : block ;
46
- border : 2px solid gray ;
47
- border-radius : 2px ;
73
+ function continueDrawing (event ) {
74
+ if (shouldPaint) {
75
+ var mousePos = getMousePos (canvas, event );
76
+ ctx .lineTo (mousePos .x , mousePos .y )
77
+ ctx .stroke ();
78
+ }
48
79
}
49
80
50
- .title {
51
- padding : 20px ;
52
- font-size : 80px ;
81
+ function endDrawing () {
82
+ shouldPaint = false ;
53
83
}
54
- </style >
84
+
85
+ // Allows user to draw on canvas
86
+ drawing ();
87
+
88
+ function drawing (event ) {
89
+ canvas .addEventListener (" mousedown" , startDrawing);
90
+ document .addEventListener (" mouseup" , endDrawing);
91
+ canvas .addEventListener (" mousemove" , continueDrawing);
92
+ }
93
+
94
+ // Changing colors
95
+ document .querySelectorAll (" .color" ).forEach (link => {
96
+ link .addEventListener (" click" , function (event ) {
97
+ ctx .strokeStyle = this .style .backgroundColor ;
98
+ })
99
+ })
100
+
101
+ // Changing brush size
102
+ document .querySelectorAll (" .size" ).forEach (link => {
103
+ link .addEventListener (" click" , function (event ) {
104
+ ctx .lineWidth = this .id ;
105
+ })
106
+ })
107
+
108
+
109
+
110
+ // Activates and deactivates buttons
111
+ function removeDraw (event ) {
112
+ canvas .removeEventListener (" mousedown" , startDrawing);
113
+ console .log (" working" );
114
+ }
115
+
116
+ selector .addEventListener (" click" , removeDraw);
117
+ pencil .addEventListener (" click" , drawing);
118
+ eraser .addEventListener (" click" , removeDraw);
119
+ square .addEventListener (" click" , removeDraw);
120
+ circle .addEventListener (" click" , removeDraw);
121
+ magic .addEventListener (" click" , removeDraw);
122
+ text .addEventListener (" click" , removeDraw);
123
+
124
+
125
+ })
126
+
127
+ </script >
0 commit comments