return normalised device coordinates together with vector, from getClickPos function
This commit is contained in:
BIN
dot-to-dot
BIN
dot-to-dot
Binary file not shown.
@@ -17,6 +17,7 @@ struct
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local
|
||||||
fun genClickPoints (windowWidth, windowHeight) =
|
fun genClickPoints (windowWidth, windowHeight) =
|
||||||
let
|
let
|
||||||
val w = Real32.fromInt windowWidth / 40.0
|
val w = Real32.fromInt windowWidth / 40.0
|
||||||
@@ -25,13 +26,12 @@ struct
|
|||||||
Vector.tabulate (41, fn idx => Real32.fromInt idx * w)
|
Vector.tabulate (41, fn idx => Real32.fromInt idx * w)
|
||||||
end
|
end
|
||||||
|
|
||||||
local
|
|
||||||
val clickPoints =
|
val clickPoints =
|
||||||
genClickPoints (Constants.windowWidth, Constants.windowHeight)
|
genClickPoints (Constants.windowWidth, Constants.windowHeight)
|
||||||
|
|
||||||
fun getVerticalClickPos (idx, horizontalPos, mouseX, mouseY, r, g, b) =
|
fun getVerticalClickPos (idx, horizontalPos, mouseX, mouseY, r, g, b) =
|
||||||
if idx = Vector.length clickPoints then
|
if idx = Vector.length clickPoints then
|
||||||
#[]
|
(#[], 0.0, 0.0)
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
val curVerticalPos = Vector.sub (clickPoints, idx)
|
val curVerticalPos = Vector.sub (clickPoints, idx)
|
||||||
@@ -49,7 +49,8 @@ struct
|
|||||||
val right = (hpos + 5.0) / halfWidth
|
val right = (hpos + 5.0) / halfWidth
|
||||||
val bottom = (vpos - 5.0) / halfHeight
|
val bottom = (vpos - 5.0) / halfHeight
|
||||||
val top = (vpos + 5.0) / halfHeight
|
val top = (vpos + 5.0) / halfHeight
|
||||||
in
|
|
||||||
|
val drawVec =
|
||||||
#[ left, bottom, r, g, b
|
#[ left, bottom, r, g, b
|
||||||
, right, bottom, r, g, b
|
, right, bottom, r, g, b
|
||||||
, left, top, r, g, b
|
, left, top, r, g, b
|
||||||
@@ -58,12 +59,17 @@ struct
|
|||||||
, right, bottom, r, g, b
|
, right, bottom, r, g, b
|
||||||
, right, top, r, g, b
|
, right, top, r, g, b
|
||||||
]
|
]
|
||||||
|
|
||||||
|
val hpos = hpos / halfWidth
|
||||||
|
val vpos = vpos / halfHeight
|
||||||
|
in
|
||||||
|
(drawVec, hpos, vpos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
fun getHorizontalClickPos (idx, mouseX, mouseY, r, g, b) =
|
fun getHorizontalClickPos (idx, mouseX, mouseY, r, g, b) =
|
||||||
if idx = Vector.length clickPoints then
|
if idx = Vector.length clickPoints then
|
||||||
#[]
|
(#[], 0.0, 0.0)
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
val curPos = Vector.sub (clickPoints, idx)
|
val curPos = Vector.sub (clickPoints, idx)
|
||||||
@@ -93,27 +99,31 @@ struct
|
|||||||
case inputMsg of
|
case inputMsg of
|
||||||
MOUSE_MOVE {x = mouseX, y = mouseY} =>
|
MOUSE_MOVE {x = mouseX, y = mouseY} =>
|
||||||
let
|
let
|
||||||
val _ = print "mouse moved\n"
|
val (drawVec, _, _) = getClickPos (mouseX, mouseY, 1.0, 0.0, 0.0)
|
||||||
val drawMsg = DRAW_BUTTON (getClickPos
|
val drawMsg = DRAW_BUTTON drawVec
|
||||||
(mouseX, mouseY, 1.0, 0.0, 0.0))
|
|
||||||
in
|
in
|
||||||
(model, drawMsg, mouseX, mouseY)
|
(model, drawMsg, mouseX, mouseY)
|
||||||
end
|
end
|
||||||
| MOUSE_LEFT_RELEASE =>
|
| MOUSE_LEFT_RELEASE =>
|
||||||
let
|
let
|
||||||
val _ = print "mouse released\n"
|
val (drawVec, _, _) = getClickPos (mouseX, mouseY, 1.0, 0.0, 0.0)
|
||||||
val drawMsg = DRAW_BUTTON (getClickPos
|
val drawMsg = DRAW_BUTTON drawVec
|
||||||
(mouseX, mouseY, 1.0, 0.0, 0.0))
|
|
||||||
in
|
in
|
||||||
(model, drawMsg, mouseX, mouseY)
|
(model, drawMsg, mouseX, mouseY)
|
||||||
end
|
end
|
||||||
| MUSE_LEFT_CLICK =>
|
| MUSE_LEFT_CLICK =>
|
||||||
let
|
let
|
||||||
val _ = print "mouse clicked\n"
|
val (buttonVec, hpos, vpos) =
|
||||||
val buttonVec = getClickPos (mouseX, mouseY, 0.0, 0.0, 1.0)
|
getClickPos (mouseX, mouseY, 0.0, 0.0, 1.0)
|
||||||
|
in
|
||||||
|
if Vector.length buttonVec > 0 then
|
||||||
|
let
|
||||||
val drawMsg = DRAW_BUTTON buttonVec
|
val drawMsg = DRAW_BUTTON buttonVec
|
||||||
in
|
in
|
||||||
(model, drawMsg, mouseX, mouseY)
|
(model, drawMsg, mouseX, mouseY)
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
(model, NO_DRAW, mouseX, mouseY)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -55,7 +55,15 @@ struct
|
|||||||
, buttonDrawObject
|
, buttonDrawObject
|
||||||
, buttonDrawLength
|
, buttonDrawLength
|
||||||
)
|
)
|
||||||
end)
|
end
|
||||||
|
| NO_DRAW =>
|
||||||
|
draw
|
||||||
|
( drawMailbox
|
||||||
|
, window
|
||||||
|
, graphDrawObject
|
||||||
|
, buttonDrawObject
|
||||||
|
, buttonDrawLength
|
||||||
|
))
|
||||||
else
|
else
|
||||||
Glfw.terminate ()
|
Glfw.terminate ()
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
signature DRAW_MESSAGE =
|
signature DRAW_MESSAGE =
|
||||||
sig
|
sig
|
||||||
datatype t = DRAW_BUTTON of Real32.real vector
|
datatype t = DRAW_BUTTON of Real32.real vector
|
||||||
|
| NO_DRAW
|
||||||
end
|
end
|
||||||
|
|
||||||
structure DrawMessage :> DRAW_MESSAGE =
|
structure DrawMessage :> DRAW_MESSAGE =
|
||||||
struct
|
struct
|
||||||
datatype t = DRAW_BUTTON of Real32.real vector
|
datatype t = DRAW_BUTTON of Real32.real vector
|
||||||
|
| NO_DRAW
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user