From 5fcf57739e68a8b5053e03778aaee0eed445babd Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Thu, 11 Mar 2021 22:00:22 -0500 Subject: settings editor, and lots of changes in service of that --- src/user/include/cxx/raleigh/d/dialog.h | 37 +++++++++++++++++++++++++ src/user/include/cxx/raleigh/d/saving_window.h | 20 +++++++++++++ src/user/include/cxx/raleigh/runtime.h | 1 + src/user/include/cxx/raleigh/w/button.h | 9 ++++-- src/user/include/cxx/raleigh/w/colorpicker.h | 1 + src/user/include/cxx/raleigh/w/entry.h | 7 ++++- src/user/include/cxx/raleigh/w/multicontainer.h | 3 ++ src/user/include/cxx/raleigh/w/vbox.h | 2 +- src/user/include/cxx/raleigh/window.h | 23 +++++++++------ 9 files changed, 89 insertions(+), 14 deletions(-) create mode 100644 src/user/include/cxx/raleigh/d/dialog.h create mode 100644 src/user/include/cxx/raleigh/d/saving_window.h (limited to 'src/user/include/cxx/raleigh') diff --git a/src/user/include/cxx/raleigh/d/dialog.h b/src/user/include/cxx/raleigh/d/dialog.h new file mode 100644 index 0000000..f207033 --- /dev/null +++ b/src/user/include/cxx/raleigh/d/dialog.h @@ -0,0 +1,37 @@ +#ifndef RALEIGH_D_DIALOG_H +#define RALEIGH_D_DIALOG_H + +#include +#include +#include +#include +#include + +namespace raleigh { + typedef uint32_t diag_result_t; + enum : diag_result_t { + NONE = 0, + YES, + NO, + CANCEL, + RETRY + }; + extern alist> &yes_no_cancel; + extern alist> &yes_no_retry; + class dialog : public window { + public: + //button names are copied + //alist isn't needed past constructor + dialog(widget &top_part, alist> buttons); + + //zero means not set yet + diag_result_t result; + + void show_modal(); + + private: + vbox *main_box; + }; +} + +#endif \ No newline at end of file diff --git a/src/user/include/cxx/raleigh/d/saving_window.h b/src/user/include/cxx/raleigh/d/saving_window.h new file mode 100644 index 0000000..84b6f69 --- /dev/null +++ b/src/user/include/cxx/raleigh/d/saving_window.h @@ -0,0 +1,20 @@ +#ifndef RALEIGH_D_SAVING_WINDOW_H +#define RALEIGH_D_SAVING_WINDOW_H + +#include +#include + +namespace raleigh { + typedef void *save_tag_t; + class saving_window : public window { + public: + //save_func returns true if saving was successful + saving_window(bool (*save_func)(save_tag_t), save_tag_t save_tag, widget &root, _pixel_t bg_color=RGB(bf, bf, bf)); + bool is_saved; + + bool (*save_func)(save_tag_t); + save_tag_t save_tag; + }; +}; + +#endif \ No newline at end of file diff --git a/src/user/include/cxx/raleigh/runtime.h b/src/user/include/cxx/raleigh/runtime.h index 92bd230..4342beb 100644 --- a/src/user/include/cxx/raleigh/runtime.h +++ b/src/user/include/cxx/raleigh/runtime.h @@ -7,6 +7,7 @@ namespace raleigh { void start_runtime() __attribute__ ((noreturn)); extern dllist open_windows; + extern dllist to_be_deleted; } #endif \ No newline at end of file diff --git a/src/user/include/cxx/raleigh/w/button.h b/src/user/include/cxx/raleigh/w/button.h index 71ccae2..c56a6e3 100644 --- a/src/user/include/cxx/raleigh/w/button.h +++ b/src/user/include/cxx/raleigh/w/button.h @@ -4,10 +4,12 @@ #include namespace raleigh { + typedef void *button_tag_t; class button : public widget { public: - button(widget &inner, void (*on_click)(button &), _pixel_t border_color=RGB(00, 00, 00), - _pixel_t bg_color=RGB(bf, bf, bf), _pixel_t pressed_color=RGB(9f, 9f, 9f)); + button(widget &inner, void (*on_click)(button_tag_t), button_tag_t tag=0, + _pixel_t border_color=RGB(00, 00, 00), _pixel_t bg_color=RGB(bf, bf, bf), + _pixel_t pressed_color=RGB(9f, 9f, 9f)); void notify_window_change() override; void paint(_pixel_t *pixbuf, uint32_t pitch) override; @@ -16,7 +18,8 @@ namespace raleigh { void notify_has_opaque_parent(widget *parent) override; private: widget &inner; - void (*on_click)(button &); + void (*on_click)(button_tag_t); + button_tag_t tag; _pixel_t border_color; _pixel_t bg_color; _pixel_t pressed_color; diff --git a/src/user/include/cxx/raleigh/w/colorpicker.h b/src/user/include/cxx/raleigh/w/colorpicker.h index 471787d..f791b2a 100644 --- a/src/user/include/cxx/raleigh/w/colorpicker.h +++ b/src/user/include/cxx/raleigh/w/colorpicker.h @@ -8,6 +8,7 @@ namespace raleigh { public: colorpicker(_pixel_t default_color=RGB(20, 70, 30), uint8_t resolution=4); _pixel_t get_picked_color() __attribute__ ((pure)); + void set_picked_color(_pixel_t c); 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; diff --git a/src/user/include/cxx/raleigh/w/entry.h b/src/user/include/cxx/raleigh/w/entry.h index 001cae2..c86b281 100644 --- a/src/user/include/cxx/raleigh/w/entry.h +++ b/src/user/include/cxx/raleigh/w/entry.h @@ -8,10 +8,15 @@ 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, uint32_t cols, const char *default_text="", + 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), _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 + 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; diff --git a/src/user/include/cxx/raleigh/w/multicontainer.h b/src/user/include/cxx/raleigh/w/multicontainer.h index 8a3497f..729f6a1 100644 --- a/src/user/include/cxx/raleigh/w/multicontainer.h +++ b/src/user/include/cxx/raleigh/w/multicontainer.h @@ -7,6 +7,9 @@ namespace raleigh { class multicontainer : public widget { public: + void add_end(widget &w); + void add_start(widget &w); + 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; diff --git a/src/user/include/cxx/raleigh/w/vbox.h b/src/user/include/cxx/raleigh/w/vbox.h index d51e61d..6bace59 100644 --- a/src/user/include/cxx/raleigh/w/vbox.h +++ b/src/user/include/cxx/raleigh/w/vbox.h @@ -7,7 +7,7 @@ namespace raleigh { class vbox : public multicontainer { public: //do not modify this list afterward - vbox(dllist widgets); + vbox(dllist widgets=dllist()); private: coord determine_size() override; diff --git a/src/user/include/cxx/raleigh/window.h b/src/user/include/cxx/raleigh/window.h index 2b759d5..3448536 100644 --- a/src/user/include/cxx/raleigh/window.h +++ b/src/user/include/cxx/raleigh/window.h @@ -1,45 +1,50 @@ #ifndef RALEIGH_WINDOW_H #define RALEIGH_WINDOW_H +#include + namespace raleigh { class window; } #include #include -#include -#include #include #include +#include +#include namespace raleigh { + typedef void *window_tag_t; class window { 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 &)=0); - void add_keybind(struct key_packet kp, void (*handler)(window &)); + window(widget &root, _pixel_t bg_color=RGB(bf, bf, bf), 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); void notify_widget_size_change(widget &from, coord old_size); void notify_wants_movements(widget &from, enum mouse_packet::mouse_button while_down); - enum try_actions_return_t {NONE, GOOD, DELETE}; - try_actions_return_t try_actions(); + void consume_actions(); void show(); void focus(widget &w); + + protected: + widget &root; private: _window_handle_t handle; _pixel_t *pixbuf; coord size; - widget &root; widget *focussed; widget *drag_reciever; enum mouse_packet::mouse_button drag_until; _pixel_t bg_color; bool needs_repaint; void paint_full(); - bool (*on_close)(window &); - dllist> keybinds; + bool (*on_close)(window_tag_t); + window_tag_t tag; + map keybinds; }; } -- cgit v1.2.3