aboutsummaryrefslogtreecommitdiff
path: root/src/QuickMedia.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r--src/QuickMedia.cpp156
1 files changed, 0 insertions, 156 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 5f65fdd..a867255 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -12,162 +12,6 @@ const sf::Color front_color(43, 45, 47);
const sf::Color back_color(33, 35, 37);
namespace QuickMedia {
- class Body {
- public:
- Body(sf::Font &font) : title_text("", font, 14), selected_item(0) {
- title_text.setFillColor(sf::Color::White);
- }
-
- void add_item(std::unique_ptr<BodyItem> item) {
- items.push_back(std::move(item));
- }
-
- // Select previous item, ignoring invisible items
- void select_previous_item() {
- if(items.empty())
- return;
-
- int num_items = (int)items.size();
- for(int i = 0; i < num_items; ++i) {
- --selected_item;
- if(selected_item < 0)
- selected_item = num_items - 1;
- if(items[selected_item]->visible)
- return;
- }
- }
-
- // Select next item, ignoring invisible items
- void select_next_item() {
- if(items.empty())
- return;
-
- int num_items = (int)items.size();
- for(int i = 0; i < num_items; ++i) {
- ++selected_item;
- if(selected_item == num_items)
- selected_item = 0;
- if(items[selected_item]->visible)
- return;
- }
- }
-
- void reset_selected() {
- selected_item = 0;
- }
-
- void clear_items() {
- items.clear();
- }
-
- BodyItem* get_selected() const {
- if(items.empty() || !items[selected_item]->visible)
- return nullptr;
- return items[selected_item].get();
- }
-
- void clamp_selection() {
- int num_items = (int)items.size();
- if(items.empty())
- return;
-
- if(selected_item < 0)
- selected_item = 0;
- else if(selected_item >= num_items)
- selected_item = num_items - 1;
-
- for(int i = selected_item; i >= 0; --i) {
- if(items[i]->visible) {
- selected_item = i;
- return;
- }
- }
-
- for(int i = selected_item; i < num_items; ++i) {
- if(items[i]->visible) {
- selected_item = i;
- return;
- }
- }
- }
-
- void draw(sf::RenderWindow &window, sf::Vector2f pos, sf::Vector2f size) {
- const float font_height = title_text.getCharacterSize() + 8.0f;
- const float image_height = 50.0f;
-
- sf::RectangleShape image(sf::Vector2f(50, image_height));
- image.setFillColor(sf::Color::White);
-
- sf::RectangleShape item_background;
- item_background.setFillColor(front_color);
- item_background.setOutlineThickness(1.0f);
- item_background.setOutlineColor(sf::Color(63, 65, 67));
-
- sf::RectangleShape selected_border(sf::Vector2f(5.0f, 50));
- selected_border.setFillColor(sf::Color::Red);
-
- int i = 0;
- for(const auto &item : items) {
- if(!item->visible) {
- ++i;
- continue;
- }
-
- sf::Vector2f item_pos = pos;
- if(i == selected_item) {
- selected_border.setPosition(pos);
- window.draw(selected_border);
- item_pos.x += selected_border.getSize().x;
- item_background.setFillColor(front_color);
- } else {
- item_background.setFillColor(sf::Color(38, 40, 42));
- }
-
- item_background.setPosition(item_pos);
- item_background.setSize(sf::Vector2f(size.x, 50));
- window.draw(item_background);
-
- image.setPosition(item_pos);
- window.draw(image);
-
- title_text.setString(item->title);
- title_text.setPosition(item_pos.x + 50 + 10, item_pos.y);
- window.draw(title_text);
-
-
- pos.y += 50 + 10;
- ++i;
- }
- }
-
- static bool string_find_case_insensitive(const std::string &str, const std::string &substr) {
- auto it = std::search(str.begin(), str.end(), substr.begin(), substr.end(),
- [](char c1, char c2) {
- return std::toupper(c1) == std::toupper(c2);
- });
- return it != str.end();
- }
-
- // TODO: Make this actually fuzzy... Right now it's just a case insensitive string find.
- // TODO: Highlight the part of the text that matches the search
- void filter_search_fuzzy(const std::string &text) {
- if(text.empty()) {
- for(auto &item : items) {
- item->visible = true;
- }
- return;
- }
-
- for(auto &item : items) {
- item->visible = string_find_case_insensitive(item->title, text);
- }
- }
-
- sf::Text title_text;
- int selected_item;
- std::vector<std::unique_ptr<BodyItem>> items;
- };
-
Program::Program() :
window(sf::VideoMode(800, 600), "QuickMedia"),
window_size(800, 600),