diff options
Diffstat (limited to 'src/user/raleigh')
-rw-r--r-- | src/user/raleigh/runtime.cpp | 21 | ||||
-rw-r--r-- | src/user/raleigh/util.cpp | 6 | ||||
-rw-r--r-- | src/user/raleigh/w/label.cpp | 27 | ||||
-rw-r--r-- | src/user/raleigh/w/padding.cpp | 31 | ||||
-rw-r--r-- | src/user/raleigh/window.cpp | 35 |
5 files changed, 120 insertions, 0 deletions
diff --git a/src/user/raleigh/runtime.cpp b/src/user/raleigh/runtime.cpp new file mode 100644 index 0000000..1152575 --- /dev/null +++ b/src/user/raleigh/runtime.cpp @@ -0,0 +1,21 @@ +#include <raleigh/runtime.h> +#include <raleigh/window.h> +#include <pland/pcrt.h> + +namespace raleigh { + dllist<window &> open_windows; + + __attribute__ ((noreturn)) + void start_runtime() { + while (1) { + if (!open_windows.first) + __pcrt_quit(); + for (dllist<window &>::node *w = open_windows.first; w; w = w->next) + if (w->d.try_actions() == window::DELETE) + if (!(w = open_windows.remove_in_place(w))) + break; + _wait_for_action(); + _yield_task(); + } + } +}
\ No newline at end of file diff --git a/src/user/raleigh/util.cpp b/src/user/raleigh/util.cpp new file mode 100644 index 0000000..958897b --- /dev/null +++ b/src/user/raleigh/util.cpp @@ -0,0 +1,6 @@ +#include <raleigh/util.h> + +coord::coord(uint32_t x, uint32_t y) + : x(x), y(y) {} +coord::coord() + : x(0), y(0) {}
\ No newline at end of file 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 diff --git a/src/user/raleigh/window.cpp b/src/user/raleigh/window.cpp new file mode 100644 index 0000000..4373b06 --- /dev/null +++ b/src/user/raleigh/window.cpp @@ -0,0 +1,35 @@ +#include <raleigh/runtime.h> +#include <raleigh/window.h> +#include <knob/heap.h> + +namespace raleigh { + window::window(widget &root) + : size(root.size), root(root) { + root.w = this; + root.window_offset = coord(0, 0); + root.notify_window_change(); + + pixbuf = (_pixel_t *)get_block(size.x * size.y * sizeof(_pixel_t)); + + root.paint(pixbuf, size.x); + handle = _new_window(size.x, size.y, pixbuf); + + open_windows.add_front(*this); + } + + window::try_actions_return_t window::try_actions() { + struct window_action wa; + window::try_actions_return_t got = NONE; + while (1) { + _get_win_action(handle, &wa); + if (!wa.action_type) + return got; + if ((wa.action_type == wa.KEY_DOWN) && + (wa.as_key.modifiers & wa.as_key.ALTS) && + (wa.as_key.key_id == wa.as_key.KEY_F4)) + return DELETE; + got = GOOD; + //TODO + } + } +}
\ No newline at end of file |