2025-07-06 01:38:02 +01:00
|
|
|
structure ClickPoints =
|
|
|
|
|
struct
|
|
|
|
|
fun generate (start, finish, numPoints) =
|
|
|
|
|
let
|
|
|
|
|
val difference = finish - start
|
|
|
|
|
val increment = Real32.fromInt difference / Real32.fromInt numPoints
|
|
|
|
|
in
|
|
|
|
|
Vector.tabulate (numPoints + 1, fn idx =>
|
2025-07-10 22:48:34 +01:00
|
|
|
(Real32.fromInt idx * increment))
|
2025-07-06 01:38:02 +01:00
|
|
|
end
|
2025-07-06 02:49:38 +01:00
|
|
|
|
2025-07-06 03:53:26 +01:00
|
|
|
fun getClickPos (clickPoints, mousePos, idx) =
|
2025-07-06 14:01:03 +01:00
|
|
|
let
|
|
|
|
|
val nextIdx = idx + 1
|
|
|
|
|
in
|
|
|
|
|
if nextIdx >= Vector.length clickPoints then
|
|
|
|
|
NONE
|
|
|
|
|
else
|
|
|
|
|
let
|
|
|
|
|
val curPos = Vector.sub (clickPoints, idx)
|
|
|
|
|
val nextPos = Vector.sub (clickPoints, nextIdx)
|
|
|
|
|
in
|
2025-07-06 14:45:20 +01:00
|
|
|
if mousePos >= curPos andalso mousePos <= nextPos then SOME idx
|
|
|
|
|
else getClickPos (clickPoints, mousePos, idx + 1)
|
2025-07-06 14:01:03 +01:00
|
|
|
end
|
|
|
|
|
end
|
2025-07-06 03:53:26 +01:00
|
|
|
|
|
|
|
|
fun getClickPositionFromMouse (app: AppType.app_type) =
|
|
|
|
|
case getClickPos (#xClickPoints app, #mouseX app, 0) of
|
|
|
|
|
SOME hIdx =>
|
|
|
|
|
(case getClickPos (#yClickPoints app, #mouseY app, 0) of
|
|
|
|
|
SOME vIdx => SOME (hIdx, vIdx)
|
|
|
|
|
| NONE => NONE)
|
|
|
|
|
| NONE => NONE
|
|
|
|
|
|
2025-07-06 02:49:38 +01:00
|
|
|
fun getDrawDot (xpos, ypos, windowWidth, windowHeight) =
|
|
|
|
|
let
|
|
|
|
|
(* calculate normalised device coordinates *)
|
|
|
|
|
val halfWidth = Real32.fromInt (windowWidth div 2)
|
|
|
|
|
val halfHeight = Real32.fromInt (windowHeight div 2)
|
|
|
|
|
val hpos = xpos - halfWidth
|
|
|
|
|
val vpos = ~(ypos - halfHeight)
|
|
|
|
|
|
|
|
|
|
(* coordinates to form small box around clicked area *)
|
|
|
|
|
val left = (hpos - 5.0) / halfWidth
|
|
|
|
|
val right = (hpos + 5.0) / halfWidth
|
|
|
|
|
val bottom = (vpos - 5.0) / halfHeight
|
|
|
|
|
val top = (vpos + 5.0) / halfHeight
|
|
|
|
|
in
|
|
|
|
|
Ndc.ltrbToVertex (left, top, right, bottom)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun getDrawDotRgb (xpos, ypos, r, g, b, windowWidth, windowHeight) =
|
|
|
|
|
let
|
|
|
|
|
(* calculate normalised device coordinates *)
|
|
|
|
|
val halfWidth = Real32.fromInt (windowWidth div 2)
|
|
|
|
|
val halfHeight = Real32.fromInt (windowHeight div 2)
|
|
|
|
|
val hpos = xpos - halfWidth
|
|
|
|
|
val vpos = ~(ypos - halfHeight)
|
|
|
|
|
|
|
|
|
|
(* coordinates to form small box around clicked area *)
|
|
|
|
|
val left = (hpos - 5.0) / halfWidth
|
|
|
|
|
val right = (hpos + 5.0) / halfWidth
|
|
|
|
|
val bottom = (vpos - 5.0) / halfHeight
|
|
|
|
|
val top = (vpos + 5.0) / halfHeight
|
|
|
|
|
in
|
|
|
|
|
Ndc.ltrbToVertexRgb (left, top, right, bottom, r, g, b)
|
|
|
|
|
end
|
2025-07-06 01:38:02 +01:00
|
|
|
end
|