diff options
author | Benji Dial <benji6283@gmail.com> | 2021-03-08 16:46:22 -0500 |
---|---|---|
committer | Benji Dial <benji6283@gmail.com> | 2021-03-08 16:46:22 -0500 |
commit | 920f1f010284d59bad86f78355ed90ac2f3e1d2c (patch) | |
tree | 19e2abcf6f546e251151582c700cfce312224eb1 /src/user/raleigh/w | |
parent | af52ddac750311ace3bd997245771b26119e1659 (diff) | |
download | portland-os-920f1f010284d59bad86f78355ed90ac2f3e1d2c.tar.gz |
mouse movement in raleigh, with colorpicker dragging example
Diffstat (limited to 'src/user/raleigh/w')
-rw-r--r-- | src/user/raleigh/w/button.cpp | 8 | ||||
-rw-r--r-- | src/user/raleigh/w/colorpicker.cpp | 46 | ||||
-rw-r--r-- | src/user/raleigh/w/padding.cpp | 8 | ||||
-rw-r--r-- | src/user/raleigh/w/vbox.cpp | 11 |
4 files changed, 71 insertions, 2 deletions
diff --git a/src/user/raleigh/w/button.cpp b/src/user/raleigh/w/button.cpp index 2abf9a9..224b930 100644 --- a/src/user/raleigh/w/button.cpp +++ b/src/user/raleigh/w/button.cpp @@ -55,4 +55,12 @@ namespace raleigh { } void button::notify_has_opaque_parent(widget *parent) {} + + void button::on_mouse_move(coord window_coords) { + if ((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.on_mouse_move(window_coords); + } }
\ No newline at end of file diff --git a/src/user/raleigh/w/colorpicker.cpp b/src/user/raleigh/w/colorpicker.cpp index faa720e..4ccd0ce 100644 --- a/src/user/raleigh/w/colorpicker.cpp +++ b/src/user/raleigh/w/colorpicker.cpp @@ -2,7 +2,8 @@ namespace raleigh { colorpicker::colorpicker(_pixel_t default_color, uint8_t resolution) - : picked_color(default_color), resolution(resolution), inv_res(256 / resolution) { + : picked_color(default_color), resolution(resolution), + inv_res(256 / resolution), selected(NO) { size = coord(inv_res * 2, inv_res * 2); closest_opaque = this; } @@ -32,19 +33,26 @@ namespace raleigh { } void colorpicker::handle_click(coord window_coords, enum mouse_packet::mouse_button click_type, bool up) { - if (up || (click_type != mouse_packet::LEFT)) + if (click_type != mouse_packet::LEFT) return; + if (up) { + selected = NO; + return; + } window_coords.x -= window_offset.x; window_coords.y -= window_offset.y; if ((window_coords.x < inv_res) && (window_coords.y < inv_res)) { + selected = R; picked_color.g = window_coords.x * resolution; picked_color.b = window_coords.y * resolution; } else if (window_coords.y < inv_res) { + selected = G; picked_color.b = (window_coords.x - inv_res) * resolution; picked_color.r = window_coords.y * resolution; } else if (window_coords.x < inv_res) { + selected = B; picked_color.r = window_coords.x * resolution; picked_color.g = (window_coords.y - inv_res) * resolution; } @@ -52,4 +60,38 @@ namespace raleigh { } void colorpicker::notify_has_opaque_parent(widget *parent) {} + + void colorpicker::on_mouse_move(coord window_coords) { + uint32_t x = window_coords.x - window_offset.x; + uint32_t y = window_coords.y - window_offset.y; + switch (selected) { + case NO: + return; + case R: + if (x >= inv_res) + x = inv_res - 1; + if (y >= inv_res) + y = inv_res - 1; + picked_color.g = x * resolution; + picked_color.b = y * resolution; + break; + case G: + if (x < inv_res) + x = inv_res; + if (y >= inv_res) + y = inv_res - 1; + picked_color.b = x * resolution; + picked_color.r = y * resolution; + break; + case B: + if (x >= inv_res) + x = inv_res - 1; + if (y < inv_res) + y = inv_res; + picked_color.r = x * resolution; + picked_color.g = y * resolution; + break; + } + w->notify_needs_paint(*this); + } }
\ No newline at end of file diff --git a/src/user/raleigh/w/padding.cpp b/src/user/raleigh/w/padding.cpp index c1f7b85..782a8a9 100644 --- a/src/user/raleigh/w/padding.cpp +++ b/src/user/raleigh/w/padding.cpp @@ -34,4 +34,12 @@ namespace raleigh { void padding::notify_child_size_change(widget &child, coord old_size) { set_size(coord(inner.size.x + pad_by * 2, inner.size.y + pad_by * 2)); } + + void padding::on_mouse_move(coord window_coords) { + if ((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.on_mouse_move(window_coords); + } }
\ No newline at end of file diff --git a/src/user/raleigh/w/vbox.cpp b/src/user/raleigh/w/vbox.cpp index 263da2a..77ce592 100644 --- a/src/user/raleigh/w/vbox.cpp +++ b/src/user/raleigh/w/vbox.cpp @@ -63,4 +63,15 @@ namespace raleigh { notify_window_change(); } } + + void vbox::on_mouse_move(coord window_coords) { + for (dllist<widget &>::node *n = widgets.first; n; n = n->next) + if ((window_coords.x >= n->d.window_offset.x) && + (window_coords.y >= n->d.window_offset.y) && + (window_coords.x < n->d.window_offset.x + n->d.size.x) && + (window_coords.y < n->d.window_offset.y + n->d.size.y)) { + n->d.on_mouse_move(window_coords); + return; + } + } }
\ No newline at end of file |