diff --git a/ffi/rgfw-export.c b/ffi/rgfw-export.c index 35ee9b1..8dae52f 100644 --- a/ffi/rgfw-export.c +++ b/ffi/rgfw-export.c @@ -28,6 +28,10 @@ void swapBuffers(RGFW_window* window) { RGFW_window_swapBuffers_OpenGL(window); } +void writeClipboard(char* string, int stringSize) { + RGFW_writeClipboard(string, stringSize); +} + // OpenGL constants used below unsigned int VERTEX_SHADER = GL_VERTEX_SHADER; unsigned int FRAGMENT_SHADER = GL_FRAGMENT_SHADER; diff --git a/ffi/rgfw-import.sml b/ffi/rgfw-import.sml index a60275a..1fa9f06 100644 --- a/ffi/rgfw-import.sml +++ b/ffi/rgfw-import.sml @@ -11,4 +11,6 @@ struct _import "shouldCloseWindow" public : window -> bool; val swapBuffers = _import "swapBuffers" public : window -> unit; + val writeClipboard = + _import "writeClipboard" public : string * int -> unit; end diff --git a/shell/glfw-loop.sml b/shell/glfw-loop.sml index 9f92b23..d6ffa13 100644 --- a/shell/glfw-loop.sml +++ b/shell/glfw-loop.sml @@ -1,7 +1,5 @@ structure GlfwLoop = struct - open DrawMsg - fun yank (window, str) = let (* print when text is yanked @@ -16,6 +14,8 @@ struct fun consumeEvent (drawState, window, msg) = let + open DrawMsg + val {textVertexBuffer, textProgram, textDrawLength = _, ...} = drawState in case msg of diff --git a/shell/rgfw-loop.sml b/shell/rgfw-loop.sml index 10cb2d5..28234fb 100644 --- a/shell/rgfw-loop.sml +++ b/shell/rgfw-loop.sml @@ -1,6 +1,34 @@ structure RgfwLoop = struct - fun loop (window, app) = + fun yank string = + Rgfw.writeClipboard (string, String.size string) + + fun consumeEvent (drawState, window, msg) = + let + open DrawMsg + + val {textVertexBuffer, textProgram, textDrawLength = _, ...} = drawState + in + case msg of + DRAW_TEXT textVec => GlDraw.uploadText (drawState, textVec) + | YANK str => (yank str; drawState) + end + + fun consumeEventsLoop (pos, msgVec, drawState, window) = + if pos = Vector.length msgVec then + drawState + else + let + val msg = Vector.sub (msgVec, pos) + val drawState = consumeEvent (drawState, window, msg) + in + consumeEventsLoop (pos + 1, msgVec, drawState, window) + end + + fun consumeEvents (drawState, window) = + consumeEventsLoop (0, DrawMailbox.getMessagesAndClear (), drawState, window) + + fun loop (window, app, drawState) = if Rgfw.shouldCloseWindow window then Rgfw.closeWindow window else @@ -10,9 +38,10 @@ struct val app = Updater.update app + val () = GlDraw.draw drawState val () = Rgfw.swapBuffers window in - loop (window, app) + loop (window, app, drawState) end local @@ -46,9 +75,11 @@ struct val io = TextIO.openIn "temp.txt" val lineGap = ioToLineGap (io, LineGap.empty) val _ = TextIO.closeIn io + val app = AppType.init (lineGap, 1920, 1080, Time.now ()) + val drawState = GlDraw.create () in - loop (window, app) + loop (window, app, drawState) end end diff --git a/shf-rgfw b/shf-rgfw index 2d99c29..14551bb 100755 Binary files a/shf-rgfw and b/shf-rgfw differ diff --git a/todo.md b/todo.md index 463d967..fa5fa81 100644 --- a/todo.md +++ b/todo.md @@ -1,7 +1,6 @@ # To-do list - Bind functions from RGFW (alternative back-end/window library) and have an option to use it - - Add key callbacks, resize callbacks, etc. - - Consume msgs stores in app + - Add callbacks so we can react to events. (Start by adding key callbacks.) - Bind gamepad functions from GLFW - Modify deletion functions to use `PersistentVector.delete` - Implement 'yj' motion and add tests for it