From 1061996056666c624130a43e7a4671d10c99f555 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Tue, 30 Sep 2025 15:30:49 -0400 Subject: libwidget: Add initial window drawing + cleanups Introduce the initial logic to draw windows as well as tidying up the interface a bit. - All callbacks must now have a state arguments - The libwidget state is now kept internally - Add helper to get pixel index - Add initial window drawing Signed-off-by: Ian Moffett --- src/lib/libwidget/include/libwidget/core.h | 10 +++++----- src/lib/libwidget/include/libwidget/window.h | 7 +++++++ 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'src/lib/libwidget/include') diff --git a/src/lib/libwidget/include/libwidget/core.h b/src/lib/libwidget/include/libwidget/core.h index 85b33d4..074edc4 100644 --- a/src/lib/libwidget/include/libwidget/core.h +++ b/src/lib/libwidget/include/libwidget/core.h @@ -30,12 +30,14 @@ #ifndef LIBWIDGET_CORE_H #define LIBWIDGET_CORE_H 1 +#include #include /* Forward declarations */ struct widget; struct libwidget_state { + struct fb_info fbinfo; uint32_t *fbdev; }; @@ -82,8 +84,8 @@ struct blueprint { * @draw: Draw the widget */ struct widget_ops { - int(*init)(struct widget *wp); - int(*draw)(struct widget *wp); + int(*init)(struct libwidget_state *lws, struct widget *wp); + int(*draw)(struct libwidget_state *lws, struct widget *wp); }; /* @@ -106,12 +108,10 @@ struct widget { /* * Initialize the library * - * @lwsp: Libwidget state pointer - * * Returns zero on success, otherwise a less than zero * value on failure. */ -int libwidget_init(struct libwidget_state *lwsp); +int libwidget_init(void); /* * Initialize a widget diff --git a/src/lib/libwidget/include/libwidget/window.h b/src/lib/libwidget/include/libwidget/window.h index 2dc58b1..8823eba 100644 --- a/src/lib/libwidget/include/libwidget/window.h +++ b/src/lib/libwidget/include/libwidget/window.h @@ -30,6 +30,7 @@ #ifndef LIBWIDGET_WINDOW_H #define LIBWIDGET_WINDOW_H +#include #include /* @@ -41,6 +42,12 @@ struct window { struct widget *wp; }; +__always_inline static inline size_t +get_pix_index(struct fb_info *info, uint32_t x, uint32_t y) +{ + return x + y * (info->pitch / 4); +} + extern struct widget_ops g_winops; #endif /* !LIBWIDGET_WINDOW_H */ -- cgit v1.2.3