From 406af09ade55553e2b064506c3ba3c89bd965d73 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Thu, 4 Mar 2021 19:11:42 -0500 Subject: start of a c++ widget toolkit, c++ runtime --- src/user/raleigh/w/label.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/user/raleigh/w/label.cpp (limited to 'src/user/raleigh/w/label.cpp') diff --git a/src/user/raleigh/w/label.cpp b/src/user/raleigh/w/label.cpp new file mode 100644 index 0000000..047126d --- /dev/null +++ b/src/user/raleigh/w/label.cpp @@ -0,0 +1,27 @@ +#include +#include +#include + +namespace raleigh { + label::label(const char *value, const char *font, _pixel_t bg, _pixel_t fg) + : value(value), fi(get_font(font)), bg(bg), fg(fg) { + size = coord( + fi->space_width * (strlen(value) - 1) + fi->char_width, + fi->char_height + ); + } + + void label::notify_window_change() {} + + void label::paint(_pixel_t *pixbuf, uint32_t pitch) { + for (uint32_t y = window_offset.y; y < window_offset.y + size.y; ++y) + for (uint32_t x = window_offset.x; x < window_offset.x + size.x; ++x) + pixbuf[y * pitch + x] = bg; + + _pixel_t *ptr = pixbuf + window_offset.y * pitch + window_offset.x; + for (const char *c = value; *c; ++c) { + put_char(fi, *c, ptr, pitch, bg, fg); + ptr += fi->space_width; + } + } +} \ No newline at end of file -- cgit v1.2.3