From cb0cd2e5a16f38e42ec52440fb347b95254ada89 Mon Sep 17 00:00:00 2001 From: Daria Volvenkova Date: Mon, 13 Nov 2017 13:52:56 +0300 Subject: [PATCH] Transit colours loading. --- android/assets/transit_colors.txt | 1 + drape_frontend/CMakeLists.txt | 1 + drape_frontend/color_constants.cpp | 124 ++++++++++++++++++ drape_frontend/color_constants.hpp | 5 + drape_frontend/drape_frontend.pro | 1 + iphone/Maps/Maps.xcodeproj/project.pbxproj | 6 + map/framework.cpp | 1 + .../drape_frontend.xcodeproj/project.pbxproj | 2 + 8 files changed, 141 insertions(+) create mode 120000 android/assets/transit_colors.txt diff --git a/android/assets/transit_colors.txt b/android/assets/transit_colors.txt new file mode 120000 index 0000000000..6efd92d76a --- /dev/null +++ b/android/assets/transit_colors.txt @@ -0,0 +1 @@ +../../data/transit_colors.txt \ No newline at end of file diff --git a/drape_frontend/CMakeLists.txt b/drape_frontend/CMakeLists.txt index 051ce02c74..bfbdae254d 100644 --- a/drape_frontend/CMakeLists.txt +++ b/drape_frontend/CMakeLists.txt @@ -15,6 +15,7 @@ include_directories( ${OMIM_ROOT}/3party/protobuf/protobuf/src ${OMIM_ROOT}/3party/expat/lib ${OMIM_ROOT}/3party/freetype/include + ${OMIM_ROOT}/3party/jansson/src ${OMIM_ROOT}/3party/glm ) diff --git a/drape_frontend/color_constants.cpp b/drape_frontend/color_constants.cpp index e8954b4636..346267b48b 100644 --- a/drape_frontend/color_constants.cpp +++ b/drape_frontend/color_constants.cpp @@ -1,15 +1,139 @@ #include "drape_frontend/color_constants.hpp" #include "drape_frontend/apply_feature_functors.hpp" +#include "platform/platform.hpp" + #include "indexer/drawing_rules.hpp" +#include "indexer/map_style_reader.hpp" + +#include "coding/reader.hpp" #include "base/assert.hpp" +#include "base/string_utils.hpp" + +#include "3party/jansson/myjansson.hpp" + +#include +#include + +namespace +{ +class TransitColorsHolder +{ +public: + dp::Color GetColor(std::string const & name) const + { + auto const style = GetStyleReader().GetCurrentStyle(); + auto const isDarkStyle = style == MapStyle::MapStyleDark || style == MapStyle::MapStyleVehicleDark; + auto const & colors = isDarkStyle ? m_nightColors : m_clearColors; + auto const it = colors.find(name); + if (it == colors.cend()) + { + LOG(LWARNING, ("Requested transit color '" + name + "' is not found")); + return dp::Color(); + } + return it->second; + } + + void Load() + { + std::string data; + try + { + ReaderPtr(GetPlatform().GetReader("transit_colors.txt")).ReadAsString(data); + } + catch (RootException const & ex) + { + LOG(LWARNING, ("Loading transit colors failed:", ex.Msg())); + return; + } + + try + { + my::Json root(data); + + if (root.get() == nullptr) + return; + + auto colors = json_object_get(root.get(), "colors"); + if (colors == nullptr) + return; + + const char * name = nullptr; + json_t * colorInfo = nullptr; + json_object_foreach(colors, name, colorInfo) + { + ASSERT(name != nullptr, ()); + ASSERT(colorInfo != nullptr, ()); + + std::string strValue; + FromJSONObject(colorInfo, "clear", strValue); + m_clearColors[df::GetTransitColorName(name)] = ParseColor(strValue); + FromJSONObject(colorInfo, "night", strValue); + m_nightColors[df::GetTransitColorName(name)] = ParseColor(strValue); + FromJSONObject(colorInfo, "text", strValue); + m_clearColors[df::GetTransitTextColorName(name)] = ParseColor(strValue); + m_nightColors[df::GetTransitTextColorName(name)] = ParseColor(strValue); + + } + } + catch (my::Json::Exception const & e) + { + LOG(LWARNING, ("Reading transit colors failed:", e.Msg())); + } + } + +private: + dp::Color ParseColor(std::string const & colorStr) + { + unsigned int color; + if (strings::to_uint(colorStr, color, 16)) + return df::ToDrapeColor(static_cast(color)); + return dp::Color(); + } + + std::map m_clearColors; + std::map m_nightColors; +}; + +TransitColorsHolder & TransitColors() +{ + static TransitColorsHolder h; + return h; +} +} // namespace namespace df { +std::string const kTransitColorPrefix = "transit_"; +std::string const kTransitTextPrefix = "text_"; +std::string const kTransitLinePrefix = "line_"; + +ColorConstant GetTransitColorName(ColorConstant const & localName) +{ + return kTransitColorPrefix + kTransitLinePrefix + localName; +} + +ColorConstant GetTransitTextColorName(ColorConstant const & localName) +{ + return kTransitColorPrefix + kTransitTextPrefix + localName; +} + +bool IsTransitColor(ColorConstant const & constant) +{ + return strings::StartsWith(constant, kTransitColorPrefix.c_str()); +} + dp::Color GetColorConstant(ColorConstant const & constant) { + if (IsTransitColor(constant)) + return TransitColors().GetColor(constant); uint32_t const color = drule::rules().GetColor(constant); return ToDrapeColor(color); } + +void LoadTransitColors() +{ + TransitColors().Load(); +} } // namespace df diff --git a/drape_frontend/color_constants.hpp b/drape_frontend/color_constants.hpp index 1ac6c5da0f..21c7868c64 100644 --- a/drape_frontend/color_constants.hpp +++ b/drape_frontend/color_constants.hpp @@ -9,4 +9,9 @@ namespace df using ColorConstant = std::string; dp::Color GetColorConstant(ColorConstant const & constant); + +void LoadTransitColors(); + +ColorConstant GetTransitColorName(ColorConstant const & localName); +ColorConstant GetTransitTextColorName(ColorConstant const & localName); } // namespace df diff --git a/drape_frontend/drape_frontend.pro b/drape_frontend/drape_frontend.pro index babebf4040..be51bbcb71 100755 --- a/drape_frontend/drape_frontend.pro +++ b/drape_frontend/drape_frontend.pro @@ -12,6 +12,7 @@ include($$ROOT_DIR/common.pri) INCLUDEPATH *= $$ROOT_DIR/3party/protobuf/protobuf/src INCLUDEPATH *= $$ROOT_DIR/3party/expat/lib INCLUDEPATH *= $$ROOT_DIR/3party/freetype/include +INCLUDEPATH *= $$ROOT_DIR/3party/jansson/src SOURCES += \ animation/animation.cpp \ diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj index 921183b381..2c3d82c230 100644 --- a/iphone/Maps/Maps.xcodeproj/project.pbxproj +++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj @@ -1149,6 +1149,8 @@ 978D4A31199A11E600D72CA7 /* faq.html in Resources */ = {isa = PBXBuildFile; fileRef = 978D4A30199A11E600D72CA7 /* faq.html */; }; 97A5967F19B9CD47007A963F /* copyright.html in Resources */ = {isa = PBXBuildFile; fileRef = 97A5967E19B9CD47007A963F /* copyright.html */; }; A367C93B1B17334800E2B6E7 /* resources-default in Resources */ = {isa = PBXBuildFile; fileRef = A367C93A1B17334800E2B6E7 /* resources-default */; }; + BB25B1A61FB32767007276FA /* transit_colors.txt in Resources */ = {isa = PBXBuildFile; fileRef = BB25B1A51FB32767007276FA /* transit_colors.txt */; }; + BB25B1A71FB32767007276FA /* transit_colors.txt in Resources */ = {isa = PBXBuildFile; fileRef = BB25B1A51FB32767007276FA /* transit_colors.txt */; }; BB7626B51E8559980031D71C /* icudt57l.dat in Resources */ = {isa = PBXBuildFile; fileRef = BB7626B41E8559980031D71C /* icudt57l.dat */; }; BB7626B61E85599C0031D71C /* icudt57l.dat in Resources */ = {isa = PBXBuildFile; fileRef = BB7626B41E8559980031D71C /* icudt57l.dat */; }; BB7626B71E85599C0031D71C /* icudt57l.dat in Resources */ = {isa = PBXBuildFile; fileRef = BB7626B41E8559980031D71C /* icudt57l.dat */; }; @@ -2433,6 +2435,7 @@ 97A5967E19B9CD47007A963F /* copyright.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = copyright.html; path = ../../data/copyright.html; sourceTree = ""; }; 9DF04B231B71010E00DACAF1 /* 02_droidsans-fallback.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = "02_droidsans-fallback.ttf"; path = "../../data/02_droidsans-fallback.ttf"; sourceTree = ""; }; A367C93A1B17334800E2B6E7 /* resources-default */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "resources-default"; path = "../../data/resources-default"; sourceTree = ""; }; + BB25B1A51FB32767007276FA /* transit_colors.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = transit_colors.txt; path = ../../data/transit_colors.txt; sourceTree = ""; }; BB7626B41E8559980031D71C /* icudt57l.dat */ = {isa = PBXFileReference; lastKnownFileType = file; name = icudt57l.dat; path = ../../data/icudt57l.dat; sourceTree = ""; }; ED48BBB317C267F5003E7E92 /* ColorPickerView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ColorPickerView.h; sourceTree = ""; }; ED48BBB417C267F5003E7E92 /* ColorPickerView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ColorPickerView.mm; sourceTree = ""; }; @@ -4848,6 +4851,7 @@ FA065FC61286143F00FEA989 /* External Resources */ = { isa = PBXGroup; children = ( + BB25B1A51FB32767007276FA /* transit_colors.txt */, F642D1221F0F9D1D005E3C25 /* ugc_types.csv */, 450703081E9E6CF000E8C029 /* local_ads_symbols.txt */, BB7626B41E8559980031D71C /* icudt57l.dat */, @@ -5250,6 +5254,7 @@ F6E2FF381E097BA00083EBEC /* MWMSearchSuggestionCell.xib in Resources */, F6664C041E6459DA00E703C2 /* PPReviewHeaderCell.xib in Resources */, F6E2FF1A1E097BA00083EBEC /* MWMSearchTabbedCollectionViewCell.xib in Resources */, + BB25B1A61FB32767007276FA /* transit_colors.txt in Resources */, F6E2FF201E097BA00083EBEC /* MWMSearchTabbedViewController.xib in Resources */, F6E2FF291E097BA00083EBEC /* MWMSearchTabButtonsView.xib in Resources */, 344532501F714FD70059FBCC /* UGCAddReviewController.xib in Resources */, @@ -5438,6 +5443,7 @@ F6E2FF211E097BA00083EBEC /* MWMSearchTabbedViewController.xib in Resources */, F6664C051E6459DA00E703C2 /* PPReviewHeaderCell.xib in Resources */, F6E2FF2A1E097BA00083EBEC /* MWMSearchTabButtonsView.xib in Resources */, + BB25B1A71FB32767007276FA /* transit_colors.txt in Resources */, F6E2FF421E097BA00083EBEC /* MWMSearchTableViewController.xib in Resources */, F6E2FEEE1E097BA00083EBEC /* MWMSearchView.xib in Resources */, 344532511F714FD70059FBCC /* UGCAddReviewController.xib in Resources */, diff --git a/map/framework.cpp b/map/framework.cpp index 3632ca92ea..c77df72a97 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -391,6 +391,7 @@ Framework::Framework(FrameworkParams const & params) if (settings::Get(kMapStyleKey, mapStyleStr)) mapStyle = MapStyleFromSettings(mapStyleStr); GetStyleReader().SetCurrentStyle(mapStyle); + df::LoadTransitColors(); m_connectToGpsTrack = GpsTracker::Instance().IsEnabled(); diff --git a/xcode/drape_frontend/drape_frontend.xcodeproj/project.pbxproj b/xcode/drape_frontend/drape_frontend.xcodeproj/project.pbxproj index 023358468f..17f9190672 100644 --- a/xcode/drape_frontend/drape_frontend.xcodeproj/project.pbxproj +++ b/xcode/drape_frontend/drape_frontend.xcodeproj/project.pbxproj @@ -1080,6 +1080,7 @@ "$(OMIM_ROOT)/3party/protobuf/protobuf/src", "$(OMIM_ROOT)/3party/protobuf", "$(OMIM_ROOT)/3party/freetype/include", + "$(OMIM_ROOT)/3party/jansson/src", ); }; name = Debug; @@ -1099,6 +1100,7 @@ "$(OMIM_ROOT)/3party/protobuf/protobuf/src", "$(OMIM_ROOT)/3party/protobuf", "$(OMIM_ROOT)/3party/freetype/include", + "$(OMIM_ROOT)/3party/jansson/src", ); }; name = Release;