diff options
author | Benji Dial <benji6283@gmail.com> | 2021-03-05 18:07:48 -0500 |
---|---|---|
committer | Benji Dial <benji6283@gmail.com> | 2021-03-05 18:07:48 -0500 |
commit | 76e39eac8cee2175ec62a191f7c91ca53857e80c (patch) | |
tree | 156946f6e8f491235453aa3cbecfda43d6baa2a7 /src/user/raleigh/window.cpp | |
parent | 5e5e524f08ad653a7bf5d6e97f3a49f6c27d08fa (diff) | |
download | portland-os-76e39eac8cee2175ec62a191f7c91ca53857e80c.tar.gz |
more raleigh, including button and vbox widgets
Diffstat (limited to 'src/user/raleigh/window.cpp')
-rw-r--r-- | src/user/raleigh/window.cpp | 51 |
1 files changed, 42 insertions, 9 deletions
diff --git a/src/user/raleigh/window.cpp b/src/user/raleigh/window.cpp index 4373b06..41eb9ce 100644 --- a/src/user/raleigh/window.cpp +++ b/src/user/raleigh/window.cpp @@ -1,20 +1,21 @@ #include <raleigh/runtime.h> #include <raleigh/window.h> +#include <popups/info.h> #include <knob/heap.h> namespace raleigh { - window::window(widget &root) - : size(root.size), root(root) { + window::window(widget &root, _pixel_t bg_color, bool (*on_close)(window &)) + : handle(0), size(root.size), root(root), bg_color(bg_color), + needs_repaint(false), on_close(on_close) { 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)); + if (!pixbuf) + show_error_and_quitf("Failed to create %d byte pixel buffer\nfor requested %dx%d pixel window.", size.x * size.y * sizeof(_pixel_t), size.x, size.y); - root.paint(pixbuf, size.x); - handle = _new_window(size.x, size.y, pixbuf); - - open_windows.add_front(*this); + paint_full(); } window::try_actions_return_t window::try_actions() { @@ -22,14 +23,46 @@ namespace raleigh { window::try_actions_return_t got = NONE; while (1) { _get_win_action(handle, &wa); - if (!wa.action_type) + if (!wa.action_type) { + if (needs_repaint) { + needs_repaint = false; + _paint_window(handle); + } 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; + if (!on_close || on_close(*this)) + return DELETE; got = GOOD; - //TODO + if (wa.action_type == wa.MOUSE_DOWN) + root.try_handle_click(coord(wa.as_mouse.x, wa.as_mouse.y), wa.as_mouse.which, false); + if (wa.action_type == wa.MOUSE_UP) + root.try_handle_click(coord(wa.as_mouse.x, wa.as_mouse.y), wa.as_mouse.which, true); } } + + void window::notify_needs_paint(widget &head) { + if (head.closest_opaque) + head.closest_opaque->paint(pixbuf, size.x); + else + paint_full(); + needs_repaint = true; + } + + void window::paint_full() { + for (uint32_t i = 0; i < size.x * size.y; ++i) + pixbuf[i] = bg_color; + root.paint(pixbuf, size.x); + } + + void window::show() { + if (handle) + return; + handle = _new_window(size.x, size.y, pixbuf); + if (!handle) + show_error_and_quitf("Failed to get window handle for requested window."); + open_windows.add_front(*this); + } }
\ No newline at end of file |