aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-05-29 13:46:14 +0200
committerdec05eba <dec05eba@protonmail.com>2021-05-29 13:46:14 +0200
commit2a364f52f194c853f2cb62122bf84039ab3e1117 (patch)
tree6065393c3273fb13e76c2dc1593da92886242f0a /src
parentf97f67ebd6a9cd3b5a2b7ee295dad7dbb8fb2828 (diff)
Readd body touch scroll
Diffstat (limited to 'src')
-rw-r--r--src/Body.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/Body.cpp b/src/Body.cpp
index bc56ef8..24cf483 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -450,6 +450,7 @@ namespace QuickMedia {
elapsed_time_sec = draw_timer.getElapsedTime().asSeconds();
const int prev_num_visible_items = num_visible_items;
+ const bool prev_items_cut_off = top_cut_off || bottom_cut_off;
num_visible_items = 0;
first_visible_item = -1;
last_visible_item = -1;
@@ -478,6 +479,58 @@ namespace QuickMedia {
return;
}
+ if(is_touch_enabled()) {
+ const sf::Vector2f mouse_pos_diff(mouse_pos_raw.x - mouse_pos.x, mouse_pos_raw.y - mouse_pos.y);
+ const float move_speed = 35.0f;
+ sf::Vector2f prev_mouse_pos = mouse_pos;
+ mouse_pos.x += (mouse_pos_diff.x * std::min(1.0f, frame_time * move_speed));
+ mouse_pos.y += (mouse_pos_diff.y * std::min(1.0f, frame_time * move_speed));
+ const sf::Vector2f mouse_pos_diff_smooth = mouse_pos - prev_mouse_pos;
+
+ sf::Vector2f mouse_pos_raw_diff(mouse_pos_raw.x - prev_mouse_pos_raw.x, mouse_pos_raw.y - prev_mouse_pos_raw.y);
+ prev_mouse_pos_raw = mouse_pos_raw;
+
+ if(prev_items_cut_off) {
+ if(mouse_left_pressed) {
+ page_scroll += mouse_pos_diff_smooth.y;
+ mouse_scroll_accel = sf::Vector2f(mouse_pos_raw_diff.x, mouse_pos_raw_diff.y);
+ mouse_scroll_accel *= (float)((double)frame_time * 120.0);
+ } else {
+ page_scroll += mouse_scroll_accel.y;
+ }
+ }
+
+ if(mouse_scroll_accel.y > 0.1f && first_visible_item != -1) {
+ selected_item = first_visible_item;
+ // TODO: Cache this
+ if(on_top_reached && get_previous_visible_item(selected_item) == -1)
+ on_top_reached();
+ } else if(mouse_scroll_accel.y < -0.1f && last_visible_item != -1) {
+ selected_item = last_visible_item;
+ // TODO: Cache this
+ if(on_bottom_reached && get_next_visible_item(selected_item) == -1)
+ on_bottom_reached();
+ }
+
+ if(!mouse_left_pressed) {
+ const float scroll_deaccel = 1.02f;
+ double deaccel = scroll_deaccel * (1.0 + frame_time);
+ if(deaccel > 0.0001) {
+ mouse_scroll_accel.x /= deaccel;
+ if(fabs(mouse_scroll_accel.x) < 0.0001)
+ mouse_scroll_accel.x = 0.0;
+
+ mouse_scroll_accel.y /= deaccel;
+ if(fabs(mouse_scroll_accel.y) < 0.0001)
+ mouse_scroll_accel.y = 0.0;
+ } else {
+ deaccel = 0.0;
+ mouse_scroll_accel.x = 0.0;
+ mouse_scroll_accel.y = 0.0;
+ }
+ }
+ }
+
const int selected_prev_item = get_previous_visible_item(selected_item);
const bool selected_merge_with_previous = selected_prev_item != -1 && body_item_merge_handler && body_item_merge_handler(items[selected_prev_item].get(), items[selected_item].get());
get_item_height(items[selected_item].get(), size.x, true, true, selected_merge_with_previous, selected_item);
@@ -544,6 +597,7 @@ namespace QuickMedia {
}
pos.y += selected_scrolled;
+ const float pos_y_start = pos.y;
BodyItem *prev_body_item = nullptr;
const double height_move_speed = 1000.0f;
@@ -653,6 +707,17 @@ namespace QuickMedia {
window.setView(prev_view);
+ // TODO: Move up where scroll is limited? then we wont delay this by 1 frame creating a small scroll overflow only in the opposite direction of attach side
+ if(attach_side == AttachSide::TOP) {
+ const float body_total_height = pos.y - pos_y_start;
+ if(top_cut_off && !bottom_cut_off && body_total_height > body_size.y)
+ page_scroll = -(body_total_height - body_size.y);
+ } else {
+ const float body_total_height = pos_y_start - pos.y;
+ if(bottom_cut_off && !top_cut_off && body_total_height > body_size.y)
+ page_scroll = (body_total_height - body_size.y);
+ }
+
const float item_target_top_diff = item_background_target_pos_y;
const float item_target_bottom_diff = (item_background_target_pos_y + item_background_target_height + spacing_y) - body_size.y;
if(((body_size_changed && attach_side == AttachSide::BOTTOM) || selected_item_diff < 0) && item_target_top_diff < 0.0f) {