Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ bin
.vscode
/tools/mikktspace/out
*.exe
.DS_store
9 changes: 8 additions & 1 deletion h3d/Engine.hx
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,14 @@ class Engine {
if( height < 32 ) height = 32;
this.width = width;
this.height = height;
if( !driver.isDisposed() ) driver.resize(width, height);

// Set the driver size to actual pixel width
// (same as window size on normal displays, differs when high DPI is enabled)
var r = window.windowToPixelRatio;
var pw = Std.int(width / r);
var ph = Std.int(height / r);

if( !driver.isDisposed() ) driver.resize(pw, ph);
}

public function begin() {
Expand Down
5 changes: 3 additions & 2 deletions hxd/System.hl.hx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class System {
var size = haxe.macro.Compiler.getDefine("windowSize");
var title = haxe.macro.Compiler.getDefine("windowTitle");
var fixed = haxe.macro.Compiler.getDefine("windowFixed") == "1";
var highDPI = haxe.macro.Compiler.getDefine("highDPI") == "1";
if( title == null )
title = "";
if( size != null ) {
Expand All @@ -108,10 +109,10 @@ class System {
#if hlsdl
sdl.Sdl.init();
@:privateAccess Window.initChars();
@:privateAccess Window.inst = new Window(title, width, height, fixed);
@:privateAccess Window.inst = new Window(title, width, height, fixed, highDPI);
init();
#elseif hldx
@:privateAccess Window.inst = new Window(title, width, height, fixed);
@:privateAccess Window.inst = new Window(title, width, height, fixed, highDPI);
init();
#else
@:privateAccess Window.inst = new Window(title, width, height);
Expand Down
13 changes: 11 additions & 2 deletions hxd/Window.hl.hx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class Window {

public var width(get, never) : Int;
public var height(get, never) : Int;
public var windowToPixelRatio(get, never) : Float;

public var mouseX(get, never) : Int;
public var mouseY(get, never) : Int;
public var mouseLock(get, set) : Bool;
Expand All @@ -50,13 +52,16 @@ class Window {
static inline var TOUCH_SCALE = #if (hl_ver >= version("1.12.0")) 10000 #else 100 #end;
#end

function new(title:String, width:Int, height:Int, fixed:Bool = false) {
function new(title:String, width:Int, height:Int, fixed:Bool = false, highDPI = false) {
this.windowWidth = width;
this.windowHeight = height;
eventTargets = new List();
resizeEvents = new List();
#if hlsdl
final sdlFlags = if (!fixed) sdl.Window.SDL_WINDOW_SHOWN | sdl.Window.SDL_WINDOW_RESIZABLE else sdl.Window.SDL_WINDOW_SHOWN;
var sdlFlags = if (!fixed) sdl.Window.SDL_WINDOW_SHOWN | sdl.Window.SDL_WINDOW_RESIZABLE else sdl.Window.SDL_WINDOW_SHOWN;
if (highDPI) {
sdlFlags |= sdl.Window.SDL_WINDOW_ALLOW_HIGHDPI;
}
window = new sdl.Window(title, width, height, sdl.Window.SDL_WINDOWPOS_CENTERED, sdl.Window.SDL_WINDOWPOS_CENTERED, sdlFlags);
#elseif hldx
final dxFlags = if (!fixed) dx.Window.RESIZABLE else 0;
Expand Down Expand Up @@ -133,6 +138,10 @@ class Window {
function get_height() : Int {
return windowHeight;
}

function get_windowToPixelRatio() : Float {
return window.windowToPixelRatio;
}

function get_mouseLock() : Bool {
return false;
Expand Down
6 changes: 6 additions & 0 deletions hxd/Window.hx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class Window {

public var width(get, never) : Int;
public var height(get, never) : Int;
public var windowToPixelRatio(get, never) : Float;

public var mouseX(get, never) : Int;
public var mouseY(get, never) : Int;
public var mouseLock(get, set) : Bool;
Expand Down Expand Up @@ -95,6 +97,10 @@ class Window {
return 0;
}

function get_windowToPixelRatio() : Float {
return 0.0;
}

function get_mouseLock() : Bool {
return false;
}
Expand Down
6 changes: 6 additions & 0 deletions hxd/Window.js.hx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class Window {

public var width(get, never) : Int;
public var height(get, never) : Int;
public var windowToPixelRatio(get, never) : Float;

public var mouseX(get, never) : Int;
public var mouseY(get, never) : Int;
public var mouseLock(get, set) : Bool;
Expand Down Expand Up @@ -201,6 +203,10 @@ class Window {
return Math.round(canvasPos.height * getPixelRatio());
}

function get_windowToPixelRatio() {
return 1.0;
}

function get_mouseX() {
return Math.round((curMouseX - canvasPos.left) * getPixelRatio());
}
Expand Down