mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 03:10:46 -06:00
UX: Render wizard previews for high-DPI displays (#7371)
* UX: Render wizard previews for high-DPI displays Sets up a canvas element of twice the required dimensions, scales all coordinates by 2x, then shrinks the display in css. * Use window.devicePixelRatio to determine scale factor
This commit is contained in:
parent
e50494bcde
commit
fd0de64e0d
@ -17,21 +17,27 @@ function canvasFor(image, w, h) {
|
|||||||
w = Math.ceil(w);
|
w = Math.ceil(w);
|
||||||
h = Math.ceil(h);
|
h = Math.ceil(h);
|
||||||
|
|
||||||
|
const scale = window.devicePixelRatio;
|
||||||
|
|
||||||
const can = document.createElement("canvas");
|
const can = document.createElement("canvas");
|
||||||
can.width = w;
|
can.width = w * scale;
|
||||||
can.height = h;
|
can.height = h * scale;
|
||||||
|
|
||||||
const ctx = can.getContext("2d");
|
const ctx = can.getContext("2d");
|
||||||
|
ctx.scale(scale, scale);
|
||||||
ctx.drawImage(image, 0, 0, w, h);
|
ctx.drawImage(image, 0, 0, w, h);
|
||||||
return can;
|
return can;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createPreviewComponent(width, height, obj) {
|
export function createPreviewComponent(width, height, obj) {
|
||||||
|
const scale = window.devicePixelRatio;
|
||||||
return Ember.Component.extend(
|
return Ember.Component.extend(
|
||||||
{
|
{
|
||||||
layoutName: "components/theme-preview",
|
layoutName: "components/theme-preview",
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
|
elementWidth: width * scale,
|
||||||
|
elementHeight: height * scale,
|
||||||
ctx: null,
|
ctx: null,
|
||||||
loaded: false,
|
loaded: false,
|
||||||
|
|
||||||
@ -39,6 +45,7 @@ export function createPreviewComponent(width, height, obj) {
|
|||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
const c = this.$("canvas")[0];
|
const c = this.$("canvas")[0];
|
||||||
this.ctx = c.getContext("2d");
|
this.ctx = c.getContext("2d");
|
||||||
|
this.ctx.scale(2, 2);
|
||||||
this.reload();
|
this.reload();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<div class='preview-area'>
|
<div class='preview-area'>
|
||||||
<canvas width={{width}} height={{height}}>
|
<canvas width={{elementWidth}} height={{elementHeight}} style={{concat "width:" width "; height:" height ";"}}>
|
||||||
</canvas>
|
</canvas>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user