cursors use cursor tag.

This commit is contained in:
Miroslav Šedivý 2021-11-01 20:56:10 +01:00
parent ec477f619b
commit ed5d2175ae
3 changed files with 12 additions and 5 deletions

View File

@ -16,7 +16,7 @@
<script lang="ts"> <script lang="ts">
import { Vue, Component, Ref, Prop, Watch } from 'vue-property-decorator' import { Vue, Component, Ref, Prop, Watch } from 'vue-property-decorator'
import { Cursor } from './types/state' import { Cursor, Session } from './types/state'
import { CursorDrawFunction, Dimension } from './types/cursors' import { CursorDrawFunction, Dimension } from './types/cursors'
const CANVAS_SCALE = 2 const CANVAS_SCALE = 2
@ -28,6 +28,9 @@
@Ref('overlay') readonly _overlay!: HTMLCanvasElement @Ref('overlay') readonly _overlay!: HTMLCanvasElement
private _ctx!: CanvasRenderingContext2D private _ctx!: CanvasRenderingContext2D
@Prop()
private readonly sessions!: Record<string, Session>
@Prop() @Prop()
private readonly sessionId!: string private readonly sessionId!: string
@ -100,9 +103,12 @@
x = Math.round((x / this.screenSize.width) * width) x = Math.round((x / this.screenSize.width) * width)
y = Math.round((y / this.screenSize.height) * height) y = Math.round((y / this.screenSize.height) * height)
// get cursor tag
const cursorTag = this.sessions[id]?.profile.name || ''
// use custom draw function, if available // use custom draw function, if available
if (this.cursorDraw) { if (this.cursorDraw) {
this.cursorDraw(this._ctx, x, y, id) this.cursorDraw(this._ctx, x, y, cursorTag)
continue continue
} }
@ -113,10 +119,10 @@
this._ctx.shadowBlur = 2 this._ctx.shadowBlur = 2
this._ctx.lineWidth = 2 this._ctx.lineWidth = 2
this._ctx.fillStyle = 'black' this._ctx.fillStyle = 'black'
this._ctx.strokeText(id, x, y) this._ctx.strokeText(cursorTag, x, y)
this._ctx.shadowBlur = 0 this._ctx.shadowBlur = 0
this._ctx.fillStyle = 'white' this._ctx.fillStyle = 'white'
this._ctx.fillText(id, x, y) this._ctx.fillText(cursorTag, x, y)
this._ctx.restore() this._ctx.restore()
} }
} }

View File

@ -5,6 +5,7 @@
<neko-screencast v-show="screencast" :enabled="screencast" :api="api.room" /> <neko-screencast v-show="screencast" :enabled="screencast" :api="api.room" />
<neko-cursors <neko-cursors
v-if="state.cursors.enabled" v-if="state.cursors.enabled"
:sessions="state.sessions"
:sessionId="state.session_id" :sessionId="state.session_id"
:screenSize="state.screen.size" :screenSize="state.screen.size"
:canvasSize="canvasSize" :canvasSize="canvasSize"

View File

@ -1,4 +1,4 @@
export type CursorDrawFunction = (ctx: CanvasRenderingContext2D, x: number, y: number, id: string) => void export type CursorDrawFunction = (ctx: CanvasRenderingContext2D, x: number, y: number, cursorTag: string) => void
export interface Dimension { export interface Dimension {
width: number width: number