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
|
, canvasHeight
|
||||||
) : app_type =
|
) : app_type =
|
||||||
let
|
let
|
||||||
val xClickPoints = ClickPoints.generate (wStart, wFinish, canvasWidth)
|
val (xClickPoints, yClickPoints) =
|
||||||
val yClickPoints = ClickPoints.generate (hStart, hFinish, canvasHeight)
|
ClickPoints.generate
|
||||||
|
(windowWidth, windowHeight, canvasWidth, canvasHeight)
|
||||||
|
|
||||||
val maxPoints = Int.max (canvasWidth, canvasHeight)
|
val maxPoints = Int.max (canvasWidth, canvasHeight)
|
||||||
val squares = Vector.tabulate (maxPoints, fn _ =>
|
val squares = Vector.tabulate (maxPoints, fn _ =>
|
||||||
|
|||||||
@@ -160,9 +160,7 @@ struct
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
fun helpWindowResize
|
fun windowResize (app: app_type, windowWidth, windowHeight) : app_type =
|
||||||
(app: app_type, windowWidth, windowHeight, wStart, wFinish, hStart, hFinish) :
|
|
||||||
app_type =
|
|
||||||
let
|
let
|
||||||
val
|
val
|
||||||
{ mode
|
{ mode
|
||||||
@@ -188,9 +186,9 @@ struct
|
|||||||
, modalNum
|
, modalNum
|
||||||
} = app
|
} = app
|
||||||
|
|
||||||
val maxPoints = Int.max (canvasWidth, canvasHeight)
|
val (xClickPoints, yClickPoints) =
|
||||||
val xClickPoints = ClickPoints.generate (wStart, wFinish, maxPoints)
|
ClickPoints.generate
|
||||||
val yClickPoints = ClickPoints.generate (hStart, hFinish, maxPoints)
|
(windowWidth, windowHeight, canvasWidth, canvasHeight)
|
||||||
in
|
in
|
||||||
{ mode = mode
|
{ mode = mode
|
||||||
, squares = squares
|
, squares = squares
|
||||||
@@ -216,29 +214,6 @@ struct
|
|||||||
}
|
}
|
||||||
end
|
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) =
|
fun mousePosition (app: app_type, mouseX, mouseY) =
|
||||||
let
|
let
|
||||||
val
|
val
|
||||||
|
|||||||
@@ -1,12 +1,23 @@
|
|||||||
structure ClickPoints =
|
structure ClickPoints =
|
||||||
struct
|
struct
|
||||||
fun generate (start, finish, numPoints) =
|
fun generate (windowWidth, windowHeight, canvasWidth, canvasHeight) =
|
||||||
let
|
let
|
||||||
val difference = finish - start
|
val realWindowWidth = Real32.fromInt windowWidth
|
||||||
val increment = Real32.fromInt difference / Real32.fromInt numPoints
|
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
|
in
|
||||||
Vector.tabulate (numPoints + 1, fn idx =>
|
(xClickPoints, yClickPoints)
|
||||||
(Real32.fromInt idx * increment))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
fun getClickPos (clickPoints, mousePos, idx) =
|
fun getClickPos (clickPoints, mousePos, idx) =
|
||||||
|
|||||||
Reference in New Issue
Block a user