aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-09-26 22:59:25 +0200
committerdec05eba <dec05eba@protonmail.com>2020-09-26 22:59:25 +0200
commita00bdf3c76cd2d813533788b83abac87d6449b18 (patch)
treee5cee3afc26c64edf38d91cfee5eff09f4452862 /src
parent98d9b6856061e6c1951b03ca6b197d581e357189 (diff)
matrix: time based animations, dont show chat input in rooms view, improve scrolling when switching tabs
Diffstat (limited to 'src')
-rw-r--r--src/QuickMedia.cpp85
1 files changed, 43 insertions, 42 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index d7a3ed7..6293e52 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -3330,23 +3330,6 @@ namespace QuickMedia {
return false;
}
return true;
- } else if(tabs[selected_tab].type == ChatTabType::ROOMS) {
- BodyItem *selected_item = tabs[selected_tab].body->get_selected();
- if(selected_item) {
- current_room_id = selected_item->url;
- selected_tab = MESSAGES_TAB_INDEX;
- tabs[MESSAGES_TAB_INDEX].body->clear_items();
-
- BodyItems new_items;
- // TODO: Make asynchronous
- if(matrix->get_all_synced_room_messages(current_room_id, new_items) == PluginResult::OK) {
- tabs[MESSAGES_TAB_INDEX].body->append_items(std::move(new_items));
- } else {
- std::string err_msg = "Failed to get messages in room: " + current_room_id;
- show_notification("QuickMedia", err_msg, Urgency::CRITICAL);
- }
- return true;
- }
}
return false;
};
@@ -3375,7 +3358,7 @@ namespace QuickMedia {
const float gradient_height = 5.0f;
sf::Vertex gradient_points[4];
- int gradient_inc = 0;
+ double gradient_inc = 0;
sf::Clock start_typing_timer;
const double typing_timeout_seconds = 3.0;
@@ -3390,7 +3373,10 @@ namespace QuickMedia {
};
std::vector<std::future<void>> typing_futures;
+ sf::Clock frame_timer;
+
while (current_page == Page::CHAT) {
+ sf::Int32 frame_time_ms = frame_timer.restart().asMilliseconds();
while (window.pollEvent(event)) {
base_event_handler(event, Page::EXIT, false, false, false);
if(event.type == sf::Event::Resized || event.type == sf::Event::GainedFocus) {
@@ -3399,7 +3385,7 @@ namespace QuickMedia {
if(event.key.code == sf::Keyboard::Up) {
bool item_changed = tabs[selected_tab].body->select_previous_item();
// Top hit
- if(!item_changed && !fetching_previous_messages_running) {
+ if(!item_changed && !fetching_previous_messages_running && tabs[selected_tab].type == ChatTabType::MESSAGES) {
gradient_inc = 0;
fetching_previous_messages_running = true;
previous_messages_future_room_id = current_room_id;
@@ -3418,22 +3404,16 @@ namespace QuickMedia {
body->clear_items();
body->reset_selected();
} else if(event.key.code == sf::Keyboard::Left) {
- tabs[selected_tab].body->filter_search_fuzzy("");
- tabs[selected_tab].body->clamp_selection();
tabs[selected_tab].body->clear_thumbnails();
selected_tab = std::max(0, selected_tab - 1);
- //chat_input.clear();
if(typing) {
fprintf(stderr, "Stopped typing\n");
typing = false;
typing_futures.push_back(std::async(typing_async_func, false, current_room_id));
}
} else if(event.key.code == sf::Keyboard::Right) {
- tabs[selected_tab].body->filter_search_fuzzy("");
- tabs[selected_tab].body->clamp_selection();
tabs[selected_tab].body->clear_thumbnails();
selected_tab = std::min((int)tabs.size() - 1, selected_tab + 1);
- //chat_input.clear();
if(typing) {
fprintf(stderr, "Stopped typing\n");
typing = false;
@@ -3441,7 +3421,7 @@ namespace QuickMedia {
}
}
- if(tabs[selected_tab].type == ChatTabType::MESSAGES && event.key.control && event.key.code == sf::Keyboard::I) {
+ if(tabs[selected_tab].type == ChatTabType::MESSAGES && event.key.control && event.key.code == sf::Keyboard::P) {
BodyItem *selected_item = tabs[selected_tab].body->get_selected();
if(!selected_item)
continue;
@@ -3458,19 +3438,37 @@ namespace QuickMedia {
}
}
- if(event.type == sf::Event::TextEntered) {
- chat_input.onTextEntered(event.text.unicode);
- // TODO: Also show typing event when ctrl+v pasting?
- if(tabs[selected_tab].type == ChatTabType::MESSAGES && event.text.unicode != 13) { // Return key
- start_typing_timer.restart();
- if(!typing) {
- fprintf(stderr, "Started typing\n");
- typing_futures.push_back(std::async(typing_async_func, true, current_room_id));
+ if(tabs[selected_tab].type == ChatTabType::MESSAGES) {
+ if(event.type == sf::Event::TextEntered) {
+ chat_input.onTextEntered(event.text.unicode);
+ // TODO: Also show typing event when ctrl+v pasting?
+ if(event.text.unicode != 13) { // Return key
+ start_typing_timer.restart();
+ if(!typing) {
+ fprintf(stderr, "Started typing\n");
+ typing_futures.push_back(std::async(typing_async_func, true, current_room_id));
+ }
+ typing = true;
+ }
+ }
+ chat_input.on_event(event);
+ } else if(tabs[selected_tab].type == ChatTabType::ROOMS && event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::Enter) {
+ BodyItem *selected_item = tabs[selected_tab].body->get_selected();
+ if(selected_item) {
+ current_room_id = selected_item->url;
+ selected_tab = MESSAGES_TAB_INDEX;
+ tabs[MESSAGES_TAB_INDEX].body->clear_items();
+
+ BodyItems new_items;
+ // TODO: Make asynchronous
+ if(matrix->get_all_synced_room_messages(current_room_id, new_items) == PluginResult::OK) {
+ tabs[MESSAGES_TAB_INDEX].body->append_items(std::move(new_items));
+ } else {
+ std::string err_msg = "Failed to get messages in room: " + current_room_id;
+ show_notification("QuickMedia", err_msg, Urgency::CRITICAL);
}
- typing = true;
}
}
- chat_input.on_event(event);
}
if(typing && start_typing_timer.getElapsedTime().asSeconds() >= typing_timeout_seconds) {
@@ -3508,9 +3506,11 @@ namespace QuickMedia {
body_padding_vertical = 10.0f;
}
- float search_bottom = chat_input.getBottomWithoutShadow();
+ float input_bottom = chat_input.getBottomWithoutShadow();
+ if(tabs[selected_tab].type != ChatTabType::MESSAGES)
+ input_bottom = 0.0f;
body_pos = sf::Vector2f(body_padding_horizontal, body_padding_vertical + tab_height);
- body_size = sf::Vector2f(body_width, window_size.y - search_bottom - body_padding_vertical - tab_height);
+ body_size = sf::Vector2f(body_width, window_size.y - input_bottom - body_padding_vertical - tab_height);
//get_body_dimensions(window_size, &chat_input, body_pos, body_size, true);
}
@@ -3547,7 +3547,7 @@ namespace QuickMedia {
sync_running = false;
}
- if(previous_messages_future.valid() && previous_messages_future.wait_for(std::chrono::seconds(0)) == std::future_status::ready) {
+ if(fetching_previous_messages_running && previous_messages_future.valid() && previous_messages_future.wait_for(std::chrono::seconds(0)) == std::future_status::ready) {
BodyItems new_body_items = previous_messages_future.get();
fprintf(stderr, "Finished fetching older messages, num new messages: %zu\n", new_body_items.size());
// Ignore finished fetch of messages if it happened in another room. When we navigate back to the room we will get the messages again
@@ -3564,7 +3564,8 @@ namespace QuickMedia {
window.clear(back_color);
- chat_input.draw(window, false);
+ if(tabs[selected_tab].type == ChatTabType::MESSAGES)
+ chat_input.draw(window, false);
const float width_per_tab = window_size.x / tabs.size();
tab_background.setSize(sf::Vector2f(std::floor(width_per_tab - tab_margin_x * 2.0f), tab_height));
@@ -3603,8 +3604,8 @@ namespace QuickMedia {
// TODO: Stop showing this when switching rooms, or have one for each room. Also add bottom one? for fetching new messages
if(fetching_previous_messages_running) {
- double progress = 0.5 + std::sin((double)(gradient_inc % 360) * 0.017453292519943295 - 1.5707963267948966*0.5) * 0.5;
- gradient_inc += 2;
+ double progress = 0.5 + std::sin(std::fmod(gradient_inc, 360.0) * 0.017453292519943295 - 1.5707963267948966*0.5) * 0.5;
+ gradient_inc += (frame_time_ms * 0.5);
sf::Color top_color = interpolate_colors(back_color, sf::Color(175, 180, 188), progress);
gradient_points[0].color = top_color;