progress towards being able to load files dynamically
This commit is contained in:
@@ -35,6 +35,8 @@ struct
|
|||||||
, showGraph = true
|
, showGraph = true
|
||||||
, arrowX = 0
|
, arrowX = 0
|
||||||
, arrowY = 0
|
, arrowY = 0
|
||||||
|
, openFilePath = ""
|
||||||
|
, fileBrowser = Vector.fromList []
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
signature APP_TYPE =
|
signature APP_TYPE =
|
||||||
sig
|
sig
|
||||||
datatype app_mode = NORMAL_MODE | SAVE_MODE
|
datatype app_mode = NORMAL_MODE | BROWSE_MODE
|
||||||
|
|
||||||
|
datatype file_browser_item = FILE of string | FOLDER of string
|
||||||
|
|
||||||
datatype triangle_stage =
|
datatype triangle_stage =
|
||||||
NO_TRIANGLE
|
NO_TRIANGLE
|
||||||
@@ -33,12 +35,16 @@ sig
|
|||||||
, mouseY: Real32.real
|
, mouseY: Real32.real
|
||||||
, arrowX: int
|
, arrowX: int
|
||||||
, arrowY: int
|
, arrowY: int
|
||||||
|
, openFilePath: string
|
||||||
|
, fileBrowser: file_browser_item vector
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
structure AppType :> APP_TYPE =
|
structure AppType :> APP_TYPE =
|
||||||
struct
|
struct
|
||||||
datatype app_mode = NORMAL_MODE | SAVE_MODE
|
datatype app_mode = NORMAL_MODE | BROWSE_MODE
|
||||||
|
|
||||||
|
datatype file_browser_item = FILE of string | FOLDER of string
|
||||||
|
|
||||||
type triangle =
|
type triangle =
|
||||||
{ x1: Real32.real
|
{ x1: Real32.real
|
||||||
@@ -79,5 +85,7 @@ struct
|
|||||||
, mouseY: Real32.real
|
, mouseY: Real32.real
|
||||||
, arrowX: int
|
, arrowX: int
|
||||||
, arrowY: int
|
, arrowY: int
|
||||||
|
, openFilePath: string
|
||||||
|
, fileBrowser: file_browser_item vector
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -355,7 +355,7 @@ struct
|
|||||||
|
|
||||||
fun trianglesLoadError model = (model, NO_MAILBOX)
|
fun trianglesLoadError model = (model, NO_MAILBOX)
|
||||||
|
|
||||||
fun update (model: app_type, inputMsg) =
|
fun updateNormalMode (model: app_type, inputMsg) =
|
||||||
case inputMsg of
|
case inputMsg of
|
||||||
MOUSE_MOVE {x = mouseX, y = mouseY} =>
|
MOUSE_MOVE {x = mouseX, y = mouseY} =>
|
||||||
let val model = AppWith.mousePosition (model, mouseX, mouseY)
|
let val model = AppWith.mousePosition (model, mouseX, mouseY)
|
||||||
@@ -378,4 +378,7 @@ struct
|
|||||||
| KEY_SPACE => enterOrSpaceCoordinates model
|
| KEY_SPACE => enterOrSpaceCoordinates model
|
||||||
| USE_TRIANGLES triangles => useTriangles (model, triangles)
|
| USE_TRIANGLES triangles => useTriangles (model, triangles)
|
||||||
| TRIANGLES_LOAD_ERROR => trianglesLoadError model
|
| TRIANGLES_LOAD_ERROR => trianglesLoadError model
|
||||||
|
|
||||||
|
fun update (model: app_type, inputMsg) =
|
||||||
|
case #mode model of NORMAL_MODE => updateNormalMode (model, inputMsg)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -78,6 +78,8 @@ struct
|
|||||||
, mouseY
|
, mouseY
|
||||||
, arrowX = _
|
, arrowX = _
|
||||||
, arrowY = _
|
, arrowY = _
|
||||||
|
, openFilePath
|
||||||
|
, fileBrowser
|
||||||
} = app
|
} = app
|
||||||
|
|
||||||
val newUndo = newUndoHd :: undo
|
val newUndo = newUndoHd :: undo
|
||||||
@@ -97,6 +99,8 @@ struct
|
|||||||
, mouseY = mouseY
|
, mouseY = mouseY
|
||||||
, arrowX = arrowX
|
, arrowX = arrowX
|
||||||
, arrowY = arrowY
|
, arrowY = arrowY
|
||||||
|
, openFilePath = openFilePath
|
||||||
|
, fileBrowser = fileBrowser
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -120,6 +124,8 @@ struct
|
|||||||
, mouseY
|
, mouseY
|
||||||
, arrowX = _
|
, arrowX = _
|
||||||
, arrowY = _
|
, arrowY = _
|
||||||
|
, openFilePath
|
||||||
|
, fileBrowser
|
||||||
} = app
|
} = app
|
||||||
|
|
||||||
val newTriangle = {x1 = x1, y1 = y1, x2 = x2, y2 = y2, x3 = x3, y3 = y3}
|
val newTriangle = {x1 = x1, y1 = y1, x2 = x2, y2 = y2, x3 = x3, y3 = y3}
|
||||||
@@ -141,6 +147,8 @@ struct
|
|||||||
, mouseY = mouseY
|
, mouseY = mouseY
|
||||||
, arrowX = arrowX
|
, arrowX = arrowX
|
||||||
, arrowY = arrowY
|
, arrowY = arrowY
|
||||||
|
, openFilePath = openFilePath
|
||||||
|
, fileBrowser = fileBrowser
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -162,6 +170,8 @@ struct
|
|||||||
, mouseY
|
, mouseY
|
||||||
, arrowX = _
|
, arrowX = _
|
||||||
, arrowY
|
, arrowY
|
||||||
|
, openFilePath
|
||||||
|
, fileBrowser
|
||||||
} = app
|
} = app
|
||||||
in
|
in
|
||||||
{ mode = mode
|
{ mode = mode
|
||||||
@@ -179,6 +189,8 @@ struct
|
|||||||
, mouseY = mouseY
|
, mouseY = mouseY
|
||||||
, arrowX = arrowX
|
, arrowX = arrowX
|
||||||
, arrowY = arrowY
|
, arrowY = arrowY
|
||||||
|
, openFilePath = openFilePath
|
||||||
|
, fileBrowser = fileBrowser
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -200,6 +212,8 @@ struct
|
|||||||
, mouseY
|
, mouseY
|
||||||
, arrowX
|
, arrowX
|
||||||
, arrowY = _
|
, arrowY = _
|
||||||
|
, openFilePath
|
||||||
|
, fileBrowser
|
||||||
} = app
|
} = app
|
||||||
in
|
in
|
||||||
{ mode = mode
|
{ mode = mode
|
||||||
@@ -217,6 +231,8 @@ struct
|
|||||||
, mouseY = mouseY
|
, mouseY = mouseY
|
||||||
, arrowX = arrowX
|
, arrowX = arrowX
|
||||||
, arrowY = arrowY
|
, arrowY = arrowY
|
||||||
|
, openFilePath = openFilePath
|
||||||
|
, fileBrowser = fileBrowser
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -240,6 +256,8 @@ struct
|
|||||||
, mouseY
|
, mouseY
|
||||||
, arrowX
|
, arrowX
|
||||||
, arrowY
|
, arrowY
|
||||||
|
, openFilePath
|
||||||
|
, fileBrowser
|
||||||
} = app
|
} = app
|
||||||
|
|
||||||
val xClickPoints = ClickPoints.generate (wStart, wFinish, numClickPoints)
|
val xClickPoints = ClickPoints.generate (wStart, wFinish, numClickPoints)
|
||||||
@@ -260,6 +278,8 @@ struct
|
|||||||
, mouseY = mouseY
|
, mouseY = mouseY
|
||||||
, arrowX = arrowX
|
, arrowX = arrowX
|
||||||
, arrowY = arrowY
|
, arrowY = arrowY
|
||||||
|
, openFilePath = openFilePath
|
||||||
|
, fileBrowser = fileBrowser
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -304,6 +324,8 @@ struct
|
|||||||
, showGraph
|
, showGraph
|
||||||
, arrowX
|
, arrowX
|
||||||
, arrowY
|
, arrowY
|
||||||
|
, openFilePath
|
||||||
|
, fileBrowser
|
||||||
} = app
|
} = app
|
||||||
in
|
in
|
||||||
{ mode = mode
|
{ mode = mode
|
||||||
@@ -321,6 +343,8 @@ struct
|
|||||||
, showGraph = showGraph
|
, showGraph = showGraph
|
||||||
, arrowX = arrowX
|
, arrowX = arrowX
|
||||||
, arrowY = arrowY
|
, arrowY = arrowY
|
||||||
|
, openFilePath = openFilePath
|
||||||
|
, fileBrowser = fileBrowser
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -343,6 +367,8 @@ struct
|
|||||||
, mouseY
|
, mouseY
|
||||||
, arrowX
|
, arrowX
|
||||||
, arrowY
|
, arrowY
|
||||||
|
, openFilePath
|
||||||
|
, fileBrowser
|
||||||
} = app
|
} = app
|
||||||
|
|
||||||
val newUndo =
|
val newUndo =
|
||||||
@@ -367,6 +393,8 @@ struct
|
|||||||
, mouseY = mouseY
|
, mouseY = mouseY
|
||||||
, arrowX = arrowX
|
, arrowX = arrowX
|
||||||
, arrowY = arrowY
|
, arrowY = arrowY
|
||||||
|
, openFilePath = openFilePath
|
||||||
|
, fileBrowser = fileBrowser
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -389,6 +417,8 @@ struct
|
|||||||
, mouseY
|
, mouseY
|
||||||
, arrowX
|
, arrowX
|
||||||
, arrowY
|
, arrowY
|
||||||
|
, openFilePath
|
||||||
|
, fileBrowser
|
||||||
} = app
|
} = app
|
||||||
|
|
||||||
val newUndo = newUndoHd :: undo
|
val newUndo = newUndoHd :: undo
|
||||||
@@ -412,6 +442,8 @@ struct
|
|||||||
, mouseY = mouseY
|
, mouseY = mouseY
|
||||||
, arrowX = arrowX
|
, arrowX = arrowX
|
||||||
, arrowY = arrowY
|
, arrowY = arrowY
|
||||||
|
, openFilePath = openFilePath
|
||||||
|
, fileBrowser = fileBrowser
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -433,6 +465,8 @@ struct
|
|||||||
, arrowX
|
, arrowX
|
||||||
, arrowY
|
, arrowY
|
||||||
, showGraph = _
|
, showGraph = _
|
||||||
|
, openFilePath
|
||||||
|
, fileBrowser
|
||||||
} = app
|
} = app
|
||||||
in
|
in
|
||||||
{ mode = mode
|
{ mode = mode
|
||||||
@@ -450,6 +484,8 @@ struct
|
|||||||
, mouseY = mouseY
|
, mouseY = mouseY
|
||||||
, arrowX = arrowX
|
, arrowX = arrowX
|
||||||
, arrowY = arrowY
|
, arrowY = arrowY
|
||||||
|
, openFilePath = openFilePath
|
||||||
|
, fileBrowser = fileBrowser
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -471,6 +507,8 @@ struct
|
|||||||
, arrowY
|
, arrowY
|
||||||
, triangles = _
|
, triangles = _
|
||||||
, triangleStage = _
|
, triangleStage = _
|
||||||
|
, openFilePath
|
||||||
|
, fileBrowser
|
||||||
} = app
|
} = app
|
||||||
|
|
||||||
val triangleStage = NO_TRIANGLE
|
val triangleStage = NO_TRIANGLE
|
||||||
@@ -490,6 +528,8 @@ struct
|
|||||||
, mouseY = mouseY
|
, mouseY = mouseY
|
||||||
, arrowX = arrowX
|
, arrowX = arrowX
|
||||||
, arrowY = arrowY
|
, arrowY = arrowY
|
||||||
|
, openFilePath = openFilePath
|
||||||
|
, fileBrowser = fileBrowser
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -23,23 +23,21 @@ struct
|
|||||||
* that is recognised as an integer, like "1" instead of "1.0".
|
* that is recognised as an integer, like "1" instead of "1.0".
|
||||||
* If that happens, we just add a ".0" to the end
|
* If that happens, we just add a ".0" to the end
|
||||||
* so it's recognised as a real. *)
|
* so it's recognised as a real. *)
|
||||||
if String.isSubstring "." num
|
if String.isSubstring "." num then num
|
||||||
then num
|
|
||||||
else num ^ ".0"
|
else num ^ ".0"
|
||||||
in
|
in
|
||||||
" (((startX * (1.0 - " ^ num ^ ")) + (endX * " ^ num ^ ")) / windowWidth) - 1.0"
|
" (((startX * (1.0 - " ^ num ^ ")) + (endX * " ^ num
|
||||||
|
^ ")) / windowWidth) - 1.0"
|
||||||
end
|
end
|
||||||
|
|
||||||
fun ndcToLerpY num =
|
fun ndcToLerpY num =
|
||||||
let
|
let
|
||||||
val num = (num + 1.0) / 2.0
|
val num = (num + 1.0) / 2.0
|
||||||
val num = Real32.toString num
|
val num = Real32.toString num
|
||||||
val num =
|
val num = if String.isSubstring "." num then num else num ^ ".0"
|
||||||
if String.isSubstring "." num
|
|
||||||
then num
|
|
||||||
else num ^ ".0"
|
|
||||||
in
|
in
|
||||||
" (((startY * (1.0 - " ^ num ^ ")) + (endY * " ^ num ^ ")) / windowHeight) - 1.0"
|
" (((startY * (1.0 - " ^ num ^ ")) + (endY * " ^ num
|
||||||
|
^ ")) / windowHeight) - 1.0"
|
||||||
end
|
end
|
||||||
|
|
||||||
fun helpExportTriangles (io, triangles) =
|
fun helpExportTriangles (io, triangles) =
|
||||||
@@ -55,10 +53,20 @@ struct
|
|||||||
val y3 = ndcToLerpY y3
|
val y3 = ndcToLerpY y3
|
||||||
|
|
||||||
val line = String.concat
|
val line = String.concat
|
||||||
[ x1, ",\n", y1, ", r, g, b,\n"
|
[ x1
|
||||||
, x2, ",\n", y2, ", r, g, b,\n"
|
, ",\n"
|
||||||
, x3, ",\n", y3
|
, y1
|
||||||
, case tl of [] => ", r, g, b\n" | _ => ", r, g, b,\n"
|
, ", r, g, b,\n"
|
||||||
|
, x2
|
||||||
|
, ",\n"
|
||||||
|
, y2
|
||||||
|
, ", r, g, b,\n"
|
||||||
|
, x3
|
||||||
|
, ",\n"
|
||||||
|
, y3
|
||||||
|
, case tl of
|
||||||
|
[] => ", r, g, b\n"
|
||||||
|
| _ => ", r, g, b,\n"
|
||||||
]
|
]
|
||||||
|
|
||||||
val _ = TextIO.output (io, line)
|
val _ = TextIO.output (io, line)
|
||||||
@@ -128,14 +136,20 @@ struct
|
|||||||
{x1, y1, x2, y2, x3, y3} :: tl =>
|
{x1, y1, x2, y2, x3, y3} :: tl =>
|
||||||
let
|
let
|
||||||
val triString = String.concat
|
val triString = String.concat
|
||||||
[ "x ", Real32.toString x1
|
[ "x "
|
||||||
, " y ", Real32.toString y1
|
, Real32.toString x1
|
||||||
|
, " y "
|
||||||
|
, Real32.toString y1
|
||||||
|
|
||||||
, " x ", Real32.toString x2
|
, " x "
|
||||||
, " y ", Real32.toString y2
|
, Real32.toString x2
|
||||||
|
, " y "
|
||||||
|
, Real32.toString y2
|
||||||
|
|
||||||
, " x ", Real32.toString x3
|
, " x "
|
||||||
, " y ", Real32.toString y3
|
, Real32.toString x3
|
||||||
|
, " y "
|
||||||
|
, Real32.toString y3
|
||||||
, "\n"
|
, "\n"
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -154,6 +168,30 @@ struct
|
|||||||
()
|
()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fun getDirList (dir, acc) =
|
||||||
|
case OS.FileSys.readDir dir of
|
||||||
|
SOME path =>
|
||||||
|
let
|
||||||
|
val _ = print (path ^ "\n")
|
||||||
|
val acc =
|
||||||
|
if OS.FileSys.isDir path then (AppType.FOLDER path) :: acc
|
||||||
|
else if OS.FileSys.isLink path then acc
|
||||||
|
else (AppType.FILE path) :: acc
|
||||||
|
in
|
||||||
|
getDirList (dir, acc)
|
||||||
|
end
|
||||||
|
| NONE => let val acc = List.rev acc in Vector.fromList acc end
|
||||||
|
|
||||||
|
fun loadFiles (path, inputMailbox) =
|
||||||
|
let
|
||||||
|
val path = if String.size path = 0 then OS.FileSys.getDir () else path
|
||||||
|
val dir = OS.FileSys.openDir path
|
||||||
|
val dirList = getDirList (dir, [])
|
||||||
|
val _ = OS.FileSys.closeDir dir
|
||||||
|
in
|
||||||
|
()
|
||||||
|
end
|
||||||
|
|
||||||
fun run (fileMailbox, inputMailbox) =
|
fun run (fileMailbox, inputMailbox) =
|
||||||
let
|
let
|
||||||
val _ =
|
val _ =
|
||||||
@@ -161,6 +199,7 @@ struct
|
|||||||
SAVE_TRIANGLES triangles => saveTriangles triangles
|
SAVE_TRIANGLES triangles => saveTriangles triangles
|
||||||
| LOAD_TRIANGLES => loadTriangles inputMailbox
|
| LOAD_TRIANGLES => loadTriangles inputMailbox
|
||||||
| EXPORT_TRIANGLES triangles => exportTriangles triangles
|
| EXPORT_TRIANGLES triangles => exportTriangles triangles
|
||||||
|
| LOAD_FILES path => loadFiles (path, inputMailbox)
|
||||||
in
|
in
|
||||||
run (fileMailbox, inputMailbox)
|
run (fileMailbox, inputMailbox)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ sig
|
|||||||
SAVE_TRIANGLES of AppType.triangle list
|
SAVE_TRIANGLES of AppType.triangle list
|
||||||
| LOAD_TRIANGLES
|
| LOAD_TRIANGLES
|
||||||
| EXPORT_TRIANGLES of AppType.triangle list
|
| EXPORT_TRIANGLES of AppType.triangle list
|
||||||
|
| LOAD_FILES of string
|
||||||
end
|
end
|
||||||
|
|
||||||
structure FileMessage :> FILE_MESSAGE =
|
structure FileMessage :> FILE_MESSAGE =
|
||||||
@@ -12,4 +13,5 @@ struct
|
|||||||
SAVE_TRIANGLES of AppType.triangle list
|
SAVE_TRIANGLES of AppType.triangle list
|
||||||
| LOAD_TRIANGLES
|
| LOAD_TRIANGLES
|
||||||
| EXPORT_TRIANGLES of AppType.triangle list
|
| EXPORT_TRIANGLES of AppType.triangle list
|
||||||
|
| LOAD_FILES of string
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user