aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-09-25 21:40:22 +0200
committerdec05eba <dec05eba@protonmail.com>2020-09-25 22:27:15 +0200
commitd5d462f555ef9d7ce7e001aca5586c19b4d9edc8 (patch)
tree8fa80cce39f3df27513ff16815bb7b5d11814d8e
parenteac2ace1c14c1ae0564d757b26a359c6bd4b754a (diff)
Matrix: add display name colors depending on user id
-rw-r--r--TODO2
-rw-r--r--include/Body.hpp11
-rw-r--r--plugins/Matrix.hpp1
-rw-r--r--src/Body.cpp8
-rw-r--r--src/QuickMedia.cpp4
-rw-r--r--src/plugins/Matrix.cpp15
6 files changed, 37 insertions, 4 deletions
diff --git a/TODO b/TODO
index dbd9e25..ffef873 100644
--- a/TODO
+++ b/TODO
@@ -25,3 +25,5 @@ Fix some japanese fonts not rendering (full width alphanumeric?).
Also add support for full chinese and korean range.
Resize text vertex arrays to 0 when not visible on screen to reduce memory usage. Text already does this but its done incorrectly (copied from dchat codebase). (Is this really necessary?).
Speed up thumbnail creating (image resizing).
+Extract thumbnail from images that are being downloaded, while its downloading and show that while the full image is downloading (upscaled, or with blurhash).
+Use one special thread to load cached files. Right now if there are multiple images on the screen and 1 needs to download while the others are cached, then the cached images wont load until that 1 image has downloaded. \ No newline at end of file
diff --git a/include/Body.hpp b/include/Body.hpp
index 79bece6..4987735 100644
--- a/include/Body.hpp
+++ b/include/Body.hpp
@@ -17,6 +17,8 @@ namespace QuickMedia {
BodyItem(const BodyItem &other);
void set_title(std::string new_title) {
+ if(title.empty() && new_title.empty())
+ return;
title = std::move(new_title);
dirty = true;
}
@@ -27,6 +29,8 @@ namespace QuickMedia {
}
void set_description(std::string new_description) {
+ if(description.empty() && new_description.empty())
+ return;
description = std::move(new_description);
dirty_description = true;
}
@@ -36,8 +40,10 @@ namespace QuickMedia {
dirty_description = true;
}
- void set_author(std::string str) {
- author = std::move(str);
+ void set_author(std::string new_author) {
+ if(author.empty() && new_author.empty())
+ return;
+ author = std::move(new_author);
dirty_author = true;
}
@@ -61,6 +67,7 @@ namespace QuickMedia {
std::vector<size_t> replies;
std::string post_number;
sf::Color title_color;
+ sf::Color author_color;
private:
std::string title;
std::string description;
diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp
index 396fc17..3382270 100644
--- a/plugins/Matrix.hpp
+++ b/plugins/Matrix.hpp
@@ -8,6 +8,7 @@ namespace QuickMedia {
struct UserInfo {
std::string display_name;
std::string avatar_url;
+ sf::Color display_name_color;
};
enum class MessageType {
diff --git a/src/Body.cpp b/src/Body.cpp
index f97d611..2bd5499 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -21,9 +21,11 @@ namespace QuickMedia {
dirty_description(false),
dirty_author(false),
thumbnail_is_local(false),
- title_color(sf::Color::White)
+ title_color(sf::Color::White),
+ author_color(sf::Color::White)
{
- set_title(std::move(_title));
+ if(!_title.empty())
+ set_title(std::move(_title));
}
BodyItem::BodyItem(const BodyItem &other) {
@@ -53,6 +55,7 @@ namespace QuickMedia {
replies = other.replies;
post_number = other.post_number;
title_color = other.title_color;
+ author_color = other.author_color;
}
Body::Body(Program *program, sf::Font *font, sf::Font *bold_font, sf::Font *cjk_font) :
@@ -405,6 +408,7 @@ namespace QuickMedia {
body_item->author_text->setString(std::move(str));
else
body_item->author_text = std::make_unique<Text>(std::move(str), bold_font, cjk_font, 14, size.x - 50 - image_padding_x * 2.0f);
+ body_item->author_text->setFillColor(body_item->author_color);
body_item->author_text->updateGeometry();
}
}
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index c701c14..1039ca7 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -3195,6 +3195,8 @@ namespace QuickMedia {
messages_tab.body->draw_thumbnails = true;
messages_tab.body->thumbnail_resize_target_size.x = 600;
messages_tab.body->thumbnail_resize_target_size.y = 337;
+ messages_tab.body->thumbnail_fallback_size.x = 32;
+ messages_tab.body->thumbnail_fallback_size.y = 32;
//messages_tab.body->line_seperator_color = sf::Color::Transparent;
messages_tab.text = sf::Text("Messages", *font, tab_text_size);
tabs.push_back(std::move(messages_tab));
@@ -3204,6 +3206,8 @@ namespace QuickMedia {
rooms_tab.body = std::make_unique<Body>(this, font.get(), bold_font.get(), cjk_font.get());
rooms_tab.body->draw_thumbnails = true;
//rooms_tab.body->line_seperator_color = sf::Color::Transparent;
+ rooms_tab.body->thumbnail_fallback_size.x = 32;
+ rooms_tab.body->thumbnail_fallback_size.y = 32;
rooms_tab.text = sf::Text("Rooms", *font, tab_text_size);
tabs.push_back(std::move(rooms_tab));
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 529d42a..a28aedc 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -182,6 +182,7 @@ namespace QuickMedia {
body_item->thumbnail_url = user_info.avatar_url;
// TODO: Show image thumbnail inline instead of url to image
body_item->url = messages[i].url;
+ body_item->author_color = user_info.display_name_color;
result_items.push_back(std::move(body_item));
prev_user_id = messages[i].user_id;
}
@@ -327,6 +328,19 @@ namespace QuickMedia {
return PluginResult::OK;
}
+ static sf::Color user_id_to_color(const std::string &user_id) {
+ uint32_t color = 2166136261;
+ for(unsigned char c : user_id) {
+ color = (color * 16777619) ^ c;
+ }
+ sf::Color result = (sf::Color)color;
+ result.r = 64 + std::max(0, (int)result.r - 64);
+ result.g = 64 + std::max(0, (int)result.g - 64);
+ result.b = 64 + std::max(0, (int)result.b - 64);
+ result.a = 255;
+ return result;
+ }
+
void Matrix::events_add_user_info(const Json::Value &events_json, RoomData *room_data) {
if(!events_json.isArray())
return;
@@ -371,6 +385,7 @@ namespace QuickMedia {
// TODO: What if the user hasn't selected an avatar?
user_info.avatar_url = homeserver + "/_matrix/media/r0/thumbnail/" + user_info.avatar_url + "?width=32&height=32&method=crop";
user_info.display_name = display_name_json.asString();
+ user_info.display_name_color = user_id_to_color(sender_json_str);
room_data->user_info.push_back(std::move(user_info));
room_data->user_info_by_user_id.insert(std::make_pair(sender_json_str, room_data->user_info.size() - 1));
}