mirror of https://github.com/Genymobile/scrcpy
hidpiscale
parent
65021416b3
commit
ae87885ffa
@ -0,0 +1,16 @@
|
||||
#include "hidpi.h"
|
||||
|
||||
void hidpi_get_scale(struct screen *screen, struct hidpi_scale *scale) {
|
||||
SDL_GL_GetDrawableSize(screen->window, &scale->horizontal.num, &scale->vertical.num);
|
||||
SDL_GetWindowSize(screen->window, &scale->horizontal.div, &scale->vertical.div);
|
||||
}
|
||||
|
||||
void hidpi_unscale_coordinates(struct hidpi_scale *scale, Sint32 *x, Sint32 *y) {
|
||||
// to unscale, we devide by the ratio (so num and div are reversed)
|
||||
if (scale->horizontal.num) {
|
||||
*x = ((Sint64) *x) * scale->horizontal.div / scale->horizontal.num;
|
||||
}
|
||||
if (scale->vertical.num) {
|
||||
*y = ((Sint64) *y) * scale->vertical.div / scale->vertical.num;
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
#ifndef HIDPI_H
|
||||
#define HIDPI_H
|
||||
|
||||
#include "common.h"
|
||||
#include "screen.h"
|
||||
|
||||
// rational number p/q
|
||||
struct rational {
|
||||
int num;
|
||||
int div;
|
||||
};
|
||||
|
||||
struct hidpi_scale {
|
||||
struct rational horizontal; // drawable.width / window.width
|
||||
struct rational vertical; // drawable.height / window.height
|
||||
};
|
||||
|
||||
void hidpi_get_scale(struct screen *screen, struct hidpi_scale *hidpi_scale);
|
||||
|
||||
// mouse location need to be "unscaled" if hidpi is enabled
|
||||
// <https://nlguillemot.wordpress.com/2016/12/11/high-dpi-rendering/>
|
||||
void hidpi_unscale_coordinates(struct hidpi_scale *hidpi_scale, Sint32 *x, Sint32 *y);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue