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
(* windowWidth < windowHeight *)
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
Vector.fromList []
end

View File

@@ -41,11 +41,7 @@ struct
val _ = Gles3.bindBuffer vertexBuffer
val _ =
Gles3.bufferData
( Constants.graphLines
, Vector.length Constants.graphLines
, Gles3.STATIC_DRAW ()
)
Gles3.bufferData (#[], 0, Gles3.STATIC_DRAW ())
val _ = Gles3.vertexAttribPointer (0, 2, 2, 0)
val _ = Gles3.enableVertexAttribArray 0
in

View File

@@ -40,9 +40,4 @@ struct
\{\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

View File

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

View File

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