refactor to allow graph lines to be shown at start up

This commit is contained in:
2024-08-03 06:05:26 +01:00
parent ee2274ffbc
commit 0d1ea9444b
6 changed files with 27 additions and 14 deletions

BIN
dotscape

Binary file not shown.

View File

@@ -247,7 +247,22 @@ struct
else else
(* windowWidth < windowHeight *) (* windowWidth < windowHeight *)
let let
(* todo; fix based on windowWidth > windowHeight *) val difference = windowHeight - windowWidth
val offset = difference div 2
val halfWidth = Real32.fromInt (windowWidth div 2)
val halfHeight = Real32.fromInt (windowHeight div 2)
val start = offset - (windowHeight div 2)
val start = Real32.fromInt start / halfHeight
val finish = (windowHeight - offset) - (windowHeight div 2)
val finish = Real32.fromInt finish / halfHeight
val lines = helpGenGraphLinesHorizontal
(0, xClickPoints, [], halfWidth, ~1.0, 1.0)
val lines = helpGenGraphLinesVertical
(0, yClickPoints, lines, halfHeight, start, finish)
in in
Vector.fromList [] Vector.fromList []
end end

View File

@@ -41,11 +41,7 @@ struct
val _ = Gles3.bindBuffer vertexBuffer val _ = Gles3.bindBuffer vertexBuffer
val _ = val _ =
Gles3.bufferData Gles3.bufferData (#[], 0, Gles3.STATIC_DRAW ())
( Constants.graphLines
, Vector.length Constants.graphLines
, 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

View File

@@ -40,9 +40,4 @@ struct
\{\n\ \{\n\
\ FragColor = vec4(frag_col.x, frag_col.y, frag_col.z, 1.0f);\n\ \ FragColor = vec4(frag_col.x, frag_col.y, frag_col.z, 1.0f);\n\
\}" \}"
(* Todo: fix. Currently an empty vector which is not desired result,
* but changing vector dynamically (through resizing) works as desired. *)
val graphLines: Real32.real vector =
Vector.fromList []
end end

View File

@@ -14,7 +14,7 @@ struct
loop (inputMailbox, drawMailbox, mouseX, mouseY, model) loop (inputMailbox, drawMailbox, mouseX, mouseY, model)
end end
in in
fun update (inputMailbox, drawMailbox) = fun update (inputMailbox, drawMailbox, initial) =
loop loop
( inputMailbox ( inputMailbox
, drawMailbox , drawMailbox

View File

@@ -15,7 +15,13 @@ struct
val _ = Glfw.makeContextCurrent window val _ = Glfw.makeContextCurrent window
val _ = Gles3.loadGlad () val _ = Gles3.loadGlad ()
val initialModel = AppType.getInitial (Constants.windowWidth, Constants.windowHeight)
val graphLines = #graphLines initialModel
val graphDrawObject = AppDraw.initGraphLines () val graphDrawObject = AppDraw.initGraphLines ()
val _ =
AppDraw.uploadGraphLines (graphDrawObject, graphLines)
val buttonDrawObject = AppDraw.initButton () val buttonDrawObject = AppDraw.initButton ()
val triangleDrawObject = AppDraw.initTriangles () val triangleDrawObject = AppDraw.initTriangles ()
@@ -24,13 +30,14 @@ struct
val _ = CML.spawn (fn () => val _ = CML.spawn (fn () =>
InputCallbacks.registerCallbacks (window, inputMailbox)) InputCallbacks.registerCallbacks (window, inputMailbox))
val _ = CML.spawn (fn () => EventLoop.update (inputMailbox, drawMailbox)) val _ = CML.spawn
(fn () => EventLoop.update (inputMailbox, drawMailbox, initialModel))
val _ = CML.spawn (fn () => val _ = CML.spawn (fn () =>
EventLoop.draw EventLoop.draw
( drawMailbox ( drawMailbox
, window , window
, graphDrawObject , graphDrawObject
, Vector.length Constants.graphLines div 2 , Vector.length graphLines div 2
, buttonDrawObject , buttonDrawObject
, 0 , 0
, triangleDrawObject , triangleDrawObject