very basic saving (hardcoded file name, which is fine fow now)
This commit is contained in:
@@ -9,6 +9,7 @@ struct
|
|||||||
open AppType
|
open AppType
|
||||||
|
|
||||||
open DrawMessage
|
open DrawMessage
|
||||||
|
open FileMessage
|
||||||
open InputMessage
|
open InputMessage
|
||||||
open UpdateMessage
|
open UpdateMessage
|
||||||
|
|
||||||
@@ -200,6 +201,14 @@ struct
|
|||||||
(model, DRAW drawMsg)
|
(model, DRAW drawMsg)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fun getSaveTrianglesMsg model =
|
||||||
|
let
|
||||||
|
val {triangles, ...} = model
|
||||||
|
val fileMsg = SAVE_TRIANGLES triangles
|
||||||
|
in
|
||||||
|
(model, FILE fileMsg)
|
||||||
|
end
|
||||||
|
|
||||||
fun update (model: app_type, inputMsg) =
|
fun update (model: app_type, inputMsg) =
|
||||||
case inputMsg of
|
case inputMsg of
|
||||||
MOUSE_MOVE {x = mouseX, y = mouseY} =>
|
MOUSE_MOVE {x = mouseX, y = mouseY} =>
|
||||||
@@ -212,4 +221,5 @@ struct
|
|||||||
| UNDO_ACTION => undoAction model
|
| UNDO_ACTION => undoAction model
|
||||||
| REDO_ACTION => redoAction model
|
| REDO_ACTION => redoAction model
|
||||||
| KEY_G => toggleGraph model
|
| KEY_G => toggleGraph model
|
||||||
|
| KEY_CTRL_S => getSaveTrianglesMsg model
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,14 +5,50 @@ end
|
|||||||
|
|
||||||
structure FileThread :> FILE_THREAD =
|
structure FileThread :> FILE_THREAD =
|
||||||
struct
|
struct
|
||||||
|
open AppType
|
||||||
open FileMessage
|
open FileMessage
|
||||||
|
|
||||||
|
val filename = "a.dsc"
|
||||||
|
|
||||||
|
fun helpSaveTriangles (triangles, io) =
|
||||||
|
case triangles of
|
||||||
|
{x1, y1, x2, y2, x3, y3} :: tl =>
|
||||||
|
let
|
||||||
|
val triString = String.concat
|
||||||
|
[ "x1:"
|
||||||
|
, Real32.toString x1
|
||||||
|
, " y1:"
|
||||||
|
, Real32.toString y1
|
||||||
|
|
||||||
|
, " x2:"
|
||||||
|
, Real32.toString x2
|
||||||
|
, " y2:"
|
||||||
|
, Real32.toString y2
|
||||||
|
|
||||||
|
, " x3:"
|
||||||
|
, Real32.toString x3
|
||||||
|
, " y3:"
|
||||||
|
, Real32.toString y3
|
||||||
|
, "\n"
|
||||||
|
]
|
||||||
|
|
||||||
|
val _ = TextIO.output (io, triString)
|
||||||
|
in
|
||||||
|
helpSaveTriangles (tl, io)
|
||||||
|
end
|
||||||
|
| [] => ()
|
||||||
|
|
||||||
|
fun saveTriangles triangles =
|
||||||
|
let val io = TextIO.openOut filename
|
||||||
|
in helpSaveTriangles (triangles, io)
|
||||||
|
end
|
||||||
|
|
||||||
fun run fileMailbox =
|
fun run fileMailbox =
|
||||||
let
|
let
|
||||||
val _ =
|
val _ =
|
||||||
case Mailbox.recv fileMailbox of
|
case Mailbox.recv fileMailbox of
|
||||||
SAVE_TRIANGLES triangles => ()
|
SAVE_TRIANGLES triangles => saveTriangles triangles
|
||||||
| LOAD_TRIANGLES triangles => ()
|
| LOAD_TRIANGLES => ()
|
||||||
| EXPORT_TRIANGLES triangles => ()
|
| EXPORT_TRIANGLES triangles => ()
|
||||||
in
|
in
|
||||||
run fileMailbox
|
run fileMailbox
|
||||||
|
|||||||
@@ -32,15 +32,20 @@ struct
|
|||||||
(* no action recognised *)
|
(* no action recognised *)
|
||||||
()
|
()
|
||||||
else if
|
else if
|
||||||
|
(* ctrl-y *)
|
||||||
key = Input.KEY_Y () andalso action <> Input.RELEASE ()
|
key = Input.KEY_Y () andalso action <> Input.RELEASE ()
|
||||||
andalso mods = 0x0002
|
andalso mods = 0x0002
|
||||||
then
|
then
|
||||||
(* ctrl-y *)
|
|
||||||
Mailbox.send (mailbox, REDO_ACTION)
|
Mailbox.send (mailbox, REDO_ACTION)
|
||||||
else if
|
else if
|
||||||
key = Input.KEY_G () andalso action <> Input.RELEASE () andalso mods = 0x0
|
key = Input.KEY_G () andalso action <> Input.RELEASE () andalso mods = 0x0
|
||||||
then
|
then
|
||||||
Mailbox.send (mailbox, KEY_G)
|
Mailbox.send (mailbox, KEY_G)
|
||||||
|
else if
|
||||||
|
(* ctrl-s *)
|
||||||
|
key = Input.KEY_S () andalso action = Input.PRESS () andalso mods = 0x002
|
||||||
|
then
|
||||||
|
Mailbox.send (mailbox, KEY_CTRL_S)
|
||||||
else
|
else
|
||||||
()
|
()
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ sig
|
|||||||
| UNDO_ACTION
|
| UNDO_ACTION
|
||||||
| REDO_ACTION
|
| REDO_ACTION
|
||||||
| KEY_G
|
| KEY_G
|
||||||
|
| KEY_CTRL_S
|
||||||
end
|
end
|
||||||
|
|
||||||
structure InputMessage :> INPUT_MESSAGE =
|
structure InputMessage :> INPUT_MESSAGE =
|
||||||
@@ -20,4 +21,5 @@ struct
|
|||||||
| UNDO_ACTION
|
| UNDO_ACTION
|
||||||
| REDO_ACTION
|
| REDO_ACTION
|
||||||
| KEY_G
|
| KEY_G
|
||||||
|
| KEY_CTRL_S
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user