summaryrefslogtreecommitdiff
path: root/src/user/raleigh/w/label.cpp
diff options
context:
space:
mode:
authorBenji Dial <benji6283@gmail.com>2021-06-21 17:47:13 -0400
committerBenji Dial <benji6283@gmail.com>2021-06-21 17:47:13 -0400
commitf57e2eabe0a10c9732c83532e01654a499fb8dcf (patch)
treecbf91a23fcdd65e0ea7ed55b0940ca7042d59bef /src/user/raleigh/w/label.cpp
parent83835306d57461205a7bcfef9f4c3e06bc504006 (diff)
downloadportland-os-f57e2eabe0a10c9732c83532e01654a499fb8dcf.tar.gz
many, many changes; settings is broken
Diffstat (limited to 'src/user/raleigh/w/label.cpp')
-rw-r--r--src/user/raleigh/w/label.cpp49
1 files changed, 28 insertions, 21 deletions
diff --git a/src/user/raleigh/w/label.cpp b/src/user/raleigh/w/label.cpp
index 21df2a2..e8be703 100644
--- a/src/user/raleigh/w/label.cpp
+++ b/src/user/raleigh/w/label.cpp
@@ -3,26 +3,36 @@
#include <knob/block.h>
namespace raleigh {
- label::label(const char *value, const char *font, bool bg_transparent, _pixel_t fg, _pixel_t bg)
- : fi(get_font(font)), bg_transparent(bg_transparent), fg(fg), bg(bg) {
+ coord label::determine_size() {
+ uint32_t longest = 0;
- v_size = strlen(value) + 1;
- this->value = new char[v_size];
- blockcpy(this->value, value, v_size);
- size = coord(fi->space_width * (v_size - 2) + fi->char_width, fi->char_height);
+ for (uint32_t i = 0; i < tf.get_n_lines(); ++i)
+ if (strlen(tf.get_nth_line(i)) > longest)
+ longest = strlen(tf.get_nth_line(i));
- closest_opaque = 0;
+ const int32_t width = fi->space_width * (longest - 1) + fi->char_width;
+ const int32_t height = fi->space_height * (tf.get_n_lines() - 1) + fi->char_height;
+ return coord(width < 0 ? 0 : width, height < 0 ? 0 : height);
+ }
+
+ label::label(const char *value, const char *font, uint32_t cols,
+ bool bg_transparent, _pixel_t fg, _pixel_t bg)
+ : fi(get_font(font)), cols(cols), bg_transparent(bg_transparent),
+ fg(fg), bg(bg), tf(strdup(value), cols) {
+
+ size = determine_size();
+ closest_opaque = bg_transparent ? 0 : this;
+ }
+
+ label::~label() {
+ free_block(tf.s);
}
void label::change_value(const char *new_value) {
- delete[] value;
- const uint32_t ns = strlen(new_value) + 1;
- if (ns != v_size) {
- v_size = ns;
- value = new char[ns];
- set_size(coord(fi->space_width * (ns - 2) + fi->char_width, fi->char_height));
- }
- blockcpy(value, new_value, ns);
+ free_block(tf.s);
+ tf.s = strdup(new_value);
+ tf.flow_text();
+ set_size(determine_size());
w->notify_needs_paint(*this);
}
@@ -31,14 +41,11 @@ namespace raleigh {
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_no_bg(fi, *c, ptr, pitch, fg);
- ptr += fi->space_width;
- }
+ tf.draw_text(pixbuf + window_offset.y * pitch + window_offset.x, pitch, fi, fg);
}
void label::notify_has_opaque_parent(widget *parent) {
- closest_opaque = parent;
+ if (bg_transparent)
+ closest_opaque = parent;
}
} \ No newline at end of file