diff --git a/.gitignore b/.gitignore index ecbbe4b..8cc4ac4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ /cmake-build-debug/ +/.idea/ CMakeLists.txt mpst_full_data.csv - diff --git a/src/app/Movie/Movie.cpp b/src/app/Movie/Movie.cpp deleted file mode 100644 index bd998c5..0000000 --- a/src/app/Movie/Movie.cpp +++ /dev/null @@ -1,20 +0,0 @@ - -#include "Movie.h" - - -const std::string &Movie::getSynopsis() const { - return synopsis; -} - -const std::unordered_set &Movie::getTags() const { - return tags; -} - -const std::string &Movie::getTitle() const { - return title; -} - -Movie::Movie(const std::string &title, const std::string &synopsis, const std::string &tags){ - this->title = title; - this->title = synopsis; -} diff --git a/src/app/Movie/Movie.h b/src/app/Movie/Movie.h deleted file mode 100644 index f759948..0000000 --- a/src/app/Movie/Movie.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef PROGRA3_MOVIE_H -#define PROGRA3_MOVIE_H -#include -#include - -class Movie { - std::string title; - std::string synopsis; - std::unordered_set tags; -public: - const std::string &getTitle() const; - const std::string &getSynopsis() const; - const std::unordered_set &getTags() const; - Movie(const std::string &title, const std::string &synopsis, const std::string &tags); - -}; - - -#endif //PROGRA3_MOVIE_H diff --git a/src/app/Movie/Review.cpp b/src/app/Movie/Review.cpp deleted file mode 100644 index 99945bc..0000000 --- a/src/app/Movie/Review.cpp +++ /dev/null @@ -1,5 +0,0 @@ -// -// Created by Badi on 7/13/2024. -// - -#include "Review.h" diff --git a/src/app/Movie/Review.h b/src/app/Movie/Review.h deleted file mode 100644 index a5eeff5..0000000 --- a/src/app/Movie/Review.h +++ /dev/null @@ -1,29 +0,0 @@ -// -// Created by Badi on 7/13/2024. -// - -#ifndef PROGRA3FINALPROJECT_REVIEW_H -#define PROGRA3FINALPROJECT_REVIEW_H - -#include -#include - -class Review { - -private: - std::string username; - std::vector comment; - float score; - int review_id; -public: - Review() = default; - Review(std::string, std::vector, float); - void getInfoBlock(); - std::string getUsername() {return username;}; - std::vector getComment() {return comment;}; - float getScore() {return score;}; - int getReviewId() {return review_id;}; -}; - - -#endif //PROGRA3FINALPROJECT_REVIEW_H diff --git a/src/app/Movie/SearchEngine/SearchEngine.cpp b/src/app/Movie/SearchEngine/SearchEngine.cpp deleted file mode 100644 index 672c169..0000000 --- a/src/app/Movie/SearchEngine/SearchEngine.cpp +++ /dev/null @@ -1,5 +0,0 @@ -// -// Created by flauta on 13/07/2024. -// - -#include "SearchEngine.h" diff --git a/src/app/Movie/SearchEngine/SearchEngine.h b/src/app/Movie/SearchEngine/SearchEngine.h deleted file mode 100644 index f91f313..0000000 --- a/src/app/Movie/SearchEngine/SearchEngine.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef PROGRA3_SEARCHENGINE_H -#define PROGRA3_SEARCHENGINE_H -#include -#include - -//Builder aplicar aca -class SearchEngine { - std::string query; - std::unordered_set tags; -}; - - -#endif //PROGRA3_SEARCHENGINE_H diff --git a/src/app/SearchEngine/SearchEngine.cpp b/src/app/SearchEngine/SearchEngine.cpp deleted file mode 100644 index 672c169..0000000 --- a/src/app/SearchEngine/SearchEngine.cpp +++ /dev/null @@ -1,5 +0,0 @@ -// -// Created by flauta on 13/07/2024. -// - -#include "SearchEngine.h" diff --git a/src/app/SearchEngine/SearchEngine.h b/src/app/SearchEngine/SearchEngine.h deleted file mode 100644 index f91f313..0000000 --- a/src/app/SearchEngine/SearchEngine.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef PROGRA3_SEARCHENGINE_H -#define PROGRA3_SEARCHENGINE_H -#include -#include - -//Builder aplicar aca -class SearchEngine { - std::string query; - std::unordered_set tags; -}; - - -#endif //PROGRA3_SEARCHENGINE_H diff --git a/src/app/SearchEngine/SearchEngineBuilder.cpp b/src/app/SearchEngine/SearchEngineBuilder.cpp deleted file mode 100644 index 66f3d8a..0000000 --- a/src/app/SearchEngine/SearchEngineBuilder.cpp +++ /dev/null @@ -1,30 +0,0 @@ - -#include "SearchEngineBuilder.h" -#include -#include - - - -SearchEngineBuilder &SearchEngineBuilder::Query(const std::string &query) { - searchEngine_->query = query; - return *this; -} - -SearchEngineBuilder &SearchEngineBuilder::Tags(const std::string &tags) { - std::stringstream ss(tags); - std::string t; - char delimiter = ','; - while (getline(ss, t, delimiter)) { - searchEngine_->tags.insert(t); - } - return *this; -} - -SearchEngine *SearchEngineBuilder::build() { - if(searchEngine_->query.empty() and searchEngine_->tags.empty()){ - throw std::runtime_error("Query is empty"); - } - return searchEngine_; -} - - diff --git a/src/app/SearchEngine/SearchEngineBuilder.h b/src/app/SearchEngine/SearchEngineBuilder.h deleted file mode 100644 index 4494945..0000000 --- a/src/app/SearchEngine/SearchEngineBuilder.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef PROGRA3_SEARCHENGINEBUILDER_H -#define PROGRA3_SEARCHENGINEBUILDER_H -#include "SearchEngine.h" - -class SearchEngineBuilder { -private: - SearchEngine* searchEngine_ = new SearchEngine(); -public: - SearchEngineBuilder& Query(const std::string& query); - SearchEngineBuilder& Tags(const std::string& tags); - SearchEngine* build(); - -}; - - -#endif //PROGRA3_SEARCHENGINEBUILDER_H diff --git a/src/app/TriePrefix/TrieNode.cpp b/src/app/TriePrefix/TrieNode.cpp deleted file mode 100644 index c860f0a..0000000 --- a/src/app/TriePrefix/TrieNode.cpp +++ /dev/null @@ -1,86 +0,0 @@ -// -// Created by jorughen on 7/13/24. -// - -#include "TrieNode.h" - -TrieNode::TrieNode() { - // constructor - // initialize the wordEnd variable with false - // initialize every index of childNode array with - // NULL - wordEnd = false; - - for (int i = 0; i < 26; i++) { - childNode[i] = nullptr; - } -} - -void insert_key(TrieNode* root, string& key) -{ - // Initialize the currentNode pointer - // with the root node - TrieNode* currentNode = root; - - // Iterate across the length of the string - for (int i = 0; i < key.length(); i++){ - char c = key[i]; - // Check if the node exist for the current - // character in the Trie. - if (isdigit(c)){ - c -= '0'+27; - } - else{ - c -= 'a'; - } - - if (currentNode->childNode[c] == nullptr) { - - // If node for current character does not exist - // then make a new node - TrieNode* newNode = new TrieNode(); - - // Keep the reference for the newly created - // node. - currentNode->childNode[c] = newNode; - } - - // Now, move the current node pointer to the newly - // created node. - currentNode = currentNode->childNode[c]; - } - - // Increment the wordEndCount for the last currentNode - // pointer this implies that there is a string ending at - // currentNode. - currentNode->wordEnd = true; - - - -} - -bool search_key(TrieNode* root, string& key) -{ - // Initialize the currentNode pointer - // with the root node - TrieNode* currentNode = root; - - // Iterate across the length of the string - for (auto c : key) { - - // Check if the node exist for the current - // character in the Trie. - if (currentNode->childNode[c - 'a'] == nullptr) { - - // Given word does not exist in Trie - return false; - } - - // Move the currentNode pointer to the already - // existing node for current character. - currentNode = currentNode->childNode[c - 'a']; - } - - return currentNode->wordEnd; -} - diff --git a/src/app/TriePrefix/TrieNode.h b/src/app/TriePrefix/TrieNode.h deleted file mode 100644 index 03af957..0000000 --- a/src/app/TriePrefix/TrieNode.h +++ /dev/null @@ -1,28 +0,0 @@ -// -// Created by jorughen on 7/13/24. -// - -#ifndef PROGRA3_TRIENODE_H -#define PROGRA3_TRIENODE_H - -#include -using namespace std; - -struct TrieNode { - - // pointer array for child nodes of each node - TrieNode* childNode[36]; - - // Used for indicating ending of string - bool wordEnd; - - TrieNode(); - -}; - - - -void insert_key(TrieNode* root, string& key); -bool search_key(TrieNode* root, string& key); - -#endif //PROGRA3_TRIENODE_H diff --git a/src/beta_modules/BST_beta.cpp b/src/beta_modules/BST_beta.cpp deleted file mode 100644 index ad170c6..0000000 --- a/src/beta_modules/BST_beta.cpp +++ /dev/null @@ -1,102 +0,0 @@ -// -// Created by Badi on 7/13/2024. -// - -#include -#include -#include -#include -#include -#include - -// Define a structure for the BST node -struct BSTNode { - std::string key; // Change this to the appropriate data type for your key - std::vector data; // Store the rest of the CSV data in a vector - BSTNode* left; - BSTNode* right; - - BSTNode(std::string k, const std::vector& d) : key(std::move(k)), data(d), left(nullptr), right(nullptr) {} -}; - -// Function to insert a new node into the BST -BSTNode* insert(BSTNode* root, const std::string& key, const std::vector& data) { - if (root == nullptr) { - return new BSTNode(key, data); - } - if (key < root->key) { - root->left = insert(root->left, key, data); - } else { - root->right = insert(root->right, key, data); - } - return root; -} - -// Function to search for a key in the BST -BSTNode* search(BSTNode* root, const std::string& key) { - if (root == nullptr || root->key == key) { - return root; - } - if (key < root->key) { - return search(root->left, key); - } - return search(root->right, key); -} - -// Function to read the CSV file and populate the BST -BSTNode* readCSVAndPopulateBST(const std::string& filename) { - std::ifstream file(filename); - std::string line; - BSTNode* root = nullptr; - - if (file.is_open()) { - // Read the header line - std::getline(file, line); - - // Read the rest of the lines - while (std::getline(file, line)) { - std::stringstream ss(line); - std::string item; - std::vector data; - - while (std::getline(ss, item, ',')) { - data.push_back(item); - } - - // Assuming the key is the first column in the CSV - std::string key = data[0]; - root = insert(root, key, data); - } - file.close(); - } else { - std::cerr << "Unable to open file"; - } - - return root; -} - -int main() { - // Path to the CSV file - std::string filename = "mpst_full_data.csv"; - - // Populate the BST - BSTNode* root = readCSVAndPopulateBST(filename); - - // Search for a specific key (example) - std::string searchKey = "example_key"; // Replace with an actual key from your CSV - BSTNode* result = search(root, searchKey); - - if (result != nullptr) { - std::cout << "Found key: " << result->key << std::endl; - // Print the associated data - for (const auto& item : result->data) { - std::cout << item << " "; - } - std::cout << std::endl; - } else { - std::cout << "Key not found" << std::endl; - } - - return 0; -} - diff --git a/src/interface/Animation/AnimationManager.cpp b/src/interface/Animation/AnimationManager.cpp new file mode 100644 index 0000000..49c419a --- /dev/null +++ b/src/interface/Animation/AnimationManager.cpp @@ -0,0 +1,307 @@ +#include "AnimationManager.h" + +volatile sig_atomic_t AnimationManager::resized = 0; +std::function AnimationManager::current_animation_func; +float AnimationManager::loading_progress = 0.0f; +int AnimationManager::loading_duration = 0; + +const std::vector AnimationManager::ascii_art_large = { + " _____ _ _ _ _ ", + " / ____| | | \\ | | | | ", + " | | | |___ __ ___ _____ ___| \\| | ___| |_ ", + " | | | __ \\ / _` \\ \\ / / _ \\_ / . ` |/ _ \\ __|", + " | |____| | | | (_| |\\ V / __// /| |\\ | __/ |_ ", + " \\_____|_| |_|\\__,_| \\_/ \\___/___|_| \\_|\\___|\\__|", + " ", + " " +}; + +const std::vector AnimationManager::ascii_art_medium = { + " _____ _ _ _ _ ", + " / ____| | | | | | | |", + "| | | |__ __ _ ___| | __| |_| |", + "| | | '_ \\ / _` |/ __| |/ / __| __|", + "| |____| | | | (_| | (__| <| |_| |_ ", + " \\_____|_| |_|\\__,_|\\___|_|\\_\\\\__|\\__|", + " ", + " " +}; + +const std::vector AnimationManager::ascii_art_small = { + " _____ _", + " / __ \\ | |", + "| / \\/ ___| |_", + "| | / _ \\ __|", + "| \\__/\\ __/ |_", + " \\____/\\___|\\__|", + " ", + " " +}; + +const std::vector AnimationManager::ascii_art_text = { + "ChavezNet" +}; + +AnimationManager& AnimationManager::getInstance() { + static AnimationManager instance; + return instance; +} + +int AnimationManager::getAsciiArtHeight(const std::vector& asciiArt) const { + return static_cast(asciiArt.size()); +} + +int AnimationManager::getAsciiArtWidth(const std::vector& asciiArt) const { + if (asciiArt.empty()) return 0; + return static_cast(asciiArt[0].size()); +} + +const std::vector& AnimationManager::getAsciiArtLarge() const { + return ascii_art_large; +} + +const std::vector& AnimationManager::getAsciiArtMedium() const { + return ascii_art_medium; +} + +const std::vector& AnimationManager::getAsciiArtSmall() const { + return ascii_art_small; +} + +const std::vector& AnimationManager::getAsciiArtText() const { + return ascii_art_text; +} + +void resizeHandler(int) { + AnimationManager::resized = 1; + endwin(); + refresh(); + clear(); + if (AnimationManager::current_animation_func) { + AnimationManager::current_animation_func(); + } +} + +void AnimationManager::handleResizeDuringAnimation(const std::function& animationFunc) const { + current_animation_func = animationFunc; + auto old_handler = signal(SIGWINCH, resizeHandler); + + while (true) { + AnimationManager::resized = 0; + animationFunc(); + if (!AnimationManager::resized) break; // Salir del bucle si no ha habido redimensión + } + + signal(SIGWINCH, old_handler); +} + +void AnimationManager::drawStaticAsciiArtLarge() const { + const std::vector& ascii_art = ascii_art_large; + attron(COLOR_PAIR(3) | A_BOLD); // Color celeste después de la animación + for (int i = 0; i < static_cast(ascii_art.size()); ++i) { + mvprintw(i + 1, (COLS - static_cast(ascii_art.at(0).size())) / 2, ascii_art.at(i).c_str()); + } + attroff(COLOR_PAIR(3) | A_BOLD); + refresh(); +} + +void AnimationManager::drawStaticAsciiArtMedium() const { + const std::vector& ascii_art = ascii_art_medium; + attron(COLOR_PAIR(3) | A_BOLD); // Color celeste después de la animación + for (int i = 0; i < static_cast(ascii_art.size()); ++i) { + mvprintw(i + 1, (COLS - static_cast(ascii_art.at(0).size())) / 2, ascii_art.at(i).c_str()); + } + attroff(COLOR_PAIR(3) | A_BOLD); + refresh(); +} + +void AnimationManager::drawStaticAsciiArtSmall() const { + const std::vector& ascii_art = ascii_art_small; + attron(COLOR_PAIR(3) | A_BOLD); // Color celeste después de la animación + for (int i = 0; i < static_cast(ascii_art.size()); ++i) { + mvprintw(i + 1, (COLS - static_cast(ascii_art.at(0).size())) / 2, ascii_art.at(i).c_str()); + } + attroff(COLOR_PAIR(3) | A_BOLD); + refresh(); +} + +void AnimationManager::drawStaticAsciiArtText() const { + const std::vector& ascii_art = ascii_art_text; + attron(COLOR_PAIR(3) | A_BOLD); // Color celeste después de la animación + for (int i = 0; i < static_cast(ascii_art.size()); ++ i) { + mvprintw(i + 1, (COLS - static_cast(ascii_art.at(0).size())) / 2, ascii_art.at(i).c_str()); + } + attroff(COLOR_PAIR(3) | A_BOLD); + refresh(); +} + +void AnimationManager::drawStaticAsciiArt() const { + if (LINES <= getAsciiArtHeight(ascii_art_small) || COLS <= getAsciiArtWidth(ascii_art_small)) { + drawStaticAsciiArtText(); + } else if (LINES <= getAsciiArtHeight(ascii_art_medium) || COLS <= getAsciiArtWidth(ascii_art_medium)) { + drawStaticAsciiArtSmall(); + } else if (LINES <= getAsciiArtHeight(ascii_art_large) || COLS <= getAsciiArtWidth(ascii_art_large)) { + drawStaticAsciiArtMedium(); + } else { + drawStaticAsciiArtLarge(); + } +} + +void AnimationManager::drawAdaptiveAsciiArtAnimation() const { + handleResizeDuringAnimation([]() { + attron(COLOR_PAIR(2) | A_BOLD); // Color morado durante la animación + + const std::vector* ascii_art; + if (LINES <= getInstance().getAsciiArtHeight(ascii_art_small) || + COLS <= getInstance().getAsciiArtWidth(ascii_art_small)) { + ascii_art = &ascii_art_text; + } else if (LINES <= getInstance().getAsciiArtHeight(ascii_art_medium) || + COLS <= getInstance().getAsciiArtWidth(ascii_art_medium)) { + ascii_art = &ascii_art_small; + } else if (LINES <= getInstance().getAsciiArtHeight(ascii_art_large) || + COLS <= getInstance().getAsciiArtWidth(ascii_art_large)) { + ascii_art = &ascii_art_medium; + } else { + ascii_art = &ascii_art_large; + } + + for (int i = 0; i < static_cast(ascii_art->size()); ++i) { + if (resized) return; + mvprintw(i + 1, (COLS - static_cast(ascii_art->at(0).size())) / 2, ascii_art->at(i).c_str()); + refresh(); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); // Pausa de 100ms para animación + } + + attroff(COLOR_PAIR(2) | A_BOLD); + getInstance().drawStaticAsciiArt(); + }); +} + +void AnimationManager::drawStaticBorder() const { + attron(COLOR_PAIR(6)); + int x_start = 0; + int y_start = 0; + int x_end = COLS - 1; + int y_end = LINES - 1; + + // Superior + mvhline(y_start, x_start + 1, '-', x_end - 1); + + // Inferior + mvhline(y_end, x_start + 1, '-', x_end - 1); + + // Izquierda + mvvline(y_start + 1, x_start, '|', y_end - 1); + + // Derecha + mvvline(y_start + 1, x_end, '|', y_end - 1); + + // Esquinas + mvprintw(y_start, x_start, "+"); + mvprintw(y_start, x_end, "+"); + mvprintw(y_end, x_start, "+"); + mvprintw(y_end, x_end, "+"); + + attroff(COLOR_PAIR(6)); + refresh(); +} + +void AnimationManager::drawBorderSnail() const { + handleResizeDuringAnimation([]() { + attron(COLOR_PAIR(6)); // Usar color morado para el borde + + int x_start = 0; + int y_start = 0; + int x_end = COLS - 1; + int y_end = LINES - 1; + + mvprintw(y_start, x_start, "+"); // Esquina superior izquierda + refresh(); + + while (x_start <= x_end && y_start <= y_end) { + for (int i = x_start + 1; i <= x_end; ++i) { + if (AnimationManager::resized) return; + mvprintw(y_start, i, "-"); + move(y_start, i); // Mover el cursor durante la animación + refresh(); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + } + mvprintw(y_start, x_end, "+"); // Esquina superior derecha + refresh(); + y_start++; + + for (int i = y_start; i <= y_end; ++i) { + if (AnimationManager::resized) return; + mvprintw(i, x_end, "|"); + move(i, x_end); // Mover el cursor durante la animación + refresh(); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + } + mvprintw(y_end, x_end, "+"); // Esquina inferior derecha + refresh(); + x_end--; + + if (y_start <= y_end) { + for (int i = x_end; i >= x_start; --i) { + if (AnimationManager::resized) return; + mvprintw(y_end, i, "-"); + move(y_end, i); // Mover el cursor durante la animación + refresh(); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + } + mvprintw(y_end, x_start, "+"); // Esquina inferior izquierda + refresh(); + y_end--; + } + + if (x_start <= x_end) { + for (int i = y_end; i >= y_start; --i) { + if (AnimationManager::resized) return; + mvprintw(i, x_start, "|"); + move(i, x_start); // Mover el cursor durante la animación + refresh(); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + } + if (y_start == 1) break; // Detener la animación al regresar a la esquina superior izquierda + mvprintw(y_start, x_start, "+"); // Esquina superior izquierda + refresh(); + x_start++; + } + } + attroff(COLOR_PAIR(6)); + }); +} + +void AnimationManager::drawLoadingBar(int duration) const { + loading_duration = duration; + handleResizeDuringAnimation([]() { + int bar_width = COLS - 4; + int bar_start_x = 2; + int bar_y = LINES / 2; + int steps = 100; + int sleep_duration = (loading_duration * 1000) / steps; + + attron(COLOR_PAIR(3) | A_BOLD); + for (int i = 0; i <= static_cast(loading_progress * steps); ++i) { + if (resized) return; + clear(); + mvprintw(bar_y - 2, (COLS - 10) / 2, "Loading..."); + mvhline(bar_y, bar_start_x, ' ', bar_width); + mvhline(bar_y, bar_start_x, '=', static_cast(loading_progress * bar_width)); + mvprintw(bar_y + 2, (COLS - 20) / 2, "%3d%% Complete", static_cast(loading_progress * 100)); + refresh(); + } + for (int i = static_cast(loading_progress * steps); i <= steps; ++i) { + if (resized) return; + clear(); + mvprintw(bar_y - 2, (COLS - 10) / 2, "Loading..."); + mvhline(bar_y, bar_start_x, ' ', bar_width); + mvhline(bar_y, bar_start_x, '=', static_cast(loading_progress * bar_width)); + mvprintw(bar_y + 2, (COLS - 20) / 2, "%3d%% Complete", static_cast(loading_progress * 100)); + refresh(); + loading_progress = static_cast(i) / steps; + std::this_thread::sleep_for(std::chrono::milliseconds(sleep_duration)); + } + attroff(COLOR_PAIR(3) | A_BOLD); + }); +} \ No newline at end of file diff --git a/src/interface/Animation/AnimationManager.h b/src/interface/Animation/AnimationManager.h new file mode 100644 index 0000000..ae49f0c --- /dev/null +++ b/src/interface/Animation/AnimationManager.h @@ -0,0 +1,49 @@ +#ifndef ANIMATIONMANAGER_H +#define ANIMATIONMANAGER_H + +#include +#include +#include +#include +#include +#include +#include + +class AnimationManager { +public: + static AnimationManager& getInstance(); + void drawStaticBorder() const; + void drawStaticAsciiArt() const; + void drawStaticAsciiArtLarge() const; + void drawStaticAsciiArtMedium() const; + void drawStaticAsciiArtSmall() const; + void drawStaticAsciiArtText() const; + void drawAdaptiveAsciiArtAnimation() const; + void drawBorderSnail() const; + void drawLoadingBar(int duration) const; // Nueva función para la barra de carga + + const std::vector& getAsciiArtLarge() const; + const std::vector& getAsciiArtMedium() const; + const std::vector& getAsciiArtSmall() const; + const std::vector& getAsciiArtText() const; + int getAsciiArtWidth(const std::vector& asciiArt) const; + int getAsciiArtHeight(const std::vector& asciiArt) const; + + friend void resizeHandler(int); + +private: + AnimationManager() = default; + void handleResizeDuringAnimation(const std::function& animationFunc) const; + + static const std::vector ascii_art_large; + static const std::vector ascii_art_medium; + static const std::vector ascii_art_small; + static const std::vector ascii_art_text; + + static volatile sig_atomic_t resized; + static std::function current_animation_func; + static float loading_progress; // Progreso de la barra de carga + static int loading_duration; // Duración de la barra de carga +}; + +#endif // ANIMATIONMANAGER_H diff --git a/src/interface/Command/Command.cpp b/src/interface/Command/Command.cpp new file mode 100644 index 0000000..0a1f0a1 --- /dev/null +++ b/src/interface/Command/Command.cpp @@ -0,0 +1,168 @@ +#include "Command.h" +#include "Menu.h" +#include +#include +//#include linux +//#include + +// Implementaciones de SearchOption +void SearchOption::execute() { + std::vector> commands; + commands.push_back(std::make_unique()); + commands.push_back(std::make_unique()); + commands.push_back(std::make_unique()); + commands.push_back(std::make_unique()); + Menu::getInstance().setCommands(std::move(commands)); +} + +// Implementaciones de CheckBookmarksOption +void CheckBookmarksOption::execute() { + std::vector> commands; + commands.push_back(std::make_unique()); + commands.push_back(std::make_unique()); + commands.push_back(std::make_unique()); + Menu::getInstance().setCommands(std::move(commands)); +} + +// Implementaciones de SeeMoreOption +void SeeMoreOption::execute() { + std::vector> commands; + commands.push_back(std::make_unique()); + commands.push_back(std::make_unique()); + commands.push_back(std::make_unique()); + Menu::getInstance().setCommands(std::move(commands)); +} + +// Implementaciones de ExitOption +void ExitOption::execute() { + std::cout << "Exiting application..." << std::endl; + exit(0); +} + +// Implementaciones de SearchByTagsSubOption +void SearchByTagsSubOption::execute() { + std::cout << "Executing Search by Tags" << std::endl; +} + +// Implementaciones de SearchByNameSubOption +void SearchByNameSubOption::execute() { + std::cout << "Executing Search by Name" << std::endl; +} + +// Implementaciones de SearchBySynopsisSubOption +void SearchBySynopsisSubOption::execute() { + std::cout << "Executing Search by Synopsis" << std::endl; +} + +// Implementaciones de WatchLaterOption +void WatchLaterOption::execute() { + std::cout << "Executing Watch Later Option" << std::endl; +} + +// Implementaciones de FavoritesOption +void FavoritesOption::execute() { + std::cout << "Executing Favorites Option" << std::endl; +} + +// Implementaciones de WhatIsChavezNetOption +void WhatIsChavezNetOption::execute() { + std::cout << "Executing What is ChavezNet Option" << std::endl; +} + +// Implementaciones de ReturnOption +void ReturnOption::execute() { + Menu::getInstance().restoreState(); +} + +// Implementaciones de ConfirmOption +void ConfirmOption::execute() { + std::cout << "Confirming selection." << std::endl; +} + +// Implementaciones de DevModeOption +void DevModeOption::execute() { + std::cout << "Attempting to engage DevMode" << std::endl; + if (authenticate()) { + std::cout << "Authentication successful!" << std::endl; + displayDebugInfo(); + showResourceUsage(); + + std::vector> commands; + commands.push_back(std::make_unique()); + commands.push_back(std::make_unique()); + Menu::getInstance().setCommands(std::move(commands)); + } else { + std::cout << "Authentication failed!" << std::endl; + } +} + +bool DevModeOption::authenticate() { + std::string password; + std::cout << "Enter password to access DevMode: "; + std::cin >> password; + return password == "devpass"; // Replace "devpass" with your secure password +} + +void DevModeOption::displayDebugInfo() { + std::cout << "\n--- Debugging Information ---" << std::endl; + std::cout << "Application Version: 1.0.0" << std::endl; + std::cout << "Build Time: " << __DATE__ << " " << __TIME__ << std::endl; + std::cout << "Running on: " << std::this_thread::get_id() << std::endl; + std::cout << "Engine F.O.R.C.E. by DynamicProjects." << std::endl; + // Add more debugging information as needed +} + +void DevModeOption::showResourceUsage() { + std::cout << "\n--- Resource Usage ---" << std::endl; +// std::cout << "CPU Usage: " << getCPUUsage() << "%" << std::endl; +// std::cout << "Memory Usage: " << getMemoryUsage() << "%" << std::endl; + std::cout << "Disk I/O: 1.2MB/s" << std::endl; // Dummy data for disk I/O + // Add real resource usage metrics if available +} + +// long CompareFileTime(FILETIME time1, FILETIME time2) { +// ULARGE_INTEGER a, b; +// a.LowPart = time1.dwLowDateTime; +// a.HighPart = time1.dwHighDateTime; + +// b.LowPart = time2.dwLowDateTime; +// b.HighPart = time2.dwHighDateTime; + +// return b.QuadPart - a.QuadPart; +//} + +float getCPUUsage() { +// static FILETIME prevSysIdle, prevSysKernel, prevSysUser; +// FILETIME sysIdle, sysKernel, sysUser; + +// if (!GetSystemTimes(&sysIdle, &sysKernel, &sysUser)) { + return -1.0f; // Error + } + +// if (prevSysIdle.dwLowDateTime != 0 && prevSysKernel.dwLowDateTime != 0 && prevSysUser.dwLowDateTime != 0) { +// auto diffSysIdle = CompareFileTime(prevSysIdle, sysIdle); +// auto diffSysKernel = CompareFileTime(prevSysKernel, sysKernel); +// auto diffSysUser = CompareFileTime(prevSysUser, sysUser); + +// auto totalSys = diffSysKernel + diffSysUser; +// return (totalSys - diffSysIdle) * 100.0f / totalSys; +// } + +// prevSysIdle = sysIdle; +// prevSysKernel = sysKernel; +// prevSysUser = sysUser; + +// return -1.0f; // First call +//} + +float getMemoryUsage() { +// MEMORYSTATUSEX memInfo; +// memInfo.dwLength = sizeof(MEMORYSTATUSEX); +// GlobalMemoryStatusEx(&memInfo); + +// DWORDLONG totalPhysMem = memInfo.ullTotalPhys; +// DWORDLONG physMemUsed = memInfo.ullTotalPhys - memInfo.ullAvailPhys; + +// return physMemUsed / (float)totalPhysMem * 100.0f; + return 0.0f; // Dummy data +} diff --git a/src/interface/Command/Command.h b/src/interface/Command/Command.h new file mode 100644 index 0000000..443ba40 --- /dev/null +++ b/src/interface/Command/Command.h @@ -0,0 +1,119 @@ +#ifndef COMMAND_H +#define COMMAND_H + +#include +#include +#include +#include // For sleep + +class Command { +public: + virtual ~Command() = default; + virtual void execute() = 0; + virtual std::string getText() const = 0; + virtual std::unique_ptr clone() const = 0; +}; + +// Primary options +class SearchOption : public Command { +public: + void execute() override; + [[nodiscard]] std::string getText() const override { return "Search"; } + [[nodiscard]] std::unique_ptr clone() const override { return std::make_unique(*this); } +}; + +class CheckBookmarksOption : public Command { +public: + void execute() override; + [[nodiscard]] std::string getText() const override { return "Check bookmarks"; } + [[nodiscard]] std::unique_ptr clone() const override { return std::make_unique(*this); } +}; + +class SeeMoreOption : public Command { +public: + void execute() override; + [[nodiscard]] std::string getText() const override { return "See more..."; } + [[nodiscard]] std::unique_ptr clone() const override { return std::make_unique(*this); } +}; + +class ExitOption : public Command { +public: + void execute() override; + [[nodiscard]] std::string getText() const override { return "Exit"; } + [[nodiscard]] std::unique_ptr clone() const override { return std::make_unique(*this); } +}; + +// SubOptions for SearchOption +class SearchByTagsSubOption : public Command { +public: + void execute() override; + [[nodiscard]] std::string getText() const override { return "Search by Tags"; } + [[nodiscard]] std::unique_ptr clone() const override { return std::make_unique(*this); } +}; + +class SearchByNameSubOption : public Command { +public: + void execute() override; + [[nodiscard]] std::string getText() const override { return "Search by Name"; } + [[nodiscard]] std::unique_ptr clone() const override { return std::make_unique(*this); } +}; + +class SearchBySynopsisSubOption : public Command { +public: + void execute() override; + [[nodiscard]] std::string getText() const override { return "Search by Synopsis"; } + [[nodiscard]] std::unique_ptr clone() const override { return std::make_unique(*this); } +}; + +// SubOptions for CheckBookmarksOption +class WatchLaterOption : public Command { +public: + void execute() override; + [[nodiscard]] std::string getText() const override { return "Watch Later list"; } + [[nodiscard]] std::unique_ptr clone() const override { return std::make_unique(*this); } +}; + +class FavoritesOption : public Command { +public: + void execute() override; + [[nodiscard]] std::string getText() const override { return "Favorites list"; } + [[nodiscard]] std::unique_ptr clone() const override { return std::make_unique(*this); } +}; + +class WhatIsChavezNetOption : public Command { +public: + void execute() override; + [[nodiscard]] std::string getText() const override { return "What is ChavezNet?"; } + [[nodiscard]] std::unique_ptr clone() const override { return std::make_unique(*this); } +}; + +// Return options for submenus +class ReturnOption : public Command { +public: + void execute() override; + [[nodiscard]] std::string getText() const override { return "Return"; } + [[nodiscard]] std::unique_ptr clone() const override { return std::make_unique(*this); } +}; + +// Confirm option for general usage +class ConfirmOption : public Command { +public: + void execute() override; + [[nodiscard]] std::string getText() const override { return "Confirm"; } + [[nodiscard]] std::unique_ptr clone() const override { return std::make_unique(*this); } +}; + +// Option for the DevMode engage +class DevModeOption : public Command { +public: + void execute() override; + [[nodiscard]] std::string getText() const override { return "Engage DevMode"; } + [[nodiscard]] std::unique_ptr clone() const override { return std::make_unique(*this); } + +private: + static bool authenticate(); + void displayDebugInfo(); + void showResourceUsage(); +}; + +#endif // COMMAND_H diff --git a/src/interface/Drawer/MenuDrawer.cpp b/src/interface/Drawer/MenuDrawer.cpp new file mode 100644 index 0000000..8823101 --- /dev/null +++ b/src/interface/Drawer/MenuDrawer.cpp @@ -0,0 +1,208 @@ +#include "MenuDrawer.h" +#include "ncurses.h" +#include "AnimationManager.h" + +const int BORDER_PADDING = 2; // Un borde a cada lado +const int ADDITIONAL_PADDING = 4; // Espacio adicional para presentación + +void MenuDrawer::drawMenu(const std::vector>& commands, int highlight) const { + clear(); + bkgd(COLOR_PAIR(1)); + + AnimationManager::getInstance().drawStaticBorder(); + + int maxWidth = 0; + for (const auto& command : commands) { + int commandWidth = static_cast(command->getText().size()); + maxWidth = std::max(maxWidth, commandWidth); + } + maxWidth += BORDER_PADDING + ADDITIONAL_PADDING; + + int logoWidthSmall = AnimationManager::getInstance().getAsciiArtWidth(AnimationManager::getInstance().getAsciiArtSmall()); + int logoHeightSmall = AnimationManager::getInstance().getAsciiArtHeight(AnimationManager::getInstance().getAsciiArtSmall()); + + int commandWidthWithPadding = maxWidth; + int totalHeightVertical = logoHeightSmall + static_cast(commands.size()) * 5; + + int verticalCommandWidth = maxWidth; + int verticalCommandHeight = logoHeightSmall + static_cast(commands.size()) * 3; + + int horizontalCommandWidth = maxWidth; + int spaceBetweenHorizontal = (COLS - horizontalCommandWidth * static_cast(commands.size())) / (static_cast(commands.size()) + 1); + int totalCommandsWidthHorizontal = horizontalCommandWidth * static_cast(commands.size()) + spaceBetweenHorizontal * (static_cast(commands.size()) - 1); + int totalHeightHorizontal = logoHeightSmall + 5; + + if (COLS <= verticalCommandWidth) { + drawVerticalTextMenu(commands, highlight); + } else if (LINES <= totalHeightVertical) { + if (LINES <= totalHeightHorizontal) { + drawHorizontalTextMenu(commands, highlight); + } else { + if (COLS <= totalCommandsWidthHorizontal) { + drawVerticalTextMenu(commands, highlight); + } else { + drawHorizontalMenu(commands, highlight); + } + } + } else { + drawVerticalMenu(commands, highlight); + } +} + +void MenuDrawer::drawVerticalTextMenu(const std::vector>& commands, int highlight) const { + clear(); + bkgd(COLOR_PAIR(1)); + AnimationManager::getInstance().drawStaticBorder(); + + int maxWidth = 0; + for (const auto& command : commands) { + int commandWidth = static_cast(command->getText().size()); + maxWidth = std::max(maxWidth, commandWidth); + } + maxWidth += BORDER_PADDING + ADDITIONAL_PADDING; + + const std::vector& asciiArtText = AnimationManager::getInstance().getAsciiArtText(); + int asciiArtTextWidth = static_cast(asciiArtText[0].size()); + for (int i = 0; i < static_cast(asciiArtText.size()); ++i) { + mvprintw(i, (COLS - asciiArtTextWidth) / 2, asciiArtText[i].c_str()); + } + + int y = static_cast(asciiArtText.size()) + 2; + for (size_t i = 0; i < commands.size(); ++i) { + int x = (COLS - static_cast(commands[i]->getText().size())) / 2; + if (static_cast(i) == highlight) { + attron(COLOR_PAIR(5)); + } else { + attron(COLOR_PAIR(4)); + } + mvprintw(y++, x, "%s", commands[i]->getText().c_str()); + + if (static_cast(i) == highlight) { + attroff(COLOR_PAIR(5)); + } else { + attroff(COLOR_PAIR(4)); + } + } + move(y - static_cast(commands.size()) + highlight, (COLS - static_cast(commands[highlight]->getText().size())) / 2 + static_cast(commands[highlight]->getText().size()) - 1); + refresh(); +} + +void MenuDrawer::drawHorizontalTextMenu(const std::vector>& commands, int highlight) const { + clear(); + bkgd(COLOR_PAIR(1)); + AnimationManager::getInstance().drawStaticBorder(); + + const std::vector& asciiArtText = AnimationManager::getInstance().getAsciiArtText(); + int asciiArtTextWidth = static_cast(asciiArtText[0].size()); + for (int i = 0; i < static_cast(asciiArtText.size()); ++i) { + mvprintw(i, (COLS - asciiArtTextWidth) / 2, asciiArtText[i].c_str()); + } + + int y = static_cast(asciiArtText.size()) + 2; + int totalWidth = 0; + int maxWidth = 0; + + for (const auto& command : commands) { + int commandWidth = static_cast(command->getText().size()); + maxWidth = std::max(maxWidth, commandWidth); + } + maxWidth += BORDER_PADDING + ADDITIONAL_PADDING; + totalWidth = maxWidth * static_cast(commands.size()); + + if (COLS <= totalWidth) { + drawVerticalTextMenu(commands, highlight); + return; + } + + int x = (COLS - totalWidth) / 2; + for (size_t i = 0; i < commands.size(); ++i) { + int xCentered = x + (maxWidth - static_cast(commands[i]->getText().size())) / 2; + if (static_cast(i) == highlight) { + attron(COLOR_PAIR(5)); + } else { + attron(COLOR_PAIR(4)); + } + mvprintw(y, xCentered, "%s", commands[i]->getText().c_str()); + x += maxWidth; + if (static_cast(i) == highlight) { + attroff(COLOR_PAIR(5)); + } else { + attroff(COLOR_PAIR(4)); + } + } + move(y, (COLS - maxWidth * static_cast(commands.size())) / 2 + highlight * maxWidth + (maxWidth - static_cast(commands[highlight]->getText().size())) / 2 + static_cast(commands[highlight]->getText().size()) - 1); + refresh(); +} + +void MenuDrawer::drawVerticalMenu(const std::vector>& commands, int highlight) const { + AnimationManager::getInstance().drawStaticAsciiArt(); + int maxWidth = 0; + + for (const auto& command : commands) { + maxWidth = std::max(maxWidth, static_cast(command->getText().size())); + } + maxWidth += BORDER_PADDING + ADDITIONAL_PADDING; + + int menuHeight = static_cast(commands.size()) * 5; + int y_offset = AnimationManager::getInstance().getAsciiArtHeight(AnimationManager::getInstance().getAsciiArtLarge()) + 1; + int y = (LINES - (menuHeight + y_offset)) / 2 + y_offset; + int spaceBetween = std::max(0, (LINES - y - menuHeight) / (static_cast(commands.size()) - 1)); + + y -= spaceBetween; + + for (size_t i = 0; i < commands.size(); ++i) { + drawOptionBox(y + static_cast(i) * (5 + spaceBetween), (COLS - maxWidth) / 2, commands[i]->getText(), static_cast(i) == highlight, maxWidth); + } + + int padding = (maxWidth - static_cast(commands[highlight]->getText().size()) - 2) / 2; + move(y + highlight * (5 + spaceBetween) + 1, (COLS - maxWidth) / 2 + padding + static_cast(commands[highlight]->getText().size()) - 1 + 1); + + refresh(); +} + +void MenuDrawer::drawHorizontalMenu(const std::vector>& commands, int highlight) const { + AnimationManager::getInstance().drawStaticAsciiArt(); + int maxWidth = 0; + + for (const auto& command : commands) { + maxWidth = std::max(maxWidth, static_cast(command->getText().size())); + } + maxWidth += BORDER_PADDING + ADDITIONAL_PADDING; + + int spaceBetween = (COLS - maxWidth * static_cast(commands.size())) / (static_cast(commands.size()) + 1); + int totalCommandsWidthHorizontal = maxWidth * static_cast(commands.size()) + spaceBetween * (static_cast(commands.size()) - 1); + + if (COLS <= totalCommandsWidthHorizontal) { + drawVerticalTextMenu(commands, highlight); + return; + } + + int y_offset = AnimationManager::getInstance().getAsciiArtHeight(AnimationManager::getInstance().getAsciiArtLarge()) + 1; + int y = y_offset + (LINES - y_offset - 5) / 2; + int totalCommandsHeight = 5; + + int x = (COLS - totalCommandsWidthHorizontal) / 2; + + for (size_t i = 0; i < commands.size(); ++i) { + drawOptionBox(y, x + static_cast(i) * (maxWidth + spaceBetween), commands[i]->getText(), static_cast(i) == highlight, maxWidth); + } + + int padding = (maxWidth - static_cast(commands[highlight]->getText().size()) - 2) / 2; + move(y + 1, x + highlight * (maxWidth + spaceBetween) + padding + static_cast(commands[highlight]->getText().size()) - 1 + 1); + + refresh(); +} + +void MenuDrawer::drawOptionBox(int y, int x, const std::string& text, bool highlight, int width) const { + int pair = highlight ? 5 : 4; + + int padding = (width - static_cast(text.size()) - 2) / 2; + + attron(COLOR_PAIR(pair)); + mvprintw(y, x, "+%s+", std::string(width - 2, '-').c_str()); + mvprintw(y + 1, x, "|%s%s%s|", std::string(padding, ' ').c_str(), text.c_str(), std::string(width - padding - static_cast(text.size()) - 2, ' ').c_str()); + mvprintw(y + 2, x, "+%s+", std::string(width - 2, '-').c_str()); + attroff(COLOR_PAIR(pair)); + + refresh(); +} diff --git a/src/interface/Drawer/MenuDrawer.h b/src/interface/Drawer/MenuDrawer.h new file mode 100644 index 0000000..2285116 --- /dev/null +++ b/src/interface/Drawer/MenuDrawer.h @@ -0,0 +1,26 @@ +#ifndef MENUDRAWER_H +#define MENUDRAWER_H + +#include +#include +#include "../Command/Command.h" +#include "../Animation/AnimationManager.h" + +class Menu; // Declaración adelantada de la clase Menu + +class MenuDrawer { +public: + MenuDrawer(const Menu& menu) : menu(menu) {} + void drawMenu(const std::vector>& commands, int highlight) const; + +private: + const Menu& menu; + + void drawVerticalTextMenu(const std::vector>& commands, int highlight) const; + void drawHorizontalTextMenu(const std::vector>& commands, int highlight) const; + void drawVerticalMenu(const std::vector>& commands, int highlight) const; + void drawHorizontalMenu(const std::vector>& commands, int highlight) const; + void drawOptionBox(int y, int x, const std::string& text, bool highlight, int width) const; +}; + +#endif // MENUDRAWER_H diff --git a/src/interface/Menu/Memento.h b/src/interface/Menu/Memento.h new file mode 100644 index 0000000..93a74d1 --- /dev/null +++ b/src/interface/Menu/Memento.h @@ -0,0 +1,31 @@ +#ifndef MEMENTO_H +#define MEMENTO_H + +#include +#include +#include "../Command/Command.h" + +class Memento { + friend class Menu; // Agregar la clase Menu como amiga +public: + Memento(int highlight, std::vector>&& commands) + : highlight_(highlight), commands_(std::move(commands)) {} + +private: + int getHighlight() const { + return highlight_; + } + + const std::vector>& getCommands() const { + return commands_; + } + + std::vector> releaseCommands() { + return std::move(commands_); + } + + int highlight_; + std::vector> commands_; +}; + +#endif // MEMENTO_H diff --git a/src/interface/Menu/Menu.cpp b/src/interface/Menu/Menu.cpp new file mode 100644 index 0000000..f91f7f9 --- /dev/null +++ b/src/interface/Menu/Menu.cpp @@ -0,0 +1,118 @@ +#include "Menu.h" +#include "AnimationManager.h" +#include +#include + +Menu Menu::instance; +bool Menu::firstTime = true; + +Menu::Menu() : highlight(0), isVertical(false), menuDrawer(*this) { + initscr(); + start_color(); // Inicializa el uso de colores + + init_pair(1, COLOR_WHITE, COLOR_BLACK); // Fondo negro, texto blanco + init_pair(2, COLOR_MAGENTA, COLOR_BLACK); // Texto morado para la animacion + init_pair(3, COLOR_CYAN, COLOR_BLACK); // Texto celeste después de la animacion + init_pair(4, COLOR_GREEN, COLOR_BLACK); // Texto verde brillante para opciones + init_pair(5, COLOR_BLACK, COLOR_WHITE); // Fondo blanco, texto negro para seleccion + init_pair(6, COLOR_MAGENTA, COLOR_BLACK); // Texto morado para el borde + + noecho(); + cbreak(); + keypad(stdscr, TRUE); + bkgd(COLOR_PAIR(1)); // Establecer fondo negro + + // Configurar la señal de redimensionamiento + signal(SIGWINCH, [](int) { + endwin(); + refresh(); + clear(); + getInstance().drawMenu(0); + }); +} + +Menu::~Menu() { + endwin(); +} + +Menu& Menu::getInstance() { + return instance; +} + +[[noreturn]] void Menu::run() { + if (firstTime) { + AnimationManager::getInstance().drawBorderSnail(); + AnimationManager::getInstance().drawAdaptiveAsciiArtAnimation(); + firstTime = false; + } + + std::vector> mainCommands; + mainCommands.push_back(std::make_unique()); + mainCommands.push_back(std::make_unique()); + mainCommands.push_back(std::make_unique()); + mainCommands.push_back(std::make_unique()); + + setCommands(std::move(mainCommands)); + highlight = 0; + + while (true) { + endwin(); + refresh(); + clear(); + drawMenu(highlight); + processInput(highlight); + } +} + +void Menu::setCommands(std::vector> newCommands) { + saveState(); + commands = std::move(newCommands); + highlight = 0; // Reset highlight to first option +} + +void Menu::saveState() { + std::vector> stateCopy; + for (auto& command : commands) { + stateCopy.push_back(command->clone()); + } + history.push(Memento(highlight, std::move(stateCopy))); +} + +void Menu::restoreState() { + if (!history.empty()) { + commands = history.top().releaseCommands(); + highlight = history.top().getHighlight(); + history.pop(); + } +} + +void Menu::drawMenu(int highlight) const { + menuDrawer.drawMenu(commands, highlight); // Utiliza la clase MenuDrawer para dibujar el menú +} + +void Menu::processInput(int& choice) { + int ch = getch(); + switch (ch) { + case KEY_UP: + case KEY_LEFT: + if (choice == 0) { + choice = static_cast(commands.size()) - 1; + } else { + choice--; + } + break; + case KEY_DOWN: + case KEY_RIGHT: + if (choice == static_cast(commands.size()) - 1) { + choice = 0; + } else { + choice++; + } + break; + case 10: // Enter key + commands[choice]->execute(); + break; + default: + break; + } +} diff --git a/src/interface/Menu/Menu.h b/src/interface/Menu/Menu.h new file mode 100644 index 0000000..dc32db4 --- /dev/null +++ b/src/interface/Menu/Menu.h @@ -0,0 +1,42 @@ +#ifndef MENU_H +#define MENU_H + +#include +#include +#include +#include "Command.h" +#include "Memento.h" +#include "AnimationManager.h" +#include "../Drawer/MenuDrawer.h" +#include + +class Menu { +public: + static Menu& getInstance(); + [[noreturn]] void run(); + void setCommands(std::vector> commands); + +private: + Menu(); + ~Menu(); + Menu(const Menu&) = delete; + Menu& operator=(const Menu&) = delete; + + void saveState(); + void restoreState(); + void drawMenu(int highlight) const; + void processInput(int& choice); + + static Menu instance; + static bool firstTime; + std::vector> commands; + std::stack history; + int highlight; + mutable bool isVertical; // Variable para almacenar la disposición del menú + + MenuDrawer menuDrawer; // Instancia de MenuDrawer + + friend class ReturnOption; // Asegúrate de que ReturnOption pueda acceder a los métodos privados de Menu +}; + +#endif // MENU_H diff --git a/src/main.cpp b/src/main.cpp index db5f254..e976f4c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,17 +1,6 @@ -#include -#include "app/Movie/Movie.h" -#include "app/TriePrefix/TrieNode.h" - -using namespace std; - -int main(){ - Movie a = Movie("title", "synopsis", {"Horror", "Action"}); - Movie b = Movie("title", "synopsis", {"Horror", "Suspense"}); - - TrieNode* root = new TrieNode(); - - - - +#include "Menu.h" +int main() { + AnimationManager::getInstance().drawLoadingBar(20); + Menu::getInstance().run(); } diff --git a/src/tools/BTS.cpp b/src/tools/BTS.cpp deleted file mode 100644 index 967942c..0000000 --- a/src/tools/BTS.cpp +++ /dev/null @@ -1,138 +0,0 @@ -// -// Created by Badi on 7/13/2024. -// - -#include - -using namespace std; - -struct Nodo { - int dato; - Nodo* left; - Nodo* right; - - // Constructor - Nodo(int dato) { - this->dato = dato; - left = nullptr; - right = nullptr; - } -}; - -class BST { -private: - Nodo* raiz=nullptr; - Nodo* insertarNodoAux(Nodo* nodo, int dato); - Nodo* buscarNodoAux(Nodo* nodo, int dato); - int heightAux(Nodo* nodo); - Nodo* minimoAux(Nodo* nodo_raiz); - bool esArbolAVLAux(Nodo* nodo); -public: - void insertarNodo(int dato); - Nodo* buscarNodo(int dato); - int height(); - int minimo(); - int maximo(); - Nodo* Sucesor(int dato); - bool esArbolAVL(); -}; - -void BST::insertarNodo(int dato) { - raiz = insertarNodoAux(raiz, dato); -} - -// Función auxiliar para insertar un nodo en el árbol -Nodo* BST::insertarNodoAux(Nodo* nodo, int dato) { - if (nodo == nullptr) - return new Nodo(dato); - - if (dato < nodo->dato) - nodo->left = insertarNodoAux(nodo->left, dato); - else - nodo->right = insertarNodoAux(nodo->right, dato); - return nodo; -} - -Nodo* BST::buscarNodo(int dato) { - return buscarNodoAux(raiz, dato); -} - -// Función auxiliar para buscar un nodo en el árbol -Nodo* BST::buscarNodoAux(Nodo* nodo, int dato) { - if (nodo == nullptr || nodo->dato == dato) - return nodo; - - if (dato < nodo->dato) - return buscarNodoAux(nodo->left, dato); - else - return buscarNodoAux(nodo->right, dato); -} - -int BST::height() { - return heightAux(raiz); -} - -int BST::heightAux(Nodo* nodo) { - if (nodo == nullptr) { - return -1; - } - return 1 + max(heightAux(nodo->left), heightAux(nodo->right)); -} - -Nodo* BST::minimoAux(Nodo* nodo_raiz){ - Nodo* nodo = nodo_raiz; - while(nodo->left != nullptr){ - nodo = nodo->left; - } - return nodo; -} - -int BST::minimo(){ - Nodo* nodo = raiz; - while(nodo->left != nullptr){ - nodo = nodo->left; - } - return nodo->dato; -} - -int BST::maximo(){ - Nodo* nodo = raiz; - while(nodo->right != nullptr){ - nodo = nodo->right; - } - return nodo->dato; -} -Nodo* BST::Sucesor(int dato){ - Nodo* nodo = buscarNodo(dato); - if(nodo == nullptr) // El dato no se encuentra en el arbol - return nullptr; - if(nodo->right != nullptr) - return minimoAux(nodo->right); - - Nodo* sucesor = nullptr; - Nodo* ancestro = raiz; - - while (ancestro != nodo){ - if(dato < ancestro->dato){ - sucesor = ancestro; - ancestro = ancestro->left; - } - else - ancestro = ancestro->right; - } - return sucesor; -} - -bool BST::esArbolAVL(){ - return esArbolAVLAux(raiz); -} -bool BST::esArbolAVLAux(Nodo* nodo){ - if (nodo == nullptr) - return true; - - int h1 = heightAux(nodo->left); - int h2 = heightAux(nodo->right); - if (abs(h1 - h2) > 1) - return false; - return esArbolAVLAux(nodo->left) and esArbolAVLAux(nodo->right); -} \ No newline at end of file