-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
86 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters