From e6c3a80b01ffb52079783cddd9be6d392d0f7039 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Mon, 29 Jul 2024 19:59:52 -0400 Subject: redesign compositor protocol, start widget library --- libraries/pake/source/widgets/fixed-text.cpp | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 libraries/pake/source/widgets/fixed-text.cpp (limited to 'libraries/pake/source/widgets/fixed-text.cpp') diff --git a/libraries/pake/source/widgets/fixed-text.cpp b/libraries/pake/source/widgets/fixed-text.cpp new file mode 100644 index 0000000..9ae55dc --- /dev/null +++ b/libraries/pake/source/widgets/fixed-text.cpp @@ -0,0 +1,41 @@ +#include + +static void draw_if_true( + daguerre::hilbert_color &out, const bool &in, + const daguerre::hilbert_color ¶m) { + if (in) out = param; +} + +namespace pake::widgets { + + fixed_text::fixed_text( + std::string &&text, + const daguerre::fixed_font *font, + daguerre::hilbert_color bg, + daguerre::hilbert_color fg) + : font(font), bg(bg), fg(fg), text(std::move(text)) {} + + void fixed_text::render( + dirtiable_image &onto, int x_off, int y_off, bool force) { + + if (force) { + onto.image.fill( bg, x_off, y_off, width, height); + onto.dirty.fill(true, x_off, y_off, width, height); + //TODO: have options for alignment + //TODO: check overflow + onto.image.render_text( + *font, fg, x_off, y_off, + text.data(), draw_if_true); + onto.dirty.fill( + true, x_off, y_off, + font->glyph_width * text.size(), + font->glyph_height); + } + + } + + void fixed_text::notify_size(int width, int height) { + this->width = width; this->height = height; + } + +} -- cgit v1.2.3