Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drawing-app
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sweng-group-15
drawing-app
Commits
1447ed42
Commit
1447ed42
authored
5 years ago
by
Giovanni Caruso
Browse files
Options
Downloads
Patches
Plain Diff
Implement basic erasing functionality
parent
e7d0f66f
No related branches found
Branches containing commit
No related tags found
1 merge request
!24
Erasing functionality first prototype
Pipeline
#101361
passed
5 years ago
Stage: fetch
Stage: deps
Stage: check
Stage: build
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
public/index.html
+2
-0
2 additions, 0 deletions
public/index.html
src/app.js
+107
-10
107 additions, 10 deletions
src/app.js
with
109 additions
and
10 deletions
public/index.html
+
2
−
0
View file @
1447ed42
...
@@ -31,6 +31,8 @@
...
@@ -31,6 +31,8 @@
Connected peers:
Connected peers:
<ul
id=
"connected-peers"
></ul>
<ul
id=
"connected-peers"
></ul>
</div>
</div>
<button
id=
"pen"
>
Pen
</button>
<button
id=
"eraser"
>
Eraser
</button>
<svg
<svg
id=
"whiteboard"
id=
"whiteboard"
...
...
This diff is collapsed.
Click to expand it.
src/app.js
+
107
−
10
View file @
1447ed42
...
@@ -29,6 +29,8 @@ Y({
...
@@ -29,6 +29,8 @@ Y({
const
peerIDElem
=
document
.
getElementById
(
"
peer-id
"
)
const
peerIDElem
=
document
.
getElementById
(
"
peer-id
"
)
const
peerButton
=
document
.
getElementById
(
"
peer-connect
"
)
const
peerButton
=
document
.
getElementById
(
"
peer-connect
"
)
const
connectedP
=
document
.
getElementById
(
"
connected-peers
"
)
const
connectedP
=
document
.
getElementById
(
"
connected-peers
"
)
const
penButton
=
document
.
getElementById
(
"
pen
"
)
const
eraserButton
=
document
.
getElementById
(
"
eraser
"
)
userIDElem
.
value
=
y
.
db
.
userId
userIDElem
.
value
=
y
.
db
.
userId
...
@@ -64,9 +66,29 @@ Y({
...
@@ -64,9 +66,29 @@ Y({
peerIDElem
.
value
=
""
peerIDElem
.
value
=
""
}
}
// Used to check what kind of tool is selected
var
addingLine
=
true
var
removingLine
=
false
penButton
.
onclick
=
function
()
{
// If pen tool selected
if
(
!
addingLine
)
{
addingLine
=
true
removingLine
=
false
}
}
eraserButton
.
onclick
=
function
()
{
// If eraser tool selected
if
(
!
removingLine
)
{
removingLine
=
true
addingLine
=
false
}
}
const
whiteboard
=
document
.
getElementById
(
"
whiteboard
"
)
const
whiteboard
=
document
.
getElementById
(
"
whiteboard
"
)
var
painting
=
false
var
input
=
false
var
paths
=
new
Map
()
var
paths
=
new
Map
()
var
pathID
var
pathID
...
@@ -104,22 +126,55 @@ Y({
...
@@ -104,22 +126,55 @@ Y({
return
path
return
path
}
}
function
removeOrUpdatePath
(
uid
)
{
var
path
=
paths
.
get
(
uid
)
if
(
path
!==
undefined
)
{
paths
.
delete
(
path
)
}
}
whiteboard
.
onmousedown
=
function
(
e
)
{
whiteboard
.
onmousedown
=
function
(
e
)
{
painting
=
true
input
=
true
const
mouse
=
{
const
mouse
=
{
x
:
e
.
offsetX
,
x
:
e
.
offsetX
,
y
:
e
.
offsetY
,
y
:
e
.
offsetY
,
}
}
pathID
=
uuidv4
()
if
(
addingLine
)
{
pathID
=
uuidv4
()
const
sharedPath
=
y
.
share
.
drawing
.
set
(
pathID
,
Y
.
Array
)
const
sharedPath
=
y
.
share
.
drawing
.
set
(
pathID
,
Y
.
Array
)
sharedPath
.
push
([[
mouse
.
x
,
mouse
.
y
]])
sharedPath
.
push
([[
mouse
.
x
,
mouse
.
y
]])
}
else
if
(
removingLine
)
{
// Iterate over all the possible paths in the Map
const
mapPaths
=
y
.
share
.
drawing
.
keys
()
for
(
var
mapPath
of
mapPaths
)
{
var
found
=
false
// Get the array of coordinates
var
mouseArray
=
y
.
share
.
drawing
.
get
(
mapPath
).
toArray
()
// Check the array for current position
for
(
var
i
=
0
;
i
<
mouseArray
.
length
;
i
++
)
{
var
mouseMap
=
mouseArray
[
i
]
if
(
mouseMap
[
0
]
==
mouse
.
x
&&
mouseMap
[
1
]
==
mouse
.
y
)
{
// Delete coordinates from the array
mouseArray
.
delete
(
i
)
// Update map
y
.
share
.
drawing
.
set
(
mapPath
,
mouseArray
)
found
=
true
break
}
}
if
(
found
)
{
break
}
}
}
}
}
whiteboard
.
onmouseup
=
function
()
{
whiteboard
.
onmouseup
=
function
()
{
painting
=
false
input
=
false
}
}
whiteboard
.
onmousemove
=
function
(
e
)
{
whiteboard
.
onmousemove
=
function
(
e
)
{
...
@@ -128,9 +183,46 @@ Y({
...
@@ -128,9 +183,46 @@ Y({
y
:
e
.
offsetY
,
y
:
e
.
offsetY
,
}
}
if
(
painting
)
{
if
(
input
)
{
const
sharedPath
=
y
.
share
.
drawing
.
get
(
pathID
)
if
(
addingLine
)
{
sharedPath
.
push
([[
mouse
.
x
,
mouse
.
y
]])
const
sharedPath
=
y
.
share
.
drawing
.
get
(
pathID
)
sharedPath
.
push
([[
mouse
.
x
,
mouse
.
y
]])
}
else
if
(
removingLine
)
{
// Iterate over all the possible paths in the Map
const
mapPaths
=
y
.
share
.
drawing
.
keys
()
for
(
var
mapPath
of
mapPaths
)
{
var
found
=
false
// Get the array of coordinates
var
mouseArray
=
y
.
share
.
drawing
.
get
(
mapPath
).
toArray
()
// Check the array for current position
for
(
var
i
=
0
;
i
<
mouseArray
.
length
;
i
++
)
{
var
mouseMap
=
mouseArray
[
i
]
if
(
mouseMap
[
0
]
==
mouse
.
x
&&
mouseMap
[
1
]
==
mouse
.
y
)
{
console
.
log
(
"
mouseMap[0] (
"
+
mouseMap
[
0
]
+
"
) == mouse.x (
"
+
mouse
.
x
+
"
mouseMap[1] (
"
+
mouseMap
[
1
]
+
"
) == mouse.y (
"
+
mouse
.
y
+
"
y
"
,
)
// Delete coordinates from the array
mouseArray
.
delete
(
i
)
// Update map
y
.
share
.
drawing
.
set
(
mapPath
,
mouseArray
)
found
=
true
break
}
}
if
(
found
)
{
break
}
}
}
}
}
}
}
...
@@ -149,6 +241,11 @@ Y({
...
@@ -149,6 +241,11 @@ Y({
}
}
})
})
break
case
"
delete
"
:
removeOrUpdatePath
(
lineID
)
break
break
}
}
})
})
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment