diff --git a/dotscape b/dotscape index 4d478fc..74d1b9b 100755 Binary files a/dotscape and b/dotscape differ diff --git a/dotscape.mlb b/dotscape.mlb index 6a4aca4..a21c328 100644 --- a/dotscape.mlb +++ b/dotscape.mlb @@ -10,6 +10,7 @@ in functional-core/app/click-points.sml functional-core/app/graph-lines.sml functional-core/app/triangles.sml + fonts/cozette-ascii.mlb end functional-core/app/triangle-stage.sml diff --git a/functional-core/app/app-type.sml b/functional-core/app/app-type.sml index c19618f..22c692c 100644 --- a/functional-core/app/app-type.sml +++ b/functional-core/app/app-type.sml @@ -2,7 +2,7 @@ signature APP_TYPE = sig datatype app_mode = NORMAL_MODE | BROWSE_MODE - datatype file_browser_item = FILE of string | FOLDER of string + datatype file_browser_item = IS_FILE of string | IS_FOLDER of string datatype triangle_stage = NO_TRIANGLE @@ -44,7 +44,7 @@ structure AppType :> APP_TYPE = struct datatype app_mode = NORMAL_MODE | BROWSE_MODE - datatype file_browser_item = FILE of string | FOLDER of string + datatype file_browser_item = IS_FILE of string | IS_FOLDER of string type triangle = { x1: Real32.real diff --git a/functional-core/app/app-update.sml b/functional-core/app/app-update.sml index 707b6e8..7a17ac6 100644 --- a/functional-core/app/app-update.sml +++ b/functional-core/app/app-update.sml @@ -386,13 +386,59 @@ struct (model, fileMsg) end - fun handleFileBrowserAndPath (model, fileBrowser, path) = + fun handleFileBrowserAndPathInNormalMode (model, fileBrowser, path) = let val model = AppWith.fileBrowserAndPath (model, fileBrowser, path) - (* todo: update and recreate vector indicating text to redraw, - * if not in normal mode *) in (model, []) end + fun stringToVec (pos, str, acc, startX, startY, windowWidth, windowHeight) = + if pos = String.size str then + acc + else + let + val chr = String.sub (str, pos) + val chrFun = Vector.sub (CozetteAscii.asciiTable, Char.ord chr) + val chrVec = chrFun + (startX, startY, 25.0, 25.0, windowWidth, windowHeight, 0.0, 0.0, 0.0) + val acc = chrVec :: acc + in + stringToVec + (pos + 1, str, acc, startX + 13, startY, windowWidth, windowHeight) + end + + fun buildFileBrowserText + (pos, fileBrowser, acc, startY, windowWidth, windowHeight) = + if pos = Vector.length fileBrowser then + Vector.concat acc + else + let + val item = Vector.sub (fileBrowser, pos) + val itemText = + case item of + IS_FILE str => str + | IS_FOLDER str => str + val acc = stringToVec + (0, itemText, acc, 10, startY, windowWidth, windowHeight) + in + buildFileBrowserText + (pos + 1, fileBrowser, acc, startY + 23, windowWidth, windowHeight) + end + + fun handleFileBrowserAndPath (model, fileBrowser, path) = + let + val model = AppWith.fileBrowserAndPath (model, fileBrowser, path) + + (* create vector indicating text to redraw *) + val {windowWidth, windowHeight, ...} = model + val ww = Real32.fromInt windowWidth + val wh = Real32.fromInt windowHeight + val textVec = buildFileBrowserText (0, fileBrowser, [], 10, ww, wh) + + val drawMsg = DRAW_MODAL_TEXT textVec + in + (model, [DRAW drawMsg]) + end + fun updateNormalMode (model: app_type, inputMsg) = case inputMsg of MOUSE_MOVE {x = mouseX, y = mouseY} => diff --git a/imperative-shell/draw-thread.sml b/imperative-shell/draw-thread.sml index 351c7b2..e6947bd 100644 --- a/imperative-shell/draw-thread.sml +++ b/imperative-shell/draw-thread.sml @@ -26,8 +26,9 @@ struct val _ = AppDraw.drawTriangles (triangleDrawObject, triangleDrawLength) val _ = AppDraw.drawDot (dotDrawObject, dotDrawLength) - val _ = AppDraw.drawModalText (modalTextDrawObject, modalTextDrawLength) - + val _ = + AppDraw.drawModalText (modalTextDrawObject, modalTextDrawLength) + val _ = Glfw.swapBuffers window val _ = Glfw.pollEvents () in @@ -167,6 +168,24 @@ struct , modalTextDrawObject , modalTextDrawLength ) + end + | DRAW_MODAL_TEXT vec => + let + val _ = AppDraw.uploadModalText (modalTextDrawObject, vec) + val modalTextDrawLength = Vector.length vec div 5 + in + run + ( drawMailbox + , window + , graphDrawObject + , drawGraphLength + , dotDrawObject + , dotDrawLength + , triangleDrawObject + , triangleDrawLength + , modalTextDrawObject + , modalTextDrawLength + ) end) else Glfw.terminate () diff --git a/imperative-shell/file-thread.sml b/imperative-shell/file-thread.sml index 7dfe7d0..a5e4428 100644 --- a/imperative-shell/file-thread.sml +++ b/imperative-shell/file-thread.sml @@ -172,11 +172,11 @@ struct case OS.FileSys.readDir dir of SOME path => if OS.FileSys.isDir path then - getDirList (dir, AppType.FOLDER path :: acc) + getDirList (dir, AppType.IS_FOLDER path :: acc) else if OS.FileSys.isLink path then getDirList (dir, acc) else - getDirList (dir, AppType.FILE path :: acc) + getDirList (dir, AppType.IS_FILE path :: acc) | NONE => let val acc = List.rev acc in Vector.fromList acc end fun loadFiles (path, inputMailbox) = @@ -185,8 +185,9 @@ struct val dir = OS.FileSys.openDir path val dirList = getDirList (dir, []) val _ = OS.FileSys.closeDir dir + val inputMsg = FILE_BROWSER_AND_PATH {fileBrowser = dirList, path = path} in - () + Mailbox.send (inputMailbox, inputMsg) end fun run (fileMailbox, inputMailbox) = diff --git a/message-types/draw-msg.sml b/message-types/draw-msg.sml index a7e9b96..40a9961 100644 --- a/message-types/draw-msg.sml +++ b/message-types/draw-msg.sml @@ -12,6 +12,7 @@ sig , dots: Real32.real vector } | CLEAR_DOTS + | DRAW_MODAL_TEXT of Real32.real vector end structure DrawMessage :> DRAW_MESSAGE = @@ -28,4 +29,5 @@ struct , dots: Real32.real vector } | CLEAR_DOTS + | DRAW_MODAL_TEXT of Real32.real vector end