[RFC] Randomized names next to mouse pointers. (#971)
* [WIP] Add names next to pointers This implements the rendering and messaging across. Still need to do the UI to set the name. Also, not really sure what's the best place to send the name and store it. * Add randomized names Co-authored-by: Christopher Chedeau <vjeux@fb.com>
This commit is contained in:
@ -167,6 +167,7 @@ export function renderScene(
|
||||
// Paint remote pointers
|
||||
for (const clientId in sceneState.remotePointerViewportCoords) {
|
||||
let { x, y } = sceneState.remotePointerViewportCoords[clientId];
|
||||
const username = sceneState.remotePointerUsernames[clientId];
|
||||
|
||||
const width = 9;
|
||||
const height = 14;
|
||||
@ -200,6 +201,30 @@ export function renderScene(
|
||||
context.lineTo(x, y);
|
||||
context.fill();
|
||||
context.stroke();
|
||||
|
||||
if (!isOutOfBounds && username) {
|
||||
const offsetX = x + width;
|
||||
const offsetY = y + height;
|
||||
const paddingHorizontal = 4;
|
||||
const paddingVertical = 4;
|
||||
const measure = context.measureText(username);
|
||||
const measureHeight =
|
||||
measure.actualBoundingBoxDescent + measure.actualBoundingBoxAscent;
|
||||
|
||||
context.fillRect(
|
||||
offsetX,
|
||||
offsetY,
|
||||
measure.width + 2 * paddingHorizontal,
|
||||
measureHeight + 2 * paddingVertical,
|
||||
);
|
||||
context.fillStyle = "white";
|
||||
context.fillText(
|
||||
username,
|
||||
offsetX + paddingHorizontal,
|
||||
offsetY + paddingVertical + measure.actualBoundingBoxAscent,
|
||||
);
|
||||
}
|
||||
|
||||
context.strokeStyle = strokeStyle;
|
||||
context.fillStyle = fillStyle;
|
||||
context.globalAlpha = globalAlpha;
|
||||
|
Reference in New Issue
Block a user