modify ClickPoints.getClickPos function to detect click for square/pixel, not for triangle. (Checking if mouse is between two click points instead of if mouse is around one click point.)

This commit is contained in:
2025-07-06 14:01:03 +01:00
parent 4a87b0f16e
commit d231edda6a
2 changed files with 28 additions and 20 deletions

View File

@@ -170,6 +170,17 @@ struct
CollisionTree.toTriangles (windowWidth, windowHeight, squares, maxSide) CollisionTree.toTriangles (windowWidth, windowHeight, squares, maxSide)
val drawMsg = DRAW_SQUARES_AND_DOTS {squares = squares, dots = dotVec} val drawMsg = DRAW_SQUARES_AND_DOTS {squares = squares, dots = dotVec}
in in
(model, drawMsg) (model, [drawMsg])
end end
fun mouseLeftClick model =
case ClickPoints.getClickPositionFromMouse model of
SOME (hIdx, vIdx) => addCoordinates (model, hIdx, vIdx)
| NONE => (model, [])
fun enterOrSpaceCoordinates model =
let val {arrowX, arrowY, ...} = model
in addCoordinates (model, arrowX, arrowY)
end
end end

View File

@@ -10,25 +10,22 @@ struct
(Real32.fromInt idx * increment) + start) (Real32.fromInt idx * increment) + start)
end end
(*
* Range to detect from clickable position.
* For example, if we have a clickable position at (x, y) = (500, 500),
* with a range of 15, we can detect clicks targeting this position
* from top left at (485, 485) to bottom right at (515, 515).
* *)
val range = 15.0
fun getClickPos (clickPoints, mousePos, idx) = fun getClickPos (clickPoints, mousePos, idx) =
if idx = Vector.length clickPoints then let
val nextIdx = idx + 1
in
if nextIdx >= Vector.length clickPoints then
NONE NONE
else else
let let
val curPos = Vector.sub (clickPoints, idx) val curPos = Vector.sub (clickPoints, idx)
val nextPos = Vector.sub (clickPoints, nextIdx)
in in
if mousePos < curPos - range orelse mousePos > curPos + range then if mousePos >= curPos andalso mousePos <= nextPos then
getClickPos (clickPoints, mousePos, idx + 1)
else
SOME idx SOME idx
else
getClickPos (clickPoints, mousePos, idx + 1)
end
end end
fun getClickPositionFromMouse (app: AppType.app_type) = fun getClickPositionFromMouse (app: AppType.app_type) =