Hello, I'm using canvas to draw some 2D scene and it works fine, but I want to be able to zoom the scene.
I added some buttons that increase/decrease a scale and uses that with
DrawScope.scale(scale)
, but it scales the thickness of the lines.
How can I scale the lines without making them thicker?
m
Michael Paus
07/18/2022, 2:37 PM
You can apply the inverse scale to the line thickness parameter.
k
Kirill Grouchnikov
07/18/2022, 2:37 PM
.scale
scales everything. You’ll need to either: a) apply your scaling factor manually on all the coordinates you pass to different calls or b) apply “inverse” scaling on the stroke width
d
Dragos Rachieru
07/18/2022, 2:41 PM
I think the first option is good, but I don't know how it impacts the position before/after the zoom.
Is the second option good for float calculations? I don't know if the stroke calculated will be too small or something and they won't be showing in some zoom levels
k
Kirill Grouchnikov
07/18/2022, 2:42 PM
The second option might or might not break pixel snapping, depending on how Skia treats these combined scales. You know how floating operations can be off a few digits after the decimal point. Like, 3.0 x (1.0 / 3.0) might not get you back to 1.0