Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added method winGetPixelSize to SDL, for getting pixel size of high DPI windows #435

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions libs/directx/dx/Window.hx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Window {
public var title(default, set) : String;
public var width(get, never) : Int;
public var height(get, never) : Int;
public var windowToPixelRatio(get, never) : Float;
public var minWidth(get, never) : Int;
public var minHeight(get, never) : Int;
public var maxWidth(get, never) : Int;
Expand Down Expand Up @@ -112,6 +113,11 @@ class Window {
return h;
}

function get_windowToPixelRatio() {
// Not yet implemented
return 1.0;
}

function get_minWidth() {
var w = 0;
winGetMinSize(win, w, null);
Expand Down
5 changes: 5 additions & 0 deletions libs/sdl/sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,10 @@ HL_PRIM void HL_NAME(win_set_max_size)(SDL_Window *win, int width, int height) {
SDL_SetWindowMaximumSize(win, width, height);
}

HL_PRIM void HL_NAME(win_get_pixel_size)(SDL_Window *win, int *width, int *height) {
SDL_GL_GetDrawableSize(win, width, height);
}

HL_PRIM void HL_NAME(win_get_size)(SDL_Window *win, int *width, int *height) {
SDL_GetWindowSize(win, width, height);
}
Expand Down Expand Up @@ -605,6 +609,7 @@ DEFINE_PRIM(_VOID, win_get_position, TWIN _REF(_I32) _REF(_I32));
DEFINE_PRIM(_VOID, win_set_size, TWIN _I32 _I32);
DEFINE_PRIM(_VOID, win_set_min_size, TWIN _I32 _I32);
DEFINE_PRIM(_VOID, win_set_max_size, TWIN _I32 _I32);
DEFINE_PRIM(_VOID, win_get_pixel_size, TWIN _REF(_I32) _REF(_I32));
DEFINE_PRIM(_VOID, win_get_size, TWIN _REF(_I32) _REF(_I32));
DEFINE_PRIM(_VOID, win_get_min_size, TWIN _REF(_I32) _REF(_I32));
DEFINE_PRIM(_VOID, win_get_max_size, TWIN _REF(_I32) _REF(_I32));
Expand Down
12 changes: 12 additions & 0 deletions libs/sdl/sdl/Window.hx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Window {
public var vsync(default, set) : Bool;
public var width(get, never) : Int;
public var height(get, never) : Int;
public var windowToPixelRatio(get, never) : Float;
public var minWidth(get, never) : Int;
public var minHeight(get, never) : Int;
public var maxWidth(get, never) : Int;
Expand Down Expand Up @@ -176,6 +177,14 @@ class Window {
return w;
}

function get_windowToPixelRatio() {
var pixelHeight = 0;
winGetPixelSize(win, null, pixelHeight);
var h : Float = height;

return h / pixelHeight;
}

function get_height() {
var h = 0;
winGetSize(win, null, h);
Expand Down Expand Up @@ -312,6 +321,9 @@ class Window {
static function winGetSize( win : WinPtr, width : hl.Ref<Int>, height : hl.Ref<Int> ) {
}

static function winGetPixelSize( win : WinPtr, width : hl.Ref<Int>, height : hl.Ref<Int> ) {
}

static function winGetMinSize( win : WinPtr, width : hl.Ref<Int>, height : hl.Ref<Int> ) {
}

Expand Down