Skip to content

Commit

Permalink
Initial allowHighDPI support for HTML5
Browse files Browse the repository at this point in the history
  • Loading branch information
jgranick committed Oct 18, 2016
1 parent 2adfd6b commit 6cd72d9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
27 changes: 22 additions & 5 deletions lime/_backend/html5/HTML5Window.hx
Expand Up @@ -55,6 +55,7 @@ class HTML5Window {
private var enableTextEvents:Bool;
private var parent:Window;
private var primaryTouch:Touch;
private var scale = 1.0;
private var setHeight:Int;
private var setWidth:Int;
private var unusedTouchesPool = new List<Touch> ();
Expand All @@ -70,6 +71,16 @@ class HTML5Window {

}

#if !dom
if (parent.config != null && Reflect.hasField (parent.config, "allowHighDPI") && parent.config.allowHighDPI) {

scale = Browser.window.devicePixelRatio;

}
#end

parent.__scale = scale;

cacheMouseX = 0;
cacheMouseY = 0;

Expand Down Expand Up @@ -161,8 +172,11 @@ class HTML5Window {

if (canvas != null) {

canvas.width = parent.width;
canvas.height = parent.height;
canvas.width = Math.round (parent.width * scale);
canvas.height = Math.round (parent.height * scale);

canvas.style.width = parent.width + "px";
canvas.style.height = parent.height + "px";

} else {

Expand Down Expand Up @@ -388,8 +402,11 @@ class HTML5Window {

if (element != cast canvas) {

canvas.width = element.clientWidth;
canvas.height = element.clientHeight;
canvas.width = Math.round (element.clientWidth * scale);
canvas.height = Math.round (element.clientHeight * scale);

canvas.style.width = element.clientWidth + "px";
canvas.style.height = element.clientHeight + "px";

}

Expand All @@ -404,7 +421,7 @@ class HTML5Window {

} else {

var scaleX = (setWidth != 0) ? (element.clientWidth / setWidth) : 1;
var scaleX = (setWidth != 0) ? (element.clientWidth / setWidth) : 1;
var scaleY = (setHeight != 0) ? (element.clientHeight / setHeight) : 1;

var targetWidth = element.clientWidth;
Expand Down
8 changes: 5 additions & 3 deletions lime/project/HXProject.hx
Expand Up @@ -133,7 +133,7 @@ class HXProject {

platformType = PlatformType.WEB;
architectures = [];

case HTML5, FIREFOX, EMSCRIPTEN:

platformType = PlatformType.WEB;
Expand All @@ -143,6 +143,8 @@ class HXProject {
defaultWindow.height = 0;
defaultWindow.fps = 60;

defaultWindow.allowHighDPI = false;

case ANDROID, BLACKBERRY, IOS, TIZEN, WEBOS, TVOS:

platformType = PlatformType.MOBILE;
Expand Down Expand Up @@ -177,7 +179,7 @@ class HXProject {
defaultWindow.height = 0;
defaultWindow.fullscreen = true;
defaultWindow.requireShaders = true;

case WINDOWS, MAC, LINUX:

platformType = PlatformType.DESKTOP;
Expand All @@ -199,7 +201,7 @@ class HXProject {
// TODO: Better handle platform type for pluggable targets

platformType = PlatformType.CONSOLE;

defaultWindow.width = 0;
defaultWindow.height = 0;
defaultWindow.fps = 60;
Expand Down

0 comments on commit 6cd72d9

Please sign in to comment.