code function that indicates which area, if any, was clicked
This commit is contained in:
BIN
dot-to-dot
BIN
dot-to-dot
Binary file not shown.
@@ -10,8 +10,9 @@ in
|
|||||||
ffi/glfw-input.sml
|
ffi/glfw-input.sml
|
||||||
end
|
end
|
||||||
|
|
||||||
|
message-types/input-msg.sml
|
||||||
|
|
||||||
functional-core/app-type.sml
|
functional-core/app-type.sml
|
||||||
functional-core/msg.sml
|
|
||||||
functional-core/app-update.sml
|
functional-core/app-update.sml
|
||||||
|
|
||||||
ann
|
ann
|
||||||
|
|||||||
@@ -1 +1,75 @@
|
|||||||
structure AppUpdate = struct end
|
structure AppUpdate =
|
||||||
|
struct
|
||||||
|
val clickPoints =
|
||||||
|
#[ 25
|
||||||
|
, 50
|
||||||
|
, 75
|
||||||
|
, 100
|
||||||
|
, 125
|
||||||
|
, 150
|
||||||
|
, 175
|
||||||
|
, 200
|
||||||
|
, 225
|
||||||
|
, 250
|
||||||
|
, 275
|
||||||
|
, 300
|
||||||
|
, 325
|
||||||
|
, 350
|
||||||
|
, 375
|
||||||
|
, 400
|
||||||
|
, 425
|
||||||
|
, 450
|
||||||
|
, 475
|
||||||
|
]
|
||||||
|
|
||||||
|
local
|
||||||
|
fun getVerticalClickPos (idx, horizontalPos, mouseX, mouseY) =
|
||||||
|
if idx = Vector.length clickPoints then
|
||||||
|
#[]
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val curVerticalPos = Vector.sub (clickPoints, idx)
|
||||||
|
in
|
||||||
|
if mouseY < curVerticalPos - 10 orelse mouseY > curVerticalPos + 10 then
|
||||||
|
getVerticalClickPos (idx + 1, horizontalPos, mouseX, mouseY)
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val left = Real32.fromInt ((horizontalPos - 10) div 500)
|
||||||
|
val right = Real32.fromInt ((horizontalPos + 10) div 500)
|
||||||
|
val bottom = Real32.fromInt ((curVerticalPos - 10) div 500)
|
||||||
|
val top = Real32.fromInt ((curVerticalPos + 10) div 500)
|
||||||
|
in
|
||||||
|
val highlightSquare = #[
|
||||||
|
left, bottom, (* lower left *)
|
||||||
|
right, bottom, (* lower right *)
|
||||||
|
left, top, (* upper left *)
|
||||||
|
|
||||||
|
left, top, (* upper left *)
|
||||||
|
right, bottom, (* lower right *)
|
||||||
|
right, top (* upper right *)
|
||||||
|
]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
fun getHorizontalClickPos (idx, mouseX, mouseY) =
|
||||||
|
if idx = Vector.length clickPoints then
|
||||||
|
#[]
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val curPos = Vector.sub (clickPoints, idx)
|
||||||
|
in
|
||||||
|
if mouseX < curPos - 10 orelse mouseX > curPos + 10 then
|
||||||
|
getHorizontalClickPos (idx + 1, mouseX, mouseY)
|
||||||
|
else
|
||||||
|
getVerticalClickPos (0, curPos, mouseX, mouseY)
|
||||||
|
end
|
||||||
|
in
|
||||||
|
(*
|
||||||
|
* This function returns a vector containing the position data of the
|
||||||
|
* clicked square.
|
||||||
|
* If a square wasn't found at the clicked position,
|
||||||
|
* an empty vector is returned.
|
||||||
|
*)
|
||||||
|
fun getClickPos (mouseX, mouseY) = getHorizontalClickPos (0, mouseX, mouseY)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
structure InputCallbacks =
|
structure InputCallbacks =
|
||||||
struct
|
struct
|
||||||
open CML
|
open CML
|
||||||
open Msg
|
open InputMessage
|
||||||
|
|
||||||
fun mouseMoveCallback mailbox (x, y) =
|
fun mouseMoveCallback mailbox (x, y) =
|
||||||
Mailbox.send (mailbox, (MOUSE_MOVE {x = x, y = y}))
|
Mailbox.send (mailbox, (MOUSE_MOVE {x = x, y = y}))
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ struct
|
|||||||
|
|
||||||
fun callbackListener mailbox =
|
fun callbackListener mailbox =
|
||||||
let
|
let
|
||||||
open Msg
|
open InputMessage
|
||||||
val _ =
|
val _ =
|
||||||
case Mailbox.recv mailbox of
|
case Mailbox.recv mailbox of
|
||||||
MOUSE_MOVE {x, y} =>
|
MOUSE_MOVE {x, y} =>
|
||||||
|
|||||||
9
message-types/draw-msg.sml
Normal file
9
message-types/draw-msg.sml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
signature DRAW_MESSAGE =
|
||||||
|
sig
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
structure DrawMessage :> DRAW_MESSAGE =
|
||||||
|
struct
|
||||||
|
|
||||||
|
end
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
signature MSG =
|
signature INPUT_MESSAGE =
|
||||||
sig
|
sig
|
||||||
datatype t =
|
datatype t =
|
||||||
MOUSE_MOVE of {x: int, y: int}
|
MOUSE_MOVE of {x: int, y: int}
|
||||||
@@ -6,7 +6,7 @@ sig
|
|||||||
| MOUSE_LEFT_RELEASE
|
| MOUSE_LEFT_RELEASE
|
||||||
end
|
end
|
||||||
|
|
||||||
structure Msg :> MSG =
|
structure InputMessage :> INPUT_MESSAGE =
|
||||||
struct
|
struct
|
||||||
datatype t =
|
datatype t =
|
||||||
MOUSE_MOVE of {x: int, y: int}
|
MOUSE_MOVE of {x: int, y: int}
|
||||||
Reference in New Issue
Block a user