Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorExMix <rahuba.youri@mapswithme.com>2015-05-21 13:02:42 +0300
committerr.kuznetsov <r.kuznetsov@corp.mail.ru>2015-11-30 16:07:46 +0300
commit5fde96bf58d2ed8f20f73232b756dae980a8147d (patch)
tree16c9948b8dd972a2f5335639795647c7e4d6c3a6
parentfa5be671cdf6c367cb60df6ceb974cdc548737f5 (diff)
[drape] my position controller
- gps, compass info messages - my position rendering fixes - remove useless code
-rw-r--r--drape/shaders/position_accuracy_shader.vsh5
-rw-r--r--drape_frontend/drape_engine.cpp62
-rw-r--r--drape_frontend/drape_engine.hpp12
-rwxr-xr-xdrape_frontend/drape_frontend.pro2
-rwxr-xr-xdrape_frontend/frontend_renderer.cpp54
-rwxr-xr-xdrape_frontend/frontend_renderer.hpp14
-rw-r--r--drape_frontend/message.hpp5
-rw-r--r--drape_frontend/message_subclasses.hpp58
-rw-r--r--drape_frontend/my_position.cpp36
-rw-r--r--drape_frontend/my_position.hpp3
-rw-r--r--drape_frontend/my_position_controller.cpp302
-rw-r--r--drape_frontend/my_position_controller.hpp88
-rw-r--r--map/framework.cpp62
-rw-r--r--map/framework.hpp29
-rw-r--r--map/location_state.cpp1096
-rw-r--r--map/location_state.hpp169
-rw-r--r--map/map.pro6
-rw-r--r--map/route_track.cpp2
-rw-r--r--map/route_track.hpp2
-rw-r--r--platform/location.hpp16
-rw-r--r--routing/route.cpp3
21 files changed, 1014 insertions, 1012 deletions
diff --git a/drape/shaders/position_accuracy_shader.vsh b/drape/shaders/position_accuracy_shader.vsh
index c4fbe1bc24..af33e3f691 100644
--- a/drape/shaders/position_accuracy_shader.vsh
+++ b/drape/shaders/position_accuracy_shader.vsh
@@ -11,8 +11,9 @@ varying vec2 v_colorTexCoords;
void main(void)
{
- vec4 position = vec4(u_position.xy + normalize(a_normal) * u_accuracy, u_position.z, 1);
- gl_Position = position * modelView * projection;
+ vec4 position = vec4(u_position, 1.0) * modelView;
+ vec4 normal = vec4(normalize(a_normal) * u_accuracy, 0.0, 0.0);
+ gl_Position = (position + normal) * projection;
v_colorTexCoords = a_colorTexCoords;
}
diff --git a/drape_frontend/drape_engine.cpp b/drape_frontend/drape_engine.cpp
index 51ae3f8c8f..f6e1b46d08 100644
--- a/drape_frontend/drape_engine.cpp
+++ b/drape_frontend/drape_engine.cpp
@@ -8,6 +8,8 @@
#include "drape/texture_manager.hpp"
+#include "platform/settings.hpp"
+
#include "platform/platform.hpp"
#include "std/bind.hpp"
@@ -30,6 +32,8 @@ void ConnectDownloadFn(gui::CountryStatusHelper::EButtonType buttonType, MapData
});
}
+string const LocationStateMode = "LastLocationStateMode";
+
}
DrapeEngine::DrapeEngine(Params const & params)
@@ -57,10 +61,16 @@ DrapeEngine::DrapeEngine(Params const & params)
m_textureManager = make_unique_dp<dp::TextureManager>();
m_threadCommutator = make_unique_dp<ThreadsCommutator>();
+ int modeValue = 0;
+ if (!Settings::Get(LocationStateMode, modeValue))
+ modeValue = location::MODE_FOLLOW;
+
FrontendRenderer::Params frParams(make_ref(m_threadCommutator), params.m_factory,
make_ref(m_textureManager), m_viewport,
bind(&DrapeEngine::ModelViewChanged, this, _1),
- params.m_model.GetIsCountryLoadedFn());
+ params.m_model.GetIsCountryLoadedFn(),
+ bind(&DrapeEngine::MyPositionModeChanged, this, _1),
+ static_cast<location::EMyPositionMode>(modeValue));
m_frontend = make_unique_dp<FrontendRenderer>(frParams);
@@ -169,6 +179,16 @@ void DrapeEngine::ModelViewChangedGuiThread(ScreenBase const & screen)
p.second(screen);
}
+void DrapeEngine::MyPositionModeChanged(location::EMyPositionMode mode)
+{
+ GetPlatform().RunOnGuiThread([this, mode]()
+ {
+ Settings::Set(LocationStateMode, static_cast<int>(mode));
+ if (m_myPositionModeChanged != nullptr)
+ m_myPositionModeChanged(mode);
+ });
+}
+
void DrapeEngine::SetCountryInfo(gui::CountryInfo const & info, bool isCurrentCountry, bool isCountryLoaded)
{
m_threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
@@ -176,4 +196,44 @@ void DrapeEngine::SetCountryInfo(gui::CountryInfo const & info, bool isCurrentCo
MessagePriority::Normal);
}
+void DrapeEngine::SetCompassInfo(location::CompassInfo const & info)
+{
+ m_threadCommutator->PostMessage(ThreadsCommutator::RenderThread,
+ make_unique_dp<CompassInfoMessage>(info),
+ MessagePriority::High);
+}
+
+void DrapeEngine::SetGpsInfo(location::GpsInfo const & info, bool isNavigable, const location::RouteMatchingInfo & routeInfo)
+{
+ m_threadCommutator->PostMessage(ThreadsCommutator::RenderThread,
+ make_unique_dp<GpsInfoMessage>(info, isNavigable, routeInfo),
+ MessagePriority::High);
+}
+
+void DrapeEngine::MyPositionNextMode()
+{
+ m_threadCommutator->PostMessage(ThreadsCommutator::RenderThread,
+ make_unique_dp<ChangeMyPositionModeMessage>(ChangeMyPositionModeMessage::TYPE_NEXT),
+ MessagePriority::High);
+}
+
+void DrapeEngine::CancelMyPosition()
+{
+ m_threadCommutator->PostMessage(ThreadsCommutator::RenderThread,
+ make_unique_dp<ChangeMyPositionModeMessage>(ChangeMyPositionModeMessage::TYPE_CANCEL),
+ MessagePriority::High);
+}
+
+void DrapeEngine::InvalidateMyPosition()
+{
+ m_threadCommutator->PostMessage(ThreadsCommutator::RenderThread,
+ make_unique_dp<ChangeMyPositionModeMessage>(ChangeMyPositionModeMessage::TYPE_INVALIDATE),
+ MessagePriority::High);
+}
+
+void DrapeEngine::SetMyPositionModeListener(location::TMyPositionModeChanged const & fn)
+{
+ m_myPositionModeChanged = fn;
+}
+
} // namespace df
diff --git a/drape_frontend/drape_engine.hpp b/drape_frontend/drape_engine.hpp
index 252b0f3c7a..00bf43f8cb 100644
--- a/drape_frontend/drape_engine.hpp
+++ b/drape_frontend/drape_engine.hpp
@@ -7,6 +7,8 @@
#include "drape/pointers.hpp"
#include "drape/texture_manager.hpp"
+#include "platform/location.hpp"
+
#include "geometry/screenbase.hpp"
#include "base/strings_bundle.hpp"
@@ -73,12 +75,20 @@ public:
void SetRenderingEnabled(bool const isEnabled);
void SetCountryInfo(gui::CountryInfo const & info, bool isCurrentCountry, bool isCountryLoaded);
+ void SetCompassInfo(location::CompassInfo const & info);
+ void SetGpsInfo(location::GpsInfo const & info, bool isNavigable, location::RouteMatchingInfo const & routeInfo);
+ void MyPositionNextMode();
+ void CancelMyPosition();
+ void InvalidateMyPosition();
+ void SetMyPositionModeListener(location::TMyPositionModeChanged const & fn);
private:
void AddUserEvent(UserEvent const & e);
void ModelViewChanged(ScreenBase const & screen);
void ModelViewChangedGuiThread(ScreenBase const & screen);
+ void MyPositionModeChanged(location::EMyPositionMode mode);
+
private:
drape_ptr<FrontendRenderer> m_frontend;
drape_ptr<BackendRenderer> m_backend;
@@ -89,6 +99,8 @@ private:
using TListenerMap = map<int, TModelViewListenerFn>;
TListenerMap m_listeners;
+
+ location::TMyPositionModeChanged m_myPositionModeChanged;
};
} // namespace df
diff --git a/drape_frontend/drape_frontend.pro b/drape_frontend/drape_frontend.pro
index fc36b2c4f4..da83108c1f 100755
--- a/drape_frontend/drape_frontend.pro
+++ b/drape_frontend/drape_frontend.pro
@@ -50,6 +50,7 @@ SOURCES += \
visual_params.cpp \
my_position.cpp \
user_event_stream.cpp \
+ my_position_controller.cpp
HEADERS += \
animation/base_interpolator.hpp \
@@ -98,3 +99,4 @@ HEADERS += \
visual_params.hpp \
my_position.hpp \
user_event_stream.hpp \
+ my_position_controller.hpp
diff --git a/drape_frontend/frontend_renderer.cpp b/drape_frontend/frontend_renderer.cpp
index 890b365098..4d1dc604e3 100755
--- a/drape_frontend/frontend_renderer.cpp
+++ b/drape_frontend/frontend_renderer.cpp
@@ -52,6 +52,9 @@ FrontendRenderer::FrontendRenderer(Params const & params)
m_fps = 0.0;
#endif
+ m_myPositionController.reset(new MyPositionController(params.m_initMyPositionMode));
+ m_myPositionController->SetModeListener(params.m_myPositionModeCallback);
+
StartThread();
}
@@ -124,9 +127,6 @@ void FrontendRenderer::AcceptMessage(ref_ptr<Message> message)
break;
}
- case Message::MyPositionShape:
- m_myPositionMark = ref_ptr<MyPositionShapeMessage>(message)->AcceptShape();
- break;
case Message::InvalidateRect:
{
@@ -156,6 +156,7 @@ void FrontendRenderer::AcceptMessage(ref_ptr<Message> message)
m_userMarkRenderGroups.erase(iter, m_userMarkRenderGroups.end());
break;
}
+
case Message::ChangeUserMarkLayerVisibility:
{
ref_ptr<ChangeUserMarkLayerVisibilityMessage> m = message;
@@ -166,6 +167,7 @@ void FrontendRenderer::AcceptMessage(ref_ptr<Message> message)
m_userMarkVisibility.erase(key);
break;
}
+
case Message::GuiLayerRecached:
{
ref_ptr<GuiLayerRecachedMessage> msg = message;
@@ -177,11 +179,52 @@ void FrontendRenderer::AcceptMessage(ref_ptr<Message> message)
m_guiRenderer->Merge(make_ref(renderer));
break;
}
+
case Message::StopRendering:
{
ProcessStopRenderingMessage();
break;
}
+
+ case Message::MyPositionShape:
+ m_myPositionController->SetRenderShape(ref_ptr<MyPositionShapeMessage>(message)->AcceptShape());
+ break;
+
+ case Message::ChangeMyPostitionMode:
+ {
+ ref_ptr<ChangeMyPositionModeMessage> msg = message;
+ switch (msg->GetChangeType())
+ {
+ case ChangeMyPositionModeMessage::TYPE_NEXT:
+ m_myPositionController->NextMode();
+ break;
+ case ChangeMyPositionModeMessage::TYPE_INVALIDATE:
+ m_myPositionController->Invalidate();
+ break;
+ case ChangeMyPositionModeMessage::TYPE_CANCEL:
+ m_myPositionController->TurnOf();
+ break;
+ default:
+ ASSERT(false, ());
+ break;
+ }
+ break;
+ }
+
+ case Message::CompassInfo:
+ {
+ ref_ptr<CompassInfoMessage> msg = message;
+ m_myPositionController->OnCompassUpdate(msg->GetInfo());
+ break;
+ }
+
+ case Message::GpsInfo:
+ {
+ ref_ptr<GpsInfoMessage> msg = message;
+ m_myPositionController->OnLocationUpdate(msg->GetInfo(), msg->IsNavigable());
+ break;
+ }
+
default:
ASSERT(false, ());
}
@@ -315,8 +358,7 @@ void FrontendRenderer::RenderScene(ScreenBase const & modelView)
if (prevLayer != layer && layer == dp::GLState::OverlayLayer)
{
GLFunctions::glClearDepth();
- if (m_myPositionMark != nullptr)
- m_myPositionMark->Render(modelView, make_ref(m_gpuProgramManager), m_generalUniforms);
+ m_myPositionController->Render(modelView, make_ref(m_gpuProgramManager), m_generalUniforms);
}
prevLayer = layer;
@@ -538,7 +580,7 @@ void FrontendRenderer::ReleaseResources()
m_deferredRenderGroups.clear();
m_userMarkRenderGroups.clear();
m_guiRenderer.reset();
- m_myPositionMark.reset();
+ m_myPositionController.reset();
m_gpuProgramManager.reset();
}
diff --git a/drape_frontend/frontend_renderer.hpp b/drape_frontend/frontend_renderer.hpp
index c01d39f670..cda4e49c25 100755
--- a/drape_frontend/frontend_renderer.hpp
+++ b/drape_frontend/frontend_renderer.hpp
@@ -14,7 +14,7 @@
#include "drape_frontend/tile_tree.hpp"
#include "drape_frontend/backend_renderer.hpp"
#include "drape_frontend/render_group.hpp"
-#include "drape_frontend/my_position.hpp"
+#include "drape_frontend/my_position_controller.hpp"
#include "drape_frontend/navigator.hpp"
#include "drape_frontend/user_event_stream.hpp"
@@ -27,6 +27,8 @@
#include "drape/overlay_tree.hpp"
#include "drape/uniform_values_storage.hpp"
+#include "platform/location.hpp"
+
#include "geometry/screenbase.hpp"
#include "std/function.hpp"
@@ -50,16 +52,22 @@ public:
ref_ptr<dp::TextureManager> texMng,
Viewport viewport,
TModelViewChanged const & modelViewChangedFn,
- TIsCountryLoaded const & isCountryLoaded)
+ TIsCountryLoaded const & isCountryLoaded,
+ location::TMyPositionModeChanged myPositionModeCallback,
+ location::EMyPositionMode initMode)
: BaseRenderer::Params(commutator, factory, texMng)
, m_viewport(viewport)
, m_modelViewChangedFn(modelViewChangedFn)
, m_isCountryLoadedFn(isCountryLoaded)
+ , m_myPositionModeCallback(myPositionModeCallback)
+ , m_initMyPositionMode(initMode)
{}
Viewport m_viewport;
TModelViewChanged m_modelViewChangedFn;
TIsCountryLoaded m_isCountryLoadedFn;
+ location::TMyPositionModeChanged m_myPositionModeCallback;
+ location::EMyPositionMode m_initMyPositionMode;
};
FrontendRenderer(Params const & params);
@@ -140,7 +148,7 @@ private:
set<TileKey> m_userMarkVisibility;
drape_ptr<gui::LayerRenderer> m_guiRenderer;
- drape_ptr<MyPosition> m_myPositionMark;
+ drape_ptr<MyPositionController> m_myPositionController;
dp::UniformValuesStorage m_generalUniforms;
diff --git a/drape_frontend/message.hpp b/drape_frontend/message.hpp
index 728c52e3c4..b02fcda1eb 100644
--- a/drape_frontend/message.hpp
+++ b/drape_frontend/message.hpp
@@ -25,7 +25,10 @@ public:
GuiRecache,
MyPositionShape,
CountryInfoUpdate,
- StopRendering
+ StopRendering,
+ ChangeMyPostitionMode,
+ CompassInfo,
+ GpsInfo
};
virtual ~Message() {}
diff --git a/drape_frontend/message_subclasses.hpp b/drape_frontend/message_subclasses.hpp
index 16bf9402a3..d760aa00dc 100644
--- a/drape_frontend/message_subclasses.hpp
+++ b/drape_frontend/message_subclasses.hpp
@@ -17,6 +17,8 @@
#include "drape/pointers.hpp"
#include "drape/render_bucket.hpp"
+#include "platform/location.hpp"
+
#include "std/shared_ptr.hpp"
#include "std/set.hpp"
#include "std/function.hpp"
@@ -290,4 +292,60 @@ public:
Type GetType() const override { return Message::StopRendering; }
};
+class ChangeMyPositionModeMessage : public Message
+{
+public:
+ enum EChangeType
+ {
+ TYPE_NEXT,
+ TYPE_CANCEL,
+ TYPE_INVALIDATE
+ };
+
+ ChangeMyPositionModeMessage(EChangeType changeType)
+ : m_changeType(changeType)
+ {
+ }
+
+ EChangeType GetChangeType() const { return m_changeType; }
+ Type GetType() const override { return Message::ChangeMyPostitionMode; }
+
+private:
+ EChangeType m_changeType;
+};
+
+class CompassInfoMessage : public Message
+{
+public:
+ CompassInfoMessage(location::CompassInfo const & info)
+ : m_info(info)
+ {}
+
+ Type GetType() const override { return Message::CompassInfo; }
+ location::CompassInfo const & GetInfo() const { return m_info; }
+
+private:
+ location::CompassInfo m_info;
+};
+
+class GpsInfoMessage : public Message
+{
+public:
+ GpsInfoMessage(location::GpsInfo const & info, bool isNavigable, location::RouteMatchingInfo const & routeInfo)
+ : m_info(info)
+ , m_isNavigable(isNavigable)
+ , m_routeInfo(routeInfo)
+ {}
+
+ Type GetType() const override { return Message::GpsInfo; }
+ location::GpsInfo const & GetInfo() const { return m_info; }
+ bool IsNavigable() const { return m_isNavigable; }
+ location::RouteMatchingInfo const & GetRouteInfo() const { return m_routeInfo; }
+
+private:
+ location::GpsInfo m_info;
+ bool m_isNavigable;
+ location::RouteMatchingInfo m_routeInfo;
+};
+
} // namespace df
diff --git a/drape_frontend/my_position.cpp b/drape_frontend/my_position.cpp
index 37e1950dd6..8b5bdbd9de 100644
--- a/drape_frontend/my_position.cpp
+++ b/drape_frontend/my_position.cpp
@@ -54,7 +54,6 @@ MyPosition::MyPosition(ref_ptr<dp::TextureManager> mng)
, m_azimut(0.0f)
, m_accuracy(0.0f)
, m_showAzimut(false)
- , m_isVisible(false)
{
m_parts.resize(3);
CacheAccuracySector(mng);
@@ -71,36 +70,35 @@ void MyPosition::SetAzimut(float azimut)
m_azimut = azimut;
}
-void MyPosition::SetAccuracy(float accuracy)
+void MyPosition::SetIsValidAzimut(bool isValid)
{
- m_accuracy = accuracy;
+ m_showAzimut = isValid;
}
-void MyPosition::SetIsVisible(bool isVisible)
+void MyPosition::SetAccuracy(float accuracy)
{
- m_isVisible = isVisible;
+ m_accuracy = accuracy;
}
void MyPosition::Render(ScreenBase const & screen,
ref_ptr<dp::GpuProgramManager> mng,
dp::UniformValuesStorage const & commonUniforms)
{
- if (!m_isVisible)
- return;
-
dp::UniformValuesStorage uniforms = commonUniforms;
{
+ m2::PointD accuracyPoint(m_position.x + m_accuracy, m_position.y);
+ float pixelAccuracy = (screen.GtoP(accuracyPoint) - screen.GtoP(m_position)).Length();
dp::UniformValuesStorage accuracyUniforms = uniforms;
accuracyUniforms.SetFloatValue("u_position", m_position.x, m_position.y, dp::depth::POSITION_ACCURACY);
- accuracyUniforms.SetFloatValue("u_accuracy", m_accuracy);
+ accuracyUniforms.SetFloatValue("u_accuracy", pixelAccuracy);
RenderPart(mng, accuracyUniforms, MY_POSITION_ACCURACY);
}
{
dp::UniformValuesStorage arrowUniforms = uniforms;
arrowUniforms.SetFloatValue("u_position", m_position.x, m_position.y, dp::depth::MY_POSITION_MARK);
- arrowUniforms.SetFloatValue("u_azimut", m_azimut - screen.GetAngle());
+ arrowUniforms.SetFloatValue("u_azimut", -(m_azimut + screen.GetAngle()));
RenderPart(mng, arrowUniforms, (m_showAzimut == true) ? MY_POSITION_ARROW : MY_POSITION_POINT);
}
}
@@ -108,7 +106,7 @@ void MyPosition::Render(ScreenBase const & screen,
void MyPosition::CacheAccuracySector(ref_ptr<dp::TextureManager> mng)
{
int const TriangleCount = 40;
- int const VertexCount = TriangleCount + 2;
+ int const VertexCount = 3 * TriangleCount;
float const etalonSector = math::twicePi / static_cast<double>(TriangleCount);
dp::TextureManager::ColorRegion color;
@@ -116,14 +114,18 @@ void MyPosition::CacheAccuracySector(ref_ptr<dp::TextureManager> mng)
glsl::vec2 colorCoord = glsl::ToVec2(color.GetTexRect().Center());
buffer_vector<Vertex, TriangleCount> buffer;
- buffer.emplace_back(glsl::vec2(0.0f, 0.0f), colorCoord);
+ //buffer.emplace_back(glsl::vec2(0.0f, 0.0f), colorCoord);
glsl::vec2 startNormal(0.0f, 1.0f);
for (size_t i = 0; i < TriangleCount + 1; ++i)
{
- glsl::vec2 rotatedNormal = glsl::rotate(startNormal, -(i * etalonSector));
- buffer.emplace_back(rotatedNormal, colorCoord);
+ glsl::vec2 normal = glsl::rotate(startNormal, i * etalonSector);
+ glsl::vec2 nextNormal = glsl::rotate(startNormal, (i + 1) * etalonSector);
+
+ buffer.emplace_back(startNormal, colorCoord);
+ buffer.emplace_back(normal, colorCoord);
+ buffer.emplace_back(nextNormal, colorCoord);
}
dp::GLState state(gpu::ACCURACY_PROGRAM, dp::GLState::OverlayLayer);
@@ -143,7 +145,7 @@ void MyPosition::CacheAccuracySector(ref_ptr<dp::TextureManager> mng)
dp::AttributeProvider provider(1 /*stream count*/, VertexCount);
provider.InitStream(0 /*stream index*/, GetBindingInfo(), make_ref(buffer.data()));
- m_parts[MY_POSITION_ACCURACY].first = batcher.InsertTriangleFan(state, make_ref(&provider), nullptr);
+ m_parts[MY_POSITION_ACCURACY].first = batcher.InsertTriangleList(state, make_ref(&provider), nullptr);
ASSERT(m_parts[MY_POSITION_ACCURACY].first.IsValid(), ());
}
}
@@ -198,9 +200,9 @@ void MyPosition::CachePointPosition(ref_ptr<dp::TextureManager> mng)
m_parts[MY_POSITION_POINT].second = m_nodes.size();
m_parts[MY_POSITION_ARROW].second = m_nodes.size();
- m_parts[MY_POSITION_POINT].first = batcher.InsertTriangleFan(state, make_ref(&pointProvider), nullptr);
+ m_parts[MY_POSITION_POINT].first = batcher.InsertTriangleStrip(state, make_ref(&pointProvider), nullptr);
ASSERT(m_parts[MY_POSITION_POINT].first.IsValid(), ());
- m_parts[MY_POSITION_ARROW].first = batcher.InsertTriangleFan(state, make_ref(&arrowProvider), nullptr);
+ m_parts[MY_POSITION_ARROW].first = batcher.InsertTriangleStrip(state, make_ref(&arrowProvider), nullptr);
ASSERT(m_parts[MY_POSITION_ARROW].first.IsValid(), ());
}
}
diff --git a/drape_frontend/my_position.hpp b/drape_frontend/my_position.hpp
index e6821e34aa..b6584dbf42 100644
--- a/drape_frontend/my_position.hpp
+++ b/drape_frontend/my_position.hpp
@@ -19,8 +19,8 @@ public:
///@param pt = mercator point
void SetPosition(m2::PointF const & pt);
void SetAzimut(float azimut);
+ void SetIsValidAzimut(bool isValid);
void SetAccuracy(float accuracy);
- void SetIsVisible(bool isVisible);
void Render(ScreenBase const & screen,
ref_ptr<dp::GpuProgramManager> mng,
@@ -62,7 +62,6 @@ private:
float m_azimut;
float m_accuracy;
bool m_showAzimut;
- bool m_isVisible;
using TPart = pair<dp::IndicesRange, size_t>;
diff --git a/drape_frontend/my_position_controller.cpp b/drape_frontend/my_position_controller.cpp
new file mode 100644
index 0000000000..c52ccc35ab
--- /dev/null
+++ b/drape_frontend/my_position_controller.cpp
@@ -0,0 +1,302 @@
+#include "my_position_controller.hpp"
+
+#include "indexer/mercator.hpp"
+
+#include "3party/Alohalytics/src/alohalytics.h"
+
+namespace df
+{
+
+namespace
+{
+
+static const double GPS_BEARING_LIFETIME_S = 5.0;
+
+uint16_t IncludeModeBit(uint16_t mode, uint16_t bit)
+{
+ return mode | bit;
+}
+
+//uint16_t ExcludeModeBit(uint16_t mode, uint16_t bit)
+//{
+// return mode & (~bit);
+//}
+
+location::EMyPositionMode ExcludeAllBits(uint16_t mode)
+{
+ return (location::EMyPositionMode)(mode & 0xF);
+}
+
+uint16_t ChangeMode(uint16_t mode, location::EMyPositionMode newMode)
+{
+ return (mode & 0xF0) | newMode;
+}
+
+bool TestModeBit(uint16_t mode, uint16_t bit)
+{
+ return (mode & bit) != 0;
+}
+
+} // namespace
+
+MyPositionController::MyPositionController(location::EMyPositionMode initMode)
+ : m_modeInfo(location::MODE_PENDING_POSITION)
+ , m_afterPendingMode(location::MODE_FOLLOW)
+ , m_errorRadius(0.0)
+ , m_position(m2::PointD::Zero())
+ , m_drawDirection(0.0)
+ , m_lastGPSBearing(false)
+ , m_isVisible(false)
+{
+ if (initMode > location::MODE_UNKNOWN_POSITION)
+ m_afterPendingMode = initMode;
+ else
+ m_modeInfo = location::MODE_UNKNOWN_POSITION;
+}
+
+m2::PointD const & MyPositionController::Position() const
+{
+ return m_position;
+}
+
+double MyPositionController::GetErrorRadius() const
+{
+ return m_errorRadius;
+}
+
+bool MyPositionController::IsModeChangeViewport() const
+{
+ return GetMode() >= location::MODE_FOLLOW;
+}
+
+bool MyPositionController::IsModeHasPosition() const
+{
+ return GetMode() >= location::MODE_NOT_FOLLOW;
+}
+
+void MyPositionController::SetRenderShape(drape_ptr<MyPosition> && shape)
+{
+ m_shape = move(shape);
+}
+
+void MyPositionController::SetFixedZoom()
+{
+ SetModeInfo(IncludeModeBit(m_modeInfo, FixedZoomBit));
+}
+
+void MyPositionController::NextMode()
+{
+ string const kAlohalyticsClickEvent = "$onClick";
+ location::EMyPositionMode currentMode = GetMode();
+ location::EMyPositionMode newMode = currentMode;
+
+ if (!IsInRouting())
+ {
+ switch (currentMode)
+ {
+ case location::MODE_UNKNOWN_POSITION:
+ alohalytics::LogEvent(kAlohalyticsClickEvent, "@UnknownPosition");
+ newMode = location::MODE_PENDING_POSITION;
+ break;
+ case location::MODE_PENDING_POSITION:
+ alohalytics::LogEvent(kAlohalyticsClickEvent, "@PendingPosition");
+ newMode = location::MODE_UNKNOWN_POSITION;
+ m_afterPendingMode = location::MODE_FOLLOW;
+ break;
+ case location::MODE_NOT_FOLLOW:
+ alohalytics::LogEvent(kAlohalyticsClickEvent, "@NotFollow");
+ newMode = location::MODE_FOLLOW;
+ break;
+ case location::MODE_FOLLOW:
+ alohalytics::LogEvent(kAlohalyticsClickEvent, "@Follow");
+ if (IsRotationActive())
+ newMode = location::MODE_ROTATE_AND_FOLLOW;
+ else
+ {
+ newMode = location::MODE_UNKNOWN_POSITION;
+ m_afterPendingMode = location::MODE_FOLLOW;
+ }
+ break;
+ case location::MODE_ROTATE_AND_FOLLOW:
+ alohalytics::LogEvent(kAlohalyticsClickEvent, "@RotateAndFollow");
+ newMode = location::MODE_UNKNOWN_POSITION;
+ m_afterPendingMode = location::MODE_FOLLOW;
+ break;
+ }
+ }
+ else
+ newMode = IsRotationActive() ? location::MODE_ROTATE_AND_FOLLOW : location::MODE_FOLLOW;
+
+ SetModeInfo(ChangeMode(m_modeInfo, newMode));
+}
+
+void MyPositionController::TurnOf()
+{
+ StopLocationFollow();
+ SetModeInfo(location::MODE_UNKNOWN_POSITION);
+ SetIsVisible(false);
+}
+
+void MyPositionController::Invalidate()
+{
+ location::EMyPositionMode currentMode = GetMode();
+ if (currentMode > location::MODE_PENDING_POSITION)
+ {
+ SetModeInfo(ChangeMode(m_modeInfo, location::MODE_UNKNOWN_POSITION));
+ SetModeInfo(ChangeMode(m_modeInfo, location::MODE_PENDING_POSITION));
+ m_afterPendingMode = currentMode;
+ SetIsVisible(true);
+ }
+ else if (currentMode == location::MODE_UNKNOWN_POSITION)
+ {
+ m_afterPendingMode = location::MODE_FOLLOW;
+ SetIsVisible(false);
+ }
+}
+
+void MyPositionController::OnLocationUpdate(location::GpsInfo const & info, bool isNavigable)
+{
+ Assign(info, isNavigable);
+
+ SetIsVisible(true);
+
+ if (GetMode() == location::MODE_PENDING_POSITION)
+ {
+ SetModeInfo(ChangeMode(m_modeInfo, m_afterPendingMode));
+ m_afterPendingMode = location::MODE_FOLLOW;
+ }
+ else
+ AnimateFollow();
+}
+
+void MyPositionController::OnCompassUpdate(location::CompassInfo const & info)
+{
+ if (Assign(info))
+ AnimateFollow();
+}
+
+void MyPositionController::SetModeListener(location::TMyPositionModeChanged const & fn)
+{
+ m_modeChangeCallback = fn;
+ CallModeListener(m_modeInfo);
+}
+
+void MyPositionController::Render(ScreenBase const & screen, ref_ptr<dp::GpuProgramManager> mng,
+ dp::UniformValuesStorage const & commonUniforms)
+{
+ if (m_shape != nullptr && IsVisible() && GetMode() > location::MODE_PENDING_POSITION)
+ {
+ m_shape->SetPosition(m_position);
+ m_shape->SetAzimut(m_drawDirection);
+ m_shape->SetIsValidAzimut(IsRotationActive());
+ m_shape->SetAccuracy(m_errorRadius);
+ m_shape->Render(screen, mng, commonUniforms);
+ }
+}
+
+void MyPositionController::AnimateStateTransition(location::EMyPositionMode oldMode, location::EMyPositionMode newMode)
+{
+
+}
+
+void MyPositionController::AnimateFollow()
+{
+
+}
+
+void MyPositionController::Assign(location::GpsInfo const & info, bool isNavigable)
+{
+ m2::RectD rect = MercatorBounds::MetresToXY(info.m_longitude,
+ info.m_latitude,
+ info.m_horizontalAccuracy);
+ m_position = rect.Center();
+ m_errorRadius = rect.SizeX() / 2;
+
+ bool const hasBearing = info.HasBearing();
+ if ((isNavigable && hasBearing)
+ || (!isNavigable && hasBearing && info.HasSpeed() && info.m_speed > 1.0))
+ {
+ SetDirection(my::DegToRad(info.m_bearing));
+ m_lastGPSBearing.Reset();
+ }
+}
+
+bool MyPositionController::Assign(location::CompassInfo const & info)
+{
+ if ((IsInRouting() && GetMode() >= location::MODE_FOLLOW) ||
+ (m_lastGPSBearing.ElapsedSeconds() < GPS_BEARING_LIFETIME_S))
+ return false;
+
+ SetDirection(info.m_bearing);
+ return true;
+}
+
+void MyPositionController::SetDirection(double bearing)
+{
+ m_drawDirection = bearing;
+ SetModeInfo(IncludeModeBit(m_modeInfo, KnownDirectionBit));
+}
+
+void MyPositionController::SetModeInfo(uint16_t modeInfo, bool force)
+{
+ location::EMyPositionMode const newMode = ExcludeAllBits(modeInfo);
+ location::EMyPositionMode const oldMode = GetMode();
+ m_modeInfo = modeInfo;
+ if (newMode != oldMode || force)
+ {
+ AnimateStateTransition(oldMode, newMode);
+ CallModeListener(newMode);
+ }
+}
+
+location::EMyPositionMode MyPositionController::GetMode() const
+{
+ return ExcludeAllBits(m_modeInfo);
+}
+
+void MyPositionController::CallModeListener(uint16_t mode)
+{
+ if (m_modeChangeCallback != nullptr)
+ m_modeChangeCallback(ExcludeAllBits(mode));
+}
+
+bool MyPositionController::IsInRouting() const
+{
+ return TestModeBit(m_modeInfo, RoutingSessionBit);
+}
+
+bool MyPositionController::IsRotationActive() const
+{
+ return TestModeBit(m_modeInfo, KnownDirectionBit);
+}
+
+void MyPositionController::StopLocationFollow()
+{
+ location::EMyPositionMode currentMode = GetMode();
+ if (currentMode > location::MODE_NOT_FOLLOW)
+ {
+ StopAllAnimations();
+ SetModeInfo(ChangeMode(m_modeInfo, location::MODE_NOT_FOLLOW));
+ }
+ else if (currentMode == location::MODE_PENDING_POSITION)
+ {
+ StopAllAnimations();
+ m_afterPendingMode = location::MODE_NOT_FOLLOW;
+ }
+}
+
+void MyPositionController::StopCompassFollow()
+{
+ if (GetMode() != location::MODE_ROTATE_AND_FOLLOW)
+ return;
+
+ StopAllAnimations();
+ SetModeInfo(ChangeMode(m_modeInfo, location::MODE_FOLLOW));
+}
+
+void MyPositionController::StopAllAnimations()
+{
+ // TODO
+}
+
+}
diff --git a/drape_frontend/my_position_controller.hpp b/drape_frontend/my_position_controller.hpp
new file mode 100644
index 0000000000..d15259d1cd
--- /dev/null
+++ b/drape_frontend/my_position_controller.hpp
@@ -0,0 +1,88 @@
+#pragma once
+
+#include "drape_frontend/my_position.hpp"
+
+#include "drape/gpu_program_manager.hpp"
+#include "drape/uniform_values_storage.hpp"
+
+#include "platform/location.hpp"
+
+#include "geometry/screenbase.hpp"
+
+#include "base/timer.hpp"
+
+namespace df
+{
+
+class MyPositionController
+{
+public:
+ MyPositionController(location::EMyPositionMode initMode);
+
+ m2::PointD const & Position() const;
+ double GetErrorRadius() const;
+
+ bool IsModeChangeViewport() const;
+ bool IsModeHasPosition() const;
+
+ void SetRenderShape(drape_ptr<MyPosition> && shape);
+
+ void SetFixedZoom();
+
+ void NextMode();
+ void TurnOf();
+ void Invalidate();
+
+ void OnLocationUpdate(location::GpsInfo const & info, bool isNavigable);
+ void OnCompassUpdate(location::CompassInfo const & info);
+
+ void SetModeListener(location::TMyPositionModeChanged const & fn);
+
+ void Render(ScreenBase const & screen, ref_ptr<dp::GpuProgramManager> mng,
+ dp::UniformValuesStorage const & commonUniforms);
+
+private:
+ void AnimateStateTransition(location::EMyPositionMode oldMode, location::EMyPositionMode newMode);
+ void AnimateFollow();
+
+ void Assign(location::GpsInfo const & info, bool isNavigable);
+ bool Assign(location::CompassInfo const & info);
+ void SetDirection(double bearing);
+
+ void SetModeInfo(uint16_t modeInfo, bool force = false);
+ location::EMyPositionMode GetMode() const;
+ void CallModeListener(uint16_t mode);
+
+ bool IsInRouting() const;
+ bool IsRotationActive() const;
+
+ void StopLocationFollow();
+ void StopCompassFollow();
+ void StopAllAnimations();
+
+ bool IsVisible() const { return m_isVisible; }
+ void SetIsVisible(bool isVisible) { m_isVisible = isVisible; }
+
+private:
+ // Mode bits
+ // {
+ static uint16_t const FixedZoomBit = 0x20;
+ static uint16_t const RoutingSessionBit = 0x40;
+ static uint16_t const KnownDirectionBit = 0x80;
+ // }
+
+ uint16_t m_modeInfo; // combination of Mode enum and "Mode bits"
+ location::EMyPositionMode m_afterPendingMode;
+
+ location::TMyPositionModeChanged m_modeChangeCallback;
+ drape_ptr<MyPosition> m_shape;
+
+ double m_errorRadius; //< error radius in mercator
+ m2::PointD m_position; //< position in mercator
+ double m_drawDirection;
+ my::Timer m_lastGPSBearing;
+
+ bool m_isVisible;
+};
+
+}
diff --git a/map/framework.cpp b/map/framework.cpp
index e55eb1525c..d49a4a2154 100644
--- a/map/framework.cpp
+++ b/map/framework.cpp
@@ -33,8 +33,6 @@
#include "storage/country_info_getter.hpp"
-#include "anim/controller.hpp"
-
#include "platform/local_country_file_utils.hpp"
#include "platform/measurement_utils.hpp"
#include "platform/mwm_version.hpp"
@@ -99,7 +97,10 @@ pair<MwmSet::MwmId, MwmSet::RegResult> Framework::RegisterMap(
return m_model.RegisterMap(localFile);
}
-void Framework::OnLocationError(TLocationError /*error*/) {}
+void Framework::OnLocationError(TLocationError /*error*/)
+{
+ CallDrapeFunction(bind(&df::DrapeEngine::CancelMyPosition, _1));
+}
void Framework::OnLocationUpdate(GpsInfo const & info)
{
@@ -130,12 +131,7 @@ void Framework::OnLocationUpdate(GpsInfo const & info)
double distanceFromBegin = 0.0;
MatchLocationToRoute(rInfo, routeMatchingInfo, hasDistanceFromBegin, distanceFromBegin);
- ///@TODO UVR
- //shared_ptr<State> const & state = GetLocationState();
- //state->OnLocationUpdate(rInfo, m_routingSession.IsNavigable());
-
- //if (state->IsModeChangeViewport())
- // UpdateUserViewportChanged();
+ CallDrapeFunction(bind(&df::DrapeEngine::SetGpsInfo, _1, rInfo, m_routingSession.IsNavigable(), routeMatchingInfo));
}
void Framework::OnCompassUpdate(CompassInfo const & info)
@@ -147,8 +143,24 @@ void Framework::OnCompassUpdate(CompassInfo const & info)
CompassInfo const & rInfo = info;
#endif
- ///@TODO UVR
- //GetLocationState()->OnCompassUpdate(rInfo);
+ CallDrapeFunction(bind(&df::DrapeEngine::SetCompassInfo, _1, rInfo));
+}
+
+void Framework::SwitchMyPositionNextMode()
+{
+ CallDrapeFunction(bind(&df::DrapeEngine::MyPositionNextMode, _1));
+}
+
+void Framework::InvalidateMyPosition()
+{
+ ASSERT(m_drapeEngine != nullptr, ());
+ CallDrapeFunction(bind(&df::DrapeEngine::InvalidateMyPosition, _1));
+}
+
+void Framework::SetMyPositionModeListener(location::TMyPositionModeChanged const & fn)
+{
+ ASSERT(m_drapeEngine != nullptr, ());
+ CallDrapeFunction(bind(&df::DrapeEngine::SetMyPositionModeListener, _1, fn));
}
void Framework::CallDrapeFunction(TDrapeFunction const & fn)
@@ -159,21 +171,11 @@ void Framework::CallDrapeFunction(TDrapeFunction const & fn)
void Framework::StopLocationFollow()
{
- ///@TODO UVR
- //GetLocationState()->StopLocationFollow();
-}
-
-InformationDisplay & Framework::GetInformationDisplay()
-{
- return m_informationDisplay;
+ CallDrapeFunction(bind(&df::DrapeEngine::CancelMyPosition, _1));
}
Framework::Framework()
- : m_queryMaxScaleMode(false),
- m_width(0),
- m_height(0),
- m_animController(new anim::Controller),
- m_bmManager(*this),
+ : m_bmManager(*this),
m_balloonManager(*this),
m_fixedSearchResults(0),
m_locationChangedSlotID(-1)
@@ -710,15 +712,7 @@ void Framework::RemoveViewportListener(int slotID)
void Framework::OnSize(int w, int h)
{
- if (w < 2) w = 2;
- if (h < 2) h = 2;
-
- CallDrapeFunction(bind(&df::DrapeEngine::Resize, _1, w, h));
-
- m_width = w;
- m_height = h;
- ///@TODO UVR
- //GetLocationState()->OnSize();
+ CallDrapeFunction(bind(&df::DrapeEngine::Resize, _1, max(w, 2), max(h, 2)));
}
namespace
@@ -1399,7 +1393,9 @@ void Framework::SetupMeasurementSystem()
Settings::Get("Units", units);
m_routingSession.SetTurnNotificationsUnits(units);
- m_informationDisplay.measurementSystemChanged();
+
+
+ //m_informationDisplay.measurementSystemChanged();
///@TODO UVR
//Invalidate();
}
diff --git a/map/framework.hpp b/map/framework.hpp
index 234220f7ab..9d0a1dd16a 100644
--- a/map/framework.hpp
+++ b/map/framework.hpp
@@ -1,14 +1,10 @@
#pragma once
#include "map/active_maps_layout.hpp"
-#include "map/animator.hpp"
#include "map/bookmark.hpp"
#include "map/bookmark_manager.hpp"
#include "map/country_tree.hpp"
#include "map/feature_vec_model.hpp"
-#include "map/information_display.hpp"
-#include "map/location_state.hpp"
-#include "map/move_screen_task.hpp"
#include "map/mwm_url.hpp"
#include "map/pin_click_manager.hpp"
#include "map/routing_session.hpp"
@@ -54,7 +50,6 @@ namespace storage
class CountryInfoGetter;
}
-namespace anim { class Controller; }
namespace routing { namespace turns{ class Settings; } }
class StorageBridge;
@@ -110,17 +105,11 @@ protected:
double m_startForegroundTime;
- bool m_queryMaxScaleMode;
-
- int m_width;
- int m_height;
-
void StopLocationFollow();
storage::Storage m_storage;
shared_ptr<storage::ActiveMapsLayout> m_activeMaps;
storage::CountryTree m_globalCntTree;
- InformationDisplay m_informationDisplay;
/// How many pixels around touch point are used to get bookmark or POI
static const int TOUCH_PIXEL_RADIUS = 20;
@@ -132,16 +121,6 @@ protected:
/// This function is called by m_model when the map file is deregistered.
void OnMapDeregistered(platform::LocalCountryFile const & localFile);
- //my::Timer m_timer;
- inline double ElapsedSeconds() const
- {
- //return m_timer.ElapsedSeconds();
- return 0.0;
- }
-
- ///@TODO UVR
- ///void DrawAdditionalInfo(shared_ptr<PaintEvent> const & e);
-
BookmarkManager m_bmManager;
PinClickManager m_balloonManager;
@@ -271,6 +250,9 @@ public:
void OnLocationError(location::TLocationError error);
void OnLocationUpdate(location::GpsInfo const & info);
void OnCompassUpdate(location::CompassInfo const & info);
+ void SwitchMyPositionNextMode();
+ void InvalidateMyPosition();
+ void SetMyPositionModeListener(location::TMyPositionModeChanged const & fn);
//@}
void CreateDrapeEngine(ref_ptr<dp::OGLContextFactory> contextFactory, float vs, int w, int h);
@@ -280,8 +262,6 @@ public:
void SetMapStyle(MapStyle mapStyle);
MapStyle GetMapStyle() const;
- InformationDisplay & GetInformationDisplay();
-
void PrepareToShutdown();
void SetupMeasurementSystem();
@@ -424,9 +404,6 @@ public:
PinClickManager & GetBalloonManager() { return m_balloonManager; }
- ///@TODO UVR
- //shared_ptr<location::State> const & GetLocationState() const;
-
/// [in] lat, lon - last known location
/// [out] lat, lon - predicted location
static void PredictLocation(double & lat, double & lon, double accuracy,
diff --git a/map/location_state.cpp b/map/location_state.cpp
index 93eaf8adcd..c964c48b5e 100644
--- a/map/location_state.cpp
+++ b/map/location_state.cpp
@@ -1,11 +1,5 @@
#include "map/location_state.hpp"
#include "map/framework.hpp"
-#include "map/move_screen_task.hpp"
-
-#include "anim/controller.hpp"
-#include "anim/task.hpp"
-#include "anim/angle_interpolation.hpp"
-#include "anim/segment_interpolation.hpp"
#include "indexer/mercator.hpp"
#include "indexer/scales.hpp"
@@ -24,803 +18,387 @@ namespace location
namespace
{
-static const int POSITION_Y_OFFSET = 75;
-static const double POSITION_TOLERANCE = 1.0E-6; // much less than coordinates coding error
-static const double ANGLE_TOLERANCE = my::DegToRad(3.0);
-static const double GPS_BEARING_LIFETIME_S = 5.0;
-
+//static const int POSITION_Y_OFFSET = 120;
+//static const double POSITION_TOLERANCE = 1.0E-6; // much less than coordinates coding error
+//static const double ANGLE_TOLERANCE = my::DegToRad(3.0);
-uint16_t IncludeModeBit(uint16_t mode, uint16_t bit)
-{
- return mode | bit;
-}
-
-uint16_t ExcludeModeBit(uint16_t mode, uint16_t bit)
-{
- return mode & (~bit);
-}
+//class RotateAndFollowAnim : public anim::Task
+//{
+//public:
+// RotateAndFollowAnim(Framework * fw, m2::PointD const & srcPos,
+// double srcAngle,
+// m2::PointD const & srcPixelBinding,
+// m2::PointD const & dstPixelbinding)
+// : m_fw(fw)
+// , m_hasPendingAnimation(false)
+// {
+// //@TODO UVR
+//// m_angleAnim.reset(new anim::SafeAngleInterpolation(srcAngle, srcAngle, 1.0));
+//// m_posAnim.reset(new anim::SafeSegmentInterpolation(srcPos, srcPos, 1.0));
+//// m2::PointD const srcInverted = InvertPxBinding(srcPixelBinding);
+//// m2::PointD const dstInverted = InvertPxBinding(dstPixelbinding);
+//// m_pxBindingAnim.reset(new anim::SafeSegmentInterpolation(srcInverted, dstInverted,
+//// m_fw->GetNavigator().ComputeMoveSpeed(srcInverted, dstInverted)));
+// }
-State::Mode ExcludeAllBits(uint16_t mode)
-{
- return (State::Mode)(mode & 0xF);
-}
+// void SetDestinationParams(m2::PointD const & dstPos, double dstAngle)
+// {
+// ASSERT(m_angleAnim != nullptr, ());
+// ASSERT(m_posAnim != nullptr, ());
+
+// if (IsVisual() || m_idleFrames > 0)
+// {
+// //Store new params even if animation is active but don't interrupt the current one.
+// //New animation to the pending params will be made after all.
+// m_hasPendingAnimation = true;
+// m_pendingDstPos = dstPos;
+// m_pendingAngle = dstAngle;
+// }
+// else
+// SetParams(dstPos, dstAngle);
+// }
-uint16_t ChangeMode(uint16_t mode, State::Mode newMode)
-{
- return (mode & 0xF0) | newMode;
-}
+// void Update()
+// {
+// if (!IsVisual() && m_hasPendingAnimation && m_idleFrames == 0)
+// {
+// m_hasPendingAnimation = false;
+// SetParams(m_pendingDstPos, m_pendingAngle);
+// ///@TODO UVR
+// //m_fw->Invalidate();
+// }
+// else if (m_idleFrames > 0)
+// {
+// --m_idleFrames;
+// ///@TODO UVR
+// //m_fw->Invalidate();
+// }
+// }
-bool TestModeBit(uint16_t mode, uint16_t bit)
-{
- return (mode & bit) != 0;
-}
+// m2::PointD const & GetPositionForDraw()
+// {
+// return m_posAnim->GetCurrentValue();
+// }
-class RotateAndFollowAnim : public anim::Task
-{
-public:
- RotateAndFollowAnim(Framework * fw, m2::PointD const & srcPos,
- double srcAngle,
- m2::PointD const & srcPixelBinding,
- m2::PointD const & dstPixelbinding)
- : m_fw(fw)
- , m_hasPendingAnimation(false)
- {
- //@TODO UVR
-// m_angleAnim.reset(new anim::SafeAngleInterpolation(srcAngle, srcAngle, 1.0));
-// m_posAnim.reset(new anim::SafeSegmentInterpolation(srcPos, srcPos, 1.0));
-// m2::PointD const srcInverted = InvertPxBinding(srcPixelBinding);
-// m2::PointD const dstInverted = InvertPxBinding(dstPixelbinding);
-// m_pxBindingAnim.reset(new anim::SafeSegmentInterpolation(srcInverted, dstInverted,
-// m_fw->GetNavigator().ComputeMoveSpeed(srcInverted, dstInverted)));
- }
-
- void SetDestinationParams(m2::PointD const & dstPos, double dstAngle)
- {
- ASSERT(m_angleAnim != nullptr, ());
- ASSERT(m_posAnim != nullptr, ());
-
- if (IsVisual() || m_idleFrames > 0)
- {
- //Store new params even if animation is active but don't interrupt the current one.
- //New animation to the pending params will be made after all.
- m_hasPendingAnimation = true;
- m_pendingDstPos = dstPos;
- m_pendingAngle = dstAngle;
- }
- else
- SetParams(dstPos, dstAngle);
- }
-
- void Update()
- {
- if (!IsVisual() && m_hasPendingAnimation && m_idleFrames == 0)
- {
- m_hasPendingAnimation = false;
- SetParams(m_pendingDstPos, m_pendingAngle);
- ///@TODO UVR
- //m_fw->Invalidate();
- }
- else if (m_idleFrames > 0)
- {
- --m_idleFrames;
- ///@TODO UVR
- //m_fw->Invalidate();
- }
- }
-
- m2::PointD const & GetPositionForDraw()
- {
- return m_posAnim->GetCurrentValue();
- }
-
- virtual void OnStep(double ts)
- {
- if (m_idleFrames > 0)
- return;
-
- ASSERT(m_angleAnim != nullptr, ());
- ASSERT(m_posAnim != nullptr, ());
- ASSERT(m_pxBindingAnim != nullptr, ());
-
- bool updateViewPort = false;
- updateViewPort |= OnStep(m_angleAnim.get(), ts);
- updateViewPort |= OnStep(m_posAnim.get(), ts);
- updateViewPort |= OnStep(m_pxBindingAnim.get(), ts);
-
- if (updateViewPort)
- {
- UpdateViewport();
- if (!IsVisual())
- m_idleFrames = 5;
- }
- }
-
- virtual bool IsVisual() const
- {
- ASSERT(m_posAnim != nullptr, ());
- ASSERT(m_angleAnim != nullptr, ());
- ASSERT(m_pxBindingAnim != nullptr, ());
-
- return m_posAnim->IsRunning() ||
- m_angleAnim->IsRunning() ||
- m_pxBindingAnim->IsRunning();
- }
-
-private:
- void UpdateViewport()
- {
- ASSERT(m_posAnim != nullptr, ());
- ASSERT(m_angleAnim != nullptr, ());
- ASSERT(m_pxBindingAnim != nullptr, ());
-
- m2::PointD const & pxBinding = m_pxBindingAnim->GetCurrentValue();
- m2::PointD const & currentPosition = m_posAnim->GetCurrentValue();
- double currentAngle = m_angleAnim->GetCurrentValue();
-
- //@{ pixel coord system
- m2::PointD const pxCenter = GetPixelRect().Center();
- m2::PointD vectorToCenter = pxCenter - pxBinding;
- if (!vectorToCenter.IsAlmostZero())
- vectorToCenter = vectorToCenter.Normalize();
- m2::PointD const vectorToTop = m2::PointD(0.0, 1.0);
- double sign = m2::CrossProduct(vectorToTop, vectorToCenter) > 0 ? 1 : -1;
- double angle = sign * acos(m2::DotProduct(vectorToTop, vectorToCenter));
- //@}
-
- //@{ global coord system
- double offset = (m_fw->PtoG(pxCenter) - m_fw->PtoG(pxBinding)).Length();
- m2::PointD const viewPoint = currentPosition.Move(1.0, currentAngle + my::DegToRad(90.0));
- m2::PointD const viewVector = viewPoint - currentPosition;
- m2::PointD rotateVector = viewVector;
- rotateVector.Rotate(angle);
- rotateVector.Normalize();
- rotateVector *= offset;
- //@}
-
- ///@TODO UVR
-// m_fw->SetViewportCenter(currentPosition + rotateVector);
-// m_fw->GetNavigator().SetAngle(currentAngle);
- //m_fw->Invalidate();
- }
-
- void SetParams(m2::PointD const & dstPos, double dstAngle)
- {
- ///@TODO UVR
-// double const angleDist = fabs(ang::GetShortestDistance(m_angleAnim->GetCurrentValue(), dstAngle));
-// if (dstPos.EqualDxDy(m_posAnim->GetCurrentValue(), POSITION_TOLERANCE) && angleDist < ANGLE_TOLERANCE)
+// virtual void OnStep(double ts)
+// {
+// if (m_idleFrames > 0)
// return;
-// double const posSpeed = 2 * m_fw->GetNavigator().ComputeMoveSpeed(m_posAnim->GetCurrentValue(), dstPos);
-// double const angleSpeed = angleDist < 1.0 ? 1.5 : m_fw->GetAnimator().GetRotationSpeed();
-// m_angleAnim->ResetDestParams(dstAngle, angleSpeed);
-// m_posAnim->ResetDestParams(dstPos, posSpeed);
- }
-
- bool OnStep(anim::Task * task, double ts)
- {
- if (!task->IsReady() && !task->IsRunning())
- return false;
-
- if (task->IsReady())
- {
- task->Start();
- task->OnStart(ts);
- }
-
- if (task->IsRunning())
- task->OnStep(ts);
-
- if (task->IsEnded())
- task->OnEnd(ts);
-
- return true;
- }
-
-private:
- m2::PointD InvertPxBinding(m2::PointD const & px) const
- {
- return m2::PointD(px.x, GetPixelRect().maxY() - px.y);
- }
-
- m2::RectD const & GetPixelRect() const
- {
- ///@TODO UVR
- return m2::RectD();
- //return m_fw->GetNavigator().Screen().PixelRect();
- }
-
-private:
- Framework * m_fw;
-
- unique_ptr<anim::SafeAngleInterpolation> m_angleAnim;
- unique_ptr<anim::SafeSegmentInterpolation> m_posAnim;
- unique_ptr<anim::SafeSegmentInterpolation> m_pxBindingAnim;
-
- bool m_hasPendingAnimation;
- m2::PointD m_pendingDstPos;
- double m_pendingAngle;
- // When map has active animation, backgroung rendering pausing
- // By this beetwen animations we wait some frames to release background rendering
- int m_idleFrames = 0;
-};
-
-string const LocationStateMode = "LastLocationStateMode";
-
-}
-
-State::Params::Params()
- : m_framework(0)
-{}
-
-State::State(Params const & p)
- : m_modeInfo(Follow),
- m_errorRadius(0),
- m_position(0, 0),
- m_drawDirection(0.0),
- m_lastGPSBearing(false),
- m_afterPendingMode(Follow),
- m_routeMatchingInfo(),
- m_currentSlotID(0)
-{
- m_framework = p.m_framework;
-
- int mode = 0;
- if (Settings::Get(LocationStateMode, mode))
- m_modeInfo = mode;
-
- bool isBench = false;
- if (Settings::Get("IsBenchmarking", isBench) && isBench)
- m_modeInfo = UnknownPosition;
-
- ///@TODO UVR
- //setIsVisible(false);
-}
-
-m2::PointD const & State::Position() const
-{
- return m_position;
-}
-
-double State::GetErrorRadius() const
-{
- return m_errorRadius;
-}
-
-State::Mode State::GetMode() const
-{
- return ExcludeAllBits(m_modeInfo);
-}
-
-bool State::IsModeChangeViewport() const
-{
- return GetMode() >= Follow;
-}
-
-bool State::IsModeHasPosition() const
-{
- return GetMode() >= NotFollow;
-}
-
-void State::SwitchToNextMode()
-{
- string const kAlohalyticsClickEvent = "$onClick";
- Mode currentMode = GetMode();
- Mode newMode = currentMode;
-
- if (!IsInRouting() || IsRoutingFollowingDisabled())
- {
- switch (currentMode)
- {
- case UnknownPosition:
- alohalytics::LogEvent(kAlohalyticsClickEvent, "@UnknownPosition");
- newMode = PendingPosition;
- break;
- case PendingPosition:
- alohalytics::LogEvent(kAlohalyticsClickEvent, "@PendingPosition");
- newMode = UnknownPosition;
- m_afterPendingMode = Follow;
- break;
- case NotFollow:
- alohalytics::LogEvent(kAlohalyticsClickEvent, "@NotFollow");
- newMode = Follow;
- break;
- case Follow:
- alohalytics::LogEvent(kAlohalyticsClickEvent, "@Follow");
- if (IsRotationActive())
- newMode = RotateAndFollow;
- else
- {
- newMode = UnknownPosition;
- m_afterPendingMode = Follow;
- }
- break;
- case RotateAndFollow:
- alohalytics::LogEvent(kAlohalyticsClickEvent, "@RotateAndFollow");
- newMode = UnknownPosition;
- m_afterPendingMode = Follow;
- break;
- }
- }
- else
- newMode = IsRotationActive() ? RotateAndFollow : Follow;
-
- SetModeInfo(ChangeMode(m_modeInfo, newMode));
-}
-
-void State::RouteBuilded()
-{
- StopAllAnimations();
- SetModeInfo(IncludeModeBit(m_modeInfo, RoutingSessionBit));
-
- Mode const mode = GetMode();
- if (mode > NotFollow)
- SetModeInfo(ChangeMode(m_modeInfo, NotFollow));
- else if (mode == UnknownPosition)
- m_afterPendingMode = NotFollow;
-}
+// ASSERT(m_angleAnim != nullptr, ());
+// ASSERT(m_posAnim != nullptr, ());
+// ASSERT(m_pxBindingAnim != nullptr, ());
+
+// bool updateViewPort = false;
+// updateViewPort |= OnStep(m_angleAnim.get(), ts);
+// updateViewPort |= OnStep(m_posAnim.get(), ts);
+// updateViewPort |= OnStep(m_pxBindingAnim.get(), ts);
+
+// if (updateViewPort)
+// {
+// UpdateViewport();
+// if (!IsVisual())
+// m_idleFrames = 5;
+// }
+// }
-void State::StartRouteFollow(int scale)
-{
- ASSERT(IsInRouting(), ());
- ASSERT(IsModeHasPosition(), ());
+// virtual bool IsVisual() const
+// {
+// ASSERT(m_posAnim != nullptr, ());
+// ASSERT(m_angleAnim != nullptr, ());
+// ASSERT(m_pxBindingAnim != nullptr, ());
- m2::PointD const size(m_errorRadius, m_errorRadius);
- m_framework->ShowRectExVisibleScale(m2::RectD(m_position - size, m_position + size), scale);
+// return m_posAnim->IsRunning() ||
+// m_angleAnim->IsRunning() ||
+// m_pxBindingAnim->IsRunning();
+// }
- SetModeInfo(ChangeMode(m_modeInfo, NotFollow));
- SetModeInfo(ChangeMode(m_modeInfo, IsRotationActive() ? RotateAndFollow : Follow));
-}
+//private:
+// void UpdateViewport()
+// {
+// ASSERT(m_posAnim != nullptr, ());
+// ASSERT(m_angleAnim != nullptr, ());
+// ASSERT(m_pxBindingAnim != nullptr, ());
+
+// m2::PointD const & pxBinding = m_pxBindingAnim->GetCurrentValue();
+// m2::PointD const & currentPosition = m_posAnim->GetCurrentValue();
+// double currentAngle = m_angleAnim->GetCurrentValue();
+
+// //@{ pixel coord system
+// m2::PointD const pxCenter = GetPixelRect().Center();
+// m2::PointD vectorToCenter = pxCenter - pxBinding;
+// if (!vectorToCenter.IsAlmostZero())
+// vectorToCenter = vectorToCenter.Normalize();
+// m2::PointD const vectorToTop = m2::PointD(0.0, 1.0);
+// double sign = m2::CrossProduct(vectorToTop, vectorToCenter) > 0 ? 1 : -1;
+// double angle = sign * acos(m2::DotProduct(vectorToTop, vectorToCenter));
+// //@}
+
+// //@{ global coord system
+// double offset = (m_fw->PtoG(pxCenter) - m_fw->PtoG(pxBinding)).Length();
+// m2::PointD const viewPoint = currentPosition.Move(1.0, currentAngle + my::DegToRad(90.0));
+// m2::PointD const viewVector = viewPoint - currentPosition;
+// m2::PointD rotateVector = viewVector;
+// rotateVector.Rotate(angle);
+// rotateVector.Normalize();
+// rotateVector *= offset;
+// //@}
+
+// ///@TODO UVR
+//// m_fw->SetViewportCenter(currentPosition + rotateVector);
+//// m_fw->GetNavigator().SetAngle(currentAngle);
+// //m_fw->Invalidate();
+// }
-void State::StopRoutingMode()
-{
- if (IsInRouting())
- {
- bool const isNotFollow = IsRoutingFollowingDisabled();
- m_modeInfo = ExcludeModeBit(m_modeInfo, RoutingNotFollowBit | RoutingSessionBit);
- if (isNotFollow)
- return;
- SetModeInfo(ChangeMode(m_modeInfo, GetMode() == RotateAndFollow ? Follow : NotFollow));
- RotateOnNorth();
- AnimateFollow();
- }
-}
+// void SetParams(m2::PointD const & dstPos, double dstAngle)
+// {
+// ///@TODO UVR
+//// double const angleDist = fabs(ang::GetShortestDistance(m_angleAnim->GetCurrentValue(), dstAngle));
+//// if (dstPos.EqualDxDy(m_posAnim->GetCurrentValue(), POSITION_TOLERANCE) && angleDist < ANGLE_TOLERANCE)
+//// return;
+
+//// double const posSpeed = 2 * m_fw->GetNavigator().ComputeMoveSpeed(m_posAnim->GetCurrentValue(), dstPos);
+//// double const angleSpeed = angleDist < 1.0 ? 1.5 : m_fw->GetAnimator().GetRotationSpeed();
+//// m_angleAnim->ResetDestParams(dstAngle, angleSpeed);
+//// m_posAnim->ResetDestParams(dstPos, posSpeed);
+// }
-void State::TurnOff()
-{
- StopLocationFollow();
- SetModeInfo(UnknownPosition);
- ///@TODO UVR
- //setIsVisible(false);
- //invalidate();
-}
+// bool OnStep(anim::Task * task, double ts)
+// {
+// if (!task->IsReady() && !task->IsRunning())
+// return false;
-void State::OnLocationUpdate(location::GpsInfo const & info, bool isNavigable, location::RouteMatchingInfo const & routeMatchingInfo)
-{
- Assign(info, isNavigable);
- m_routeMatchingInfo = routeMatchingInfo;
-
- ///@TODO UVR
- //setIsVisible(true);
-
- if (GetMode() == PendingPosition)
- {
- SetModeInfo(ChangeMode(m_modeInfo, m_afterPendingMode));
- m_afterPendingMode = Follow;
- }
- else
- AnimateFollow();
-
- CallPositionChangedListeners(m_position);
- ///@TODO UVR
- //invalidate();
-}
+// if (task->IsReady())
+// {
+// task->Start();
+// task->OnStart(ts);
+// }
-void State::OnCompassUpdate(location::CompassInfo const & info)
-{
- if (Assign(info))
- {
- AnimateFollow();
- ///@TODO UVR
- //invalidate();
- }
-}
+// if (task->IsRunning())
+// task->OnStep(ts);
-void State::CallStateModeListeners()
-{
- Mode const currentMode = GetMode();
- for (auto it : m_modeListeners)
- it.second(currentMode);
-}
+// if (task->IsEnded())
+// task->OnEnd(ts);
-int State::AddStateModeListener(TStateModeListener const & l)
-{
- int const slotID = m_currentSlotID++;
- m_modeListeners[slotID] = l;
- return slotID;
-}
+// return true;
+// }
-void State::RemoveStateModeListener(int slotID)
-{
- m_modeListeners.erase(slotID);
-}
+//private:
+// m2::PointD InvertPxBinding(m2::PointD const & px) const
+// {
+// return m2::PointD(px.x, GetPixelRect().maxY() - px.y);
+// }
-void State::CallPositionChangedListeners(m2::PointD const & pt)
-{
- for (auto it : m_positionListeners)
- it.second(pt);
-}
+// m2::RectD const & GetPixelRect() const
+// {
+// ///@TODO UVR
+// return m2::RectD();
+// //return m_fw->GetNavigator().Screen().PixelRect();
+// }
-int State::AddPositionChangedListener(State::TPositionListener const & func)
-{
- int const slotID = m_currentSlotID++;
- m_positionListeners[slotID] = func;
- return slotID;
-}
+//private:
+// Framework * m_fw;
-void State::RemovePositionChangedListener(int slotID)
-{
- m_positionListeners.erase(slotID);
-}
+// unique_ptr<anim::SafeAngleInterpolation> m_angleAnim;
+// unique_ptr<anim::SafeSegmentInterpolation> m_posAnim;
+// unique_ptr<anim::SafeSegmentInterpolation> m_pxBindingAnim;
-void State::InvalidatePosition()
-{
- Mode currentMode = GetMode();
- if (currentMode > PendingPosition)
- {
- SetModeInfo(ChangeMode(m_modeInfo, UnknownPosition));
- SetModeInfo(ChangeMode(m_modeInfo, PendingPosition));
- m_afterPendingMode = currentMode;
- ///@TODO UVR
- //setIsVisible(true);
- }
- else if (currentMode == UnknownPosition)
- {
- m_afterPendingMode = Follow;
- ///@TODO UVR
- //setIsVisible(false);
- }
-
- ///@TODO UVR
- //invalidate();
-}
+// bool m_hasPendingAnimation;
+// m2::PointD m_pendingDstPos;
+// double m_pendingAngle;
+// // When map has active animation, backgroung rendering pausing
+// // By this beetwen animations we wait some frames to release background rendering
+// int m_idleFrames = 0;
+//};
-void State::cache()
-{
}
-void State::purge()
-{
-}
+//void State::RouteBuilded()
+//{
+// StopAllAnimations();
+// SetModeInfo(IncludeModeBit(m_modeInfo, RoutingSessionBit));
-void State::update()
-{
- ///@TODO UVR
-// if (isVisible() && IsModeHasPosition())
+// Mode const mode = GetMode();
+// if (mode > NotFollow)
+// SetModeInfo(ChangeMode(m_modeInfo, NotFollow));
+// else if (mode == UnknownPosition)
// {
-// m2::PointD const pxPosition = m_framework->GetNavigator().GtoP(Position());
-// setPivot(pxPosition, false);
-
-// if (m_animTask)
-// static_cast<RotateAndFollowAnim *>(m_animTask.get())->Update();
+// m_afterPendingMode = NotFollow;
+// SetModeInfo(ChangeMode(m_modeInfo, PendingPosition));
// }
-}
+//}
-bool State::IsRotationActive() const
-{
- return IsDirectionKnown();
-}
+//void State::StartRouteFollow()
+//{
+// ASSERT(IsInRouting(), ());
+// ASSERT(IsModeHasPosition(), ());
-bool State::IsDirectionKnown() const
-{
- return TestModeBit(m_modeInfo, KnownDirectionBit);
-}
+// m2::PointD const size(m_errorRadius, m_errorRadius);
+// m_framework->ShowRect(m2::RectD(m_position - size, m_position + size),
+// scales::GetNavigationScale());
-bool State::IsInRouting() const
-{
- return TestModeBit(m_modeInfo, RoutingSessionBit);
-}
+// SetModeInfo(ChangeMode(m_modeInfo, NotFollow));
+// SetModeInfo(ChangeMode(m_modeInfo, IsRotationActive() ? RotateAndFollow : Follow));
+//}
-bool State::IsRoutingFollowingDisabled() const
-{
- return TestModeBit(m_modeInfo, RoutingNotFollowBit);
-}
+//void State::StopRoutingMode()
+//{
+// if (IsInRouting())
+// {
+// SetModeInfo(ChangeMode(ExcludeModeBit(m_modeInfo, RoutingSessionBit), GetMode() == RotateAndFollow ? Follow : NotFollow));
+// RotateOnNorth();
+// AnimateFollow();
+// }
+//}
-m2::PointD const State::GetModeDefaultPixelBinding(State::Mode mode) const
-{
- switch (mode)
- {
- case Follow: return m_framework->GetPixelCenter();
- case RotateAndFollow: return GetRaFModeDefaultPxBind();
- default: return m2::PointD(0.0, 0.0);
- }
-}
-bool State::FollowCompass()
-{
- if (!IsRotationActive() || GetMode() != RotateAndFollow || m_animTask == nullptr)
- return false;
+//m2::PointD const State::GetModeDefaultPixelBinding(State::Mode mode) const
+//{
+// switch (mode)
+// {
+// case Follow: return m_framework->GetPixelCenter();
+// case RotateAndFollow: return GetRaFModeDefaultPxBind();
+// default: return m2::PointD(0.0, 0.0);
+// }
+//}
+
+//bool State::FollowCompass()
+//{
+// if (!IsRotationActive() || GetMode() != RotateAndFollow || m_animTask == nullptr)
+// return false;
+
+// RotateAndFollowAnim * task = static_cast<RotateAndFollowAnim *>(m_animTask.get());
+// task->SetDestinationParams(Position(), -m_drawDirection);
+// return true;
+//}
+
+//m2::PointD const State::GetRaFModeDefaultPxBind() const
+//{
+// return m2::PointD();
+// ///@TODO UVR
+//// m2::RectD const & pixelRect = GetModelView().PixelRect();
+//// return m2::PointD(pixelRect.Center().x,
+//// pixelRect.maxY() - POSITION_Y_OFFSET * visualScale());
+//}
+
+//void State::DragStarted()
+//{
+// m_dragModeInfo = m_modeInfo;
+// m_afterPendingMode = NotFollow;
+// StopLocationFollow();
+//}
+
+//void State::DragEnded()
+//{
+// // reset GPS centering mode if we have dragged far from current location
+// ScreenBase const & s = GetModelView();
+// m2::PointD const defaultPxBinding = GetModeDefaultPixelBinding(ExcludeAllBits(m_dragModeInfo));
+// m2::PointD const pxPosition = s.GtoP(Position());
+
+// if (ExcludeAllBits(m_dragModeInfo) > NotFollow &&
+// defaultPxBinding.Length(pxPosition) < s.GetMinPixelRectSize() / 5.0)
+// {
+// SetModeInfo(m_dragModeInfo);
+// }
- RotateAndFollowAnim * task = static_cast<RotateAndFollowAnim *>(m_animTask.get());
- task->SetDestinationParams(Position(), -m_drawDirection);
- return true;
-}
+// m_dragModeInfo = 0;
+//}
-void State::CreateAnimTask()
-{
-// CreateAnimTask(m_framework->GtoP(Position()),
-// GetModeDefaultPixelBinding(GetMode()));
-}
+//void State::ScaleStarted()
+//{
+// m_scaleModeInfo = m_modeInfo;
+//}
-void State::CreateAnimTask(const m2::PointD & srcPx, const m2::PointD & dstPx)
-{
-// EndAnimation();
-// m_animTask.reset(new RotateAndFollowAnim(m_framework, Position(),
-// GetModelView().GetAngle(),
-// srcPx, dstPx));
-// m_framework->GetAnimController()->AddTask(m_animTask);
-}
+//void State::CorrectScalePoint(m2::PointD & pt) const
+//{
+// if (IsModeChangeViewport() || ExcludeAllBits(m_scaleModeInfo) > NotFollow)
+// pt = m_framework->GtoP(Position());
+//}
-void State::EndAnimation()
-{
- if (m_animTask != nullptr)
- {
- m_animTask->End();
- m_animTask.reset();
- }
-}
+//void State::CorrectScalePoint(m2::PointD & pt1, m2::PointD & pt2) const
+//{
+// if (IsModeChangeViewport() || ExcludeAllBits(m_scaleModeInfo) > NotFollow)
+// {
+// m2::PointD const ptDiff = m_framework->GtoP(Position()) - (pt1 + pt2) / 2;
+// pt1 += ptDiff;
+// pt2 += ptDiff;
+// }
+//}
-void State::SetModeInfo(uint16_t modeInfo, bool callListeners)
-{
- Mode const newMode = ExcludeAllBits(modeInfo);
- Mode const oldMode = GetMode();
- m_modeInfo = modeInfo;
- if (newMode != oldMode)
- {
- Settings::Set(LocationStateMode, static_cast<int>(GetMode()));
-
- if (callListeners)
- CallStateModeListeners();
-
- AnimateStateTransition(oldMode, newMode);
- ///@TODO UVR
- //invalidate();
- }
-}
+//void State::ScaleEnded()
+//{
+// m_scaleModeInfo = 0;
+//}
-void State::StopAllAnimations()
-{
+//void State::Rotated()
+//{
+// m_afterPendingMode = NotFollow;
// EndAnimation();
-// Animator & animator = m_framework->GetAnimator();
-// animator.StopRotation();
-// animator.StopChangeViewport();
-// animator.StopMoveScreen();
-}
-
-ScreenBase const & State::GetModelView() const
-{
- ///@TODO UVR
- return ScreenBase();
- //return m_framework->GetNavigator().Screen();
-}
-
-m2::PointD const State::GetRaFModeDefaultPxBind() const
-{
- return m2::PointD();
- ///@TODO UVR
-// m2::RectD const & pixelRect = GetModelView().PixelRect();
-// return m2::PointD(pixelRect.Center().x,
-// pixelRect.maxY() - POSITION_Y_OFFSET * visualScale());
-}
-
-void State::StopCompassFollowing()
-{
- if (GetMode() != RotateAndFollow)
- return;
-
- StopAllAnimations();
- SetModeInfo(ChangeMode(m_modeInfo, Follow));
-}
-
-void State::StopLocationFollow(bool callListeners)
-{
- Mode const currentMode = GetMode();
- if (currentMode > NotFollow)
- {
- StopAllAnimations();
- SetModeInfo(ChangeMode(m_modeInfo, NotFollow), callListeners);
- }
- else if (currentMode == PendingPosition)
- {
- StopAllAnimations();
- m_afterPendingMode = NotFollow;
- }
-}
-
-void State::SetFixedZoom()
-{
- SetModeInfo(IncludeModeBit(m_modeInfo, FixedZoomBit));
-}
-
-void State::SetRoutingNotFollow()
-{
- SetModeInfo(IncludeModeBit(m_modeInfo, RoutingNotFollowBit));
-}
-
-void State::DragStarted()
-{
- m_dragModeInfo = m_modeInfo;
- m_afterPendingMode = Follow;
- StopLocationFollow(false);
-}
-
-void State::DragEnded()
-{
- Mode const currentMode = ExcludeAllBits(m_dragModeInfo);
- if (currentMode > NotFollow)
- {
- // reset GPS centering mode if we have dragged far from the current location
- ScreenBase const & s = GetModelView();
- m2::PointD const defaultPxBinding = GetModeDefaultPixelBinding(currentMode);
- m2::PointD const pxPosition = s.GtoP(Position());
-
- if (defaultPxBinding.Length(pxPosition) < s.GetMinPixelRectSize() / 5.0)
- SetModeInfo(m_dragModeInfo, false);
- else
- CallStateModeListeners();
- }
-
- m_dragModeInfo = 0;
-}
-
-void State::ScaleStarted()
-{
- m_scaleModeInfo = m_modeInfo;
-}
-
-void State::CorrectScalePoint(m2::PointD & pt) const
-{
- if (IsModeChangeViewport() || ExcludeAllBits(m_scaleModeInfo) > NotFollow)
- pt = m_framework->GtoP(Position());
-}
-
-void State::CorrectScalePoint(m2::PointD & pt1, m2::PointD & pt2) const
-{
- if (IsModeChangeViewport() || ExcludeAllBits(m_scaleModeInfo) > NotFollow)
- {
- m2::PointD const ptDiff = m_framework->GtoP(Position()) - (pt1 + pt2) / 2;
- pt1 += ptDiff;
- pt2 += ptDiff;
- }
-}
-
-void State::ScaleEnded()
-{
- m_scaleModeInfo = 0;
-}
-
-void State::Rotated()
-{
- m_afterPendingMode = NotFollow;
- EndAnimation();
- if (GetMode() == RotateAndFollow)
- SetModeInfo(ChangeMode(m_modeInfo, NotFollow));
-}
-
-void State::OnCompassTaped()
-{
- StopCompassFollowing();
- RotateOnNorth();
- AnimateFollow();
-}
-
-void State::OnSize()
-{
- if (GetMode() == RotateAndFollow)
- {
- EndAnimation();
- CreateAnimTask(m_framework->GtoP(Position()), GetModeDefaultPixelBinding(GetMode()));
- }
-}
-
-void State::AnimateStateTransition(Mode oldMode, Mode newMode)
-{
- StopAllAnimations();
-
- if (oldMode == PendingPosition && newMode == Follow)
- {
- if (!TestModeBit(m_modeInfo, FixedZoomBit))
- {
- m2::PointD const size(m_errorRadius, m_errorRadius);
- m_framework->ShowRect(m2::RectD(m_position - size, m_position + size),
- scales::GetUpperComfortScale());
- }
- }
- else if (newMode == RotateAndFollow)
- {
- CreateAnimTask();
- }
- else if (oldMode == RotateAndFollow && newMode == UnknownPosition)
- {
- RotateOnNorth();
- }
- else if (oldMode == NotFollow && newMode == Follow)
- {
- m2::AnyRectD screenRect = GetModelView().GlobalRect();
- m2::RectD const & clipRect = GetModelView().ClipRect();
- screenRect.Inflate(clipRect.SizeX() / 2.0, clipRect.SizeY() / 2.0);
- if (!screenRect.IsPointInside(m_position))
- m_framework->SetViewportCenter(m_position);
- }
-
- AnimateFollow();
-}
-
-void State::AnimateFollow()
-{
- if (!IsModeChangeViewport())
- return;
-
- SetModeInfo(ExcludeModeBit(m_modeInfo, FixedZoomBit));
-
- if (!FollowCompass())
- {
- ///@TODO UVR
-// if (!m_position.EqualDxDy(m_framework->GetViewportCenter(), POSITION_TOLERANCE))
-// m_framework->SetViewportCenterAnimated(m_position);
- }
-}
-
-void State::RotateOnNorth()
-{
- //m_framework->GetAnimator().RotateScreen(GetModelView().GetAngle(), 0.0);
-}
-
-void State::Assign(location::GpsInfo const & info, bool isNavigable)
-{
- m2::RectD rect = MercatorBounds::MetresToXY(info.m_longitude,
- info.m_latitude,
- info.m_horizontalAccuracy);
- m_position = rect.Center();
- m_errorRadius = rect.SizeX() / 2;
-
- bool const hasBearing = info.HasBearing();
- if ((isNavigable && hasBearing)
- || (!isNavigable && hasBearing && info.HasSpeed() && info.m_speed > 1.0))
- {
- SetDirection(my::DegToRad(info.m_bearing));
- m_lastGPSBearing.Reset();
- }
-}
-
-bool State::Assign(location::CompassInfo const & info)
-{
- if ((IsInRouting() && GetMode() >= Follow) ||
- (m_lastGPSBearing.ElapsedSeconds() < GPS_BEARING_LIFETIME_S))
- return false;
+// if (GetMode() == RotateAndFollow)
+// SetModeInfo(ChangeMode(m_modeInfo, NotFollow));
+//}
+
+//void State::OnCompassTaped()
+//{
+// StopCompassFollowing();
+// RotateOnNorth();
+// AnimateFollow();
+//}
+
+//void State::OnSize()
+//{
+// if (GetMode() == RotateAndFollow)
+// {
+// EndAnimation();
+// CreateAnimTask(m_framework->GtoP(Position()), GetModeDefaultPixelBinding(GetMode()));
+// }
+//}
- SetDirection(info.m_bearing);
- return true;
-}
+//void State::AnimateStateTransition(Mode oldMode, Mode newMode)
+//{
+// StopAllAnimations();
-void State::SetDirection(double bearing)
-{
- m_drawDirection = bearing;
- SetModeInfo(IncludeModeBit(m_modeInfo, KnownDirectionBit));
-}
+// if (oldMode == PendingPosition && newMode == Follow)
+// {
+// if (!TestModeBit(m_modeInfo, FixedZoomBit))
+// {
+// m2::PointD const size(m_errorRadius, m_errorRadius);
+// m_framework->ShowRect(m2::RectD(m_position - size, m_position + size),
+// scales::GetUpperComfortScale());
+// }
+// }
+// else if (newMode == RotateAndFollow)
+// {
+// CreateAnimTask();
+// }
+// else if (oldMode == RotateAndFollow && newMode == UnknownPosition)
+// {
+// RotateOnNorth();
+// }
+// else if (oldMode == NotFollow && newMode == Follow)
+// {
+// m2::AnyRectD screenRect = GetModelView().GlobalRect();
+// m2::RectD const & clipRect = GetModelView().ClipRect();
+// screenRect.Inflate(clipRect.SizeX() / 2.0, clipRect.SizeY() / 2.0);
+// if (!screenRect.IsPointInside(m_position))
+// m_framework->SetViewportCenter(m_position);
+// }
-void State::ResetDirection()
-{
- SetModeInfo(ExcludeModeBit(m_modeInfo, KnownDirectionBit));
-}
+// AnimateFollow();
+//}
-m2::PointD const State::GetPositionForDraw() const
-{
- if (m_animTask != nullptr)
- return m_framework->GtoP(static_cast<RotateAndFollowAnim *>(m_animTask.get())->GetPositionForDraw());
+//void State::AnimateFollow()
+//{
+// if (!IsModeChangeViewport())
+// return;
- return m2::PointD();
- ///@TODO UVR
- //return pivot();
-}
+// SetModeInfo(ExcludeModeBit(m_modeInfo, FixedZoomBit));
+// if (!FollowCompass())
+// {
+// ///@TODO UVR
+//// if (!m_position.EqualDxDy(m_framework->GetViewportCenter(), POSITION_TOLERANCE))
+//// m_framework->SetViewportCenterAnimated(m_position);
+// }
+//}
}
diff --git a/map/location_state.hpp b/map/location_state.hpp
index a62fde9772..e5029533da 100644
--- a/map/location_state.hpp
+++ b/map/location_state.hpp
@@ -16,8 +16,6 @@
class Framework;
class ScreenBase;
-namespace anim { class Task;}
-
namespace location
{
class GpsInfo;
@@ -30,165 +28,34 @@ namespace location
{
public:
- struct Params
- {
- ///@TODO UVR
- //graphics::Color m_locationAreaColor;
- Framework * m_framework;
- Params();
- };
-
- // Do not change the order and values
- enum Mode
- {
- UnknownPosition = 0x0,
- PendingPosition = 0x1,
- NotFollow = 0x2,
- Follow = 0x3,
- RotateAndFollow = 0x4,
- };
-
- typedef function<void(Mode)> TStateModeListener;
- typedef function<void (m2::PointD const &)> TPositionListener;
-
- State(Params const & p);
-
- /// @return GPS center point in mercator
- m2::PointD const & Position() const;
- double GetErrorRadius() const;
- double GetDirection() const { return m_drawDirection; }
- bool IsDirectionKnown() const;
-
- Mode GetMode() const;
- bool IsModeChangeViewport() const;
- bool IsModeHasPosition() const;
- void SwitchToNextMode();
-
- void RouteBuilded();
- void StartRouteFollow(int scale);
- void StopRoutingMode();
-
- int AddStateModeListener(TStateModeListener const & l);
- void RemoveStateModeListener(int slotID);
-
- int AddPositionChangedListener(TPositionListener const & func);
- void RemovePositionChangedListener(int slotID);
-
- void InvalidatePosition();
- void TurnOff();
- void StopCompassFollowing();
- void StopLocationFollow(bool callListeners = true);
- void SetFixedZoom();
- void SetRoutingNotFollow();
-
- /// @name User input notification block
- //@{
- void DragStarted();
- void DragEnded();
-
- void ScaleStarted();
- void CorrectScalePoint(m2::PointD & pt) const;
- void CorrectScalePoint(m2::PointD & pt1, m2::PointD & pt2) const;
- void ScaleEnded();
-
- void Rotated();
- //@}
-
- void OnCompassTaped();
-
- void OnSize();
-
- /// @name GPS location updates routine.
- //@{
- void OnLocationUpdate(location::GpsInfo const & info, bool isNavigable, location::RouteMatchingInfo const & routeMatchingInfo);
- void OnCompassUpdate(location::CompassInfo const & info);
- //@}
-
- RouteMatchingInfo const & GetRouteMatchingInfo() const { return m_routeMatchingInfo; }
- void ResetRouteMatchingInfo() { m_routeMatchingInfo.Reset(); }
- void ResetDirection();
-
- /// @name Override from graphics::OverlayElement and gui::Element.
- //@{
- ///@TODO UVR
- //virtual m2::RectD GetBoundRect() const { return m2::RectD(); }
-
- bool hitTest(m2::PointD const & /*pt*/) const { return false; }
-
- void cache();
- void purge();
- void update();
- //@}
-
- private:
- void AnimateStateTransition(Mode oldMode, Mode newMode);
- void AnimateFollow();
+// void RouteBuilded();
+// void StartRouteFollow();
+// void StopRoutingMode();
- void RotateOnNorth();
+// /// @name User input notification block
+// //@{
+// void DragStarted();
+// void DragEnded();
- void CallPositionChangedListeners(m2::PointD const & pt);
- void CallStateModeListeners();
+// void ScaleStarted();
+// void CorrectScalePoint(m2::PointD & pt) const;
+// void CorrectScalePoint(m2::PointD & pt1, m2::PointD & pt2) const;
+// void ScaleEnded();
- bool IsRotationActive() const;
- bool IsInRouting() const;
- bool IsRoutingFollowingDisabled() const;
+// void Rotated();
+// //@}
- m2::PointD const GetModeDefaultPixelBinding(Mode mode) const;
- m2::PointD const GetRaFModeDefaultPxBind() const;
+// void OnCompassTaped();
- void SetModeInfo(uint16_t modeInfo, bool callListeners = true);
+// void OnSize();
- void StopAllAnimations();
-
- ScreenBase const & GetModelView() const;
+ private:
- void Assign(location::GpsInfo const & info, bool isNavigable);
- bool Assign(location::CompassInfo const & info);
- void SetDirection(double bearing);
- const m2::PointD GetPositionForDraw() const;
+ //m2::PointD const GetModeDefaultPixelBinding(Mode mode) const;
+ //m2::PointD const GetRaFModeDefaultPxBind() const;
private:
-
- enum ExternalMode
- {
- RoutingNotFollowBit = 0x10,
- FixedZoomBit = 0x20,
- RoutingSessionBit = 0x40,
- KnownDirectionBit = 0x80
- };
- static uint16_t const s_cacheRadius = 500.0f;
-
- uint16_t m_modeInfo; // combination of Mode enum and "Mode bits"
uint16_t m_dragModeInfo = 0;
uint16_t m_scaleModeInfo = 0;
- Framework * m_framework;
-
- double m_errorRadius; //< error radius in mercator
- m2::PointD m_position; //< position in mercator
- double m_drawDirection;
- my::Timer m_lastGPSBearing;
- Mode m_afterPendingMode;
-
- RouteMatchingInfo m_routeMatchingInfo;
-
- typedef map<int, TStateModeListener> TModeListeners;
- typedef map<int, TPositionListener> TPositionListeners;
-
- TModeListeners m_modeListeners;
- TPositionListeners m_positionListeners;
- int m_currentSlotID;
-
- /// @name Compass Rendering Parameters
- //@{
- //@}
-
- /// @name Rotation mode animation
- //@{
- shared_ptr<anim::Task> m_animTask;
- bool FollowCompass();
- void CreateAnimTask();
- void CreateAnimTask(m2::PointD const & srcPx, m2::PointD const & dstPx);
- void EndAnimation();
- //@}
};
}
diff --git a/map/map.pro b/map/map.pro
index 83379836c7..6b7615b189 100644
--- a/map/map.pro
+++ b/map/map.pro
@@ -24,9 +24,6 @@ HEADERS += \
framework.hpp \
ge0_parser.hpp \
geourl_process.hpp \
- information_display.hpp \
- location_state.hpp \
- move_screen_task.hpp \
mwm_url.hpp \
pin_click_manager.hpp \
route_track.hpp \
@@ -52,9 +49,6 @@ SOURCES += \
framework.cpp \
ge0_parser.cpp \
geourl_process.cpp \
- information_display.cpp \
- location_state.cpp \
- move_screen_task.cpp \
mwm_url.cpp \
pin_click_manager.cpp \
route_track.cpp \
diff --git a/map/route_track.cpp b/map/route_track.cpp
index ef6434953b..1144157497 100644
--- a/map/route_track.cpp
+++ b/map/route_track.cpp
@@ -1,7 +1,5 @@
#include "map/route_track.hpp"
-#include "map/location_state.hpp"
-
#include "indexer/scales.hpp"
#include "std/array.hpp"
diff --git a/map/route_track.hpp b/map/route_track.hpp
index f441f773ff..d768e78090 100644
--- a/map/route_track.hpp
+++ b/map/route_track.hpp
@@ -2,6 +2,8 @@
#include "map/track.hpp"
+#include "platform/location.hpp"
+
#include "routing/turns.hpp"
#include "drape/drape_global.hpp"
diff --git a/platform/location.hpp b/platform/location.hpp
index d57dbd083b..ba640a60cb 100644
--- a/platform/location.hpp
+++ b/platform/location.hpp
@@ -1,5 +1,7 @@
#pragma once
+#include "geometry/point2d.hpp"
+
#include "base/base.hpp"
#include "geometry/latlon.hpp"
@@ -8,6 +10,7 @@
#include "routing/turns_sound_settings.hpp"
#include "std/cmath.hpp"
+#include "std/function.hpp"
#include "std/string.hpp"
#include "std/vector.hpp"
@@ -189,4 +192,17 @@ namespace location
size_t GetIndexInRoute() const { return m_indexInRoute; }
m2::PointD GetPosition() const { return m_matchedPosition; }
};
+
+ // Do not change the order and values
+ enum EMyPositionMode
+ {
+ MODE_UNKNOWN_POSITION = 0x0,
+ MODE_PENDING_POSITION = 0x1,
+ MODE_NOT_FOLLOW = 0x2,
+ MODE_FOLLOW = 0x3,
+ MODE_ROTATE_AND_FOLLOW = 0x4,
+ };
+
+ using TMyPositionModeChanged = function<void (location::EMyPositionMode)>;
+
} // namespace location
diff --git a/routing/route.cpp b/routing/route.cpp
index d144c70901..44578ac760 100644
--- a/routing/route.cpp
+++ b/routing/route.cpp
@@ -12,9 +12,6 @@
#include "base/logging.hpp"
#include "std/numeric.hpp"
-#include "std/utility.hpp"
-#include "std/algorithm.hpp"
-
namespace routing
{