mitchcurtis/slate

Custom cursors are not so responsive

vakokako opened this issue · 1 comments

When moving crosshair cursor, there is a slight delay compared to standard mouse. I've seen that custom cursor was done with quick items and sending mouse position via signals/slots.

I'm not so familiar with qt quick, but could this be implemented without signal/slots to remove the delay?

Hi, thank you for the feedback. :)

I am using Qt Quick items for the cursors currently:

CrosshairCursor {
id: crosshairCursor
x: canvas ? canvas.cursorX - width / 2 : 0
y: canvas ? canvas.cursorY - height / 2 : 0
z: 1
colour: canvas ? canvas.invertedCursorPixelColour : defaultColour
visible: canvas && canvas.hasBlankCursor && !canvas.useIconCursor && (canvas.useCrosshairCursor || settings.alwaysShowCrosshair)
}
RectangularCursor {
id: rectangleCursor
x: canvas ? Math.floor(canvas.cursorX - width / 2) : 0
y: canvas ? Math.floor(canvas.cursorY - height / 2) : 0
z: 1
width: canvas ? canvas.toolSize * canvas.currentPaneZoomLevel : 0
height: canvas ? canvas.toolSize * canvas.currentPaneZoomLevel : 0
visible: canvas && canvas.hasBlankCursor && !canvas.useIconCursor && !canvas.useCrosshairCursor
}
Label {
id: iconCursor
x: canvas ? canvas.cursorX : 0
y: canvas ? canvas.cursorY - height + 3 : 0
z: 1
visible: canvas && canvas.hasBlankCursor && canvas.useIconCursor
text: visible && checkedToolButton ? checkedToolButton.text : ""
font.family: "FontAwesome"
color: canvas ? canvas.invertedCursorPixelColour : crosshairCursor.defaultColour
}

The benefit of this approach is that the cursors can be coloured, which means we can also use the inverse of the colour under the pixel to ensure that the cursor has good visibility due to contrast.

Another advantage is that we can have nice, smooth cursors. From memory, a custom QCursor shape will be quite blocky and not smooth, but I'd have to double-check that.

The disadvantage is, as you've seen, it can lag behind the mouse a bit due to it not being a system cursor. That's unrelated to signals and slots though, I think.