From 7e848c132f171617db4f903b50473b1a5f639d8b Mon Sep 17 00:00:00 2001 From: "r.kuznetsov" Date: Mon, 20 Feb 2017 14:45:05 +0300 Subject: [PATCH] Added simplified traffic colors --- android/jni/com/mapswithme/maps/Framework.cpp | 13 +++++++++++++ android/src/com/mapswithme/maps/Framework.java | 4 ++++ drape/support_manager.hpp | 1 + drape_frontend/backend_renderer.cpp | 17 +++++++++++++++++ drape_frontend/backend_renderer.hpp | 4 +++- drape_frontend/drape_engine.cpp | 9 ++++++++- drape_frontend/drape_engine.hpp | 6 +++++- drape_frontend/frontend_renderer.cpp | 1 + drape_frontend/message.hpp | 1 + drape_frontend/message_subclasses.hpp | 15 +++++++++++++++ drape_frontend/traffic_generator.cpp | 15 ++++++++++++++- drape_frontend/traffic_generator.hpp | 3 +++ map/framework.cpp | 18 +++++++++++++++++- map/framework.hpp | 3 +++ map/traffic_manager.cpp | 6 ++++++ map/traffic_manager.hpp | 2 ++ qt/search_panel.cpp | 17 +++++++++++++++++ qt/search_panel.hpp | 1 + 18 files changed, 131 insertions(+), 5 deletions(-) diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index f386e6a6ef..10fd33885c 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -1150,6 +1150,19 @@ Java_com_mapswithme_maps_Framework_nativeGetAutoZoomEnabled(JNIEnv * env, jclass return frm()->LoadAutoZoom(); } +JNIEXPORT void JNICALL +Java_com_mapswithme_maps_Framework_nativeSetSimplifiedTrafficColorsEnabled(JNIEnv * env, jclass, jboolean enabled) +{ + bool const simplifiedEnabled = static_cast(enabled); + frm()->SaveTrafficSimplifiedColors(simplifiedEnabled); +} + +JNIEXPORT jboolean JNICALL +Java_com_mapswithme_maps_Framework_nativeGetSimplifiedTrafficColorsEnabled(JNIEnv * env, jclass) +{ + return frm()->LoadTrafficSimplifiedColors(); +} + // static void nativeZoomToPoint(double lat, double lon, int zoom, boolean animate); JNIEXPORT void JNICALL Java_com_mapswithme_maps_Framework_nativeZoomToPoint(JNIEnv * env, jclass, jdouble lat, jdouble lon, jint zoom, jboolean animate) diff --git a/android/src/com/mapswithme/maps/Framework.java b/android/src/com/mapswithme/maps/Framework.java index b43a93412b..37edb84d6a 100644 --- a/android/src/com/mapswithme/maps/Framework.java +++ b/android/src/com/mapswithme/maps/Framework.java @@ -241,6 +241,10 @@ public class Framework public static native void nativeSetAutoZoomEnabled(boolean enabled); + public static native boolean nativeGetSimplifiedTrafficColorsEnabled(); + + public static native void nativeSetSimplifiedTrafficColorsEnabled(boolean enabled); + @NonNull public static native MapObject nativeDeleteBookmarkFromMapObject(); diff --git a/drape/support_manager.hpp b/drape/support_manager.hpp index bac71bd2e1..c59fdbcbbe 100644 --- a/drape/support_manager.hpp +++ b/drape/support_manager.hpp @@ -8,6 +8,7 @@ namespace dp class SupportManager : public noncopyable { public: + // This singleton must be available only from rendering threads. static SupportManager & Instance(); // Initialization must be called only when OpenGL context is created. diff --git a/drape_frontend/backend_renderer.cpp b/drape_frontend/backend_renderer.cpp index 481bc14ebd..ce75b4cd96 100644 --- a/drape_frontend/backend_renderer.cpp +++ b/drape_frontend/backend_renderer.cpp @@ -38,6 +38,8 @@ BackendRenderer::BackendRenderer(Params const & params) m_isTeardowned = false; #endif + TrafficGenerator::SetSimplifiedColorSchemeEnabled(params.m_simplifiedTrafficColors); + ASSERT(m_updateCurrentCountryFn != nullptr, ()); m_routeBuilder = make_unique_dp([this](drape_ptr && routeData) @@ -380,6 +382,7 @@ void BackendRenderer::AcceptMessage(ref_ptr message) MessagePriority::Normal); break; } + case Message::ClearTrafficData: { ref_ptr msg = message; @@ -391,6 +394,20 @@ void BackendRenderer::AcceptMessage(ref_ptr message) MessagePriority::Normal); break; } + + case Message::SetSimplifiedTrafficColors: + { + ref_ptr msg = message; + + m_trafficGenerator->SetSimplifiedColorSchemeEnabled(msg->IsSimplified()); + m_trafficGenerator->InvalidateTexturesCache(); + + m_commutator->PostMessage(ThreadsCommutator::RenderThread, + make_unique_dp(msg->IsSimplified()), + MessagePriority::Normal); + break; + } + case Message::DrapeApiAddLines: { ref_ptr msg = message; diff --git a/drape_frontend/backend_renderer.hpp b/drape_frontend/backend_renderer.hpp index 15d138e0a3..b8b1f8a417 100644 --- a/drape_frontend/backend_renderer.hpp +++ b/drape_frontend/backend_renderer.hpp @@ -39,13 +39,14 @@ public: ref_ptr texMng, MapDataProvider const & model, TUpdateCurrentCountryFn const & updateCurrentCountryFn, ref_ptr requestedTiles, bool allow3dBuildings, - bool trafficEnabled) + bool trafficEnabled, bool simplifiedTrafficColors) : BaseRenderer::Params(commutator, factory, texMng) , m_model(model) , m_updateCurrentCountryFn(updateCurrentCountryFn) , m_requestedTiles(requestedTiles) , m_allow3dBuildings(allow3dBuildings) , m_trafficEnabled(trafficEnabled) + , m_simplifiedTrafficColors(simplifiedTrafficColors) {} MapDataProvider const & m_model; @@ -53,6 +54,7 @@ public: ref_ptr m_requestedTiles; bool m_allow3dBuildings; bool m_trafficEnabled; + bool m_simplifiedTrafficColors; }; BackendRenderer(Params const & params); diff --git a/drape_frontend/drape_engine.cpp b/drape_frontend/drape_engine.cpp index c81c5f8fa3..d39a1c0851 100644 --- a/drape_frontend/drape_engine.cpp +++ b/drape_frontend/drape_engine.cpp @@ -67,7 +67,7 @@ DrapeEngine::DrapeEngine(Params && params) frParams.m_texMng, params.m_model, params.m_model.UpdateCurrentCountryFn(), make_ref(m_requestedTiles), params.m_allow3dBuildings, - params.m_trafficEnabled); + params.m_trafficEnabled, params.m_simplifiedTrafficColors); m_backend = make_unique_dp(brParams); m_widgetsInfo = move(params.m_info); @@ -560,6 +560,13 @@ void DrapeEngine::ClearTrafficCache(MwmSet::MwmId const & mwmId) MessagePriority::Normal); } +void DrapeEngine::SetSimplifiedTrafficColors(bool simplified) +{ + m_threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread, + make_unique_dp(simplified), + MessagePriority::Normal); +} + void DrapeEngine::SetFontScaleFactor(double scaleFactor) { double const kMinScaleFactor = 0.5; diff --git a/drape_frontend/drape_engine.hpp b/drape_frontend/drape_engine.hpp index 76ddb562a7..6d70cedd31 100644 --- a/drape_frontend/drape_engine.hpp +++ b/drape_frontend/drape_engine.hpp @@ -54,7 +54,8 @@ public: vector && boundAreaTriangles, bool firstLaunch, bool isRoutingActive, - bool isAutozoomEnabled) + bool isAutozoomEnabled, + bool simplifiedTrafficColors) : m_factory(factory) , m_stringsBundle(stringBundle) , m_viewport(viewport) @@ -72,6 +73,7 @@ public: , m_isFirstLaunch(firstLaunch) , m_isRoutingActive(isRoutingActive) , m_isAutozoomEnabled(isAutozoomEnabled) + , m_simplifiedTrafficColors(simplifiedTrafficColors) {} ref_ptr m_factory; @@ -91,6 +93,7 @@ public: bool m_isFirstLaunch; bool m_isRoutingActive; bool m_isAutozoomEnabled; + bool m_simplifiedTrafficColors; }; DrapeEngine(Params && params); @@ -176,6 +179,7 @@ public: void EnableTraffic(bool trafficEnabled); void UpdateTraffic(traffic::TrafficInfo const & info); void ClearTrafficCache(MwmSet::MwmId const & mwmId); + void SetSimplifiedTrafficColors(bool simplified); void SetFontScaleFactor(double scaleFactor); diff --git a/drape_frontend/frontend_renderer.cpp b/drape_frontend/frontend_renderer.cpp index 2f9a1d1b01..e1b6327c30 100755 --- a/drape_frontend/frontend_renderer.cpp +++ b/drape_frontend/frontend_renderer.cpp @@ -737,6 +737,7 @@ void FrontendRenderer::AcceptMessage(ref_ptr message) } case Message::RegenerateTraffic: + case Message::SetSimplifiedTrafficColors: { m_needRegenerateTraffic = true; break; diff --git a/drape_frontend/message.hpp b/drape_frontend/message.hpp index dfccdf43f7..2b268aab79 100644 --- a/drape_frontend/message.hpp +++ b/drape_frontend/message.hpp @@ -71,6 +71,7 @@ public: UpdateTraffic, FlushTrafficData, ClearTrafficData, + SetSimplifiedTrafficColors, DrapeApiAddLines, DrapeApiRemove, DrapeApiFlush, diff --git a/drape_frontend/message_subclasses.hpp b/drape_frontend/message_subclasses.hpp index 2109c8a04d..ec023666e1 100644 --- a/drape_frontend/message_subclasses.hpp +++ b/drape_frontend/message_subclasses.hpp @@ -1085,6 +1085,21 @@ private: MwmSet::MwmId m_mwmId; }; +class SetSimplifiedTrafficColorsMessage : public Message +{ +public: + SetSimplifiedTrafficColorsMessage(bool isSimplified) + : m_isSimplified(isSimplified) + {} + + Type GetType() const override { return Message::SetSimplifiedTrafficColors; } + + bool IsSimplified() const { return m_isSimplified; } + +private: + bool const m_isSimplified; +}; + class DrapeApiAddLinesMessage : public Message { public: diff --git a/drape_frontend/traffic_generator.cpp b/drape_frontend/traffic_generator.cpp index 574e626425..399312cf09 100644 --- a/drape_frontend/traffic_generator.cpp +++ b/drape_frontend/traffic_generator.cpp @@ -103,6 +103,8 @@ void GenerateCapTriangles(glsl::vec3 const & pivot, vector const & n } // namespace +bool TrafficGenerator::m_simplifiedColorScheme = true; + void TrafficGenerator::Init() { int constexpr kBatchersCount = 3; @@ -331,6 +333,12 @@ void TrafficGenerator::GenerateLineSegment(dp::TextureManager::ColorRegion const } } +// static +void TrafficGenerator::SetSimplifiedColorSchemeEnabled(bool enabled) +{ + m_simplifiedColorScheme = enabled; +} + // static df::ColorConstant TrafficGenerator::GetColorBySpeedGroup(traffic::SpeedGroup const & speedGroup, bool route) { @@ -359,7 +367,12 @@ df::ColorConstant TrafficGenerator::GetColorBySpeedGroup(traffic::SpeedGroup con "TrafficUnknown", }}; - size_t const index = static_cast(speedGroup); + traffic::SpeedGroup group = speedGroup; + // In simplified color scheme we reduce amount of speed groups visually. + if (m_simplifiedColorScheme && speedGroup == traffic::SpeedGroup::G4) + group = traffic::SpeedGroup::G3; + + size_t const index = static_cast(group); ASSERT_LESS(index, kSpeedGroupsCount, ()); return route ? kColorMapRoute[index] : kColorMap[index]; } diff --git a/drape_frontend/traffic_generator.hpp b/drape_frontend/traffic_generator.hpp index e9c331c8d2..3bc9d4608a 100644 --- a/drape_frontend/traffic_generator.hpp +++ b/drape_frontend/traffic_generator.hpp @@ -147,6 +147,7 @@ public: void ClearCache(MwmSet::MwmId const & mwmId); void InvalidateTexturesCache(); + static void SetSimplifiedColorSchemeEnabled(bool enabled); static df::ColorConstant GetColorBySpeedGroup(traffic::SpeedGroup const & speedGroup, bool route); private: @@ -200,6 +201,8 @@ private: dp::AttributeProvider m_providerTriangles; dp::AttributeProvider m_providerLines; + + static bool m_simplifiedColorScheme; }; } // namespace df diff --git a/map/framework.cpp b/map/framework.cpp index fa2fb7e4b9..09663c52b2 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -126,6 +126,7 @@ char const kAllow3dKey[] = "Allow3d"; char const kAllow3dBuildingsKey[] = "Buildings3d"; char const kAllowAutoZoom[] = "AutoZoom"; char const kTrafficEnabledKey[] = "TrafficEnabled"; +char const kTrafficSimplifiedColorsKey[] = "TrafficSimplifiedColors"; char const kLargeFontsSize[] = "LargeFontsSize"; double const kDistEqualQueryMeters = 100.0; @@ -1676,6 +1677,8 @@ void Framework::CreateDrapeEngine(ref_ptr contextFactory, bool const isAutozoomEnabled = LoadAutoZoom(); bool const trafficEnabled = LoadTrafficEnabled(); m_trafficManager.SetEnabled(trafficEnabled); + bool const simplifiedTrafficColors = LoadTrafficSimplifiedColors(); + m_trafficManager.SetSimplifiedColorScheme(simplifiedTrafficColors); double const fontsScaleFactor = LoadLargeFontsSize() ? kLargeFontsScaleFactor : 1.0; @@ -1687,7 +1690,8 @@ void Framework::CreateDrapeEngine(ref_ptr contextFactory, make_pair(params.m_initialMyPositionState, params.m_hasMyPositionState), move(myPositionModeChangedFn), allow3dBuildings, trafficEnabled, params.m_isChoosePositionMode, params.m_isChoosePositionMode, GetSelectedFeatureTriangles(), params.m_isFirstLaunch, - m_routingSession.IsActive() && m_routingSession.IsFollowing(), isAutozoomEnabled); + m_routingSession.IsActive() && m_routingSession.IsFollowing(), isAutozoomEnabled, + simplifiedTrafficColors); m_drapeEngine = make_unique_dp(move(p)); m_drapeEngine->SetModelViewListener([this](ScreenBase const & screen) @@ -2769,6 +2773,18 @@ void Framework::SaveTrafficEnabled(bool trafficEnabled) settings::Set(kTrafficEnabledKey, trafficEnabled); } +bool Framework::LoadTrafficSimplifiedColors() +{ + bool simplified = true; + settings::Get(kTrafficSimplifiedColorsKey, simplified); + return simplified; +} + +void Framework::SaveTrafficSimplifiedColors(bool simplified) +{ + settings::Set(kTrafficSimplifiedColorsKey, simplified); +} + bool Framework::LoadAutoZoom() { bool allowAutoZoom = true; diff --git a/map/framework.hpp b/map/framework.hpp index 70d5e113d4..41b8f04fc7 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -786,6 +786,9 @@ public: bool LoadTrafficEnabled(); void SaveTrafficEnabled(bool trafficEnabled); + bool LoadTrafficSimplifiedColors(); + void SaveTrafficSimplifiedColors(bool simplified); + /// \returns true if altitude information along |m_route| is available and /// false otherwise. bool HasRouteAltitude() const; diff --git a/map/traffic_manager.cpp b/map/traffic_manager.cpp index b4ada5ff92..e6c93f01f6 100644 --- a/map/traffic_manager.cpp +++ b/map/traffic_manager.cpp @@ -558,6 +558,12 @@ void TrafficManager::Resume() Invalidate(); } +void TrafficManager::SetSimplifiedColorScheme(bool simplified) +{ + if (m_drapeEngine != nullptr) + m_drapeEngine->SetSimplifiedTrafficColors(simplified); +} + string DebugPrint(TrafficManager::TrafficState state) { switch (state) diff --git a/map/traffic_manager.hpp b/map/traffic_manager.hpp index b126cbabb1..d2116f70df 100644 --- a/map/traffic_manager.hpp +++ b/map/traffic_manager.hpp @@ -84,6 +84,8 @@ public: void OnEnterForeground(); void OnEnterBackground(); + void SetSimplifiedColorScheme(bool simplified); + private: struct CacheEntry { diff --git a/qt/search_panel.cpp b/qt/search_panel.cpp index b1f63a1136..9a843ea68c 100644 --- a/qt/search_panel.cpp +++ b/qt/search_panel.cpp @@ -266,6 +266,21 @@ bool SearchPanel::TryDisplacementModeCmd(QString const & str) return true; } +bool SearchPanel::TryTrafficSimplifiedColorsCmd(QString const & str) +{ + bool const simplifiedMode = (str == "?tc:simp"); + bool const normalMode = (str == "?tc:norm"); + + if (!simplifiedMode && !normalMode) + return false; + + bool const isSimplified = simplifiedMode; + m_pDrawWidget->GetFramework().GetTrafficManager().SetSimplifiedColorScheme(isSimplified); + m_pDrawWidget->GetFramework().SaveTrafficSimplifiedColors(isSimplified); + + return true; +} + void SearchPanel::OnSearchTextChanged(QString const & str) { QString const normalized = str.normalized(QString::NormalizationForm_KC); @@ -281,6 +296,8 @@ void SearchPanel::OnSearchTextChanged(QString const & str) return; if (TryDisplacementModeCmd(normalized)) return; + if (TryTrafficSimplifiedColorsCmd(normalized)) + return; // search even with empty query if (!normalized.isEmpty()) diff --git a/qt/search_panel.hpp b/qt/search_panel.hpp index 1d253481fb..d5cc2ef4c5 100644 --- a/qt/search_panel.hpp +++ b/qt/search_panel.hpp @@ -68,5 +68,6 @@ private slots: bool Try3dModeCmd(QString const & str); bool TryMigrate(QString const & str); bool TryDisplacementModeCmd(QString const & str); + bool TryTrafficSimplifiedColorsCmd(QString const & str); }; } // namespace qt