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

View File

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