diff options
author | Slendi <slendi@socopon.com> | 2024-03-08 15:21:25 +0200 |
---|---|---|
committer | Slendi <slendi@socopon.com> | 2024-03-08 19:25:55 +0200 |
commit | bce9357ee839ac1afef23c4b37f1a855dcbc1307 (patch) | |
tree | daa6f46736256da218c92181760cc5cf909cacfd | |
parent | 8182a2592705b972eea3dfab202f951ea00e6048 (diff) |
Fix
Signed-off-by: Slendi <slendi@socopon.com>
-rw-r--r-- | config.h | 18 | ||||
-rw-r--r-- | main.cpp | 644 |
2 files changed, 337 insertions, 325 deletions
@@ -1,22 +1,18 @@ #ifdef _WIN32 -<<<<<<< Updated upstream -static char const constexpr *const FONT_PATH = "C:\\Windows\\Fonts\\DejaVuSans.ttf"; -======= static char const constexpr *const FONT_PATH = "C:\\Windows\\Fonts\\DejaVuSans.ttf"; #elif __APPLE__ static char const constexpr *const FONT_PATH = "/Library/Fonts/Arial Unicode.ttf"; ->>>>>>> Stashed changes #else -static char const constexpr *const FONT_PATH = "/usr/share/fonts/TTF/DejaVuSans.ttf"; +static char const constexpr *const FONT_PATH = + "/usr/share/fonts/TTF/DejaVuSans.ttf"; #endif #define PROGRESS_BAR_DEFAULT_POSITION ProgressBarPosition::BOTTOM -#define PROGRESS_BAR_DEFAULT_COLOR BLACK -#define TEXT_DEFAULT_COLOR BLACK -#define BACKGROUND_DEFAULT_COLOR WHITE - -#define PADDING_X_DEFAULT 32 -#define PADDING_Y_DEFAULT 32 +#define PROGRESS_BAR_DEFAULT_COLOR BLACK +#define TEXT_DEFAULT_COLOR BLACK +#define BACKGROUND_DEFAULT_COLOR WHITE +#define PADDING_X_DEFAULT 32 +#define PADDING_Y_DEFAULT 32 @@ -10,10 +10,10 @@ struct Config { enum class ProgressBarPosition { - TOP, - BOTTOM, - LEFT, - RIGHT, + TOP, + BOTTOM, + LEFT, + RIGHT, }; int width = 1280; @@ -34,8 +34,8 @@ struct Config { struct Slide { enum class Type { - TEXT, - IMAGE, + TEXT, + IMAGE, }; Type type; std::string text; @@ -47,12 +47,10 @@ using Slides = std::vector<Slide>; class Application { public: Application(Config config, Slides slides) - : m_config(config), m_slides(slides) { + : m_config(config), m_slides(slides) { -<<<<<<< Updated upstream - int w = m_config.width; - int h = m_config.height; -======= + int w = m_config.width; + int h = m_config.height; #ifdef __APPLE__ SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_MSAA_4X_HINT | FLAG_WINDOW_HIGHDPI); @@ -61,205 +59,212 @@ public: #endif InitWindow(w, h, "Presentation"); SetTargetFPS(30); ->>>>>>> Stashed changes - if (m_config.fullscreen) { - w = GetMonitorWidth(GetCurrentMonitor()); - h = GetMonitorHeight(GetCurrentMonitor()); - } + if (m_config.fullscreen) { + w = GetMonitorWidth(GetCurrentMonitor()); + h = GetMonitorHeight(GetCurrentMonitor()); + } - SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_MSAA_4X_HINT); - InitWindow(w, h, "Presentation"); - SetTargetFPS(30); + SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_MSAA_4X_HINT); + InitWindow(w, h, "Presentation"); + SetTargetFPS(30); - auto time_begin = std::chrono::high_resolution_clock::now(); - m_font = LoadFontEx(m_config.font_path.c_str(), 128, nullptr, 0x2030); - auto time_end = std::chrono::high_resolution_clock::now(); - std::cout << "Loading font took " - << std::chrono::duration_cast<std::chrono::milliseconds>( - time_end - time_begin) - .count() - << "ms" << std::endl; - std::cout.flush(); + auto time_begin = std::chrono::high_resolution_clock::now(); + m_font = LoadFontEx(m_config.font_path.c_str(), 128, nullptr, 0x2030); + auto time_end = std::chrono::high_resolution_clock::now(); + std::cout << "Loading font took " + << std::chrono::duration_cast<std::chrono::milliseconds>( + time_end - time_begin) + .count() + << "ms" << std::endl; + std::cout.flush(); - SetTextureFilter(m_font.texture, TEXTURE_FILTER_TRILINEAR); + SetTextureFilter(m_font.texture, TEXTURE_FILTER_TRILINEAR); - int display_width = GetMonitorWidth(GetCurrentMonitor()); - int display_height = GetMonitorHeight(GetCurrentMonitor()); + int display_width = GetMonitorWidth(GetCurrentMonitor()); + int display_height = GetMonitorHeight(GetCurrentMonitor()); - if (m_config.fullscreen) - ToggleFullscreen(); + if (m_config.fullscreen) + ToggleFullscreen(); - SetExitKey(KEY_Q); + SetExitKey(KEY_Q); } ~Application() { - if (m_texture.id != 0) - UnloadTexture(m_texture); - CloseWindow(); + if (m_texture.id != 0) + UnloadTexture(m_texture); + CloseWindow(); } void run() { - HideCursor(); - while (!WindowShouldClose()) { - float font_scale = - (GetMonitorWidth(GetCurrentMonitor()) / (float)GetScreenWidth() + - GetMonitorHeight(GetCurrentMonitor()) / (float)GetScreenHeight()) / - 2.0f; - - if (IsKeyPressed(KEY_F)) - ToggleFullscreen(); - - if (IsKeyPressed(KEY_RIGHT) || IsKeyPressed(KEY_SPACE) || - IsKeyPressed(KEY_ENTER) || IsKeyPressed(KEY_J) || - IsKeyPressed(KEY_L) || IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) - advance_slide(); - - if (IsKeyPressed(KEY_LEFT) || IsKeyPressed(KEY_K) || - IsKeyPressed(KEY_H) || IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) - previous_slide(); - - if (IsKeyPressed(KEY_HOME) || - (IsKeyPressed(KEY_G) && - !(IsKeyDown(KEY_LEFT_SHIFT) || IsKeyDown(KEY_RIGHT_SHIFT))) || - IsKeyPressed(KEY_ZERO)) - beginning_slide(); - - if (IsKeyPressed(KEY_END) || - (IsKeyPressed(KEY_G) && - (IsKeyDown(KEY_LEFT_SHIFT) || IsKeyDown(KEY_RIGHT_SHIFT))) || - IsKeyPressed(KEY_NINE)) - end_slide(); - - BeginDrawing(); - ClearBackground(m_config.background_color); - - SetTextLineSpacing(font_scale * m_config.font_size); - if (m_slides[m_current_slide].type == Slide::Type::TEXT) { - // Draw centered - auto &txt = m_slides[m_current_slide].text; - auto measurement = MeasureTextEx(m_font, txt.c_str(), - m_config.font_size * font_scale, 0); - - float scale = 1.0f; - if (measurement.x > - GetScreenWidth() - m_config.padding_x * font_scale * 2) { - scale = (GetScreenWidth() - m_config.padding_x * font_scale * 2) / measurement.x; - } - if (measurement.y > - GetScreenHeight() - m_config.padding_y * font_scale * 2) { - scale = (GetScreenHeight() - m_config.padding_y * font_scale * 2) / measurement.y; - } - - measurement.x *= scale; - measurement.y *= scale; - SetTextLineSpacing(font_scale * m_config.font_size * scale); - - DrawTextEx(m_font, txt.c_str(), - { - .x = (GetScreenWidth() - measurement.x) / 2.0f, - .y = (GetScreenHeight() - measurement.y) / 2.0f, - }, - m_config.font_size * font_scale * scale, 0, - m_config.text_color); - - } else if (m_slides[m_current_slide].type == Slide::Type::IMAGE && - m_texture.id != 0) { - float yoffset = 0; - - if (m_slides[m_current_slide].text.size() > 0) { - auto txt = m_slides[m_current_slide].text; - auto measurement = MeasureTextEx(m_font, txt.c_str(), - m_config.font_size * font_scale, 0); - yoffset = measurement.y + m_config.padding_y; - DrawTextEx(m_font, txt.c_str(), - { - .x = (GetScreenWidth() - measurement.x) / 2.0f, - .y = m_config.padding_y * font_scale, - }, - m_config.font_size * font_scale, 0, m_config.text_color); - } - - float scale = - std::min((GetScreenWidth() - m_config.padding_x * font_scale * 2) / - m_texture.width, - (GetScreenHeight() - yoffset * font_scale - - m_config.padding_y * font_scale * 2) / - m_texture.height); - - DrawTextureEx( - m_texture, - { - .x = (GetScreenWidth() - m_texture.width * scale) / 2.0f, - .y = (GetScreenHeight() - m_texture.height * scale) / 2.0f + yoffset * font_scale * 0.5f, - }, - 0, scale, WHITE); - } - - float progress = m_current_slide / ((float)m_slides.size() - 1); - if (m_config.progress_bar_position == Config::ProgressBarPosition::TOP || - m_config.progress_bar_position == Config::ProgressBarPosition::BOTTOM) { - DrawRectangle( - 0, - m_config.progress_bar_position == Config::ProgressBarPosition::TOP - ? 0 - : GetScreenHeight() - 8, - GetScreenWidth() * progress, 8, m_config.progress_bar_color); - } else if (m_config.progress_bar_position == Config::ProgressBarPosition::LEFT) { - DrawRectangle(0, 0, 8, GetScreenHeight() * progress, m_config.progress_bar_color); - } else if (m_config.progress_bar_position == Config::ProgressBarPosition::RIGHT) { - DrawRectangle(GetScreenWidth() - 8, 0, 8, GetScreenHeight() * progress, m_config.progress_bar_color); - } - - auto text = TextFormat("(%d/%d)", m_current_slide + 1, m_slides.size()); - auto measurement = MeasureTextEx(m_font, text, 20, 0); - DrawTextEx(m_font, text, - { - .x = (GetScreenWidth() - measurement.x) / 2.0f, - .y = GetScreenHeight() - 8 - measurement.y, - }, - 20, 0, m_config.progress_bar_color); - - EndDrawing(); - } + HideCursor(); + while (!WindowShouldClose()) { + float font_scale = + (GetMonitorWidth(GetCurrentMonitor()) / (float)GetScreenWidth() + + GetMonitorHeight(GetCurrentMonitor()) / (float)GetScreenHeight()) / + 2.0f; + + if (IsKeyPressed(KEY_F)) + ToggleFullscreen(); + + if (IsKeyPressed(KEY_RIGHT) || IsKeyPressed(KEY_SPACE) || + IsKeyPressed(KEY_ENTER) || IsKeyPressed(KEY_J) || + IsKeyPressed(KEY_L) || IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) + advance_slide(); + + if (IsKeyPressed(KEY_LEFT) || IsKeyPressed(KEY_K) || + IsKeyPressed(KEY_H) || IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) + previous_slide(); + + if (IsKeyPressed(KEY_HOME) || + (IsKeyPressed(KEY_G) && + !(IsKeyDown(KEY_LEFT_SHIFT) || IsKeyDown(KEY_RIGHT_SHIFT))) || + IsKeyPressed(KEY_ZERO)) + beginning_slide(); + + if (IsKeyPressed(KEY_END) || + (IsKeyPressed(KEY_G) && + (IsKeyDown(KEY_LEFT_SHIFT) || IsKeyDown(KEY_RIGHT_SHIFT))) || + IsKeyPressed(KEY_NINE)) + end_slide(); + + BeginDrawing(); + ClearBackground(m_config.background_color); + + SetTextLineSpacing(font_scale * m_config.font_size); + if (m_slides[m_current_slide].type == Slide::Type::TEXT) { + // Draw centered + auto &txt = m_slides[m_current_slide].text; + auto measurement = MeasureTextEx(m_font, txt.c_str(), + m_config.font_size * font_scale, 0); + + float scale = 1.0f; + if (measurement.x > + GetScreenWidth() - m_config.padding_x * font_scale * 2) { + scale = (GetScreenWidth() - m_config.padding_x * font_scale * 2) / + measurement.x; + } + if (measurement.y > + GetScreenHeight() - m_config.padding_y * font_scale * 2) { + scale = (GetScreenHeight() - m_config.padding_y * font_scale * 2) / + measurement.y; + } + + measurement.x *= scale; + measurement.y *= scale; + SetTextLineSpacing(font_scale * m_config.font_size * scale); + + DrawTextEx(m_font, txt.c_str(), + { + .x = (GetScreenWidth() - measurement.x) / 2.0f, + .y = (GetScreenHeight() - measurement.y) / 2.0f, + }, + m_config.font_size * font_scale * scale, 0, + m_config.text_color); + + } else if (m_slides[m_current_slide].type == Slide::Type::IMAGE && + m_texture.id != 0) { + float yoffset = 0; + + if (m_slides[m_current_slide].text.size() > 0) { + auto txt = m_slides[m_current_slide].text; + auto measurement = MeasureTextEx(m_font, txt.c_str(), + m_config.font_size * font_scale, 0); + yoffset = measurement.y + m_config.padding_y; + DrawTextEx(m_font, txt.c_str(), + { + .x = (GetScreenWidth() - measurement.x) / 2.0f, + .y = m_config.padding_y * font_scale, + }, + m_config.font_size * font_scale, 0, m_config.text_color); + } + + float scale = + std::min((GetScreenWidth() - m_config.padding_x * font_scale * 2) / + m_texture.width, + (GetScreenHeight() - yoffset * font_scale - + m_config.padding_y * font_scale * 2) / + m_texture.height); + + DrawTextureEx( + m_texture, + { + .x = (GetScreenWidth() - m_texture.width * scale) / 2.0f, + .y = (GetScreenHeight() - m_texture.height * scale) / 2.0f + + yoffset * font_scale * 0.5f, + }, + 0, scale, WHITE); + } + + float progress = m_current_slide / ((float)m_slides.size() - 1); + if (m_config.progress_bar_position == Config::ProgressBarPosition::TOP || + m_config.progress_bar_position == + Config::ProgressBarPosition::BOTTOM) { + DrawRectangle( + 0, + m_config.progress_bar_position == Config::ProgressBarPosition::TOP + ? 0 + : GetScreenHeight() - 8, + GetScreenWidth() * progress, 8, m_config.progress_bar_color); + } else if (m_config.progress_bar_position == + Config::ProgressBarPosition::LEFT) { + DrawRectangle(0, 0, 8, GetScreenHeight() * progress, + m_config.progress_bar_color); + } else if (m_config.progress_bar_position == + Config::ProgressBarPosition::RIGHT) { + DrawRectangle(GetScreenWidth() - 8, 0, 8, GetScreenHeight() * progress, + m_config.progress_bar_color); + } + + auto text = TextFormat("(%d/%d)", m_current_slide + 1, m_slides.size()); + auto measurement = MeasureTextEx(m_font, text, 20, 0); + DrawTextEx(m_font, text, + { + .x = (GetScreenWidth() - measurement.x) / 2.0f, + .y = GetScreenHeight() - 8 - measurement.y, + }, + 20, 0, m_config.progress_bar_color); + + EndDrawing(); + } } void advance_slide() { - m_current_slide++; - if (m_current_slide >= m_slides.size()) { - m_current_slide--; - return; - } + m_current_slide++; + if (m_current_slide >= m_slides.size()) { + m_current_slide--; + return; + } - handle_image_slide(); + handle_image_slide(); } void previous_slide() { - m_current_slide--; - if (m_current_slide < 0) { - m_current_slide++; - return; - } + m_current_slide--; + if (m_current_slide < 0) { + m_current_slide++; + return; + } - handle_image_slide(); + handle_image_slide(); } void handle_image_slide() { - if (m_slides[m_current_slide].type == Slide::Type::IMAGE) { - if (m_texture.id != 0) - UnloadTexture(m_texture); - m_texture = LoadTexture(m_slides[m_current_slide].image_path.c_str()); - } + if (m_slides[m_current_slide].type == Slide::Type::IMAGE) { + if (m_texture.id != 0) + UnloadTexture(m_texture); + m_texture = LoadTexture(m_slides[m_current_slide].image_path.c_str()); + } } void beginning_slide() { - m_current_slide = 0; - handle_image_slide(); + m_current_slide = 0; + handle_image_slide(); } void end_slide() { - m_current_slide = m_slides.size() - 1; - handle_image_slide(); + m_current_slide = m_slides.size() - 1; + handle_image_slide(); } private: @@ -279,160 +284,171 @@ Slides parse_input(std::istream *stream) { bool just_started_parsing = true; for (std::string line; std::getline(*stream, line);) { - if (line.empty()) { - if (!just_started_parsing) { - if (c_slide.text.size() > 0 || !c_slide.image_path.empty()) { - if (c_slide.text.size() > 0) - c_slide.text.pop_back(); - slides.push_back(c_slide); - c_slide = {}; - } - } - continue; - } - - if (line[0] == '#') - continue; - - just_started_parsing = false; - - if (line[0] == '@') { - c_slide.type = Slide::Type::IMAGE; - if (!c_slide.image_path.empty()) { - c_slide.text.pop_back(); - slides.push_back(c_slide); - c_slide = {}; - } - c_slide.image_path = line.substr(1); - } else { - c_slide.type = Slide::Type::TEXT; - c_slide.text += line + '\n'; - } - } + if (line.empty()) { + if (!just_started_parsing) { + if (c_slide.text.size() > 0 || !c_slide.image_path.empty()) { + if (c_slide.text.size() > 0) + c_slide.text.pop_back(); + slides.push_back(c_slide); + c_slide = {}; + } + } + continue; + } + + if (line[0] == '#') + continue; + + just_started_parsing = false; + + if (line[0] == '@') { + c_slide.type = Slide::Type::IMAGE; + if (!c_slide.image_path.empty()) { + c_slide.text.pop_back(); + slides.push_back(c_slide); + c_slide = {}; + } + c_slide.image_path = line.substr(1); + } else { + c_slide.type = Slide::Type::TEXT; + c_slide.text += line + '\n'; + } + } if (!just_started_parsing) { - if (c_slide.text.size() > 0 && '\n' == c_slide.text.back()) - c_slide.text.pop_back(); - slides.push_back(c_slide); + if (c_slide.text.size() > 0 && '\n' == c_slide.text.back()) + c_slide.text.pop_back(); + slides.push_back(c_slide); } return slides; } Color parse_color(const std::string &color) { - if (color.size() != 6) - throw std::runtime_error("Invalid color: " + color); + if (color.size() != 6) + throw std::runtime_error("Invalid color: " + color); - unsigned char r = std::stoi(color.substr(0, 2), nullptr, 16); - unsigned char g = std::stoi(color.substr(2, 2), nullptr, 16); - unsigned char b = std::stoi(color.substr(4, 2), nullptr, 16); + unsigned char r = std::stoi(color.substr(0, 2), nullptr, 16); + unsigned char g = std::stoi(color.substr(2, 2), nullptr, 16); + unsigned char b = std::stoi(color.substr(4, 2), nullptr, 16); - return {r, g, b, 255}; + return {r, g, b, 255}; } -std::pair<int, Config> parse_arguments(int argc, char **argv, std::istream **is) { - Config conf {}; +std::pair<int, Config> parse_arguments(int argc, char **argv, + std::istream **is) { + Config conf{}; *is = &std::cin; - for (int i = 1; i < argc; i++) { - std::string arg = argv[i]; - if (arg == "-h" || arg == "--help") { - std::cout << "Usage: " << argv[0] << " [FILE]" << std::endl - << "If FILE is not provided, input will be read from stdin." << std::endl - << "Options:" << std::endl - << " -pos <BOTTOM|TOP|LEFT|RIGHT> Set the position of the progress bar" << std::endl - << " -bg <rgb_hex> Set the background color" << std::endl - << " -fg <rgb_hex> Set the text color" << std::endl - << " -pb <rgb_hex> Set the progress bar color" << std::endl - << " -w Start in windowed mode" << std::endl - << " -px <int> Set the horizontal padding" << std::endl - << " -py <int> Set the vertical padding" << std::endl; - exit(0); - } else if (arg == "-") { // Read from stdin - continue; - } else if (arg == "-w") { - conf.fullscreen = false; - } else if (arg == "-pos") { - if (i + 1 < argc) { - i++; - std::string pos = argv[i]; - for (auto &c: pos) c = toupper(c); - if (pos == "BOTTOM") { - conf.progress_bar_position = Config::ProgressBarPosition::BOTTOM; - } else if (pos == "TOP") { - conf.progress_bar_position = Config::ProgressBarPosition::TOP; - } else if (pos == "LEFT") { - conf.progress_bar_position = Config::ProgressBarPosition::LEFT; - } else if (pos == "RIGHT") { - conf.progress_bar_position = Config::ProgressBarPosition::RIGHT; - } else { - std::cerr << "Invalid position: " << pos << std::endl; - return {0, conf}; - } - } else { - std::cerr << "Position not provided" << std::endl; - return {0, conf}; - } - } else if (arg == "-bg") { - if (i + 1 < argc) { - i++; - conf.background_color = parse_color(argv[i]); - } else { - std::cerr << "Background color not provided" << std::endl; - return {0, conf}; - } - } else if (arg == "-fg") { - if (i + 1 < argc) { - i++; - conf.text_color = parse_color(argv[i]); - } else { - std::cerr << "Text color not provided" << std::endl; - return {0, conf}; - } - } else if (arg == "-pb") { - if (i + 1 < argc) { - i++; - conf.progress_bar_color = parse_color(argv[i]); - } else { - std::cerr << "Progress bar color not provided" << std::endl; - return {0, conf}; - } - } else if (arg == "-px") { - if (i + 1 < argc) { - i++; - conf.padding_x = std::stoi(argv[i]); - } else { - std::cerr << "Horizontal padding not provided" << std::endl; - return {0, conf}; - } - } else if (arg == "-py") { - if (i + 1 < argc) { - i++; - conf.padding_y = std::stoi(argv[i]); - } else { - std::cerr << "Vertical padding not provided" << std::endl; - return {0, conf}; - } - } else { - auto file = new std::ifstream(argv[1]); - if (!file->is_open()) { - std::cerr << "Could not open file: " << argv[1] << std::endl; - return {0, conf}; - } - *is = file; - } + for (int i = 1; i < argc; i++) { + std::string arg = argv[i]; + if (arg == "-h" || arg == "--help") { + std::cout + << "Usage: " << argv[0] << " [FILE]" << std::endl + << "If FILE is not provided, input will be read from stdin." + << std::endl + << "Options:" << std::endl + << " -pos <BOTTOM|TOP|LEFT|RIGHT> Set the position of the progress " + "bar" + << std::endl + << " -bg <rgb_hex> Set the background color" + << std::endl + << " -fg <rgb_hex> Set the text color" << std::endl + << " -pb <rgb_hex> Set the progress bar color" + << std::endl + << " -w Start in windowed mode" + << std::endl + << " -px <int> Set the horizontal padding" + << std::endl + << " -py <int> Set the vertical padding" + << std::endl; + exit(0); + } else if (arg == "-") { // Read from stdin + continue; + } else if (arg == "-w") { + conf.fullscreen = false; + } else if (arg == "-pos") { + if (i + 1 < argc) { + i++; + std::string pos = argv[i]; + for (auto &c : pos) + c = toupper(c); + if (pos == "BOTTOM") { + conf.progress_bar_position = Config::ProgressBarPosition::BOTTOM; + } else if (pos == "TOP") { + conf.progress_bar_position = Config::ProgressBarPosition::TOP; + } else if (pos == "LEFT") { + conf.progress_bar_position = Config::ProgressBarPosition::LEFT; + } else if (pos == "RIGHT") { + conf.progress_bar_position = Config::ProgressBarPosition::RIGHT; + } else { + std::cerr << "Invalid position: " << pos << std::endl; + return {0, conf}; + } + } else { + std::cerr << "Position not provided" << std::endl; + return {0, conf}; + } + } else if (arg == "-bg") { + if (i + 1 < argc) { + i++; + conf.background_color = parse_color(argv[i]); + } else { + std::cerr << "Background color not provided" << std::endl; + return {0, conf}; + } + } else if (arg == "-fg") { + if (i + 1 < argc) { + i++; + conf.text_color = parse_color(argv[i]); + } else { + std::cerr << "Text color not provided" << std::endl; + return {0, conf}; + } + } else if (arg == "-pb") { + if (i + 1 < argc) { + i++; + conf.progress_bar_color = parse_color(argv[i]); + } else { + std::cerr << "Progress bar color not provided" << std::endl; + return {0, conf}; + } + } else if (arg == "-px") { + if (i + 1 < argc) { + i++; + conf.padding_x = std::stoi(argv[i]); + } else { + std::cerr << "Horizontal padding not provided" << std::endl; + return {0, conf}; + } + } else if (arg == "-py") { + if (i + 1 < argc) { + i++; + conf.padding_y = std::stoi(argv[i]); + } else { + std::cerr << "Vertical padding not provided" << std::endl; + return {0, conf}; + } + } else { + auto file = new std::ifstream(argv[1]); + if (!file->is_open()) { + std::cerr << "Could not open file: " << argv[1] << std::endl; + return {0, conf}; + } + *is = file; + } } - return {1, conf}; + return {1, conf}; } int main(int argc, char **argv) { - std::istream *is; - auto ret = parse_arguments(argc, argv, &is); - if (!ret.first) - return 1; + std::istream *is; + auto ret = parse_arguments(argc, argv, &is); + if (!ret.first) + return 1; - auto conf = ret.second; + auto conf = ret.second; auto slides = parse_input(is); Application app(conf, slides); |