a little refactoring
This commit is contained in:
@@ -137,79 +137,81 @@ struct
|
|||||||
| SECOND {x1, y1, x2, y2} =>
|
| SECOND {x1, y1, x2, y2} =>
|
||||||
getSecondTriangleStageVector (x1, y1, x2, y2, drawVec)
|
getSecondTriangleStageVector (x1, y1, x2, y2, drawVec)
|
||||||
|
|
||||||
fun update (model, mouseX, mouseY, inputMsg) =
|
local
|
||||||
let
|
open DrawMessage
|
||||||
open DrawMessage
|
open InputMessage
|
||||||
open InputMessage
|
|
||||||
in
|
fun mouseMoveOrRelease (model, mouseX, mouseY) =
|
||||||
|
let
|
||||||
|
val (drawVec, _, _) = getClickPos
|
||||||
|
(#clickPoints model, mouseX, mouseY, 1.0, 0.0, 0.0)
|
||||||
|
val drawVec = getTriangleStageVector (model, drawVec)
|
||||||
|
val drawMsg = DRAW_BUTTON drawVec
|
||||||
|
in
|
||||||
|
(model, drawMsg, mouseX, mouseY)
|
||||||
|
end
|
||||||
|
|
||||||
|
fun mouseLeftClick (model, mouseX, mouseY) =
|
||||||
|
let
|
||||||
|
val (buttonVec, hpos, vpos) = getClickPos
|
||||||
|
(#clickPoints model, mouseX, mouseY, 0.0, 0.0, 1.0)
|
||||||
|
in
|
||||||
|
if Vector.length buttonVec > 0 then
|
||||||
|
case #triangleStage model of
|
||||||
|
NO_TRIANGLE =>
|
||||||
|
let
|
||||||
|
val drawVec = getTriangleStageVector (model, buttonVec)
|
||||||
|
val drawMsg = DRAW_BUTTON drawVec
|
||||||
|
|
||||||
|
val newTriangleStage = FIRST {x1 = hpos, y1 = vpos}
|
||||||
|
val model = AppType.withTriangleStage (model, newTriangleStage)
|
||||||
|
in
|
||||||
|
(model, drawMsg, mouseX, mouseY)
|
||||||
|
end
|
||||||
|
| FIRST {x1, y1} =>
|
||||||
|
let
|
||||||
|
val drawVec = getFirstTriangleStageVector (x1, y1, buttonVec)
|
||||||
|
val drawMsg = DRAW_BUTTON drawVec
|
||||||
|
|
||||||
|
val newTriangleStage = SECOND
|
||||||
|
{x1 = x1, y1 = y1, x2 = hpos, y2 = vpos}
|
||||||
|
val model = AppType.withTriangleStage (model, newTriangleStage)
|
||||||
|
in
|
||||||
|
(model, drawMsg, mouseX, mouseY)
|
||||||
|
end
|
||||||
|
| SECOND {x1, y1, x2, y2} =>
|
||||||
|
let
|
||||||
|
val model = AppType.addTriangleAndResetStage
|
||||||
|
(model, x1, y1, x2, y2, hpos, vpos)
|
||||||
|
|
||||||
|
val drawVec = getTrianglesVector model
|
||||||
|
val drawMsg = DRAW_TRIANGLES_AND_RESET_BUTTONS drawVec
|
||||||
|
in
|
||||||
|
(model, drawMsg, mouseX, mouseY)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
(model, NO_DRAW, mouseX, mouseY)
|
||||||
|
end
|
||||||
|
|
||||||
|
fun resizeWindow (model, mouseX, mouseY, width, height) =
|
||||||
|
let
|
||||||
|
val low = Int.min (width, height)
|
||||||
|
val high = Int.min (width, height)
|
||||||
|
|
||||||
|
val difference = high - low
|
||||||
|
val offset = difference div 2
|
||||||
|
val _ = print "resized window \n"
|
||||||
|
in
|
||||||
|
(model, NO_DRAW, mouseX, mouseY)
|
||||||
|
end
|
||||||
|
in
|
||||||
|
fun update (model, mouseX, mouseY, inputMsg) =
|
||||||
case inputMsg of
|
case inputMsg of
|
||||||
MOUSE_MOVE {x = mouseX, y = mouseY} =>
|
MOUSE_MOVE {x = mouseX, y = mouseY} =>
|
||||||
let
|
mouseMoveOrRelease (model, mouseX, mouseY)
|
||||||
val (drawVec, _, _) = getClickPos
|
| MOUSE_LEFT_RELEASE => mouseMoveOrRelease (model, mouseX, mouseY)
|
||||||
(#clickPoints model, mouseX, mouseY, 1.0, 0.0, 0.0)
|
| MOUSE_LEFT_CLICK => mouseLeftClick (model, mouseX, mouseY)
|
||||||
val drawVec = getTriangleStageVector (model, drawVec)
|
| RESIZE_WINDOW {width, height} =>
|
||||||
val drawMsg = DRAW_BUTTON drawVec
|
resizeWindow (model, mouseX, mouseY, width, height)
|
||||||
in
|
end
|
||||||
(model, drawMsg, mouseX, mouseY)
|
|
||||||
end
|
|
||||||
| MOUSE_LEFT_RELEASE =>
|
|
||||||
let
|
|
||||||
val (drawVec, _, _) = getClickPos
|
|
||||||
(#clickPoints model, mouseX, mouseY, 1.0, 0.0, 0.0)
|
|
||||||
val drawVec = getTriangleStageVector (model, drawVec)
|
|
||||||
val drawMsg = DRAW_BUTTON drawVec
|
|
||||||
in
|
|
||||||
(model, drawMsg, mouseX, mouseY)
|
|
||||||
end
|
|
||||||
| MOUSE_LEFT_CLICK =>
|
|
||||||
let
|
|
||||||
val (buttonVec, hpos, vpos) = getClickPos
|
|
||||||
(#clickPoints model, mouseX, mouseY, 0.0, 0.0, 1.0)
|
|
||||||
in
|
|
||||||
if Vector.length buttonVec > 0 then
|
|
||||||
(case #triangleStage model of
|
|
||||||
NO_TRIANGLE =>
|
|
||||||
let
|
|
||||||
val drawVec = getTriangleStageVector (model, buttonVec)
|
|
||||||
val drawMsg = DRAW_BUTTON drawVec
|
|
||||||
|
|
||||||
val newTriangleStage = FIRST {x1 = hpos, y1 = vpos}
|
|
||||||
val model =
|
|
||||||
AppType.withTriangleStage (model, newTriangleStage)
|
|
||||||
in
|
|
||||||
(model, drawMsg, mouseX, mouseY)
|
|
||||||
end
|
|
||||||
| FIRST {x1, y1} =>
|
|
||||||
let
|
|
||||||
val drawVec =
|
|
||||||
getFirstTriangleStageVector (x1, y1, buttonVec)
|
|
||||||
val drawMsg = DRAW_BUTTON drawVec
|
|
||||||
|
|
||||||
val newTriangleStage = SECOND
|
|
||||||
{x1 = x1, y1 = y1, x2 = hpos, y2 = vpos}
|
|
||||||
val model =
|
|
||||||
AppType.withTriangleStage (model, newTriangleStage)
|
|
||||||
in
|
|
||||||
(model, drawMsg, mouseX, mouseY)
|
|
||||||
end
|
|
||||||
| SECOND {x1, y1, x2, y2} =>
|
|
||||||
let
|
|
||||||
val model = AppType.addTriangleAndResetStage
|
|
||||||
(model, x1, y1, x2, y2, hpos, vpos)
|
|
||||||
|
|
||||||
val drawVec = getTrianglesVector model
|
|
||||||
val drawMsg = DRAW_TRIANGLES_AND_RESET_BUTTONS drawVec
|
|
||||||
in
|
|
||||||
(model, drawMsg, mouseX, mouseY)
|
|
||||||
end)
|
|
||||||
else
|
|
||||||
(model, NO_DRAW, mouseX, mouseY)
|
|
||||||
end
|
|
||||||
| RESIZE_WINDOW {width, height} =>
|
|
||||||
let
|
|
||||||
val _ = print "resized window \n"
|
|
||||||
in
|
|
||||||
(model, NO_DRAW, mouseX, mouseY)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -94,18 +94,21 @@ struct
|
|||||||
end
|
end
|
||||||
|
|
||||||
fun drawButton (buttonDrawObject: draw_object, buttonDrawLength) =
|
fun drawButton (buttonDrawObject: draw_object, buttonDrawLength) =
|
||||||
let
|
if buttonDrawLength > 0 then
|
||||||
val {vertexBuffer, program, ...} = buttonDrawObject
|
let
|
||||||
val _ = Gles3.bindBuffer vertexBuffer
|
val {vertexBuffer, program, ...} = buttonDrawObject
|
||||||
val _ = Gles3.vertexAttribPointer (0, 2, 5, 0)
|
val _ = Gles3.bindBuffer vertexBuffer
|
||||||
val _ = Gles3.enableVertexAttribArray 0
|
val _ = Gles3.vertexAttribPointer (0, 2, 5, 0)
|
||||||
val _ = Gles3.vertexAttribPointer (1, 3, 5, 8)
|
val _ = Gles3.enableVertexAttribArray 0
|
||||||
val _ = Gles3.enableVertexAttribArray 1
|
val _ = Gles3.vertexAttribPointer (1, 3, 5, 8)
|
||||||
val _ = Gles3.useProgram program
|
val _ = Gles3.enableVertexAttribArray 1
|
||||||
val _ = Gles3.drawArrays (Gles3.TRIANGLES (), 0, buttonDrawLength)
|
val _ = Gles3.useProgram program
|
||||||
in
|
val _ = Gles3.drawArrays (Gles3.TRIANGLES (), 0, buttonDrawLength)
|
||||||
|
in
|
||||||
|
()
|
||||||
|
end
|
||||||
|
else
|
||||||
()
|
()
|
||||||
end
|
|
||||||
|
|
||||||
fun initTriangles () =
|
fun initTriangles () =
|
||||||
let
|
let
|
||||||
@@ -114,12 +117,7 @@ struct
|
|||||||
val {vertexBuffer, program, ...} = triangleDrawObject
|
val {vertexBuffer, program, ...} = triangleDrawObject
|
||||||
|
|
||||||
val _ = Gles3.bindBuffer vertexBuffer
|
val _ = Gles3.bindBuffer vertexBuffer
|
||||||
val _ =
|
val _ = Gles3.bufferData (#[], 0, Gles3.STATIC_DRAW ())
|
||||||
Gles3.bufferData
|
|
||||||
( #[]
|
|
||||||
, 0
|
|
||||||
, Gles3.STATIC_DRAW ()
|
|
||||||
)
|
|
||||||
val _ = Gles3.vertexAttribPointer (0, 2, 2, 0)
|
val _ = Gles3.vertexAttribPointer (0, 2, 2, 0)
|
||||||
val _ = Gles3.enableVertexAttribArray 0
|
val _ = Gles3.enableVertexAttribArray 0
|
||||||
in
|
in
|
||||||
@@ -136,15 +134,17 @@ struct
|
|||||||
end
|
end
|
||||||
|
|
||||||
fun drawTriangles (triangleDrawObject: draw_object, triangleDrawLength) =
|
fun drawTriangles (triangleDrawObject: draw_object, triangleDrawLength) =
|
||||||
let
|
if triangleDrawLength > 0 then
|
||||||
val {vertexBuffer, program, ...} = triangleDrawObject
|
let
|
||||||
val _ = Gles3.bindBuffer vertexBuffer
|
val {vertexBuffer, program, ...} = triangleDrawObject
|
||||||
val _ = Gles3.vertexAttribPointer (0, 2, 2, 0)
|
val _ = Gles3.bindBuffer vertexBuffer
|
||||||
val _ = Gles3.enableVertexAttribArray 0
|
val _ = Gles3.vertexAttribPointer (0, 2, 2, 0)
|
||||||
val _ = Gles3.useProgram program
|
val _ = Gles3.enableVertexAttribArray 0
|
||||||
val _ = Gles3.drawArrays
|
val _ = Gles3.useProgram program
|
||||||
(Gles3.TRIANGLES (), 0, triangleDrawLength)
|
val _ = Gles3.drawArrays (Gles3.TRIANGLES (), 0, triangleDrawLength)
|
||||||
in
|
in
|
||||||
|
()
|
||||||
|
end
|
||||||
|
else
|
||||||
()
|
()
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user