adjust click points to always keep the canvas at the centre of the screen, even when the canvas width is different from the canvas height
This commit is contained in:
@@ -12,10 +12,18 @@ struct
|
|||||||
|
|
||||||
val pixelSize = Real32.min (xPixelSize, yPixelSize)
|
val pixelSize = Real32.min (xPixelSize, yPixelSize)
|
||||||
|
|
||||||
|
val actualWidth = pixelSize * realCanvasWidth
|
||||||
|
val actualHeight = pixelSize * realCanvasHeight
|
||||||
|
|
||||||
|
val heightDifference = realWindowHeight - actualHeight
|
||||||
|
val yOffset = heightDifference / 2.0
|
||||||
|
val widthDifference = realWindowWidth - actualWidth
|
||||||
|
val xOffset = widthDifference / 2.0
|
||||||
|
|
||||||
val xClickPoints = Vector.tabulate (canvasWidth + 1, fn i =>
|
val xClickPoints = Vector.tabulate (canvasWidth + 1, fn i =>
|
||||||
Real32.fromInt i * pixelSize)
|
(Real32.fromInt i * pixelSize) + xOffset)
|
||||||
val yClickPoints = Vector.tabulate (canvasHeight + 1, fn i =>
|
val yClickPoints = Vector.tabulate (canvasHeight + 1, fn i =>
|
||||||
Real32.fromInt i * pixelSize)
|
(Real32.fromInt i * pixelSize) + yOffset)
|
||||||
in
|
in
|
||||||
(xClickPoints, yClickPoints)
|
(xClickPoints, yClickPoints)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user