Transit colours loading.

This commit is contained in:
Daria Volvenkova 2017-11-13 13:52:56 +03:00 committed by Vladimir Byko-Ianko
parent 9cdf58ca77
commit cb0cd2e5a1
8 changed files with 141 additions and 0 deletions

View file

@ -0,0 +1 @@
../../data/transit_colors.txt

View file

@ -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
)

View file

@ -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 <fstream>
#include <map>
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<Reader>(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<uint32_t>(color));
return dp::Color();
}
std::map<std::string, dp::Color> m_clearColors;
std::map<std::string, dp::Color> 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

View file

@ -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

View file

@ -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 \

View file

@ -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 = "<group>"; };
9DF04B231B71010E00DACAF1 /* 02_droidsans-fallback.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = "02_droidsans-fallback.ttf"; path = "../../data/02_droidsans-fallback.ttf"; sourceTree = "<group>"; };
A367C93A1B17334800E2B6E7 /* resources-default */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "resources-default"; path = "../../data/resources-default"; sourceTree = "<group>"; };
BB25B1A51FB32767007276FA /* transit_colors.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = transit_colors.txt; path = ../../data/transit_colors.txt; sourceTree = "<group>"; };
BB7626B41E8559980031D71C /* icudt57l.dat */ = {isa = PBXFileReference; lastKnownFileType = file; name = icudt57l.dat; path = ../../data/icudt57l.dat; sourceTree = "<group>"; };
ED48BBB317C267F5003E7E92 /* ColorPickerView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ColorPickerView.h; sourceTree = "<group>"; };
ED48BBB417C267F5003E7E92 /* ColorPickerView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ColorPickerView.mm; sourceTree = "<group>"; };
@ -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 */,

View file

@ -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();

View file

@ -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;