begin drawing file browser text

This commit is contained in:
2024-09-27 10:06:21 +01:00
parent 6fa88769aa
commit be379e1fe0
7 changed files with 79 additions and 10 deletions

BIN
dotscape

Binary file not shown.

View File

@@ -10,6 +10,7 @@ in
functional-core/app/click-points.sml functional-core/app/click-points.sml
functional-core/app/graph-lines.sml functional-core/app/graph-lines.sml
functional-core/app/triangles.sml functional-core/app/triangles.sml
fonts/cozette-ascii.mlb
end end
functional-core/app/triangle-stage.sml functional-core/app/triangle-stage.sml

View File

@@ -2,7 +2,7 @@ signature APP_TYPE =
sig sig
datatype app_mode = NORMAL_MODE | BROWSE_MODE 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 = datatype triangle_stage =
NO_TRIANGLE NO_TRIANGLE
@@ -44,7 +44,7 @@ structure AppType :> APP_TYPE =
struct struct
datatype app_mode = NORMAL_MODE | BROWSE_MODE 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 = type triangle =
{ x1: Real32.real { x1: Real32.real

View File

@@ -386,13 +386,59 @@ struct
(model, fileMsg) (model, fileMsg)
end end
fun handleFileBrowserAndPath (model, fileBrowser, path) = fun handleFileBrowserAndPathInNormalMode (model, fileBrowser, path) =
let val model = AppWith.fileBrowserAndPath (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, []) in (model, [])
end 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) = fun updateNormalMode (model: app_type, inputMsg) =
case inputMsg of case inputMsg of
MOUSE_MOVE {x = mouseX, y = mouseY} => MOUSE_MOVE {x = mouseX, y = mouseY} =>

View File

@@ -26,8 +26,9 @@ struct
val _ = val _ =
AppDraw.drawTriangles (triangleDrawObject, triangleDrawLength) AppDraw.drawTriangles (triangleDrawObject, triangleDrawLength)
val _ = AppDraw.drawDot (dotDrawObject, dotDrawLength) val _ = AppDraw.drawDot (dotDrawObject, dotDrawLength)
val _ = AppDraw.drawModalText (modalTextDrawObject, modalTextDrawLength) val _ =
AppDraw.drawModalText (modalTextDrawObject, modalTextDrawLength)
val _ = Glfw.swapBuffers window val _ = Glfw.swapBuffers window
val _ = Glfw.pollEvents () val _ = Glfw.pollEvents ()
in in
@@ -167,6 +168,24 @@ struct
, modalTextDrawObject , modalTextDrawObject
, modalTextDrawLength , 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) end)
else else
Glfw.terminate () Glfw.terminate ()

View File

@@ -172,11 +172,11 @@ struct
case OS.FileSys.readDir dir of case OS.FileSys.readDir dir of
SOME path => SOME path =>
if OS.FileSys.isDir path then 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 else if OS.FileSys.isLink path then
getDirList (dir, acc) getDirList (dir, acc)
else 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 | NONE => let val acc = List.rev acc in Vector.fromList acc end
fun loadFiles (path, inputMailbox) = fun loadFiles (path, inputMailbox) =
@@ -185,8 +185,9 @@ struct
val dir = OS.FileSys.openDir path val dir = OS.FileSys.openDir path
val dirList = getDirList (dir, []) val dirList = getDirList (dir, [])
val _ = OS.FileSys.closeDir dir val _ = OS.FileSys.closeDir dir
val inputMsg = FILE_BROWSER_AND_PATH {fileBrowser = dirList, path = path}
in in
() Mailbox.send (inputMailbox, inputMsg)
end end
fun run (fileMailbox, inputMailbox) = fun run (fileMailbox, inputMailbox) =

View File

@@ -12,6 +12,7 @@ sig
, dots: Real32.real vector , dots: Real32.real vector
} }
| CLEAR_DOTS | CLEAR_DOTS
| DRAW_MODAL_TEXT of Real32.real vector
end end
structure DrawMessage :> DRAW_MESSAGE = structure DrawMessage :> DRAW_MESSAGE =
@@ -28,4 +29,5 @@ struct
, dots: Real32.real vector , dots: Real32.real vector
} }
| CLEAR_DOTS | CLEAR_DOTS
| DRAW_MODAL_TEXT of Real32.real vector
end end