Skip to content
Snippets Groups Projects
Commit 47ad7d8e authored by Yuriy Maksymets's avatar Yuriy Maksymets
Browse files

Drawing recognized upcoming before converting

parent c6c41cab
No related branches found
No related tags found
No related merge requests found
...@@ -130,7 +130,7 @@ const onRoomConnect = (room_) => { ...@@ -130,7 +130,7 @@ const onRoomConnect = (room_) => {
room.addEventListener("addOrUpdatePath", ({ detail: { id, points } }) => { room.addEventListener("addOrUpdatePath", ({ detail: { id, points } }) => {
canvas.renderPath(id, points, room.erasureIntervals) canvas.renderPath(id, points, room.erasureIntervals)
//drawRecognized(id, points) drawRecognizedUpcoming(points)
}) })
room.addEventListener( room.addEventListener(
...@@ -145,35 +145,67 @@ const onRoomConnect = (room_) => { ...@@ -145,35 +145,67 @@ const onRoomConnect = (room_) => {
) )
} }
const mp = (x, y) => [x, y, 1, "black"] const mp = (x, y) => [x, y, 1, "#00000033"]
const r = []
function drawRecognized(pathID, points) { function attributedPoint(x, y, pressure = 0) {
if (r.includes(pathID)) return return [
console.log(123) x,
y,
toolSelection.getStrokeRadius() * getPressureFactor(pressure),
toolSelection.getStrokeColour(),
]
}
function getRecognizedShapePoints(points) {
const recognizedShape = recognizeFromPoints(points) const recognizedShape = recognizeFromPoints(points)
if (recognizedShape.shape === Shapes.line) { if (recognizedShape.shape === Shapes.line) {
console.log(recognizedShape) console.log(recognizedShape)
const [x, y] = points[0] const [x, y] = points[0]
const a = (recognizedShape.angle * Math.PI) / 180 const a = (recognizedShape.angle * Math.PI) / 180
const [x0, y0] = [x - 2000 * Math.cos(a), y + 2000 * Math.sin(a)] const p1 = [x - 2000 * Math.cos(a), y + 2000 * Math.sin(a)]
const [x1, y1] = [x + 2000 * Math.cos(a), y - 2000 * Math.sin(a)] const p2 = [x + 2000 * Math.cos(a), y - 2000 * Math.sin(a)]
canvas.renderPath("lastRecognizedLine", [mp(x0, y0), mp(x1, y1)]) return [p1, p2]
} else if (recognizedShape.shape === Shapes.rectangle) { } else if (recognizedShape.shape === Shapes.rectangle) {
console.log(recognizedShape) console.log(recognizedShape)
r.push(pathID) return recognizedShape.boundingPoints
canvas.renderPath( }
"lastRecognizedLine", return undefined
recognizedShape.boundingPoints.map((x) => mp(...x)), }
)
room.setInvisible(pathID) const LAST_RECOGNIZED_PATH_ID = "LSP"
recognizedShape.boundingPoints.forEach((point) =>
room.extendPath(pathID, mp(...point)), function drawIfRecognized(points, callback, notRecCallback) {
) const recognizedPoints = getRecognizedShapePoints(points)
if (recognizedPoints) {
callback(recognizedPoints)
} else { } else {
canvas.renderPath("lastRecognizedLine", []) notRecCallback()
} }
} }
function clearRecognizedUpcoming() {
canvas.renderPath(LAST_RECOGNIZED_PATH_ID, [])
}
function drawRecognizedUpcoming(points) {
drawIfRecognized(
points,
(recognizedPoints) =>
canvas.renderPath(
LAST_RECOGNIZED_PATH_ID,
recognizedPoints.map((x) => mp(...x)),
),
clearRecognizedUpcoming,
)
}
function drawRecognized(pathID, points) {
drawIfRecognized(points, (newPoints) =>
room.replacePath(pathID, newPoints.map((x) => attributedPoint(...x))),
)
clearRecognizedUpcoming()
}
const tryRoomConnect = async (roomID) => { const tryRoomConnect = async (roomID) => {
return await connect(roomID) return await connect(roomID)
.then(onRoomConnect) .then(onRoomConnect)
...@@ -269,10 +301,10 @@ const updateOverallStatusIcon = () => { ...@@ -269,10 +301,10 @@ const updateOverallStatusIcon = () => {
canvas.input.addEventListener("strokestart", ({ detail: e }) => { canvas.input.addEventListener("strokestart", ({ detail: e }) => {
e.preventDefault() e.preventDefault()
clearRecognizedUpcoming()
if (room == null) { if (room == null) {
return return
} }
console.log(pathIDsByPointerID)
const currentTool = toolSelection.getTool() const currentTool = toolSelection.getTool()
const mousePos = [e.offsetX, e.offsetY] const mousePos = [e.offsetX, e.offsetY]
if (currentTool == toolSelection.Tools.PEN) { if (currentTool == toolSelection.Tools.PEN) {
...@@ -295,13 +327,10 @@ canvas.input.addEventListener("strokestart", ({ detail: e }) => { ...@@ -295,13 +327,10 @@ canvas.input.addEventListener("strokestart", ({ detail: e }) => {
}) })
canvas.input.addEventListener("strokeend", ({ detail: e }) => { canvas.input.addEventListener("strokeend", ({ detail: e }) => {
console.log(12331)
console.log(12331)
console.log(12331)
const pathID = pathIDsByPointerID.get(e.pointerId) const pathID = pathIDsByPointerID.get(e.pointerId)
drawRecognized(pathID, room.getPoints(pathID)) drawRecognized(pathID, room.getPoints(pathID))
//pathIDsByPointerID.delete(e.pointerId) pathIDsByPointerID.delete(e.pointerId)
clearRecognizedUpcoming()
}) })
canvas.input.addEventListener("strokemove", ({ detail: e }) => { canvas.input.addEventListener("strokemove", ({ detail: e }) => {
...@@ -311,12 +340,10 @@ canvas.input.addEventListener("strokemove", ({ detail: e }) => { ...@@ -311,12 +340,10 @@ canvas.input.addEventListener("strokemove", ({ detail: e }) => {
const currentTool = toolSelection.getTool() const currentTool = toolSelection.getTool()
const mousePos = [e.offsetX, e.offsetY] const mousePos = [e.offsetX, e.offsetY]
if (currentTool == toolSelection.Tools.PEN) { if (currentTool == toolSelection.Tools.PEN) {
console.log(pathIDsByPointerID.get(e.pointerId)) room.extendPath(
room.extendPath(pathIDsByPointerID.get(e.pointerId), [ pathIDsByPointerID.get(e.pointerId),
...mousePos, attributedPoint(...mousePos, e.pressure),
toolSelection.getStrokeRadius() * getPressureFactor(e.pressure), )
toolSelection.getStrokeColour(),
])
} else if (currentTool == toolSelection.Tools.ERASER) { } else if (currentTool == toolSelection.Tools.ERASER) {
eraseEverythingAtPosition( eraseEverythingAtPosition(
mousePos[0], mousePos[0],
......
...@@ -63,7 +63,7 @@ class Room extends EventTarget { ...@@ -63,7 +63,7 @@ class Room extends EventTarget {
}) })
} }
setInvisible(pathID) { replacePath(pathID, newPoints) {
const self = this const self = this
// eslint-disable-next-line require-yield // eslint-disable-next-line require-yield
...@@ -77,6 +77,7 @@ class Room extends EventTarget { ...@@ -77,6 +77,7 @@ class Room extends EventTarget {
return return
} }
newPoints.forEach((point) => self.extendPath(pathID, point))
self.shared.eraseIntervals.set(pathID, postJSON) self.shared.eraseIntervals.set(pathID, postJSON)
}) })
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment