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
730b6488
Commit
730b6488
authored
5 years ago
by
Yuriy Maksymets
Committed by
Momo Langenstein
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Canvas offset during dragging
parent
426c8175
No related branches found
Branches containing commit
No related tags found
1 merge request
!74
Canvas dragging
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/app.js
+59
-15
59 additions, 15 deletions
src/app.js
src/tool-selection.js
+4
-0
4 additions, 0 deletions
src/tool-selection.js
with
63 additions
and
15 deletions
src/app.js
+
59
−
15
View file @
730b6488
...
...
@@ -474,6 +474,25 @@ const updateOverallStatusIcon = () => {
HTML
.
overallStatusIconImage
.
src
=
"
synchronised.svg
"
}
let
canvasDraggingStart
=
null
function
startCanvasDragging
(
mousePos
)
{
canvasDraggingStart
=
mousePos
}
function
stopCanvasDragging
()
{
canvasDraggingStart
=
null
}
function
dragCanvas
(
mousePos
)
{
if
(
canvasDraggingStart
)
{
let
[
x0
,
y0
]
=
canvasDraggingStart
let
[
x1
,
y1
]
=
mousePos
let
offset
=
[
x0
-
x1
,
y0
-
y1
]
toolSelection
.
applyCanvasOffset
(
offset
)
}
}
canvas
.
input
.
addEventListener
(
"
strokestart
"
,
({
detail
:
e
})
=>
{
e
.
preventDefault
()
const
pressure
=
getNormalizedPressure
(
e
)
...
...
@@ -484,13 +503,23 @@ canvas.input.addEventListener("strokestart", ({ detail: e }) => {
}
const
currentTool
=
toolSelection
.
getTool
()
const
mousePos
=
[
e
.
offsetX
,
e
.
offsetY
]
if
(
currentTool
==
toolSelection
.
Tools
.
PEN
)
{
pathIDsByPointerID
.
set
(
e
.
pointerId
,
room
.
addPath
(
selectedColorAndRadiusPoint
(...
mousePos
,
pressure
)),
)
}
else
if
(
currentTool
==
toolSelection
.
Tools
.
ERASER
)
{
eraseEverythingAtPosition
(...
mousePos
,
toolSelection
.
getEraseRadius
(),
room
)
switch
(
currentTool
)
{
case
toolSelection
.
Tools
.
PEN
:
pathIDsByPointerID
.
set
(
e
.
pointerId
,
room
.
addPath
(
selectedColorAndRadiusPoint
(...
mousePos
,
pressure
)),
)
break
case
toolSelection
.
Tools
.
ERASER
:
eraseEverythingAtPosition
(
...
mousePos
,
toolSelection
.
getEraseRadius
(),
room
,
)
break
case
toolSelection
.
Tools
.
DRAGGER
:
startCanvasDragging
(
mousePos
)
break
}
})
...
...
@@ -498,11 +527,13 @@ canvas.input.addEventListener("strokeend", ({ detail: e }) => {
const
{
pointerId
}
=
e
const
pressure
=
getNormalizedPressure
(
e
)
const
pathID
=
pathIDsByPointerID
.
get
(
pointerId
)
if
(
toolSelection
.
isRecognitionModeSet
())
{
drawRecognized
(
pathID
,
room
.
getPathPoints
(
pathID
),
pressure
)
}
pathIDsByPointerID
.
delete
(
pointerId
)
clearRecognizedUpcoming
()
stopCanvasDragging
()
})
canvas
.
input
.
addEventListener
(
"
strokemove
"
,
({
detail
:
e
})
=>
{
...
...
@@ -512,14 +543,27 @@ canvas.input.addEventListener("strokemove", ({ detail: e }) => {
const
pressure
=
getNormalizedPressure
(
e
)
const
currentTool
=
toolSelection
.
getTool
()
const
mousePos
=
[
e
.
offsetX
,
e
.
offsetY
]
if
(
currentTool
==
toolSelection
.
Tools
.
PEN
)
{
const
pathID
=
pathIDsByPointerID
.
get
(
e
.
pointerId
)
room
.
extendPath
(
pathID
,
selectedColorAndRadiusPoint
(...
mousePos
,
pressure
))
if
(
toolSelection
.
isRecognitionModeSet
())
{
drawRecognizedUpcoming
(
room
.
getPathPoints
(
pathID
),
pressure
)
}
}
else
if
(
currentTool
==
toolSelection
.
Tools
.
ERASER
)
{
eraseEverythingAtPosition
(...
mousePos
,
toolSelection
.
getEraseRadius
(),
room
)
switch
(
currentTool
)
{
case
toolSelection
.
Tools
.
PEN
:
const
pathID
=
pathIDsByPointerID
.
get
(
e
.
pointerId
)
room
.
extendPath
(
pathID
,
selectedColorAndRadiusPoint
(...
mousePos
,
pressure
),
)
if
(
toolSelection
.
isRecognitionModeSet
())
{
drawRecognizedUpcoming
(
room
.
getPathPoints
(
pathID
),
pressure
)
}
break
case
toolSelection
.
Tools
.
ERASER
:
eraseEverythingAtPosition
(
...
mousePos
,
toolSelection
.
getEraseRadius
(),
room
,
)
break
case
toolSelection
.
Tools
.
DRAGGER
:
dragCanvas
(
mousePos
)
break
}
})
...
...
This diff is collapsed.
Click to expand it.
src/tool-selection.js
+
4
−
0
View file @
730b6488
...
...
@@ -18,6 +18,10 @@ export const getTool = () => selectedTool
export
const
getStrokeColour
=
()
=>
strokeColour
export
const
getStrokeRadius
=
()
=>
strokeRadius
export
const
getCanvasOffset
=
()
=>
canvasOffset
export
const
applyCanvasOffset
=
([
x
,
y
])
=>
{
canvasOffset
[
0
]
+=
x
canvasOffset
[
1
]
+=
y
}
export
const
getEraseRadius
=
()
=>
ERASE_RADIUS
export
const
isRecognitionModeSet
=
()
=>
recognitionEnabled
...
...
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