summaryrefslogtreecommitdiff
path: root/src/user/raleigh/w
diff options
context:
space:
mode:
Diffstat (limited to 'src/user/raleigh/w')
-rw-r--r--src/user/raleigh/w/button.cpp54
-rw-r--r--src/user/raleigh/w/label.cpp29
-rw-r--r--src/user/raleigh/w/padding.cpp30
-rw-r--r--src/user/raleigh/w/vbox.cpp45
4 files changed, 132 insertions, 26 deletions
diff --git a/src/user/raleigh/w/button.cpp b/src/user/raleigh/w/button.cpp
new file mode 100644
index 0000000..06d9c1d
--- /dev/null
+++ b/src/user/raleigh/w/button.cpp
@@ -0,0 +1,54 @@
+#include <raleigh/w/button.h>
+
+namespace raleigh {
+ button::button(widget &inner, void (*on_click)(button &),
+ _pixel_t border_color, _pixel_t bg_color, _pixel_t pressed_color)
+ : inner(inner), on_click(on_click), border_color(border_color),
+ bg_color(bg_color), pressed_color(pressed_color), is_pressed(false) {
+ size = coord(inner.size.x + 2, inner.size.y + 2);
+ closest_opaque = this;
+ inner.notify_has_opaque_parent(this);
+ }
+
+ void button::notify_window_change() {
+ inner.window_offset = coord(window_offset.x + 1, window_offset.y + 1);
+ inner.w = w;
+ inner.notify_window_change();
+ }
+
+ void button::paint(_pixel_t *pixbuf, uint32_t pitch) {
+ for (uint32_t y = window_offset.y + 1; y < window_offset.y + size.y - 1; ++y)
+ for (uint32_t x = window_offset.x + 1; x < window_offset.x + size.x - 1; ++x)
+ pixbuf[y * pitch + x] = is_pressed ? pressed_color : bg_color;
+ inner.paint(pixbuf, pitch);
+ for (uint32_t x = window_offset.x; x < window_offset.x + size.x; ++x) {
+ pixbuf[window_offset.y * pitch + x] = border_color;
+ pixbuf[(window_offset.y + size.y - 1) * pitch + x] = border_color;
+ }
+ for (uint32_t y = window_offset.y + 1; y < window_offset.y + size.y - 1; ++y) {
+ pixbuf[y * pitch + window_offset.x] = border_color;
+ pixbuf[y * pitch + window_offset.x + size.x - 1] = border_color;
+ }
+ }
+
+ bool button::try_handle_click(coord window_coords, enum mouse_packet::mouse_button click_type, bool up) {
+ if (click_type != mouse_packet::LEFT)
+ return false;
+ if (up) {
+ is_pressed = false;
+ inner.window_offset = coord(window_offset.x + 1, window_offset.y + 1);
+ inner.notify_window_change();
+ w->notify_needs_paint(*this);
+ on_click(*this);
+ }
+ else {
+ is_pressed = true;
+ inner.window_offset = coord(window_offset.x + 2, window_offset.y + 2);
+ inner.notify_window_change();
+ w->notify_needs_paint(*this);
+ }
+ return true;
+ }
+
+ void button::notify_has_opaque_parent(widget *parent) {}
+} \ No newline at end of file
diff --git a/src/user/raleigh/w/label.cpp b/src/user/raleigh/w/label.cpp
index 047126d..5b74175 100644
--- a/src/user/raleigh/w/label.cpp
+++ b/src/user/raleigh/w/label.cpp
@@ -3,25 +3,32 @@
#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
- );
+ label::label(const char *value, const char *font, bool bg_transparent, _pixel_t fg, _pixel_t bg)
+ : value(value), fi(get_font(font)), bg_transparent(bg_transparent), fg(fg), bg(bg) {
+ size = coord(fi->space_width * (strlen(value) - 1) + fi->char_width, fi->char_height);
+ closest_opaque = 0;
}
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;
-
+ if (!bg_transparent)
+ 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);
+ put_char_no_bg(fi, *c, ptr, pitch, fg);
ptr += fi->space_width;
}
}
+
+ __attribute__ ((const))
+ bool label::try_handle_click(coord window_coords, enum mouse_packet::mouse_button click_type, bool up) {
+ return false;
+ }
+
+ void label::notify_has_opaque_parent(widget *parent) {
+ closest_opaque = parent;
+ }
} \ No newline at end of file
diff --git a/src/user/raleigh/w/padding.cpp b/src/user/raleigh/w/padding.cpp
index 6833c5d..3dd027b 100644
--- a/src/user/raleigh/w/padding.cpp
+++ b/src/user/raleigh/w/padding.cpp
@@ -1,9 +1,10 @@
#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) {
+ padding::padding(widget &inner, uint32_t pad_by)
+ : inner(inner), pad_by(pad_by) {
size = coord(inner.size.x + pad_by * 2, inner.size.y + pad_by * 2);
+ closest_opaque = 0;
}
void padding::notify_window_change() {
@@ -13,19 +14,18 @@ namespace raleigh {
}
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);
}
+
+ bool padding::try_handle_click(coord window_coords, enum mouse_packet::mouse_button click_type, bool up) {
+ return (window_coords.x >= inner.window_offset.x) &&
+ (window_coords.y >= inner.window_offset.y) &&
+ (window_coords.x < inner.window_offset.x + inner.size.x) &&
+ (window_coords.y < inner.window_offset.y + inner.size.y) &&
+ inner.try_handle_click(window_coords, click_type, up);
+ }
+
+ void padding::notify_has_opaque_parent(widget *parent) {
+ closest_opaque = parent;
+ }
} \ No newline at end of file
diff --git a/src/user/raleigh/w/vbox.cpp b/src/user/raleigh/w/vbox.cpp
new file mode 100644
index 0000000..30b0902
--- /dev/null
+++ b/src/user/raleigh/w/vbox.cpp
@@ -0,0 +1,45 @@
+#include <raleigh/w/vbox.h>
+
+namespace raleigh {
+ vbox::vbox(dllist<widget &> widgets) : widgets(widgets) {
+ uint32_t w = 0, h = 0;
+ for (dllist<widget &>::node *n = widgets.first; n; n = n->next) {
+ h += n->d.size.y;
+ if (n->d.size.x > w)
+ w = n->d.size.x;
+ }
+ size = coord(w, h);
+ closest_opaque = 0;
+ }
+
+ void vbox::notify_window_change() {
+ uint32_t h = window_offset.y;
+ for (dllist<widget &>::node *n = widgets.first; n; n = n->next) {
+ n->d.w = w;
+ n->d.window_offset = coord(window_offset.x + size.x / 2 - n->d.size.x / 2, h);
+ n->d.notify_window_change();
+ h += n->d.size.y;
+ }
+ }
+
+ void vbox::paint(_pixel_t *pixbuf, uint32_t pitch) {
+ for (dllist<widget &>::node *n = widgets.first; n; n = n->next)
+ n->d.paint(pixbuf, pitch);
+ }
+
+ bool vbox::try_handle_click(coord window_coords, enum mouse_packet::mouse_button click_type, bool up) {
+ uint32_t h = window_offset.y;
+ dllist<widget &>::node *n = widgets.first;
+ while (h + n->d.size.y <= window_coords.y) {
+ h += n->d.size.y;
+ n = n->next;
+ }
+ return (window_coords.x >= n->d.window_offset.x) &&
+ (window_coords.x < n->d.window_offset.x + n->d.size.x) &&
+ n->d.try_handle_click(window_coords, click_type, up);
+ }
+
+ void vbox::notify_has_opaque_parent(widget *parent) {
+ closest_opaque = parent;
+ }
+} \ No newline at end of file