From 4690ba0cc66338b1f00e08fb6054ee95c1c0dcc6 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 23 Sep 2020 23:45:21 +0200 Subject: Fallback to cjk font, change font to system noto sans --- src/Body.cpp | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) (limited to 'src/Body.cpp') diff --git a/src/Body.cpp b/src/Body.cpp index 3ebd11e..fd6ad07 100644 --- a/src/Body.cpp +++ b/src/Body.cpp @@ -15,7 +15,14 @@ const sf::Color front_color(32, 36, 42); const sf::Color back_color(33, 35, 37); namespace QuickMedia { - BodyItem::BodyItem(std::string _title): visible(true), dirty(false), dirty_description(false), thumbnail_is_local(false), title_color(sf::Color::White) { + BodyItem::BodyItem(std::string _title) : + visible(true), + dirty(false), + dirty_description(false), + dirty_author(false), + thumbnail_is_local(false), + title_color(sf::Color::White) + { set_title(std::move(_title)); } @@ -29,6 +36,7 @@ namespace QuickMedia { visible = other.visible; dirty = other.dirty; dirty_description = other.dirty_description; + dirty_author = other.dirty_author; thumbnail_is_local = other.thumbnail_is_local; if(other.title_text) title_text = std::make_unique(*other.title_text); @@ -43,9 +51,10 @@ namespace QuickMedia { title_color = other.title_color; } - Body::Body(Program *program, sf::Font *font, sf::Font *bold_font) : + Body::Body(Program *program, sf::Font *font, sf::Font *bold_font, sf::Font *cjk_font) : font(font), bold_font(bold_font), + cjk_font(cjk_font), progress_text("", *font, 14), author_text("", *bold_font, 16), replies_text("", *font, 14), @@ -355,26 +364,34 @@ namespace QuickMedia { thumbnail_it.second.referenced = false; } - // TODO: Change font size. Currently it doesn't work because it glitches out. Why does that happen?? for(auto &body_item : items) { if(body_item->dirty) { body_item->dirty = false; + // TODO: Find a way to optimize fromUtf8 + sf::String str = sf::String::fromUtf8(body_item->get_title().data(), body_item->get_title().data() + body_item->get_title().size()); if(body_item->title_text) - body_item->title_text->setString(body_item->get_title()); + body_item->title_text->setString(std::move(str)); else - body_item->title_text = std::make_unique(body_item->get_title(), font, 16, size.x - 50 - image_padding_x * 2.0f); + body_item->title_text = std::make_unique(std::move(str), font, cjk_font, 16, size.x - 50 - image_padding_x * 2.0f); body_item->title_text->setFillColor(body_item->title_color); body_item->title_text->updateGeometry(); } if(body_item->dirty_description) { - body_item->dirty_description = true; + body_item->dirty_description = false; + sf::String str = sf::String::fromUtf8(body_item->get_description().data(), body_item->get_description().data() + body_item->get_description().size()); if(body_item->description_text) - body_item->description_text->setString(body_item->get_description()); + body_item->description_text->setString(std::move(str)); else - body_item->description_text = std::make_unique(body_item->get_description(), font, 14, size.x - 50 - image_padding_x * 2.0f); + body_item->description_text = std::make_unique(std::move(str), font, cjk_font, 14, size.x - 50 - image_padding_x * 2.0f); body_item->description_text->updateGeometry(); } + + if(body_item->dirty_author) { + body_item->dirty_author = false; + sf::String str = sf::String::fromUtf8(body_item->get_author().data(), body_item->get_author().data() + body_item->get_author().size()); + author_text.setString(std::move(str)); + } } // Find the starting row that can be drawn to make selected row visible as well @@ -388,7 +405,7 @@ namespace QuickMedia { if(!item->get_title().empty()) { item_height += item->title_text->getHeight(); } - if(!item->author.empty()) { + if(!item->get_author().empty()) { item_height += author_text.getCharacterSize() + 2.0f; } if(item->description_text) { @@ -437,7 +454,7 @@ namespace QuickMedia { if(!item->get_title().empty()) { item_height += item->title_text->getHeight(); } - if(!item->author.empty()) { + if(!item->get_author().empty()) { item_height += author_text.getCharacterSize() + 2.0f; } if(item->description_text) { @@ -496,9 +513,7 @@ namespace QuickMedia { } } - if(!item->author.empty()) { - // TODO: Remove this call, should not be called every frame - author_text.setString(item->author); + if(!item->get_author().empty()) { author_text.setPosition(std::floor(item_pos.x + text_offset_x), std::floor(item_pos.y + padding_y)); window.draw(author_text); -- cgit v1.2.3