From d231edda6a800714749f83f2f170054189bd4f6a Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Sun, 6 Jul 2025 14:01:03 +0100 Subject: [PATCH] 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.) --- temp-squares/fcore/app-update.sml | 13 ++++++++++- temp-squares/fcore/click-points.sml | 35 +++++++++++++---------------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/temp-squares/fcore/app-update.sml b/temp-squares/fcore/app-update.sml index 51cf756..b0391ce 100644 --- a/temp-squares/fcore/app-update.sml +++ b/temp-squares/fcore/app-update.sml @@ -170,6 +170,17 @@ struct CollisionTree.toTriangles (windowWidth, windowHeight, squares, maxSide) val drawMsg = DRAW_SQUARES_AND_DOTS {squares = squares, dots = dotVec} in - (model, drawMsg) + (model, [drawMsg]) 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 diff --git a/temp-squares/fcore/click-points.sml b/temp-squares/fcore/click-points.sml index 0b9edd2..c532e5a 100644 --- a/temp-squares/fcore/click-points.sml +++ b/temp-squares/fcore/click-points.sml @@ -10,26 +10,23 @@ struct (Real32.fromInt idx * increment) + start) 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) = - if idx = Vector.length clickPoints then - NONE - else - let - val curPos = Vector.sub (clickPoints, idx) - in - if mousePos < curPos - range orelse mousePos > curPos + range then - getClickPos (clickPoints, mousePos, idx + 1) - else - SOME idx - end + 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 + if mousePos >= curPos andalso mousePos <= nextPos then + SOME idx + else + getClickPos (clickPoints, mousePos, idx + 1) + end + end fun getClickPositionFromMouse (app: AppType.app_type) = case getClickPos (#xClickPoints app, #mouseX app, 0) of