fix: (flutter/web) use window.devicePixelRatio for viewport
This commit is contained in:
@@ -43,8 +43,10 @@ class _ThermionWidgetState extends State<ThermionWidget> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
var dpr = MediaQuery.of(context).devicePixelRatio;
|
var dpr = MediaQuery.of(context).devicePixelRatio;
|
||||||
|
|
||||||
var size = ((context.findRenderObject()) as RenderBox).size;
|
var size = ((context.findRenderObject()) as RenderBox).size;
|
||||||
_texture = await ThermionFlutterPlugin.createTexture(size.width, size.height, 0, 0, dpr);
|
_texture = await ThermionFlutterPlugin.createTexture(
|
||||||
|
size.width, size.height, 0, 0, dpr);
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {});
|
setState(() {});
|
||||||
@@ -140,4 +142,3 @@ class TransparencyPainter extends CustomPainter {
|
|||||||
@override
|
@override
|
||||||
bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
|
bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,17 +16,14 @@ class ThermionFlutterWebPlugin extends ThermionFlutterPlatform {
|
|||||||
Future<ThermionFlutterTexture?> createTexture(double width, double height,
|
Future<ThermionFlutterTexture?> createTexture(double width, double height,
|
||||||
double offsetLeft, double offsetRight, double pixelRatio) async {
|
double offsetLeft, double offsetRight, double pixelRatio) async {
|
||||||
await _viewer!.destroySwapChain();
|
await _viewer!.destroySwapChain();
|
||||||
var physicalWidth = (width * pixelRatio).ceil();
|
await _viewer!.createSwapChain(width.ceil(), height.ceil());
|
||||||
var physicalHeight = (width * pixelRatio).ceil();
|
|
||||||
await _viewer!.createSwapChain(physicalWidth, physicalHeight);
|
|
||||||
|
|
||||||
final canvas = document.getElementById("canvas") as HTMLCanvasElement;
|
final canvas = document.getElementById("canvas") as HTMLCanvasElement;
|
||||||
canvas.width = physicalWidth;
|
canvas.width = (width * pixelRatio).ceil();
|
||||||
canvas.height = physicalHeight;
|
canvas.height = (height * pixelRatio).ceil();
|
||||||
|
|
||||||
print("canvas dimensions ${width}x${height}");
|
_viewer!
|
||||||
|
.updateViewportAndCameraProjection(width.ceil(), height.ceil(), 1.0);
|
||||||
_viewer!.updateViewportAndCameraProjection(physicalWidth, physicalHeight, 1.0);
|
|
||||||
|
|
||||||
return ThermionFlutterTexture(null, null, 0, 0, null);
|
return ThermionFlutterTexture(null, null, 0, 0, null);
|
||||||
}
|
}
|
||||||
@@ -52,7 +49,10 @@ class ThermionFlutterWebPlugin extends ThermionFlutterPlatform {
|
|||||||
canvas.id = "canvas";
|
canvas.id = "canvas";
|
||||||
document.body!.appendChild(canvas);
|
document.body!.appendChild(canvas);
|
||||||
canvas.style.display = 'none';
|
canvas.style.display = 'none';
|
||||||
await _viewer!.initialize(1, 1, uberArchivePath: uberArchivePath);
|
final pixelRatio = window.devicePixelRatio;
|
||||||
|
|
||||||
|
await _viewer!
|
||||||
|
.initialize(1, 1, pixelRatio, uberArchivePath: uberArchivePath);
|
||||||
return _viewer!;
|
return _viewer!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user