From 45b860a28fa8d6df454dbd96fcc1fdf228a01cd5 Mon Sep 17 00:00:00 2001 From: Jamie Vital Date: Sat, 14 Oct 2023 13:06:21 -0400 Subject: [PATCH] Honor saved border/city color everywhere in viewer --- src-interface/viewer/image_handler.cpp | 8 ++++---- src-interface/viewer/image_handler.h | 3 --- .../viewer/scatterometer_handler.cpp | 4 ++-- src-interface/viewer/scatterometer_handler.h | 1 - src-interface/viewer/viewer.cpp | 19 +++++++++++-------- src-interface/viewer/viewer.h | 5 ++--- src-interface/viewer/viewer_projection.cpp | 8 ++++---- 7 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src-interface/viewer/image_handler.cpp b/src-interface/viewer/image_handler.cpp index f426a456e..2419ff46d 100644 --- a/src-interface/viewer/image_handler.cpp +++ b/src-interface/viewer/image_handler.cpp @@ -184,7 +184,7 @@ namespace satdump if (map_overlay) { logger->info("Drawing map overlay..."); - unsigned short color[3] = {(unsigned short)(color_borders.x * 65535.0f), (unsigned short)(color_borders.y * 65535.0f), (unsigned short)(color_borders.z * 65535.0f)}; + unsigned short color[3] = {(unsigned short)(viewer_color_borders.x * 65535.0f), (unsigned short)(viewer_color_borders.y * 65535.0f), (unsigned short)(viewer_color_borders.z * 65535.0f)}; map::drawProjectedMapShapefile({resources::getResourcePath("maps/ne_10m_admin_0_countries.shp")}, current_image, color, @@ -194,7 +194,7 @@ namespace satdump if (cities_overlay) { logger->info("Drawing cities overlay..."); - unsigned short color[3] = {(unsigned short)(color_cities.x * 65535.0f), (unsigned short)(color_cities.y * 65535.0f), (unsigned short)(color_cities.z * 65535.0f)}; + unsigned short color[3] = {(unsigned short)(viewer_color_cities.x * 65535.0f), (unsigned short)(viewer_color_cities.y * 65535.0f), (unsigned short)(viewer_color_cities.z * 65535.0f)}; map::drawProjectedCitiesGeoJson({resources::getResourcePath("maps/ne_10m_populated_places_simple.json")}, current_image, color, @@ -674,11 +674,11 @@ namespace satdump if (ImGui::Checkbox("Borders", &map_overlay)) asyncUpdate(); ImGui::SameLine(); - ImGui::ColorEdit3("##borders", (float *)&color_borders, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel); + ImGui::ColorEdit3("##borders", (float *)&viewer_color_borders, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel); if (ImGui::Checkbox("Cities", &cities_overlay)) asyncUpdate(); ImGui::SameLine(); - ImGui::ColorEdit3("##cities", (float *)&color_cities, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel); + ImGui::ColorEdit3("##cities", (float *)&viewer_color_cities, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel); ImGui::SliderInt("Cities Font Size", &cities_size, 10, 500); static const char *items[] = {"Capitals Only", "Capitals + Regional Capitals", "All (by Scale Rank)"}; if (ImGui::Combo("Cities Type", &cities_type, items, IM_ARRAYSIZE(items))) diff --git a/src-interface/viewer/image_handler.h b/src-interface/viewer/image_handler.h index 58051f661..4ca31b04b 100644 --- a/src-interface/viewer/image_handler.h +++ b/src-interface/viewer/image_handler.h @@ -80,9 +80,6 @@ namespace satdump bool project_old_algorithm = false; - ImVec4 color_borders = {0, 1, 0, 1}; - ImVec4 color_cities = {1, 0, 0, 1}; - // Utils void updateScaleImage(); void updateCorrectionFactors(bool first = false); diff --git a/src-interface/viewer/scatterometer_handler.cpp b/src-interface/viewer/scatterometer_handler.cpp index 2925fb4c6..bf46c36fb 100644 --- a/src-interface/viewer/scatterometer_handler.cpp +++ b/src-interface/viewer/scatterometer_handler.cpp @@ -68,7 +68,7 @@ namespace satdump { auto proj_func = satdump::reprojection::setupProjectionFunction(current_img.width(), current_img.height(), current_image_proj, {}); logger->info("Drawing map overlay..."); - unsigned short color[3] = {(unsigned short)(color_borders.x * 65535.0f), (unsigned short)(color_borders.y * 65535.0f), (unsigned short)(color_borders.z * 65535.0f)}; + unsigned short color[3] = {(unsigned short)(viewer_color_borders.x * 65535.0f), (unsigned short)(viewer_color_borders.y * 65535.0f), (unsigned short)(viewer_color_borders.z * 65535.0f)}; map::drawProjectedMapShapefile({resources::getResourcePath("maps/ne_10m_admin_0_countries.shp")}, current_img, color, @@ -157,7 +157,7 @@ namespace satdump if (ImGui::Checkbox("Borders", &map_overlay)) update(); ImGui::SameLine(); - ImGui::ColorEdit3("##borders", (float *)&color_borders, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel); + ImGui::ColorEdit3("##borders", (float *)&viewer_color_borders, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel); if (selected_visualization_id != 1) style::endDisabled(); } diff --git a/src-interface/viewer/scatterometer_handler.h b/src-interface/viewer/scatterometer_handler.h index 46c4f0428..73c00c61e 100644 --- a/src-interface/viewer/scatterometer_handler.h +++ b/src-interface/viewer/scatterometer_handler.h @@ -44,7 +44,6 @@ namespace satdump image::Image projected_img; bool map_overlay = false; - ImVec4 color_borders = {0, 1, 0, 1}; void init(); void update(); diff --git a/src-interface/viewer/viewer.cpp b/src-interface/viewer/viewer.cpp index b5ca11c64..d526496ce 100644 --- a/src-interface/viewer/viewer.cpp +++ b/src-interface/viewer/viewer.cpp @@ -16,6 +16,9 @@ void SelectableColor(ImU32 color) // funkcja pozwalająca na pokolorowanie komó namespace satdump { + ImVec4 viewer_color_borders = { 0, 1, 0, 1 }; + ImVec4 viewer_color_cities = { 1, 0, 0, 1 }; + ViewerApplication::ViewerApplication() : Application("viewer") { @@ -27,17 +30,17 @@ namespace satdump if (config::main_cfg["user"]["viewer_state"].contains("borders_color")) { std::vector color = config::main_cfg["user"]["viewer_state"]["borders_color"].get>(); - color_borders.x = color[0]; - color_borders.y = color[1]; - color_borders.z = color[2]; + viewer_color_borders.x = color[0]; + viewer_color_borders.y = color[1]; + viewer_color_borders.z = color[2]; } if (config::main_cfg["user"]["viewer_state"].contains("cities_color")) { std::vector color = config::main_cfg["user"]["viewer_state"]["cities_color"].get>(); - color_cities.x = color[0]; - color_cities.y = color[1]; - color_cities.z = color[2]; + viewer_color_cities.x = color[0]; + viewer_color_cities.y = color[1]; + viewer_color_cities.z = color[2]; } @@ -153,8 +156,8 @@ namespace satdump ViewerApplication::~ViewerApplication() { config::main_cfg["user"]["viewer_state"]["panel_ratio"] = panel_ratio; - config::main_cfg["user"]["viewer_state"]["borders_color"] = {color_borders.x, color_borders.y, color_borders.z}; - config::main_cfg["user"]["viewer_state"]["cities_color"] = {color_cities.x, color_cities.y, color_cities.z}; + config::main_cfg["user"]["viewer_state"]["borders_color"] = { viewer_color_borders.x, viewer_color_borders.y, viewer_color_borders.z}; + config::main_cfg["user"]["viewer_state"]["cities_color"] = { viewer_color_cities.x, viewer_color_cities.y, viewer_color_cities.z}; } ImRect ViewerApplication::renderHandler(ProductsHandler &ph, int index) diff --git a/src-interface/viewer/viewer.h b/src-interface/viewer/viewer.h index 07a4bc8f1..76bfb38d4 100644 --- a/src-interface/viewer/viewer.h +++ b/src-interface/viewer/viewer.h @@ -40,6 +40,8 @@ namespace satdump static std::shared_ptr getInstance(); }; + extern ImVec4 viewer_color_borders; + extern ImVec4 viewer_color_cities; extern std::map()>> viewer_handlers_registry; void registerViewerHandlers(); @@ -163,9 +165,6 @@ namespace satdump bool projections_draw_cities_overlay = true; int projections_cities_scale = 50; - ImVec4 color_borders = {0, 1, 0, 1}; - ImVec4 color_cities = {1, 0, 0, 1}; - int projections_current_selected_proj = 0; ///////////// float projections_equirectangular_tl_lon = -180; diff --git a/src-interface/viewer/viewer_projection.cpp b/src-interface/viewer/viewer_projection.cpp index b7b244142..708ac39b7 100644 --- a/src-interface/viewer/viewer_projection.cpp +++ b/src-interface/viewer/viewer_projection.cpp @@ -399,10 +399,10 @@ namespace satdump { ImGui::Checkbox("Map Overlay##Projs", &projections_draw_map_overlay); ImGui::SameLine(); - ImGui::ColorEdit3("##borders", (float *)&color_borders, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel); + ImGui::ColorEdit3("##borders", (float *)&viewer_color_borders, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel); ImGui::Checkbox("Cities Overlay##Projs", &projections_draw_cities_overlay); ImGui::SameLine(); - ImGui::ColorEdit3("##cities", (float *)&color_cities, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel); + ImGui::ColorEdit3("##cities", (float *)&viewer_color_cities, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel); ImGui::SliderInt("Cities Font Size##Projs", &projections_cities_scale, 10, 500); } @@ -518,7 +518,7 @@ namespace satdump if (projections_draw_map_overlay) { logger->info("Drawing map overlay..."); - unsigned short color[4] = {(unsigned short)(color_borders.x * 65535.0f), (unsigned short)(color_borders.y * 65535.0f), (unsigned short)(color_borders.z * 65535.0f), 65535}; + unsigned short color[4] = {(unsigned short)(viewer_color_borders.x * 65535.0f), (unsigned short)(viewer_color_borders.y * 65535.0f), (unsigned short)(viewer_color_borders.z * 65535.0f), 65535}; map::drawProjectedMapShapefile({resources::getResourcePath("maps/ne_10m_admin_0_countries.shp")}, projected_image_result, color, @@ -529,7 +529,7 @@ namespace satdump if (projections_draw_cities_overlay) { logger->info("Drawing map overlay..."); - unsigned short color[4] = {(unsigned short)(color_cities.x * 65535.0f), (unsigned short)(color_cities.y * 65535.0f), (unsigned short)(color_cities.z * 65535.0f), 65535}; + unsigned short color[4] = {(unsigned short)(viewer_color_cities.x * 65535.0f), (unsigned short)(viewer_color_cities.y * 65535.0f), (unsigned short)(viewer_color_cities.z * 65535.0f), 65535}; map::drawProjectedCapitalsGeoJson({resources::getResourcePath("maps/ne_10m_populated_places_simple.json")}, projected_image_result, color,