From a59acdce5e21a65dd06d8d1d17359bd3159f518c Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 22 Mar 2021 13:21:29 +0100 Subject: Matrix: do not open url when posting a message with an url --- include/Text.hpp | 1 - src/QuickMedia.cpp | 14 +++++++------- src/Text.cpp | 29 +++++++++++++---------------- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/include/Text.hpp b/include/Text.hpp index 135a89c..3981f13 100644 --- a/include/Text.hpp +++ b/include/Text.hpp @@ -143,7 +143,6 @@ namespace QuickMedia float maxWidth; sf::Vector2f position; sf::Color color; - sf::Color urlColor; bool dirty; bool dirtyText; bool dirtyCaret; diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index e18aa9a..85c3241 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -3650,10 +3650,14 @@ namespace QuickMedia { tabs[MESSAGES_TAB_INDEX].body->select_last_item(); } }; + + bool frame_skip_text_entry = false; - chat_input.on_submit_callback = [this, &tabs, &me, &chat_input, &selected_tab, ¤t_room, &new_page, &chat_state, &pending_sent_replies, ¤tly_operating_on_item, &post_task_queue, &process_reactions, &find_body_item_by_event_id](std::string text) mutable { + chat_input.on_submit_callback = [this, &frame_skip_text_entry, &tabs, &me, &chat_input, &selected_tab, ¤t_room, &new_page, &chat_state, &pending_sent_replies, ¤tly_operating_on_item, &post_task_queue, &process_reactions, &find_body_item_by_event_id](std::string text) mutable { if(!current_room) return false; + + frame_skip_text_entry = true; if(selected_tab == MESSAGES_TAB_INDEX) { if(text.empty()) @@ -3702,7 +3706,7 @@ namespace QuickMedia { message->type = MessageType::TEXT; message->timestamp = time(NULL) * 1000; - const sf::Color provisional_message_color(171, 175, 180); + const sf::Color provisional_message_color(255, 255, 255, 180); int num_items = tabs[MESSAGES_TAB_INDEX].body->items.size(); bool scroll_to_end = num_items == 0; @@ -4305,7 +4309,6 @@ namespace QuickMedia { } float tab_shade_height = 0.0f; - bool frame_skip_text_entry = false; room_tabs[room_selected_tab].body->body_item_select_callback = [&move_room](BodyItem *body_item) { move_room = true; @@ -4439,7 +4442,7 @@ namespace QuickMedia { goto chat_page_end; } - if((selected_tab == MESSAGES_TAB_INDEX || selected_tab == PINNED_TAB_INDEX) && event.key.code == sf::Keyboard::Enter) { + if((selected_tab == MESSAGES_TAB_INDEX || selected_tab == PINNED_TAB_INDEX) && event.key.code == sf::Keyboard::Enter && !frame_skip_text_entry) { BodyItem *selected = tabs[selected_tab].body->get_selected(); if(selected) { if(!display_url_or_image(selected)) @@ -5054,17 +5057,14 @@ namespace QuickMedia { exit(exit_code); auto rooms_body = create_body(); - rooms_body->thumbnail_mask_shader = &circle_mask_shader; auto matrix_rooms_page_search_bar = create_search_bar("Search...", SEARCH_DELAY_FILTER); auto matrix_rooms_page = std::make_unique(this, rooms_body.get(), "All rooms", nullptr, matrix_rooms_page_search_bar.get()); auto rooms_tags_body = create_body(); - rooms_tags_body->thumbnail_mask_shader = &circle_mask_shader; auto matrix_rooms_tage_page_search_bar = create_search_bar("Search...", SEARCH_DELAY_FILTER); auto matrix_rooms_tag_page = std::make_unique(this, rooms_tags_body.get(), matrix_rooms_tage_page_search_bar.get()); auto invites_body = create_body(); - invites_body->thumbnail_mask_shader = &circle_mask_shader; auto matrix_invites_page_search_bar = create_search_bar("Search...", SEARCH_DELAY_FILTER); auto matrix_invites_page = std::make_unique(this, matrix, invites_body.get(), matrix_invites_page_search_bar.get()); diff --git a/src/Text.cpp b/src/Text.cpp index ee6bd55..171bd70 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -13,7 +13,6 @@ namespace QuickMedia { static const float TAB_WIDTH = 4.0f; - static const sf::Color URL_COLOR(15, 192, 252); static const float WORD_WRAP_MIN_SIZE = 80.0f; size_t StringViewUtf32::find(const StringViewUtf32 &other, size_t offset) const { @@ -34,7 +33,6 @@ namespace QuickMedia characterSize(_characterSize), maxWidth(_maxWidth), color(sf::Color::White), - urlColor(URL_COLOR), dirty(true), dirtyText(false), dirtyCaret(false), @@ -359,6 +357,7 @@ namespace QuickMedia } else if(textElement.text_type == TextElement::TextType::EMOJI) { vertices_index = 2; textElement.position = glyphPos; + sf::Color emoji_color(255, 255, 255, color.a); for(size_t i = 0; i < textElement.text.size; ++i) { sf::Uint32 codePoint = textElement.text[i]; @@ -376,12 +375,12 @@ namespace QuickMedia sf::Vector2f textureBottomLeft(emoji_rec.x, emoji_rec.y + emoji_rec.height); sf::Vector2f textureBottomRight(emoji_rec.x + emoji_rec.width, emoji_rec.y + emoji_rec.height); - vertices[vertices_index].append({ vertexTopRight, sf::Color::White, textureTopRight }); - vertices[vertices_index].append({ vertexTopLeft, sf::Color::White, textureTopLeft }); - vertices[vertices_index].append({ vertexBottomLeft, sf::Color::White, textureBottomLeft }); - vertices[vertices_index].append({ vertexBottomLeft, sf::Color::White, textureBottomLeft }); - vertices[vertices_index].append({ vertexBottomRight, sf::Color::White, textureBottomRight }); - vertices[vertices_index].append({ vertexTopRight, sf::Color::White, textureTopRight }); + vertices[vertices_index].append({ vertexTopRight, emoji_color, textureTopRight }); + vertices[vertices_index].append({ vertexTopLeft, emoji_color, textureTopLeft }); + vertices[vertices_index].append({ vertexBottomLeft, emoji_color, textureBottomLeft }); + vertices[vertices_index].append({ vertexBottomLeft, emoji_color, textureBottomLeft }); + vertices[vertices_index].append({ vertexBottomRight, emoji_color, textureBottomRight }); + vertices[vertices_index].append({ vertexTopRight, emoji_color, textureTopRight }); glyphPos.x += std::floor(emoji_rec.width * get_ui_scale()) + characterSpacing; vertices_linear.push_back({vertices_index, vertexStart, 0, codePoint}); @@ -474,14 +473,12 @@ namespace QuickMedia sf::Vector2f textureBottomLeft(glyph.textureRect.left, glyph.textureRect.top + glyph.textureRect.height); sf::Vector2f textureBottomRight(glyph.textureRect.left + glyph.textureRect.width, glyph.textureRect.top + glyph.textureRect.height); - sf::Color fontColor = (textElement.type == TextElement::Type::TEXT ? color : urlColor); - - vertices[vertices_index].append({ vertexTopRight, fontColor, textureTopRight }); - vertices[vertices_index].append({ vertexTopLeft, fontColor, textureTopLeft }); - vertices[vertices_index].append({ vertexBottomLeft, fontColor, textureBottomLeft }); - vertices[vertices_index].append({ vertexBottomLeft, fontColor, textureBottomLeft }); - vertices[vertices_index].append({ vertexBottomRight, fontColor, textureBottomRight }); - vertices[vertices_index].append({ vertexTopRight, fontColor, textureTopRight }); + vertices[vertices_index].append({ vertexTopRight, color, textureTopRight }); + vertices[vertices_index].append({ vertexTopLeft, color, textureTopLeft }); + vertices[vertices_index].append({ vertexBottomLeft, color, textureBottomLeft }); + vertices[vertices_index].append({ vertexBottomLeft, color, textureBottomLeft }); + vertices[vertices_index].append({ vertexBottomRight, color, textureBottomRight }); + vertices[vertices_index].append({ vertexTopRight, color, textureTopRight }); glyphPos.x += glyph.advance + characterSpacing; vertices_linear.push_back({vertices_index, vertexStart, 0, codePoint}); -- cgit v1.2.3