From fbfc078e9f44c1c1e95c9c484f1d5650bcf631b7 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Sat, 27 Jul 2024 16:57:39 -0400 Subject: lots and lots of userspace stuff --- applications/goldman/source/main.cpp | 79 +++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 2 deletions(-) (limited to 'applications/goldman/source') diff --git a/applications/goldman/source/main.cpp b/applications/goldman/source/main.cpp index 28ed00a..d74eaad 100644 --- a/applications/goldman/source/main.cpp +++ b/applications/goldman/source/main.cpp @@ -1,4 +1,79 @@ +#include +#include + +daguerre::hilbert_color trans_color; + +void convert_pointer( + daguerre::hilbert_color &dest, const daguerre::hilbert_color &src) { + if (src != trans_color) + dest = src; +} + int main(int, char **) { - while (1) - ; + + trans_color = euler::syscall::encode_color(0xff, 0x00, 0xff); + + daguerre::image framebuffer = + daguerre::get_hilbert_framebuffer(); + + int fw = framebuffer.width; + int fh = framebuffer.height; + + daguerre::image double_buffer(fw, fh); + + std::optional> + background_original = daguerre::try_load_ppm("/assets/background.ppm"); + + daguerre::image background; + + if (background_original.has_value()) + background = background_original->stretch(fw, fh); + else { + background = daguerre::image(fw, fh); + background.fill(euler::syscall::encode_color(0, 0, 0)); + } + + std::optional> + pointer_original = daguerre::try_load_ppm("/assets/pointer.ppm"); + + if (!pointer_original.has_value()) + //TODO + while (1) + ; + + daguerre::image + pointer = std::move(*pointer_original); + + int mouse_x = fw / 2; + int mouse_y = fh / 2; + + while (true) { + + double_buffer.copy_from(background, 0, 0); + double_buffer.convert_from(pointer, mouse_x, mouse_y, 0, 0, + std::min(pointer. width, double_buffer. width - mouse_x), + std::min(pointer.height, double_buffer.height - mouse_y), + &convert_pointer); + + framebuffer.copy_from(double_buffer, 0, 0); + + auto result = euler::syscall::get_input_packet(); + if (std::holds_alternative(result)) { + const auto &packet = std::get(result); + mouse_x += packet.x_changed; + mouse_y += packet.y_changed; + if (mouse_x < 0) + mouse_x = 0; + else if (mouse_x >= fw) + mouse_x = fw - 1; + if (mouse_y < 0) + mouse_y = 0; + else if (mouse_y >= fh) + mouse_y = fh - 1; + } + + } + + return 0; + } -- cgit v1.2.3