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

[7.7.x] RHPAM-1216 Stunner - Disable/Enable HiDPI on Stunner / Lienzo #46

Merged
merged 1 commit into from Jun 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/java/com/ait/lienzo/client/core/Context2D.java
Expand Up @@ -16,6 +16,7 @@

package com.ait.lienzo.client.core;

import com.ait.lienzo.client.core.config.LienzoCore;
import com.ait.lienzo.client.core.types.DashArray;
import com.ait.lienzo.client.core.types.ImageData;
import com.ait.lienzo.client.core.types.ImageDataPixelColor;
Expand Down Expand Up @@ -46,7 +47,7 @@ public class Context2D

public Context2D(final CanvasElement element)
{
this(NativeContext2D.make(element));
this(NativeContext2D.make(element, LienzoCore.get().isHidpiEnabled()));
}

public Context2D(final INativeContext2D jso)
Expand Down
30 changes: 21 additions & 9 deletions src/main/java/com/ait/lienzo/client/core/NativeContext2D.java
Expand Up @@ -42,9 +42,9 @@ private static final native NativeContext2D make_0(CanvasElement element)
return element.getContext("2d");
}-*/;

public static final NativeContext2D make(final CanvasElement element)
public static final NativeContext2D make(final CanvasElement element, final boolean enableHidpi)
{
return make_0(element).init();
return make_0(element).init(enableHidpi);
}

protected NativeContext2D()
Expand All @@ -53,6 +53,10 @@ protected NativeContext2D()

public final native void initDeviceRatio()
/*-{
if(!this.hidpiEnabled){
return;
}

var canvas = this.canvas;

var devicePixelRatio = window.devicePixelRatio || 1
Expand All @@ -76,16 +80,19 @@ public final native void initDeviceRatio()

}-*/;

private final native NativeContext2D init()
private final native NativeContext2D init(boolean enableHidpi)
/*-{
this.imageSmoothingEnabled = false;
this.imageSmoothingEnabled = false;
this.scalingRatio = 1;

this.backingStorePixelRatio = this.backingStorePixelRatio
|| this.webkitBackingStorePixelRatio
|| this.mozBackingStorePixelRatio
|| this.msBackingStorePixelRatio
|| this.oBackingStorePixelRatio || 1;
this.hidpiEnabled = enableHidpi;
if(enableHidpi) {
this.backingStorePixelRatio = this.backingStorePixelRatio
|| this.webkitBackingStorePixelRatio
|| this.mozBackingStorePixelRatio
|| this.msBackingStorePixelRatio
|| this.oBackingStorePixelRatio || 1;
}

if (this.setLineDash) {
this.setLineDashOffset = function(d) {
Expand Down Expand Up @@ -124,6 +131,11 @@ private final native NativeContext2D init()
return this;
}-*/;

public final native boolean isHidpiEnabled()
/*-{
return this.hidpiEnabled;
}-*/;

public final void saveContainer(String id) {
this.save();
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/ait/lienzo/client/core/config/LienzoCore.java
Expand Up @@ -85,6 +85,8 @@ public final class LienzoCore

private boolean m_nativeLineDashExamine = false;

private boolean m_hidpiEnabled = false;

private Cursor m_normal_cursor = Cursor.DEFAULT;

private Cursor m_select_cursor = Cursor.CROSSHAIR;
Expand Down Expand Up @@ -517,6 +519,14 @@ public final double getDeviceScale()
return (m_deviceScale = getDevicePixelRatio() / getBackingStorePixelRatio());
}

public boolean isHidpiEnabled() {
return m_hidpiEnabled;
}

public boolean setHidpiEnabled(boolean hidpiEnabled) {
return m_hidpiEnabled;
}

private final boolean examineNativeLineDashSupported()
{
if (IS_CANVAS_SUPPORTED)
Expand Down