consume events in RGFW loop. (Next: react to input events.)
This commit is contained in:
@@ -28,6 +28,10 @@ void swapBuffers(RGFW_window* window) {
|
|||||||
RGFW_window_swapBuffers_OpenGL(window);
|
RGFW_window_swapBuffers_OpenGL(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void writeClipboard(char* string, int stringSize) {
|
||||||
|
RGFW_writeClipboard(string, stringSize);
|
||||||
|
}
|
||||||
|
|
||||||
// OpenGL constants used below
|
// OpenGL constants used below
|
||||||
unsigned int VERTEX_SHADER = GL_VERTEX_SHADER;
|
unsigned int VERTEX_SHADER = GL_VERTEX_SHADER;
|
||||||
unsigned int FRAGMENT_SHADER = GL_FRAGMENT_SHADER;
|
unsigned int FRAGMENT_SHADER = GL_FRAGMENT_SHADER;
|
||||||
|
|||||||
@@ -11,4 +11,6 @@ struct
|
|||||||
_import "shouldCloseWindow" public : window -> bool;
|
_import "shouldCloseWindow" public : window -> bool;
|
||||||
val swapBuffers =
|
val swapBuffers =
|
||||||
_import "swapBuffers" public : window -> unit;
|
_import "swapBuffers" public : window -> unit;
|
||||||
|
val writeClipboard =
|
||||||
|
_import "writeClipboard" public : string * int -> unit;
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
structure GlfwLoop =
|
structure GlfwLoop =
|
||||||
struct
|
struct
|
||||||
open DrawMsg
|
|
||||||
|
|
||||||
fun yank (window, str) =
|
fun yank (window, str) =
|
||||||
let
|
let
|
||||||
(* print when text is yanked
|
(* print when text is yanked
|
||||||
@@ -16,6 +14,8 @@ struct
|
|||||||
|
|
||||||
fun consumeEvent (drawState, window, msg) =
|
fun consumeEvent (drawState, window, msg) =
|
||||||
let
|
let
|
||||||
|
open DrawMsg
|
||||||
|
|
||||||
val {textVertexBuffer, textProgram, textDrawLength = _, ...} = drawState
|
val {textVertexBuffer, textProgram, textDrawLength = _, ...} = drawState
|
||||||
in
|
in
|
||||||
case msg of
|
case msg of
|
||||||
|
|||||||
@@ -1,6 +1,34 @@
|
|||||||
structure RgfwLoop =
|
structure RgfwLoop =
|
||||||
struct
|
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
|
if Rgfw.shouldCloseWindow window then
|
||||||
Rgfw.closeWindow window
|
Rgfw.closeWindow window
|
||||||
else
|
else
|
||||||
@@ -10,9 +38,10 @@ struct
|
|||||||
|
|
||||||
val app = Updater.update app
|
val app = Updater.update app
|
||||||
|
|
||||||
|
val () = GlDraw.draw drawState
|
||||||
val () = Rgfw.swapBuffers window
|
val () = Rgfw.swapBuffers window
|
||||||
in
|
in
|
||||||
loop (window, app)
|
loop (window, app, drawState)
|
||||||
end
|
end
|
||||||
|
|
||||||
local
|
local
|
||||||
@@ -46,9 +75,11 @@ struct
|
|||||||
val io = TextIO.openIn "temp.txt"
|
val io = TextIO.openIn "temp.txt"
|
||||||
val lineGap = ioToLineGap (io, LineGap.empty)
|
val lineGap = ioToLineGap (io, LineGap.empty)
|
||||||
val _ = TextIO.closeIn io
|
val _ = TextIO.closeIn io
|
||||||
|
|
||||||
val app = AppType.init (lineGap, 1920, 1080, Time.now ())
|
val app = AppType.init (lineGap, 1920, 1080, Time.now ())
|
||||||
|
val drawState = GlDraw.create ()
|
||||||
in
|
in
|
||||||
loop (window, app)
|
loop (window, app, drawState)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
3
todo.md
3
todo.md
@@ -1,7 +1,6 @@
|
|||||||
# To-do list
|
# To-do list
|
||||||
- Bind functions from RGFW (alternative back-end/window library) and have an option to use it
|
- Bind functions from RGFW (alternative back-end/window library) and have an option to use it
|
||||||
- Add key callbacks, resize callbacks, etc.
|
- Add callbacks so we can react to events. (Start by adding key callbacks.)
|
||||||
- Consume msgs stores in app
|
|
||||||
- Bind gamepad functions from GLFW
|
- Bind gamepad functions from GLFW
|
||||||
- Modify deletion functions to use `PersistentVector.delete`
|
- Modify deletion functions to use `PersistentVector.delete`
|
||||||
- Implement 'yj' motion and add tests for it
|
- Implement 'yj' motion and add tests for it
|
||||||
|
|||||||
Reference in New Issue
Block a user