diff options
Diffstat (limited to 'src/user')
-rw-r--r-- | src/user/include/cxx/raleigh/w/button.h | 1 | ||||
-rw-r--r-- | src/user/include/cxx/raleigh/w/colorpicker.h | 2 | ||||
-rw-r--r-- | src/user/include/cxx/raleigh/w/multicontainer.h | 1 | ||||
-rw-r--r-- | src/user/include/cxx/raleigh/w/padding.h | 1 | ||||
-rw-r--r-- | src/user/include/cxx/raleigh/window.h | 3 | ||||
-rw-r--r-- | src/user/raleigh/w/button.cpp | 8 | ||||
-rw-r--r-- | src/user/raleigh/w/colorpicker.cpp | 27 | ||||
-rw-r--r-- | src/user/raleigh/w/multicontainer.cpp | 11 | ||||
-rw-r--r-- | src/user/raleigh/w/padding.cpp | 8 | ||||
-rw-r--r-- | src/user/raleigh/window.cpp | 16 |
10 files changed, 33 insertions, 45 deletions
diff --git a/src/user/include/cxx/raleigh/w/button.h b/src/user/include/cxx/raleigh/w/button.h index 0e40f81..71ccae2 100644 --- a/src/user/include/cxx/raleigh/w/button.h +++ b/src/user/include/cxx/raleigh/w/button.h @@ -14,7 +14,6 @@ namespace raleigh { void handle_click(coord window_coords, enum mouse_packet::mouse_button click_type, bool up) override; void notify_child_size_change(widget &child, coord old_size) override; void notify_has_opaque_parent(widget *parent) override; - void on_mouse_move(coord window_coords) override; private: widget &inner; void (*on_click)(button &); diff --git a/src/user/include/cxx/raleigh/w/colorpicker.h b/src/user/include/cxx/raleigh/w/colorpicker.h index a282c9e..471787d 100644 --- a/src/user/include/cxx/raleigh/w/colorpicker.h +++ b/src/user/include/cxx/raleigh/w/colorpicker.h @@ -19,7 +19,7 @@ namespace raleigh { uint8_t resolution; uint8_t inv_res; - enum {NO, R, G, B} selected; + enum {R, G, B} selected; }; } diff --git a/src/user/include/cxx/raleigh/w/multicontainer.h b/src/user/include/cxx/raleigh/w/multicontainer.h index 5ced74f..8a3497f 100644 --- a/src/user/include/cxx/raleigh/w/multicontainer.h +++ b/src/user/include/cxx/raleigh/w/multicontainer.h @@ -12,7 +12,6 @@ namespace raleigh { 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 notify_child_size_change(widget &from, coord old_size) override; - void on_mouse_move(coord window_coords) override; protected: //do not modify this list afterward diff --git a/src/user/include/cxx/raleigh/w/padding.h b/src/user/include/cxx/raleigh/w/padding.h index ab732f1..1bdb9ee 100644 --- a/src/user/include/cxx/raleigh/w/padding.h +++ b/src/user/include/cxx/raleigh/w/padding.h @@ -13,7 +13,6 @@ namespace raleigh { 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 notify_child_size_change(widget &child, coord old_size) override; - void on_mouse_move(coord window_coords) override; private: widget &inner; uint32_t pad_by; diff --git a/src/user/include/cxx/raleigh/window.h b/src/user/include/cxx/raleigh/window.h index 0dd9341..2b759d5 100644 --- a/src/user/include/cxx/raleigh/window.h +++ b/src/user/include/cxx/raleigh/window.h @@ -22,6 +22,7 @@ namespace raleigh { 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 show(); @@ -32,6 +33,8 @@ namespace raleigh { 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(); diff --git a/src/user/raleigh/w/button.cpp b/src/user/raleigh/w/button.cpp index da88f6a..5b5f756 100644 --- a/src/user/raleigh/w/button.cpp +++ b/src/user/raleigh/w/button.cpp @@ -59,12 +59,4 @@ 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 4ccd0ce..5a9aa82 100644 --- a/src/user/raleigh/w/colorpicker.cpp +++ b/src/user/raleigh/w/colorpicker.cpp @@ -3,7 +3,7 @@ namespace raleigh { colorpicker::colorpicker(_pixel_t default_color, uint8_t resolution) : picked_color(default_color), resolution(resolution), - inv_res(256 / resolution), selected(NO) { + inv_res(256 / resolution) { size = coord(inv_res * 2, inv_res * 2); closest_opaque = this; } @@ -33,12 +33,8 @@ namespace raleigh { } void colorpicker::handle_click(coord window_coords, enum mouse_packet::mouse_button click_type, bool up) { - if (click_type != mouse_packet::LEFT) + if (up || (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)) { @@ -57,37 +53,48 @@ namespace raleigh { picked_color.g = (window_coords.y - inv_res) * resolution; } w->notify_needs_paint(*this); + w->notify_wants_movements(*this, mouse_packet::LEFT); } 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; + int32_t x = window_coords.x - window_offset.x; + int32_t y = window_coords.y - window_offset.y; switch (selected) { - case NO: - return; case R: if (x >= inv_res) x = inv_res - 1; + if (x < 0) + x = 0; if (y >= inv_res) y = inv_res - 1; + if (y < 0) + y = 0; picked_color.g = x * resolution; picked_color.b = y * resolution; break; case G: if (x < inv_res) x = inv_res; + if (x >= inv_res * 2) + x = inv_res * 2 - 1; if (y >= inv_res) y = inv_res - 1; + if (y < 0) + y = 0; picked_color.b = x * resolution; picked_color.r = y * resolution; break; case B: if (x >= inv_res) x = inv_res - 1; + if (x < 0) + x = 0; if (y < inv_res) y = inv_res; + if (y >= inv_res * 2) + y = inv_res * 2 - 1; picked_color.r = x * resolution; picked_color.g = y * resolution; break; diff --git a/src/user/raleigh/w/multicontainer.cpp b/src/user/raleigh/w/multicontainer.cpp index 3021deb..edc60aa 100644 --- a/src/user/raleigh/w/multicontainer.cpp +++ b/src/user/raleigh/w/multicontainer.cpp @@ -39,15 +39,4 @@ namespace raleigh { set_size(determine_size()); set_child_offsets(); } - - void multicontainer::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 diff --git a/src/user/raleigh/w/padding.cpp b/src/user/raleigh/w/padding.cpp index 21289d4..57ac011 100644 --- a/src/user/raleigh/w/padding.cpp +++ b/src/user/raleigh/w/padding.cpp @@ -38,12 +38,4 @@ 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/window.cpp b/src/user/raleigh/window.cpp index 8501f7e..b99346d 100644 --- a/src/user/raleigh/window.cpp +++ b/src/user/raleigh/window.cpp @@ -7,7 +7,7 @@ namespace raleigh { window::window(widget &root, _pixel_t bg_color, bool (*on_close)(window &)) : handle(0), size(root.size), root(root), focussed(&root), - bg_color(bg_color), on_close(on_close) { + drag_reciever(0), bg_color(bg_color), on_close(on_close) { root.w = this; root.window_offset = coord(0, 0); root.notify_window_change(); @@ -41,8 +41,11 @@ namespace raleigh { got = GOOD; if (wa.action_type == wa.MOUSE_DOWN) root.handle_click(coord(wa.as_mouse.x, wa.as_mouse.y), wa.as_mouse.which, false); - else if (wa.action_type == wa.MOUSE_UP) + else if (wa.action_type == wa.MOUSE_UP) { + if (drag_reciever && (wa.as_mouse.which == drag_until)) + drag_reciever = 0; root.handle_click(coord(wa.as_mouse.x, wa.as_mouse.y), wa.as_mouse.which, true); + } else if (wa.action_type == wa.KEY_DOWN) { for (dllist<duple<struct key_packet, void (*)(window &)>>::node *n = keybinds.first; n; n = n->next) if (match_side_agnostic(wa.as_key, n->d.a)) { @@ -57,8 +60,8 @@ namespace raleigh { focussed->on_focus(); else if (wa.action_type == wa.FOCUS_LEAVE) focussed->on_unfocus(); - else if (wa.action_type == wa.MOUSE_MOVE) - root.on_mouse_move(coord(wa.moved_to.x, wa.moved_to.y)); + else if (drag_reciever && (wa.action_type == wa.MOUSE_MOVE)) + drag_reciever->on_mouse_move(coord(wa.moved_to.x, wa.moved_to.y)); } } @@ -112,4 +115,9 @@ namespace raleigh { void window::add_keybind(struct key_packet kp, void (*handler)(window &)) { keybinds.add_front(duple<struct key_packet, void (*)(window &)>(kp, handler)); } + + void window::notify_wants_movements(widget &from, enum mouse_packet::mouse_button while_down) { + drag_reciever = &from; + drag_until = while_down; + } }
\ No newline at end of file |