UI: Scale Interact cursor position based on display DPI

This commit is contained in:
Matt Gajownik 2020-12-06 14:23:55 +11:00 committed by Matt Gajownik
parent 448599e761
commit fff45a4114

View File

@ -218,6 +218,14 @@ static int TranslateQtMouseEventModifiers(QMouseEvent *event)
bool OBSBasicInteraction::GetSourceRelativeXY(int mouseX, int mouseY, int &relX,
int &relY)
{
#ifdef SUPPORTS_FRACTIONAL_SCALING
float pixelRatio = devicePixelRatioF();
#else
float pixelRatio = devicePixelRatio();
#endif
int mouseXscaled = (int)roundf(mouseX * pixelRatio);
int mouseYscaled = (int)roundf(mouseY * pixelRatio);
QSize size = GetPixelSize(ui->preview);
uint32_t sourceCX = max(obs_source_get_width(source), 1u);
@ -230,11 +238,11 @@ bool OBSBasicInteraction::GetSourceRelativeXY(int mouseX, int mouseY, int &relX,
y, scale);
if (x > 0) {
relX = int(float(mouseX - x) / scale);
relY = int(float(mouseY / scale));
relX = int(float(mouseXscaled - x) / scale);
relY = int(float(mouseYscaled / scale));
} else {
relX = int(float(mouseX / scale));
relY = int(float(mouseY - y) / scale);
relX = int(float(mouseXscaled / scale));
relY = int(float(mouseYscaled - y) / scale);
}
// Confirm mouse is inside the source