diff --git a/dotscape b/dotscape index 8e6a97b..66f2e3c 100755 Binary files a/dotscape and b/dotscape differ diff --git a/temp-squares/fcore/app-update.sml b/temp-squares/fcore/app-update.sml index c0005c8..e9083ff 100644 --- a/temp-squares/fcore/app-update.sml +++ b/temp-squares/fcore/app-update.sml @@ -41,4 +41,16 @@ struct Vector.concat [tl, tr, bl, br] end + fun mouseMoveOrRelease (model: app_type) = + let + val drawVec = + case ClickPoints.getClickPositionFromMouse model of + SOME (hIdx, vIdx) => getDotVecFromIndices (model, hIdx, vIdx) + | NONE => Vector.fromList [] + + val drawMsg = DRAW_DOT drawVec + val drawMsg = [DRAW drawMsg] + in + (model, drawMsg) + end end diff --git a/temp-squares/fcore/click-points.sml b/temp-squares/fcore/click-points.sml index d0922de..0b9edd2 100644 --- a/temp-squares/fcore/click-points.sml +++ b/temp-squares/fcore/click-points.sml @@ -10,6 +10,35 @@ 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 + + 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 + fun getDrawDot (xpos, ypos, windowWidth, windowHeight) = let (* calculate normalised device coordinates *)