diff options
author | dec05eba <dec05eba@protonmail.com> | 2022-08-14 11:26:37 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2022-08-14 11:26:37 +0200 |
commit | ef28e7c26568cbd3f39949eee04997d210e98f8b (patch) | |
tree | 62cfef6e1e8f014b6b5f221c9057d461ba1f68e7 | |
parent | 809141aae58b6aaa70c07d845392d6ced86c3eb0 (diff) |
Add option to disable rounded corners
-rw-r--r-- | example-config.json | 1 | ||||
-rw-r--r-- | include/Config.hpp | 1 | ||||
-rw-r--r-- | include/Theme.hpp | 2 | ||||
-rw-r--r-- | src/Config.cpp | 141 | ||||
-rw-r--r-- | src/QuickMedia.cpp | 30 | ||||
-rw-r--r-- | src/Theme.cpp | 2 | ||||
-rw-r--r-- | themes/default.json | 4 | ||||
-rw-r--r-- | themes/nord.json | 4 |
8 files changed, 83 insertions, 102 deletions
diff --git a/example-config.json b/example-config.json index 6103f3d..49f83eb 100644 --- a/example-config.json +++ b/example-config.json @@ -36,6 +36,7 @@ }, "use_system_fonts": false, "use_system_mpv_config": false, + "enable_shaders": true, "theme": "default", "scale": 1.0, "font_scale": 1.0, diff --git a/include/Config.hpp b/include/Config.hpp index 665024a..101b0be 100644 --- a/include/Config.hpp +++ b/include/Config.hpp @@ -61,6 +61,7 @@ namespace QuickMedia { YoutubeConfig youtube; bool use_system_fonts = false; bool use_system_mpv_config = false; + bool enable_shaders = true; std::string theme = "default"; float scale = 1.0f; float font_scale = 1.0f; diff --git a/include/Theme.hpp b/include/Theme.hpp index 974f4f7..91856eb 100644 --- a/include/Theme.hpp +++ b/include/Theme.hpp @@ -31,6 +31,8 @@ namespace QuickMedia { mgl::Color loading_page_color = mgl::Color(175, 180, 188); mgl::Color more_items_color = mgl::Color(150, 175, 255, 100); bool drop_shadow = false; + bool circle_mask_enabled = true; + bool rounded_rectangles = true; }; const Theme& get_theme(); diff --git a/src/Config.cpp b/src/Config.cpp index e0f39fd..50cab3c 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -62,6 +62,33 @@ namespace QuickMedia { return result; } + template <typename T> + static void get_json_value(const Json::Value &json_obj, const char *field_name, T &val) { + const Json::Value &json_val = json_obj[field_name]; + if(json_val.isNull()) + return; + + if(!json_val.is<T>()) { + fprintf(stderr, "Warning: config variable \"%s\" is not a %s\n", field_name, typeid(T).name()); + return; + } + + val = json_val.as<T>(); + } + + static void get_json_value(const Json::Value &json_obj, const char *field_name, float &val) { + const Json::Value &json_val = json_obj[field_name]; + if(json_val.isNull()) + return; + + if(!json_val.isDouble()) { + fprintf(stderr, "Warning: config variable \"%s\" is not a float\n", field_name); + return; + } + + val = json_val.asDouble(); + } + // No-op if this has already been called before static void init_config() { if(config_initialized) @@ -86,59 +113,30 @@ namespace QuickMedia { } const Json::Value &search_json = json_root["search"]; - if(search_json.isObject()) { - const Json::Value &font_size_json = search_json["font_size"]; - if(font_size_json.isNumeric()) - config->search.font_size = font_size_json.asInt(); - } + if(search_json.isObject()) + get_json_value(search_json, "font_size", config->search.font_size); const Json::Value &tab_json = json_root["tab"]; - if(tab_json.isObject()) { - const Json::Value &font_size_json = tab_json["font_size"]; - if(font_size_json.isNumeric()) - config->tab.font_size = font_size_json.asInt(); - } + if(tab_json.isObject()) + get_json_value(tab_json, "font_size", config->tab.font_size); const Json::Value &body_json = json_root["body"]; if(body_json.isObject()) { - const Json::Value &title_font_size = body_json["title_font_size"]; - if(title_font_size.isNumeric()) - config->body.title_font_size = title_font_size.asInt(); - - const Json::Value &author_font_size = body_json["author_font_size"]; - if(author_font_size.isNumeric()) - config->body.author_font_size = author_font_size.asInt(); - - const Json::Value &description_font_size = body_json["description_font_size"]; - if(description_font_size.isNumeric()) - config->body.description_font_size = description_font_size.asInt(); - - const Json::Value ×tamp_font_size = body_json["timestamp_font_size"]; - if(timestamp_font_size.isNumeric()) - config->body.timestamp_font_size = timestamp_font_size.asInt(); - - const Json::Value &reaction_font_size = body_json["reaction_font_size"]; - if(reaction_font_size.isNumeric()) - config->body.reaction_font_size = reaction_font_size.asInt(); - - const Json::Value &embedded_load_font_size = body_json["embedded_load_font_size"]; - if(embedded_load_font_size.isNumeric()) - config->body.embedded_load_font_size = embedded_load_font_size.asInt(); + get_json_value(body_json, "title_font_size", config->body.title_font_size); + get_json_value(body_json, "author_font_size", config->body.author_font_size); + get_json_value(body_json, "description_font_size", config->body.description_font_size); + get_json_value(body_json, "timestamp_font_size", config->body.timestamp_font_size); + get_json_value(body_json, "reaction_font_size", config->body.reaction_font_size); + get_json_value(body_json, "embedded_load_font_size", config->body.embedded_load_font_size); } const Json::Value &input_json = json_root["input"]; - if(input_json.isObject()) { - const Json::Value &font_size_json = input_json["font_size"]; - if(font_size_json.isNumeric()) - config->input.font_size = font_size_json.asInt(); - } + if(input_json.isObject()) + get_json_value(input_json, "font_size", config->input.font_size); const Json::Value &video_json = json_root["video"]; - if(video_json.isObject()) { - const Json::Value &max_height_json = video_json["max_height"]; - if(max_height_json.isNumeric()) - config->video.max_height = max_height_json.asInt(); - } + if(video_json.isObject()) + get_json_value(video_json, "max_height", config->video.max_height); const Json::Value &local_manga_json = json_root["local_manga"]; if(local_manga_json.isObject()) { @@ -150,13 +148,8 @@ namespace QuickMedia { } } - const Json::Value &sort_by_name_json = local_manga_json["sort_by_name"]; - if(sort_by_name_json.isBool()) - config->local_manga.sort_by_name = sort_by_name_json.asBool(); - - const Json::Value &sort_chapters_by_name_json = local_manga_json["sort_chapters_by_name"]; - if(sort_chapters_by_name_json.isBool()) - config->local_manga.sort_chapters_by_name = sort_chapters_by_name_json.asBool(); + get_json_value(local_manga_json, "load_progress", config->local_manga.sort_by_name); + get_json_value(local_manga_json, "sort_chapters_by_name", config->local_manga.sort_chapters_by_name); } const Json::Value &local_anime_json = json_root["local_anime"]; @@ -169,45 +162,21 @@ namespace QuickMedia { } } - const Json::Value &sort_by_name_json = local_anime_json["sort_by_name"]; - if(sort_by_name_json.isBool()) - config->local_anime.sort_by_name = sort_by_name_json.asBool(); - - const Json::Value &auto_group_episodes_json = local_anime_json["auto_group_episodes"]; - if(auto_group_episodes_json.isBool()) - config->local_anime.auto_group_episodes = auto_group_episodes_json.asBool(); + get_json_value(local_anime_json, "sort_by_name", config->local_anime.sort_by_name); + get_json_value(local_anime_json, "auto_group_episodes", config->local_anime.auto_group_episodes); } const Json::Value &youtube_json = json_root["youtube"]; - if(youtube_json.isObject()) { - const Json::Value &load_progress_json = youtube_json["load_progress"]; - if(load_progress_json.isBool()) - config->youtube.load_progress = load_progress_json.asBool(); - } - - const Json::Value &use_system_fonts_json = json_root["use_system_fonts"]; - if(use_system_fonts_json.isBool()) - config->use_system_fonts = use_system_fonts_json.asBool(); - - const Json::Value &use_system_mpv_config_json = json_root["use_system_mpv_config"]; - if(use_system_mpv_config_json.isBool()) - config->use_system_mpv_config = use_system_mpv_config_json.asBool(); - - const Json::Value &theme_json = json_root["theme"]; - if(theme_json.isString()) - config->theme = theme_json.asString(); - - const Json::Value &scale_json = json_root["scale"]; - if(scale_json.isNumeric()) - config->scale = scale_json.asFloat(); - - const Json::Value &font_scale = json_root["font_scale"]; - if(font_scale.isNumeric()) - config->font_scale = font_scale.asFloat(); - - const Json::Value &spacing_scale = json_root["spacing_scale"]; - if(spacing_scale.isNumeric()) - config->spacing_scale = spacing_scale.asFloat(); + if(youtube_json.isObject()) + get_json_value(youtube_json, "load_progress", config->youtube.load_progress); + + get_json_value(json_root, "use_system_fonts", config->use_system_fonts); + get_json_value(json_root, "use_system_mpv_config", config->use_system_mpv_config); + get_json_value(json_root, "enable_shaders", config->enable_shaders); + get_json_value(json_root, "theme", config->theme); + get_json_value(json_root, "scale", config->scale); + get_json_value(json_root, "font_scale", config->font_scale); + get_json_value(json_root, "spacing_scale", config->spacing_scale); } const Config& get_config() { diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index e710fb5..ebd6ac4 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -675,28 +675,30 @@ namespace QuickMedia { set_window_icon(disp, window.get_system_handle(), resources_root + "icons/qm_logo.png"); - if(!is_touch_enabled()) { - if(!circle_mask_shader.load_from_file((resources_root + "shaders/circle_mask.glsl").c_str(), mgl::Shader::Type::Fragment)) { + if(!is_touch_enabled() && get_config().enable_shaders) { + if(get_theme().circle_mask_enabled && !circle_mask_shader.load_from_file((resources_root + "shaders/circle_mask.glsl").c_str(), mgl::Shader::Type::Fragment)) { show_notification("QuickMedia", "Failed to load " + resources_root + "/shaders/circle_mask.glsl", Urgency::CRITICAL); abort(); } - if(get_theme().drop_shadow) { - if(!rounded_rectangle_shader.load_from_file((resources_root + "shaders/rounded_rectangle.glsl").c_str(), mgl::Shader::Type::Fragment)) { - show_notification("QuickMedia", "Failed to load " + resources_root + "/shaders/rounded_rectangle.glsl", Urgency::CRITICAL); - abort(); + if(get_theme().rounded_rectangles) { + if(get_theme().drop_shadow) { + if(!rounded_rectangle_shader.load_from_file((resources_root + "shaders/rounded_rectangle.glsl").c_str(), mgl::Shader::Type::Fragment)) { + show_notification("QuickMedia", "Failed to load " + resources_root + "/shaders/rounded_rectangle.glsl", Urgency::CRITICAL); + abort(); + } + } else { + if(!rounded_rectangle_shader.load_from_file((resources_root + "shaders/rounded_rectangle_no_shadow.glsl").c_str(), mgl::Shader::Type::Fragment)) { + show_notification("QuickMedia", "Failed to load " + resources_root + "/shaders/rounded_rectangle_no_shadow.glsl", Urgency::CRITICAL); + abort(); + } } - } else { - if(!rounded_rectangle_shader.load_from_file((resources_root + "shaders/rounded_rectangle_no_shadow.glsl").c_str(), mgl::Shader::Type::Fragment)) { - show_notification("QuickMedia", "Failed to load " + resources_root + "/shaders/rounded_rectangle_no_shadow.glsl", Urgency::CRITICAL); + + if(!rounded_rectangle_mask_shader.load_from_file((resources_root + "shaders/rounded_rectangle_mask.glsl").c_str(), mgl::Shader::Type::Fragment)) { + show_notification("QuickMedia", "Failed to load " + resources_root + "/shaders/rounded_rectangle_mask.glsl", Urgency::CRITICAL); abort(); } } - - if(!rounded_rectangle_mask_shader.load_from_file((resources_root + "shaders/rounded_rectangle_mask.glsl").c_str(), mgl::Shader::Type::Fragment)) { - show_notification("QuickMedia", "Failed to load " + resources_root + "/shaders/rounded_rectangle_mask.glsl", Urgency::CRITICAL); - abort(); - } } if(!loading_icon.load_from_file((resources_root + "images/loading_icon.png").c_str())) { diff --git a/src/Theme.cpp b/src/Theme.cpp index 9f525d5..2d5bfd4 100644 --- a/src/Theme.cpp +++ b/src/Theme.cpp @@ -120,6 +120,8 @@ namespace QuickMedia { parse_hex_set_color(json_root, "loading_page_color", theme->loading_page_color); parse_hex_set_color(json_root, "more_items_color", theme->more_items_color); get_bool_value(json_root, "drop_shadow", theme->drop_shadow); + get_bool_value(json_root, "circle_mask_enabled", theme->circle_mask_enabled); + get_bool_value(json_root, "rounded_rectangles", theme->rounded_rectangles); } const Theme& get_theme() { diff --git a/themes/default.json b/themes/default.json index ad028a9..fe156c7 100644 --- a/themes/default.json +++ b/themes/default.json @@ -21,5 +21,7 @@ "url_text_color": "#238cf5", "loading_page_color": "#afb4bc", "more_items_color": "#96afff64", - "drop_shadow": false + "drop_shadow": false, + "circle_mask_enabled": true, + "rounded_rectangles": true }
\ No newline at end of file diff --git a/themes/nord.json b/themes/nord.json index c82bd86..bf1e3f6 100644 --- a/themes/nord.json +++ b/themes/nord.json @@ -21,5 +21,7 @@ "url_text_color": "#88c0d0", "loading_page_color": "#e5e9f0", "more_items_color": "#96afff64", - "drop_shadow": false + "drop_shadow": false, + "circle_mask_enabled": true, + "rounded_rectangles": true }
\ No newline at end of file |