aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO4
-rw-r--r--include/Body.hpp4
-rw-r--r--src/Body.cpp55
3 files changed, 46 insertions, 17 deletions
diff --git a/TODO b/TODO
index 1968ffd..4c17bf5 100644
--- a/TODO
+++ b/TODO
@@ -132,4 +132,6 @@ Submit on notifications item in matrix should jump to the message in the room.
Notifications should load their replied-to-message.
Readd copying of Text in Body copy constructor. Find out why we need to make the text dirty on copy.
Body items that are no longer visible should stop their thumbnail download/creation (moving to bottom of file-manager is very slow).
-Fix body flickering when moving up and there is a new local image to load. It happens because we have no idea how large the thumbnail is before loading it. \ No newline at end of file
+Fix body flickering when moving up and there is a new local image to load. It happens because we have no idea how large the thumbnail is before loading it.
+Make body width the same as the window width (for the main body when there isn't a room list beside it) and pass margin to body draw. This is needed to allow swiping body from the window (screen) edge.
+Restrict sf::View viewport in Body to x axis as well, to hide the body in the end when swiping right. \ No newline at end of file
diff --git a/include/Body.hpp b/include/Body.hpp
index a7b0045..388d825 100644
--- a/include/Body.hpp
+++ b/include/Body.hpp
@@ -268,6 +268,7 @@ namespace QuickMedia {
sf::Shader *thumbnail_mask_shader;
AttachSide attach_side = AttachSide::TOP;
bool title_mark_urls = false;
+ bool swiping_enabled = false;
std::function<void()> on_top_reached = nullptr;
std::function<void()> on_bottom_reached = nullptr;
@@ -336,6 +337,9 @@ namespace QuickMedia {
sf::Vector2f mouse_scroll_accel;
sf::Vector2f body_pos;
sf::Vector2f body_size;
+ double body_swipe_x = 0.0;
+ bool body_swipe_move_right = false;
+ bool grabbed_left_side = false;
float selected_item_height = 0.0f;
std::shared_ptr<BodyItem> clicked_body_item = nullptr;
RoundedRectangle item_background;
diff --git a/src/Body.cpp b/src/Body.cpp
index 24cf483..42a3b35 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -393,12 +393,17 @@ namespace QuickMedia {
mouse_press_pixels_moved_abs = 0.0;
has_scrolled_with_input = true;
render_selected_item_bg = false;
- click_counts = std::abs(mouse_scroll_accel.y) < 5.0f;
+ click_counts = std::abs(mouse_scroll_accel.y) < 5.0f; // Touching the body while it scrolls should stop it, not select the touched item
+ body_swipe_x = 0.0;
+ body_swipe_move_right = false;
+ grabbed_left_side = (event.mouseButton.x < body_pos.x + body_size.x * 0.15f);
return true;
} else if(event.type == sf::Event::MouseButtonReleased && event.mouseButton.button == sf::Mouse::Left && mouse_left_pressed) {
mouse_left_pressed = false;
mouse_left_clicked = true;
mouse_release_pos = sf::Vector2f(event.mouseButton.x, event.mouseButton.y);
+ if(event.mouseButton.x > body_pos.x + body_size.x * 0.5f || mouse_scroll_accel.x > 20.0f)
+ body_swipe_move_right = true;
return true;
} else if(event.type == sf::Event::MouseMoved && mouse_left_pressed) {
sf::Vector2i mouse_pos_diff(event.mouseMove.x - mouse_pos_raw.x, event.mouseMove.y - mouse_pos_raw.y);
@@ -451,6 +456,8 @@ namespace QuickMedia {
const int prev_num_visible_items = num_visible_items;
const bool prev_items_cut_off = top_cut_off || bottom_cut_off;
+ const int prev_first_visible_item = first_visible_item;
+ const int prev_last_visible_item = last_visible_item;
num_visible_items = 0;
first_visible_item = -1;
last_visible_item = -1;
@@ -492,21 +499,23 @@ namespace QuickMedia {
if(prev_items_cut_off) {
if(mouse_left_pressed) {
+ body_swipe_x += mouse_pos_diff_smooth.x;
+ if(body_swipe_x < 0.0)
+ body_swipe_x = 0.0;
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);
+ mouse_scroll_accel = sf::Vector2f(mouse_pos_raw_diff.x, mouse_pos_raw_diff.y) / (frame_time * 120.0f);
} else {
page_scroll += mouse_scroll_accel.y;
}
}
- if(mouse_scroll_accel.y > 0.1f && first_visible_item != -1) {
- selected_item = first_visible_item;
+ if(mouse_scroll_accel.y > 0.1f && prev_first_visible_item != -1) {
+ selected_item = prev_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;
+ } else if(mouse_scroll_accel.y < -0.1f && prev_last_visible_item != -1) {
+ selected_item = prev_last_visible_item;
// TODO: Cache this
if(on_bottom_reached && get_next_visible_item(selected_item) == -1)
on_bottom_reached();
@@ -528,9 +537,19 @@ namespace QuickMedia {
mouse_scroll_accel.x = 0.0;
mouse_scroll_accel.y = 0.0;
}
+
+ double dist_to_target;
+ if(body_swipe_move_right)
+ dist_to_target = body_size.x - body_swipe_x;
+ else
+ dist_to_target = 0.0f - body_swipe_x;
+ body_swipe_x += (dist_to_target * std::min(1.0f, frame_time * move_speed));
}
}
+ if(swiping_enabled && grabbed_left_side)
+ pos.x += body_swipe_x;
+
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);
@@ -707,7 +726,8 @@ 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
+ // 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.
+ // Also take |selected_scrolled| into consideration
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)
@@ -718,6 +738,17 @@ namespace QuickMedia {
page_scroll = (body_total_height - body_size.y);
}
+ mouse_left_clicked = false;
+ if(clicked_body_item) {
+ auto clicked_body_item_tmp = clicked_body_item; // tmp because below call to body_item_select_callback may call this same draw function
+ clicked_body_item = nullptr;
+ if(body_item_select_callback)
+ body_item_select_callback(clicked_body_item_tmp.get());
+ }
+
+ if(is_touch_enabled())
+ return;
+
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) {
@@ -748,14 +779,6 @@ namespace QuickMedia {
else
page_scroll -= item_target_bottom_diff*page_scroll_speed;
}
-
- mouse_left_clicked = false;
- if(clicked_body_item) {
- auto clicked_body_item_tmp = clicked_body_item; // tmp because below call to body_item_select_callback may call this same draw function
- clicked_body_item = nullptr;
- if(body_item_select_callback)
- body_item_select_callback(clicked_body_item_tmp.get());
- }
}
void Body::update_dirty_state(BodyItem *body_item, float width) {