Skip to content
Snippets Groups Projects
Commit 659074d3 authored by Giovanni Caruso's avatar Giovanni Caruso
Browse files

Add colour sync

parent ad78eac9
No related branches found
No related tags found
1 merge request!38Colouredlines
Pipeline #102724 passed
...@@ -160,7 +160,10 @@ canvas.input.addEventListener("strokestart", ({ detail: e }) => { ...@@ -160,7 +160,10 @@ canvas.input.addEventListener("strokestart", ({ detail: e }) => {
const mousePos = [e.offsetX, e.offsetY] const mousePos = [e.offsetX, e.offsetY]
if (currentTool == tools.PEN) { if (currentTool == tools.PEN) {
pathIDsByPointerID.set(e.pointerId, room.addPath([...mousePos, e.pressure])) pathIDsByPointerID.set(
e.pointerId,
room.addPath([...mousePos, e.pressure, canvas.stroke_colour]),
)
} else if (currentTool == tools.ERASER) { } else if (currentTool == tools.ERASER) {
erasePoint(mousePos) erasePoint(mousePos)
} }
...@@ -181,6 +184,7 @@ canvas.input.addEventListener("strokemove", ({ detail: e }) => { ...@@ -181,6 +184,7 @@ canvas.input.addEventListener("strokemove", ({ detail: e }) => {
room.extendPath(pathIDsByPointerID.get(e.pointerId), [ room.extendPath(pathIDsByPointerID.get(e.pointerId), [
...mousePos, ...mousePos,
e.pressure, e.pressure,
canvas.stroke_colour,
]) ])
} else if (currentTool == tools.ERASER) { } else if (currentTool == tools.ERASER) {
erasePoint(mousePos) erasePoint(mousePos)
......
...@@ -35,11 +35,13 @@ const createPathElem = (d, width) => { ...@@ -35,11 +35,13 @@ const createPathElem = (d, width) => {
export const renderPath = (id, points) => { export const renderPath = (id, points) => {
points = points.filter(([x]) => x != null) points = points.filter(([x]) => x != null)
var colour = ""
// Split up points into completely non-erased segments. // Split up points into completely non-erased segments.
let segments = [[]] let segments = [[]]
for (const point of points) { for (const point of points) {
if (point[3] != false) { colour = point[3]
if (point[4] != false) {
segments[segments.length - 1].push(point) segments[segments.length - 1].push(point)
} else { } else {
segments.push([]) segments.push([])
...@@ -59,7 +61,7 @@ export const renderPath = (id, points) => { ...@@ -59,7 +61,7 @@ export const renderPath = (id, points) => {
if (pathGroupElem == null) { if (pathGroupElem == null) {
pathGroupElem = document.createElementNS(SVG_URL, "g") pathGroupElem = document.createElementNS(SVG_URL, "g")
pathGroupElem.setAttribute("stroke", stroke_colour) pathGroupElem.setAttribute("stroke", colour)
pathGroupElem.setAttribute("fill", "none") pathGroupElem.setAttribute("fill", "none")
pathGroupElem.setAttribute("stroke-linecap", "round") pathGroupElem.setAttribute("stroke-linecap", "round")
pathGroupElem.setAttribute("pointer-events", "none") pathGroupElem.setAttribute("pointer-events", "none")
...@@ -73,7 +75,7 @@ export const renderPath = (id, points) => { ...@@ -73,7 +75,7 @@ export const renderPath = (id, points) => {
if (subpath.length == 1) { if (subpath.length == 1) {
const circleElem = document.createElementNS(SVG_URL, "circle") const circleElem = document.createElementNS(SVG_URL, "circle")
circleElem.setAttribute("stroke", "none") circleElem.setAttribute("stroke", "none")
circleElem.setAttribute("fill", stroke_colour) circleElem.setAttribute("fill", colour)
circleElem.setAttribute("cx", subpath[0][0]) circleElem.setAttribute("cx", subpath[0][0])
circleElem.setAttribute("cy", subpath[0][1]) circleElem.setAttribute("cy", subpath[0][1])
circleElem.setAttribute("r", getStrokeRadius(subpath[0][2])) circleElem.setAttribute("r", getStrokeRadius(subpath[0][2]))
...@@ -82,6 +84,7 @@ export const renderPath = (id, points) => { ...@@ -82,6 +84,7 @@ export const renderPath = (id, points) => {
// Further split up segments based on thickness. // Further split up segments based on thickness.
const subpath_ = subpath.slice() const subpath_ = subpath.slice()
let w = subpath_[0][2] let w = subpath_[0][2]
console.log(w)
for (let i = 1; i < subpath_.length; i++) { for (let i = 1; i < subpath_.length; i++) {
if (subpath_[i][2] != w) { if (subpath_[i][2] != w) {
const d = lineFn([...subpath_.splice(0, i), subpath_[0]]) const d = lineFn([...subpath_.splice(0, i), subpath_[0]])
......
...@@ -23,14 +23,14 @@ class Room extends EventTarget { ...@@ -23,14 +23,14 @@ class Room extends EventTarget {
this._y.destroy() this._y.destroy()
} }
addPath([x, y, w]) { addPath([x, y, w, z]) {
const id = uuidv4() const id = uuidv4()
this._y.share.strokeAdd.set(id, Y.Array).push([[x, y, w]]) this._y.share.strokeAdd.set(id, Y.Array).push([[x, y, w, z]])
return id return id
} }
extendPath(id, [x, y, w]) { extendPath(id, [x, y, w, z]) {
this._y.share.strokeAdd.get(id).push([[x, y, w]]) this._y.share.strokeAdd.get(id).push([[x, y, w, z]])
} }
getPaths() { getPaths() {
...@@ -65,7 +65,7 @@ class Room extends EventTarget { ...@@ -65,7 +65,7 @@ class Room extends EventTarget {
return addSet return addSet
.toArray() .toArray()
.map((p = [], i) => [p[0], p[1], p[2], !eraseSet.get(i.toString())]) .map((p = [], i) => [p[0], p[1], p[2], p[3], !eraseSet.get(i.toString())])
} }
inviteUser(id) { inviteUser(id) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment