summaryrefslogtreecommitdiff
path: root/src/user/raleigh/w
diff options
context:
space:
mode:
authorBenji Dial <benji6283@gmail.com>2021-03-04 19:11:42 -0500
committerBenji Dial <benji6283@gmail.com>2021-03-04 19:11:42 -0500
commit406af09ade55553e2b064506c3ba3c89bd965d73 (patch)
treedd6da93bc329d6b1097aa1afcde2af19491dfc8e /src/user/raleigh/w
parent86af7f631080bc4b45846bd7f382c4cedcbec2b4 (diff)
downloadportland-os-406af09ade55553e2b064506c3ba3c89bd965d73.tar.gz
start of a c++ widget toolkit, c++ runtime
Diffstat (limited to 'src/user/raleigh/w')
-rw-r--r--src/user/raleigh/w/label.cpp27
-rw-r--r--src/user/raleigh/w/padding.cpp31
2 files changed, 58 insertions, 0 deletions
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 <raleigh/w/label.h>
+#include <libfont/fonts.h>
+#include <knob/block.h>
+
+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
diff --git a/src/user/raleigh/w/padding.cpp b/src/user/raleigh/w/padding.cpp
new file mode 100644
index 0000000..6833c5d
--- /dev/null
+++ b/src/user/raleigh/w/padding.cpp
@@ -0,0 +1,31 @@
+#include <raleigh/w/padding.h>
+
+namespace raleigh {
+ padding::padding(uint32_t pad_by, _pixel_t color, widget &inner)
+ : pad_by(pad_by), color(color), inner(inner) {
+ size = coord(inner.size.x + pad_by * 2, inner.size.y + pad_by * 2);
+ }
+
+ void padding::notify_window_change() {
+ inner.w = w;
+ inner.window_offset = coord(window_offset.x + pad_by, window_offset.y + pad_by);
+ inner.notify_window_change();
+ }
+
+ void padding::paint(_pixel_t *pixbuf, uint32_t pitch) {
+ for (uint32_t y = window_offset.y; y < window_offset.y + pad_by; ++y)
+ for (uint32_t x = window_offset.x; x < window_offset.x + size.x; ++x)
+ pixbuf[y * pitch + x] = color;
+ for (uint32_t y = window_offset.y + size.y - pad_by; 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] = color;
+ for (uint32_t y = window_offset.y + pad_by; y < window_offset.y + size.y - pad_by; ++y) {
+ for (uint32_t x = window_offset.x; x < window_offset.x + pad_by; ++x)
+ pixbuf[y * pitch + x] = color;
+ for (uint32_t x = window_offset.x + size.x - pad_by; x < window_offset.x + size.x; ++x)
+ pixbuf[y * pitch + x] = color;
+ }
+
+ inner.paint(pixbuf, pitch);
+ }
+} \ No newline at end of file