summaryrefslogtreecommitdiff
path: root/src/user/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/user/include')
-rw-r--r--src/user/include/cxx/raleigh/d/dialog.h14
-rw-r--r--src/user/include/cxx/raleigh/s/text_flower.h40
-rw-r--r--src/user/include/cxx/raleigh/util.h4
-rw-r--r--src/user/include/cxx/raleigh/w/entry.h67
-rw-r--r--src/user/include/cxx/raleigh/w/label.h16
-rw-r--r--src/user/include/cxx/raleigh/widget.h2
-rw-r--r--src/user/include/cxx/raleigh/window.h2
-rw-r--r--src/user/include/cxx/structs/alist.h63
-rw-r--r--src/user/include/cxx/structs/duple.h1
-rw-r--r--src/user/include/cxx/structs/map.h7
-rw-r--r--src/user/include/knob/block.h1
-rw-r--r--src/user/include/knob/file.h4
-rw-r--r--src/user/include/knob/heap.h2
-rw-r--r--src/user/include/libterm/terminal.h8
-rw-r--r--src/user/include/pland/syscall.h16
15 files changed, 172 insertions, 75 deletions
diff --git a/src/user/include/cxx/raleigh/d/dialog.h b/src/user/include/cxx/raleigh/d/dialog.h
index f207033..1712b03 100644
--- a/src/user/include/cxx/raleigh/d/dialog.h
+++ b/src/user/include/cxx/raleigh/d/dialog.h
@@ -14,15 +14,21 @@ namespace raleigh {
YES,
NO,
CANCEL,
- RETRY
+ RETRY,
+ OKAY
};
- extern alist<duple<const char *, diag_result_t>> &yes_no_cancel;
- extern alist<duple<const char *, diag_result_t>> &yes_no_retry;
+
+ typedef alist<duple<const char *, diag_result_t>> button_list;
+ extern button_list &yes_no_cancel;
+ extern button_list &yes_no_retry;
+ extern button_list &okay_cancel;
+ extern button_list &okay;
+
class dialog : public window {
public:
//button names are copied
//alist isn't needed past constructor
- dialog(widget &top_part, alist<duple<const char *, diag_result_t>> buttons);
+ dialog(widget &top_part, button_list buttons);
//zero means not set yet
diag_result_t result;
diff --git a/src/user/include/cxx/raleigh/s/text_flower.h b/src/user/include/cxx/raleigh/s/text_flower.h
new file mode 100644
index 0000000..f5cfcca
--- /dev/null
+++ b/src/user/include/cxx/raleigh/s/text_flower.h
@@ -0,0 +1,40 @@
+#ifndef RALEIGH_S_TEXT_FLOWER_H
+#define RALEIGH_S_TEXT_FLOWER_H
+
+#include <libfont/fonts.h>
+#include <structs/alist.h>
+
+namespace raleigh {
+ class text_flower {
+ public:
+ //max_rows or cols 0 means no limit
+ //s is not copied
+ text_flower(const char *s, uint32_t cols=50, uint32_t max_rows=0);
+
+ uint32_t get_n_lines() __attribute__ ((pure));
+ //not a copy
+ char *get_nth_line(uint32_t n) __attribute__ ((pure));
+ uint32_t get_line_offset(uint32_t n) __attribute__ ((pure));
+
+ void draw_text(_pixel_t *start, uint32_t pitch, const struct font_info *fi, _pixel_t color);
+ void flow_text();
+
+ //call flow_text after any changes
+ const char *s;
+
+ private:
+ alist<char *> lines;
+ alist<uint32_t> offsets;
+
+ uint32_t max_rows;
+ uint32_t cols;
+
+ //for use inside flow_text
+ const char *on_char;
+ const char *line_start;
+ uint32_t row_len;
+ void push_line();
+ };
+}
+
+#endif \ No newline at end of file
diff --git a/src/user/include/cxx/raleigh/util.h b/src/user/include/cxx/raleigh/util.h
index 9142b69..c366e80 100644
--- a/src/user/include/cxx/raleigh/util.h
+++ b/src/user/include/cxx/raleigh/util.h
@@ -5,6 +5,9 @@
#define RGB(R, G, B) ((_pixel_t){.r = 0x##R, .g = 0x##G, .b = 0x##B})
+#define RALEIGH_FG RGB(00, 00, 00)
+#define RALEIGH_BG RGB(bf, bf, bf)
+
namespace raleigh {
struct coord {
uint32_t x;
@@ -14,6 +17,7 @@ namespace raleigh {
};
void show_error_and_quitf(const char *fmt, ...) __attribute__ ((noreturn));
+ void show_error_popup_and_quitf(const char *fmt, ...) __attribute__ ((noreturn));
}
#endif \ No newline at end of file
diff --git a/src/user/include/cxx/raleigh/w/entry.h b/src/user/include/cxx/raleigh/w/entry.h
index c86b281..cc797b0 100644
--- a/src/user/include/cxx/raleigh/w/entry.h
+++ b/src/user/include/cxx/raleigh/w/entry.h
@@ -1,72 +1,61 @@
#ifndef RALEIGH_W_ENTRY_H
#define RALEIGH_W_ENTRY_H
+#include <raleigh/s/text_flower.h>
#include <raleigh/widget.h>
#include <libfont/fonts.h>
namespace raleigh {
class entry : public widget {
public:
- //default_text's data is copied, so it's okay if it changes or if the memory is freed
entry(uint32_t rows=25, uint32_t cols=25, const char *default_text="",
- const char *font="fixed-10", _pixel_t bg=RGB(ff, ff, ff),
+ const struct font_info *fi=get_font("fixed-10"), _pixel_t bg=RGB(ff, ff, ff),
_pixel_t fg=RGB(00, 00, 00), _pixel_t border_color=RGB(00, 00, 00));
//not a copy
- const char *get_contents();
- //s's data is copied
+ const char *get_contents() __attribute__ ((pure));
+ //s is copied
void set_contents(const char *s);
- void notify_window_change() override;
void paint(_pixel_t *pixbuf, uint32_t pitch) override;
- void handle_click(coord window_coords, enum mouse_packet::mouse_button click_type, bool up) override;
void notify_has_opaque_parent(widget *parent) override;
+ void handle_click(coord window_coords, enum mouse_packet::mouse_button click_type, bool up) override;
void handle_key(struct key_packet kp) override;
void on_focus() override;
void on_unfocus() override;
+
private:
+ const struct font_info *fi;
+ _pixel_t border_color;
+ _pixel_t fg;
+ _pixel_t bg;
uint32_t rows;
uint32_t cols;
- _pixel_t bg;
- _pixel_t fg;
- _pixel_t border_color;
- struct font_info *fi;
- char *data;
- //line_indices[end_y + 1] == end_d
- uint32_t *line_indices;
+ void left();
+ void right();
+ void up();
+ void down();
- uint32_t cur_y;
- uint32_t cur_x;
- uint32_t cur_d;
+ void check_y();
+ void check_x();
- //the row of the last character
- uint32_t end_y;
- //the column after the last character
- uint32_t end_x;
- //the index of the null terminator
- uint32_t end_d;
+ void on_text_change();
+ void on_cursor_change();
- bool has_focus;
- bool had_focus_last_paint;
- bool text_changed_since_last_paint;
- uint32_t cur_y_last_paint;
- uint32_t cur_x_last_paint;
- uint32_t cur_d_last_paint;
+ alist<char> text_back;
+ text_flower flower;
- //uses cur_x, not cur_d; sets both
- //will not modify cur_y
- void ensure_cursor_in_line();
+ bool text_change;
+ bool cursor_change;
- void paint_text(_pixel_t *pixbuf, uint32_t pitch);
- //sets line_indices[from_y + 1 .. end_y + 1], end_y, end_x and end_d
- void get_indices(uint32_t from_y, uint32_t from_x, uint32_t from_d);
+ bool was_cur_before;
+ uint32_t old_cur_x;
+ uint32_t old_cur_y;
- //these four return true on success, and do not send a paint request to the window
- bool cursor_left();
- bool cursor_right();
- bool cursor_up();
- bool cursor_down();
+ bool is_cur;
+ uint32_t cur_x;
+ uint32_t cur_y;
};
}
diff --git a/src/user/include/cxx/raleigh/w/label.h b/src/user/include/cxx/raleigh/w/label.h
index a78ce46..ebc6890 100644
--- a/src/user/include/cxx/raleigh/w/label.h
+++ b/src/user/include/cxx/raleigh/w/label.h
@@ -1,6 +1,7 @@
#ifndef RALEIGH_W_LABEL_H
#define RALEIGH_W_LABEL_H
+#include <raleigh/s/text_flower.h>
#include <raleigh/widget.h>
#include <libfont/fonts.h>
@@ -8,20 +9,27 @@ namespace raleigh {
class label : public widget {
public:
//value's data is copied
- label(const char *value, const char *font="fixed-10", bool bg_transparent=true,
- _pixel_t fg=RGB(00, 00, 00), _pixel_t bg=RGB(bf, bf, bf));
+ label(const char *value, const char *font="fixed-10",
+ uint32_t cols=0, bool bg_transparent=true,
+ _pixel_t fg=RALEIGH_FG, _pixel_t bg=RALEIGH_BG);
+ ~label();
+
+ //new_value's data is copied
void change_value(const char *new_value);
void paint(_pixel_t *pixbuf, uint32_t pitch) override;
void notify_has_opaque_parent(widget *parent) override;
private:
- char *value;
- uint32_t v_size;
const struct font_info *const fi;
+ uint32_t cols;
bool bg_transparent;
const _pixel_t fg;
const _pixel_t bg;
+
+ text_flower tf;
+
+ coord determine_size();
};
}
diff --git a/src/user/include/cxx/raleigh/widget.h b/src/user/include/cxx/raleigh/widget.h
index b53718a..cbd499c 100644
--- a/src/user/include/cxx/raleigh/widget.h
+++ b/src/user/include/cxx/raleigh/widget.h
@@ -12,7 +12,7 @@ namespace raleigh {
namespace raleigh {
class widget {
public:
- //these three are set by window class (or parent widget)
+ //these four are set by window class (or parent widget)
widget *parent;//set to zero when root widget
window *w;
coord window_offset;
diff --git a/src/user/include/cxx/raleigh/window.h b/src/user/include/cxx/raleigh/window.h
index 3448536..63a3786 100644
--- a/src/user/include/cxx/raleigh/window.h
+++ b/src/user/include/cxx/raleigh/window.h
@@ -20,7 +20,7 @@ namespace raleigh {
friend void start_runtime();
public:
//pass on_close to specify a close handler. if on_close returns false, the window will not be closed.
- window(widget &root, _pixel_t bg_color=RGB(bf, bf, bf), bool (*on_close)(window_tag_t)=0, window_tag_t tag=0);
+ window(widget &root, _pixel_t bg_color=RALEIGH_BG, bool (*on_close)(window_tag_t)=0, window_tag_t tag=0);
void add_keybind(struct key_packet kp, void (*handler)(window_tag_t));
void notify_needs_paint(widget &from);
diff --git a/src/user/include/cxx/structs/alist.h b/src/user/include/cxx/structs/alist.h
index 050f775..13a24c4 100644
--- a/src/user/include/cxx/structs/alist.h
+++ b/src/user/include/cxx/structs/alist.h
@@ -15,20 +15,67 @@ public:
uint32_t expand_by;
data *buf;
- alist(uint32_t default_size=10, uint32_t expand_by=10)
+ alist(uint32_t default_size = 10, uint32_t expand_by = 10)
: n_entries(0), buf_size(default_size), expand_by(expand_by),
- buf((data *)get_block(default_size * sizeof(data))) {}
+ buf(new data[default_size]) {}
+
+ //from is copied
+ alist(const data *from, uint32_t count, uint32_t extra_size = 10, uint32_t expand_by = 10)
+ : n_entries(count), buf_size(count + extra_size), expand_by(expand_by),
+ buf(new data[count + extra_size]) {
+ for (uint32_t i = 0; i < count; ++i)
+ buf[i] = from[i];
+ }
+
+ ~alist() {
+ delete[] buf;
+ }
+
+ void copy_from(const data *from, uint32_t count) {
+ expand_to(count);
+ n_entries = count;
+ for (uint32_t i = 0; i < count; ++i)
+ buf[i] = from[i];
+ }
+
+ void expand_to(uint32_t size) {
+ if (size <= buf_size)
+ return;
+ data *const new_buf = new data[size * sizeof(data)];
+ for (uint32_t i = 0; i < buf_size; ++i)
+ new_buf[i] = buf[i];
+ delete[] buf;
+ buf = new_buf;
+ buf_size = size;
+ }
+
+ void copy_from(const alist<data> &other) {
+ expand_to(n_entries = other.n_entries);
+ for (uint32_t i = 0; i < n_entries; ++i)
+ buf[i] = other.buf[i];
+ }
void add_back(data d) {
- if (n_entries == buf_size) {
- data *const new_buf = (data *)get_block((buf_size += expand_by) * sizeof(data));
- blockcpy(new_buf, buf, n_entries * sizeof(data));
- free_block(buf);
- buf = new_buf;
- }
+ if (n_entries == buf_size)
+ expand_to(buf_size + expand_by);
buf[n_entries++] = d;
}
+ void insert(uint32_t i, data d) {
+ if (n_entries == buf_size)
+ expand_to(buf_size + expand_by);
+ for (uint32_t n = n_entries; n > i; --n)
+ buf[n] = buf[n - 1];
+ buf[i] = d;
+ ++n_entries;
+ }
+
+ void remove(uint32_t i) {
+ --n_entries;
+ for (uint32_t n = i; n < n_entries; ++n)
+ buf[n] = buf[n + 1];
+ }
+
//returns -1 if not found
uint32_t index_of(data d) {
for (uint32_t i = 0; i < n_entries; ++i)
diff --git a/src/user/include/cxx/structs/duple.h b/src/user/include/cxx/structs/duple.h
index 874e4f6..0b23c92 100644
--- a/src/user/include/cxx/structs/duple.h
+++ b/src/user/include/cxx/structs/duple.h
@@ -4,6 +4,7 @@
template<class at, class bt>
class duple {
public:
+ duple() : a(), b() {}
duple(at a, bt b)
: a(a), b(b) {}
at a;
diff --git a/src/user/include/cxx/structs/map.h b/src/user/include/cxx/structs/map.h
index f9c477f..311bfa9 100644
--- a/src/user/include/cxx/structs/map.h
+++ b/src/user/include/cxx/structs/map.h
@@ -3,12 +3,7 @@
#include <structs/alist.h>
-template<class type>
-bool default_equals(type a, type b) {
- return a == b;
-}
-
-template<class key, class value, bool (*equals)(key, key) = &default_equals<key>>
+template<class key, class value, bool (*equals)(key, key) = &key::operator==>
class map {
public:
alist<key> keys;
diff --git a/src/user/include/knob/block.h b/src/user/include/knob/block.h
index 27cb83b..5766245 100644
--- a/src/user/include/knob/block.h
+++ b/src/user/include/knob/block.h
@@ -16,6 +16,7 @@ uint32_t strcpy(char *to, const char *from);
//allocates new memory
char *strdup(const char *from);
+char *strndup(const char *from, uint32_t new_len);
//without null-terminator
uint32_t strlen(const char *str) __attribute__ ((pure));
diff --git a/src/user/include/knob/file.h b/src/user/include/knob/file.h
index 04fc201..f98a15c 100644
--- a/src/user/include/knob/file.h
+++ b/src/user/include/knob/file.h
@@ -10,13 +10,11 @@ extern "C" {
struct file;
-const char *remove_prefix(const char *path, uint8_t *dn_out);
-
struct file *open_file(const char *path);
void close_file(struct file *f);
uint32_t read_from_file(struct file *f, uint32_t max, void *buf);
-uint32_t write_to_file(struct file *f, uint32_t max, void *buf);
+uint32_t write_to_file(struct file *f, uint32_t max, const void *buf);
//return value and max_length don't include null terminator
uint32_t read_line_from_file(struct file *f, char *sz, uint32_t max_length);
uint32_t seek_file_to(struct file *f, uint32_t to);
diff --git a/src/user/include/knob/heap.h b/src/user/include/knob/heap.h
index c0d7006..d7b0773 100644
--- a/src/user/include/knob/heap.h
+++ b/src/user/include/knob/heap.h
@@ -8,7 +8,7 @@ extern "C" {
#include <stdint.h>
void *get_block(uint32_t bytes) __attribute__ ((malloc));
-void free_block(void *block);
+void free_block(const void *block);
#ifdef __cplusplus
}
diff --git a/src/user/include/libterm/terminal.h b/src/user/include/libterm/terminal.h
index 40536e0..a069a22 100644
--- a/src/user/include/libterm/terminal.h
+++ b/src/user/include/libterm/terminal.h
@@ -1,6 +1,10 @@
#ifndef LIBTERM_TERMINAL_H
#define LIBTERM_TERMINAL_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#include <pland/syscall.h>
#include <stdarg.h>
@@ -32,4 +36,8 @@ void term_addf(const char *fmt, ...);
struct key_packet term_get_key_blocking();
+#ifdef __cplusplus
+}
+#endif
+
#endif \ No newline at end of file
diff --git a/src/user/include/pland/syscall.h b/src/user/include/pland/syscall.h
index 1e040f4..566e7b8 100644
--- a/src/user/include/pland/syscall.h
+++ b/src/user/include/pland/syscall.h
@@ -127,8 +127,8 @@ static inline void _exit_task() {
__builtin_unreachable();
}
-static inline _file_handle_t _open_file(_drive_number_t drive_number, const char *path) {
- return (_file_handle_t)_sc2(_SCN_OPEN_FILE, drive_number, (uint32_t)path);
+static inline _file_handle_t _open_file(const char *path) {
+ return (_file_handle_t)_sc1(_SCN_OPEN_FILE, (uint32_t)path);
}
static inline void _close_file(_file_handle_t handle) {
@@ -143,8 +143,8 @@ static inline uint32_t _file_size(_file_handle_t handle) {
return _sc1(_SCN_FILE_SIZE, handle);
}
-static inline _task_handle_t _start_task(_drive_number_t drive_number, const char *path, const char *pass, _task_handle_t stdio_task) {
- return (_task_handle_t)_sc4(_SCN_START_TASK, drive_number, (uint32_t)path, (uint32_t)pass, (uint32_t)stdio_task);
+static inline _task_handle_t _start_task(const char *path, const char *pass, _task_handle_t stdio_task) {
+ return (_task_handle_t)_sc3(_SCN_START_TASK, (uint32_t)path, (uint32_t)pass, (uint32_t)stdio_task);
}
static inline uint32_t _ipc_send(_task_handle_t handle, uint32_t count, const void *buffer) {
@@ -183,12 +183,12 @@ static inline void _wait_for_task(_task_handle_t handle) {
_sc1(_SCN_WAIT_FOR_TASK, handle);
}
-static inline uint32_t _enumerate_dir(_drive_number_t drive_number, const char *path, _dir_info_entry_t *buffer, uint32_t max_count) {
- return _sc4(_SCN_ENUMERATE_DIR, drive_number, (uint32_t)path, (uint32_t)buffer, max_count);
+static inline uint32_t _enumerate_dir(const char *path, _dir_info_entry_t *buffer, uint32_t max_count) {
+ return _sc3(_SCN_ENUMERATE_DIR, (uint32_t)path, (uint32_t)buffer, max_count);
}
-static inline uint32_t _count_of_dir(uint8_t drive_number, const char *path) {
- return _sc2(_SCN_COUNT_OF_DIR, drive_number, (uint32_t)path);
+static inline uint32_t _count_of_dir(const char *path) {
+ return _sc1(_SCN_COUNT_OF_DIR, (uint32_t)path);
}
static inline _window_handle_t _new_window(uint16_t width, uint16_t height, _pixel_t *pixel_buffer) {