refactoring progress
This commit is contained in:
@@ -41,4 +41,16 @@ struct
|
|||||||
Vector.concat [tl, tr, bl, br]
|
Vector.concat [tl, tr, bl, br]
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -10,6 +10,35 @@ 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) =
|
||||||
|
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) =
|
fun getDrawDot (xpos, ypos, windowWidth, windowHeight) =
|
||||||
let
|
let
|
||||||
(* calculate normalised device coordinates *)
|
(* calculate normalised device coordinates *)
|
||||||
|
|||||||
Reference in New Issue
Block a user