Add hidpi support
This commit is contained in:
parent
ae129f717c
commit
2d38d30784
|
@ -278,6 +278,8 @@ button.active, .info-icon {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
left: 0px;
|
left: 0px;
|
||||||
top: 0px;
|
top: 0px;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
textarea {
|
textarea {
|
||||||
|
|
|
@ -14,6 +14,7 @@ export default class View {
|
||||||
|
|
||||||
/** @type {Element} */ this.canvas = document.getElementById('ascii-canvas');
|
/** @type {Element} */ this.canvas = document.getElementById('ascii-canvas');
|
||||||
/** @type {Object} */ this.context = this.canvas.getContext('2d');
|
/** @type {Object} */ this.context = this.canvas.getContext('2d');
|
||||||
|
this.resizeCanvas();
|
||||||
|
|
||||||
/** @type {number} */ this.zoom = 1;
|
/** @type {number} */ this.zoom = 1;
|
||||||
/** @type {Vector} */ this.offset = new Vector(
|
/** @type {Vector} */ this.offset = new Vector(
|
||||||
|
@ -23,19 +24,21 @@ export default class View {
|
||||||
/** @type {boolean} */ this.dirty = true;
|
/** @type {boolean} */ this.dirty = true;
|
||||||
// TODO: Should probably save this setting in a cookie or something.
|
// TODO: Should probably save this setting in a cookie or something.
|
||||||
/** @type {boolean} */ this.useLines = false;
|
/** @type {boolean} */ this.useLines = false;
|
||||||
|
|
||||||
this.resizeCanvas();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resizes the canvas, should be called if the viewport size changes.
|
* Resizes the canvas, should be called if the viewport size changes.
|
||||||
*/
|
*/
|
||||||
resizeCanvas() {
|
resizeCanvas() {
|
||||||
this.canvas.width = document.documentElement.clientWidth;
|
let dpr = window.devicePixelRatio || 1;
|
||||||
this.canvas.height = document.documentElement.clientHeight;
|
this.canvas.width = document.documentElement.clientWidth * dpr;
|
||||||
|
this.canvas.height = document.documentElement.clientHeight * dpr;
|
||||||
this.dirty = true;
|
this.dirty = true;
|
||||||
|
this.context.setTransform(1, 0, 0, 1, 0, 0);
|
||||||
|
this.context.scale(dpr, dpr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the animation loop for the canvas. Should only be called once.
|
* Starts the animation loop for the canvas. Should only be called once.
|
||||||
*/
|
*/
|
||||||
|
@ -55,8 +58,10 @@ export default class View {
|
||||||
*/
|
*/
|
||||||
render() {
|
render() {
|
||||||
var context = this.context;
|
var context = this.context;
|
||||||
|
let dpr = window.devicePixelRatio || 1;
|
||||||
|
|
||||||
|
context.save();
|
||||||
|
|
||||||
context.setTransform(1, 0, 0, 1, 0, 0);
|
|
||||||
// Clear the visible area.
|
// Clear the visible area.
|
||||||
context.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
context.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
||||||
|
|
||||||
|
@ -107,6 +112,8 @@ export default class View {
|
||||||
if (this.useLines) {
|
if (this.useLines) {
|
||||||
this.renderCellsAsLines(context, startOffset, endOffset);
|
this.renderCellsAsLines(context, startOffset, endOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
renderText(context, startOffset, endOffset, drawSpecials) {
|
renderText(context, startOffset, endOffset, drawSpecials) {
|
||||||
|
|
Loading…
Reference in New Issue