change ClickPoints.getMousePosition function to return indices to the click points array rather than the click points themselves; this will help adding functionality to use arrows for selecting click points later

This commit is contained in:
2024-09-20 09:07:54 +01:00
parent 415f06f0c0
commit 80e1a68843
3 changed files with 19 additions and 11 deletions

BIN
dotscape

Binary file not shown.

View File

@@ -17,11 +17,16 @@ struct
let
val drawVec =
case ClickPoints.getClickPositionFromMouse model of
SOME (xpos, ypos) =>
ClickPoints.getDrawDot (xpos, ypos, 1.0, 0.0, 0.0, model)
SOME (hIdx, vIdx) =>
let
val xpos = Vector.sub (#xClickPoints model, hIdx)
val ypos = Vector.sub (#yClickPoints model, vIdx)
in
ClickPoints.getDrawDot (xpos, ypos, 1.0, 0.0, 0.0, model)
end
| NONE => Vector.fromList []
val drawVec = TriangleStage.toVector (model, drawVec)
val drawMsg = DRAW_DOT drawVec
in
(model, DRAW drawMsg)
@@ -29,11 +34,15 @@ struct
fun mouseLeftClick (model: app_type) =
case ClickPoints.getClickPositionFromMouse model of
SOME (xpos, ypos) =>
SOME (hIdx, vIdx) =>
let
val {windowWidth, windowHeight, xClickPoints, yClickPoints, ...} =
model
val xpos = Vector.sub (xClickPoints, hIdx)
val ypos = Vector.sub (yClickPoints, vIdx)
val dotVec = ClickPoints.getDrawDot (xpos, ypos, 0.0, 0.0, 1.0, model)
val {windowWidth, windowHeight, ...} = model
val halfWidth = Real32.fromInt (windowWidth div 2)
val halfHeight = Real32.fromInt (windowHeight div 2)
val hpos =

View File

@@ -1,8 +1,7 @@
signature CLICK_POINTS =
sig
val generate: int * int -> Real32.real vector
val getClickPositionFromMouse: AppType.app_type
-> (Real32.real * Real32.real) option
val getClickPositionFromMouse: AppType.app_type -> (int * int) option
val getDrawDot:
Real32.real
* Real32.real
@@ -46,14 +45,14 @@ struct
if mousePos < curPos - range orelse mousePos > curPos + range then
getClickPos (clickPoints, mousePos, idx + 1)
else
SOME (Vector.sub (clickPoints, idx))
SOME idx
end
fun getClickPositionFromMouse (app: AppType.app_type) =
case getClickPos (#xClickPoints app, #mouseX app, 0) of
SOME xPos =>
SOME hIdx =>
(case getClickPos (#yClickPoints app, #mouseY app, 0) of
SOME yPos => SOME (xPos, yPos)
SOME vIdx => SOME (hIdx, vIdx)
| NONE => NONE)
| NONE => NONE