improve creation of click points, so that we can have a pixel be a perfect square, even if the canvas isn't
This commit is contained in:
@@ -18,8 +18,9 @@ struct
|
||||
, canvasHeight
|
||||
) : app_type =
|
||||
let
|
||||
val xClickPoints = ClickPoints.generate (wStart, wFinish, canvasWidth)
|
||||
val yClickPoints = ClickPoints.generate (hStart, hFinish, canvasHeight)
|
||||
val (xClickPoints, yClickPoints) =
|
||||
ClickPoints.generate
|
||||
(windowWidth, windowHeight, canvasWidth, canvasHeight)
|
||||
|
||||
val maxPoints = Int.max (canvasWidth, canvasHeight)
|
||||
val squares = Vector.tabulate (maxPoints, fn _ =>
|
||||
|
||||
@@ -160,9 +160,7 @@ struct
|
||||
}
|
||||
end
|
||||
|
||||
fun helpWindowResize
|
||||
(app: app_type, windowWidth, windowHeight, wStart, wFinish, hStart, hFinish) :
|
||||
app_type =
|
||||
fun windowResize (app: app_type, windowWidth, windowHeight) : app_type =
|
||||
let
|
||||
val
|
||||
{ mode
|
||||
@@ -188,9 +186,9 @@ struct
|
||||
, modalNum
|
||||
} = app
|
||||
|
||||
val maxPoints = Int.max (canvasWidth, canvasHeight)
|
||||
val xClickPoints = ClickPoints.generate (wStart, wFinish, maxPoints)
|
||||
val yClickPoints = ClickPoints.generate (hStart, hFinish, maxPoints)
|
||||
val (xClickPoints, yClickPoints) =
|
||||
ClickPoints.generate
|
||||
(windowWidth, windowHeight, canvasWidth, canvasHeight)
|
||||
in
|
||||
{ mode = mode
|
||||
, squares = squares
|
||||
@@ -216,29 +214,6 @@ struct
|
||||
}
|
||||
end
|
||||
|
||||
fun windowResize (app: app_type, windowWidth, windowHeight) =
|
||||
if windowWidth = windowHeight then
|
||||
helpWindowResize
|
||||
(app, windowWidth, windowHeight, 0, windowWidth, 0, windowHeight)
|
||||
else if windowWidth > windowHeight then
|
||||
let
|
||||
val difference = windowWidth - windowHeight
|
||||
val wStart = difference div 2
|
||||
val wFinish = wStart + windowHeight
|
||||
in
|
||||
helpWindowResize
|
||||
(app, windowWidth, windowHeight, wStart, wFinish, 0, windowHeight)
|
||||
end
|
||||
else
|
||||
let
|
||||
val difference = windowHeight - windowWidth
|
||||
val hStart = difference div 2
|
||||
val hFinish = hStart + windowWidth
|
||||
in
|
||||
helpWindowResize
|
||||
(app, windowWidth, windowHeight, 0, windowWidth, hStart, hFinish)
|
||||
end
|
||||
|
||||
fun mousePosition (app: app_type, mouseX, mouseY) =
|
||||
let
|
||||
val
|
||||
|
||||
@@ -1,12 +1,23 @@
|
||||
structure ClickPoints =
|
||||
struct
|
||||
fun generate (start, finish, numPoints) =
|
||||
fun generate (windowWidth, windowHeight, canvasWidth, canvasHeight) =
|
||||
let
|
||||
val difference = finish - start
|
||||
val increment = Real32.fromInt difference / Real32.fromInt numPoints
|
||||
val realWindowWidth = Real32.fromInt windowWidth
|
||||
val realCanvasWidth = Real32.fromInt canvasWidth
|
||||
val realWindowHeight = Real32.fromInt windowHeight
|
||||
val realCanvasHeight = Real32.fromInt canvasHeight
|
||||
|
||||
val xPixelSize = realWindowWidth / realCanvasWidth
|
||||
val yPixelSize = realWindowHeight / realCanvasHeight
|
||||
|
||||
val pixelSize = Real32.min (xPixelSize, yPixelSize)
|
||||
|
||||
val xClickPoints = Vector.tabulate (canvasWidth + 1, fn i =>
|
||||
Real32.fromInt i * pixelSize)
|
||||
val yClickPoints = Vector.tabulate (canvasHeight + 1, fn i =>
|
||||
Real32.fromInt i * pixelSize)
|
||||
in
|
||||
Vector.tabulate (numPoints + 1, fn idx =>
|
||||
(Real32.fromInt idx * increment))
|
||||
(xClickPoints, yClickPoints)
|
||||
end
|
||||
|
||||
fun getClickPos (clickPoints, mousePos, idx) =
|
||||
|
||||
Reference in New Issue
Block a user