From a863b1774656c448ec5a88d58bb43602dc608a96 Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 31 Mar 2024 13:38:39 +0200 Subject: [PATCH] wind+libui: Ignore alpha bits in the window buffer --- libui/include/ui/Canvas.h | 8 ++++++++ libui/src/Canvas.cpp | 13 +++++++++++++ wind/Window.cpp | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/libui/include/ui/Canvas.h b/libui/include/ui/Canvas.h index fb410638..9ec1aa9f 100644 --- a/libui/include/ui/Canvas.h +++ b/libui/include/ui/Canvas.h @@ -69,5 +69,13 @@ namespace ui * @param stride The number of pixels to skip to go to the next line. */ void fill(u32* pixels, int stride); + + /** + * @brief Fill the canvas with pixels, without doing any extra processing. + * + * @param pixels The array of pixels (must be at least width*height). + * @param stride The number of pixels to skip to go to the next line. + */ + void copy(u32* pixels, int stride); }; }; diff --git a/libui/src/Canvas.cpp b/libui/src/Canvas.cpp index 002f1592..89514b9c 100644 --- a/libui/src/Canvas.cpp +++ b/libui/src/Canvas.cpp @@ -7,6 +7,7 @@ * */ +#include #include namespace ui @@ -59,4 +60,16 @@ namespace ui p += stride * sizeof(Color); } } + + void Canvas::copy(u32* pixels, int _stride) + { + u8* p = ptr; + for (int i = 0; i < height; i++) + { + u32* colorp = (u32*)p; + memcpy(colorp, pixels, width * sizeof(u32)); + pixels += _stride; + p += stride * sizeof(Color); + } + } } diff --git a/wind/Window.cpp b/wind/Window.cpp index ce3dd942..12463057 100644 --- a/wind/Window.cpp +++ b/wind/Window.cpp @@ -12,7 +12,7 @@ void Window::draw(ui::Canvas& screen) dirty = false; auto window = screen.subcanvas(surface); - window.fill(pixels, surface.width); + window.copy(pixels, surface.width); } void Window::focus()