diff options
Diffstat (limited to 'src/Body.cpp')
-rw-r--r-- | src/Body.cpp | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/src/Body.cpp b/src/Body.cpp index 718baee..5927831 100644 --- a/src/Body.cpp +++ b/src/Body.cpp @@ -24,7 +24,8 @@ namespace QuickMedia { dirty_author(false), thumbnail_is_local(false), title_color(sf::Color::White), - author_color(sf::Color::White) + author_color(sf::Color::White), + userdata(nullptr) { if(!_title.empty()) set_title(std::move(_title)); @@ -58,6 +59,7 @@ namespace QuickMedia { post_number = other.post_number; title_color = other.title_color; author_color = other.author_color; + userdata = other.userdata; } Body::Body(Program *program, sf::Font *font, sf::Font *bold_font, sf::Font *cjk_font) : @@ -233,6 +235,12 @@ namespace QuickMedia { return items[selected_item].get(); } + std::shared_ptr<BodyItem> Body::get_selected_shared() { + if(selected_item < 0 || selected_item >= (int)items.size() || !items[selected_item]->visible) + return nullptr; + return items[selected_item]; + } + void Body::clamp_selection() { int num_items = (int)items.size(); if(items.empty()) @@ -373,8 +381,7 @@ namespace QuickMedia { } void Body::draw(sf::RenderWindow &window, sf::Vector2f pos, sf::Vector2f size) { - Json::Value empty_object(Json::objectValue); - draw(window, pos, size, empty_object); + draw(window, pos, size, Json::nullValue); } // TODO: Use a render target for the whole body so all images can be put into one. @@ -502,9 +509,9 @@ namespace QuickMedia { continue; float item_height = get_item_height(item.get()); - prev_pos.y -= item_height + spacing_y; + prev_pos.y -= (item_height + spacing_y); - if(prev_pos.y + item_height <= 0.0f) + if(prev_pos.y + item_height + spacing_y < start_y) break; draw_item(window, item.get(), prev_pos, size, item_height, i, content_progress); @@ -521,10 +528,10 @@ namespace QuickMedia { float item_height = get_item_height(item.get()); - if(after_pos.y + item_height > start_y + size.y) + if((after_pos.y - start_y) + item_height + spacing_y > size.y) last_item_fully_visible = false; - if(after_pos.y >= start_y + size.y) + if(after_pos.y - start_y >= size.y) break; draw_item(window, item.get(), after_pos, size, item_height, i, content_progress); @@ -542,6 +549,14 @@ namespace QuickMedia { } } + void Body::draw_item(sf::RenderWindow &window, BodyItem *item, sf::Vector2f pos, sf::Vector2f size) { + //sf::Vector2u window_size = window.getSize(); + // glEnable(GL_SCISSOR_TEST); + //glScissor(pos.x, (int)window_size.y - (int)pos.y - (int)pos.y, size.x, size.y); + draw_item(window, item, pos, size, get_item_height(item) + spacing_y, -1, Json::nullValue); + //glDisable(GL_SCISSOR_TEST); + } + void Body::draw_item(sf::RenderWindow &window, BodyItem *item, const sf::Vector2f &pos, const sf::Vector2f &size, const float item_height, const int item_index, const Json::Value &content_progress) { // TODO: Instead of generating a new hash everytime to access textures, cache the hash of the thumbnail url std::shared_ptr<ThumbnailData> item_thumbnail; @@ -646,6 +661,9 @@ namespace QuickMedia { item->description_text->draw(window); } + if(!content_progress.isObject()) + return; + // TODO: Do the same for non-manga content. // TODO: Cache this instead of hash access every item every frame. const Json::Value &item_progress = content_progress[item->get_title()]; @@ -692,6 +710,10 @@ namespace QuickMedia { return item_height + padding_y * 2.0f; } + float Body::get_spacing_y() const { + return spacing_y; + } + //static bool Body::string_find_case_insensitive(const std::string &str, const std::string &substr) { auto it = std::search(str.begin(), str.end(), substr.begin(), substr.end(), |