diff --git a/build_file.cpp b/build_file.cpp index 6bb804c..bb16fd4 100644 --- a/build_file.cpp +++ b/build_file.cpp @@ -88,7 +88,7 @@ int main() { cmd.add("../src/basic/win32.cpp"); cmd.add("/link"); - cmd.add("../src/external/raylib/lib/raylib.lib"); + cmd.add("../src/external/raylib/raylib.lib"); cmd.add("opengl32.lib kernel32.lib user32.lib gdi32.lib winmm.lib msvcrt.lib shell32.lib"); cmd.add("/NODEFAULTLIB:LIBCMT"); cmd.add("/incremental:no"); @@ -110,8 +110,8 @@ int main() { cmd.add("../src/basic/win32.cpp"); cmd.add("/link"); - cmd.add("../src/external/raylib/lib/raylib.lib"); - cmd.add("opengl32.lib kernel32.lib user32.lib gdi32.lib winmm.lib msvcrt.lib shell32.lib"); + cmd.add("../src/external/raylib/raylib.lib"); + cmd.add("opengl32.lib kernel32.lib user32.lib gdi32.lib winmm.lib shell32.lib"); cmd.add("/NODEFAULTLIB:LIBCMT"); cmd.add("/incremental:no"); diff --git a/src/text_editor/main.cpp b/src/text_editor/main.cpp index 665224c..8b9ab54 100644 --- a/src/text_editor/main.cpp +++ b/src/text_editor/main.cpp @@ -126,6 +126,68 @@ void Dbg_Draw() { } } +bool EventRecording = false; +bool EventPlaying = false; +AutomationEventList EventList; + +void InitEventRecording() { + EventList = LoadAutomationEventList(0); + SetAutomationEventList(&EventList); + EventList = LoadAutomationEventList("automation.rae"); + EventPlaying = true; +} + +int ModifiedGetCharPressed() { + static int i; + int result = GetCharPressed(); + if (EventPlaying && (i % 2) == 0) { + result = 'a'; + } + i += 1; + + return result; +} + +void UpdateEventRecording() { + static unsigned int frameCounter; + static unsigned int playFrameCounter; + static unsigned int currentPlayFrame; + + if (IsKeyPressed(KEY_F5)) { + if (EventRecording) { + StopAutomationEventRecording(); + ExportAutomationEventList(EventList, "automation.rae"); + EventRecording = false; + } else { + SetAutomationEventBaseFrame(0); + StartAutomationEventRecording(); + EventRecording = true; + } + } + + if (EventPlaying) { + // NOTE: Multiple events could be executed in a single frame + while (playFrameCounter == EventList.events[currentPlayFrame].frame) { + TraceLog(LOG_INFO, "PLAYING: PlayFrameCount: %i | currentPlayFrame: %i | Event Frame: %i, param: %i", + playFrameCounter, currentPlayFrame, EventList.events[currentPlayFrame].frame, EventList.events[currentPlayFrame].params[0]); + + PlayAutomationEvent(EventList.events[currentPlayFrame]); + currentPlayFrame++; + + if (currentPlayFrame == EventList.count) { + EventPlaying = false; + currentPlayFrame = 0; + playFrameCounter = 0; + + TraceLog(LOG_INFO, "FINISH PLAYING!"); + break; + } + } + + playFrameCounter++; + } +} + int main() { InitScratch(); InitWindow(800, 600, "Hello"); @@ -135,10 +197,8 @@ int main() { InitArena(&PermArena); float font_size = 64; float font_spacing = 1; - Font font = LoadFontEx("C:/Windows/Fonts/times.ttf", (int)font_size, NULL, 250); + Font font = LoadFontEx("C:/Windows/Fonts/consola.ttf", (int)font_size, NULL, 250); - float title_bar_font_size = 15; - Font title_bar_font = LoadFontEx("C:/Windows/Fonts/times.ttf", (int)title_bar_font_size, NULL, 250); if (0) font = LoadFontEx("C:/Windows/Fonts/consola.ttf", (int)font_size, NULL, 250); Array windows = {}; @@ -152,14 +212,14 @@ int main() { InitBuffer(&window.buffer); if (1) { - Array edits = {FrameArena}; - AddEdit(&edits, GetEnd(window.buffer), Format(FrameArena, "line number: 1")); - ApplyEdits(&window.buffer, edits); - // for (int i = 0; i < 5; i += 1) { - // Array edits = {FrameArena}; - // AddEdit(&edits, GetEnd(window.buffer), Format(FrameArena, "line number: %d\n", i)); - // ApplyEdits(&window.buffer, edits); - // } + // Array edits = {FrameArena}; + // AddEdit(&edits, GetEnd(window.buffer), Format(FrameArena, "line number: 1")); + // ApplyEdits(&window.buffer, edits); + for (int i = 0; i < 5; i += 1) { + Array edits = {FrameArena}; + AddEdit(&edits, GetEnd(window.buffer), Format(FrameArena, "line number: %d\n", i)); + ApplyEdits(&window.buffer, edits); + } } window.cursors.add({}); @@ -168,6 +228,7 @@ int main() { windows.add(window); } + InitEventRecording(); // @todo: multiple ui elements, add focus // @todo: immediate mode interface for all this Vec2 camera_offset_world_to_render_units = {}; @@ -176,6 +237,9 @@ int main() { Assert(it.cursors.len); it.main_cursor_begin_frame = it.cursors[0]; } + + UpdateEventRecording(); + { Window *focused_window = &windows[0]; @@ -247,10 +311,14 @@ int main() { } if (IsKeyPressed(KEY_DOWN) || IsKeyPressedRepeat(KEY_DOWN)) { if (IsKeyDown(KEY_LEFT_SHIFT) && IsKeyDown(KEY_LEFT_ALT)) { // Default in VSCode seems to be Ctrl + Alt + down + Array cursors_to_add = {FrameArena}; For(focused_window->cursors) { int64_t front = GetFront(it); front = MoveDown(focused_window->buffer, front); - focused_window->cursors.add({front, front}); + cursors_to_add.add({front, front}); + } + For(cursors_to_add) { + focused_window->cursors.add(it); } } else if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyDown(KEY_LEFT_ALT)) { // Default in VSCode seems to be Shift + Alt + down BeforeEdit(focused_window); @@ -281,11 +349,13 @@ int main() { if (IsKeyPressed(KEY_UP) || IsKeyPressedRepeat(KEY_UP)) { if (IsKeyDown(KEY_LEFT_SHIFT) && IsKeyDown(KEY_LEFT_ALT)) { // Default in VSCode seems to be Ctrl + Alt + up + Array cursors_to_add = {FrameArena}; For(focused_window->cursors) { int64_t front = GetFront(it); front = MoveUp(focused_window->buffer, front); - focused_window->cursors.add({front, front}); + cursors_to_add.add({front, front}); } + For(cursors_to_add) focused_window->cursors.add(it); } else if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyDown(KEY_LEFT_ALT)) { // Default in VSCode seems to be Shift + Alt + up BeforeEdit(focused_window); Array edits = {FrameArena}; @@ -423,7 +493,7 @@ int main() { // Handle user input for (;;) { - int c = GetCharPressed(); + int c = ModifiedGetCharPressed(); if (!c) break; String string = "?";