forked from organicmaps/organicmaps
Added arrow recoloring
This commit is contained in:
parent
0947ace7f8
commit
d2fc26b0b2
8 changed files with 74 additions and 48 deletions
|
@ -125,6 +125,11 @@ void Arrow3d::Build(ref_ptr<dp::GpuProgram> prg)
|
|||
GLFunctions::glBindBuffer(0, gl_const::GLArrayBuffer);
|
||||
}
|
||||
|
||||
void Arrow3d::SetPositionObsolete(bool obsolete)
|
||||
{
|
||||
m_obsoletePosition = obsolete;
|
||||
}
|
||||
|
||||
void Arrow3d::Render(ScreenBase const & screen, ref_ptr<dp::GpuProgramManager> mng)
|
||||
{
|
||||
// Unbind current VAO, because glVertexAttributePointer and glEnableVertexAttribute can affect it.
|
||||
|
@ -177,7 +182,8 @@ void Arrow3d::Render(ScreenBase const & screen, ref_ptr<dp::GpuProgramManager> m
|
|||
dp::UniformValuesStorage uniforms;
|
||||
uniforms.SetMatrix4x4Value("m_transform", modelTransform.m_data);
|
||||
|
||||
glsl::vec4 const color = glsl::ToVec4(df::GetColorConstant(GetStyleReader().GetCurrentStyle(), df::Arrow3D));
|
||||
glsl::vec4 const color = glsl::ToVec4(df::GetColorConstant(GetStyleReader().GetCurrentStyle(),
|
||||
m_obsoletePosition ? df::Arrow3DObsolete : df::Arrow3D));
|
||||
uniforms.SetFloatValue("u_color", color.r, color.g, color.b, color.a);
|
||||
|
||||
dp::ApplyUniforms(uniforms, prg);
|
||||
|
|
|
@ -29,6 +29,7 @@ public:
|
|||
void SetAzimuth(double azimuth);
|
||||
void SetSize(uint32_t width, uint32_t height);
|
||||
void SetTexture(ref_ptr<dp::TextureManager> texMng);
|
||||
void SetPositionObsolete(bool obsolete);
|
||||
|
||||
void Render(ScreenBase const & screen, ref_ptr<dp::GpuProgramManager> mng);
|
||||
|
||||
|
@ -36,7 +37,8 @@ private:
|
|||
void Build(ref_ptr<dp::GpuProgram> prg);
|
||||
|
||||
m2::PointD m_position;
|
||||
double m_azimuth;
|
||||
double m_azimuth = 0.0;
|
||||
bool m_obsoletePosition = false;
|
||||
|
||||
uint32_t m_pixelWidth = 0;
|
||||
uint32_t m_pixelHeight = 0;
|
||||
|
|
|
@ -22,6 +22,7 @@ unordered_map<int, unordered_map<int, dp::Color>> kColorConstants =
|
|||
{ TrackCarSpeed, dp::Color(21, 121, 244, 255) },
|
||||
{ TrackPlaneSpeed, dp::Color(10, 196, 255, 255) },
|
||||
{ TrackUnknownDistance, dp::Color(97, 97, 97, 255) },
|
||||
{ Arrow3DObsolete, dp::Color(105, 135, 155, 255) },
|
||||
}
|
||||
},
|
||||
{ MapStyleDark,
|
||||
|
@ -36,6 +37,7 @@ unordered_map<int, unordered_map<int, dp::Color>> kColorConstants =
|
|||
{ TrackCarSpeed, dp::Color(255, 202, 40, 255) },
|
||||
{ TrackPlaneSpeed, dp::Color(255, 245, 160, 255) },
|
||||
{ TrackUnknownDistance, dp::Color(150, 150, 150, 255) },
|
||||
{ Arrow3DObsolete, dp::Color(230, 230, 170, 255) },
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -18,7 +18,8 @@ enum ColorConstant
|
|||
TrackHumanSpeed,
|
||||
TrackCarSpeed,
|
||||
TrackPlaneSpeed,
|
||||
TrackUnknownDistance
|
||||
TrackUnknownDistance,
|
||||
Arrow3DObsolete
|
||||
};
|
||||
|
||||
dp::Color GetColorConstant(MapStyle style, ColorConstant constant);
|
||||
|
|
|
@ -57,6 +57,7 @@ MyPosition::MyPosition(ref_ptr<dp::TextureManager> mng)
|
|||
, m_accuracy(0.0f)
|
||||
, m_showAzimuth(false)
|
||||
, m_isRoutingMode(false)
|
||||
, m_obsoletePosition(false)
|
||||
{
|
||||
m_parts.resize(4);
|
||||
CacheAccuracySector(mng);
|
||||
|
@ -88,6 +89,12 @@ void MyPosition::SetRoutingMode(bool routingMode)
|
|||
m_isRoutingMode = routingMode;
|
||||
}
|
||||
|
||||
void MyPosition::SetPositionObsolete(bool obsolete)
|
||||
{
|
||||
m_obsoletePosition = obsolete;
|
||||
m_arrow3d.SetPositionObsolete(obsolete);
|
||||
}
|
||||
|
||||
void MyPosition::RenderAccuracy(ScreenBase const & screen,
|
||||
ref_ptr<dp::GpuProgramManager> mng,
|
||||
dp::UniformValuesStorage const & commonUniforms)
|
||||
|
@ -119,7 +126,9 @@ void MyPosition::RenderMyPosition(ScreenBase const & screen,
|
|||
uniforms.SetFloatValue("u_position", m_position.x, m_position.y, dp::depth::MY_POSITION_MARK);
|
||||
uniforms.SetFloatValue("u_azimut", -(m_azimuth + screen.GetAngle()));
|
||||
uniforms.SetFloatValue("u_opacity", 1.0);
|
||||
RenderPart(mng, uniforms, (m_showAzimuth == true) ? MY_POSITION_ARROW : MY_POSITION_POINT);
|
||||
RenderPart(mng, uniforms, (m_showAzimuth == true) ?
|
||||
(m_obsoletePosition ? MY_POSITION_ARROW_GRAY : MY_POSITION_ARROW) :
|
||||
MY_POSITION_POINT);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -168,43 +177,47 @@ void MyPosition::CacheAccuracySector(ref_ptr<dp::TextureManager> mng)
|
|||
}
|
||||
}
|
||||
|
||||
void MyPosition::CacheSymbol(dp::TextureManager::SymbolRegion const & symbol,
|
||||
dp::GLState const & state, dp::Batcher & batcher,
|
||||
EMyPositionPart part)
|
||||
{
|
||||
m2::RectF const & texRect = symbol.GetTexRect();
|
||||
m2::PointF const halfSize = m2::PointF(symbol.GetPixelSize()) * 0.5f;
|
||||
|
||||
Vertex data[4] =
|
||||
{
|
||||
{ glsl::vec2(-halfSize.x, halfSize.y), glsl::ToVec2(texRect.LeftTop()) },
|
||||
{ glsl::vec2(-halfSize.x, -halfSize.y), glsl::ToVec2(texRect.LeftBottom()) },
|
||||
{ glsl::vec2( halfSize.x, halfSize.y), glsl::ToVec2(texRect.RightTop()) },
|
||||
{ glsl::vec2( halfSize.x, -halfSize.y), glsl::ToVec2(texRect.RightBottom())}
|
||||
};
|
||||
|
||||
dp::AttributeProvider provider(1 /* streamCount */, dp::Batcher::VertexPerQuad);
|
||||
provider.InitStream(0 /* streamIndex */, GetBindingInfo(), make_ref(data));
|
||||
m_parts[part].first = batcher.InsertTriangleStrip(state, make_ref(&provider), nullptr);
|
||||
ASSERT(m_parts[part].first.IsValid(), ());
|
||||
}
|
||||
|
||||
void MyPosition::CachePointPosition(ref_ptr<dp::TextureManager> mng)
|
||||
{
|
||||
dp::TextureManager::SymbolRegion pointSymbol, arrowSymbol;
|
||||
int const kSymbolsCount = 3;
|
||||
dp::TextureManager::SymbolRegion pointSymbol, arrowSymbol, arrowGraySymbol;
|
||||
mng->GetSymbolRegion("current-position", pointSymbol);
|
||||
mng->GetSymbolRegion("current-position-compas", arrowSymbol);
|
||||
|
||||
m2::RectF const & pointTexRect = pointSymbol.GetTexRect();
|
||||
m2::PointF pointHalfSize = m2::PointF(pointSymbol.GetPixelSize()) * 0.5f;
|
||||
|
||||
Vertex pointData[4]=
|
||||
{
|
||||
{ glsl::vec2(-pointHalfSize.x, pointHalfSize.y), glsl::ToVec2(pointTexRect.LeftTop()) },
|
||||
{ glsl::vec2(-pointHalfSize.x, -pointHalfSize.y), glsl::ToVec2(pointTexRect.LeftBottom()) },
|
||||
{ glsl::vec2( pointHalfSize.x, pointHalfSize.y), glsl::ToVec2(pointTexRect.RightTop()) },
|
||||
{ glsl::vec2( pointHalfSize.x, -pointHalfSize.y), glsl::ToVec2(pointTexRect.RightBottom())}
|
||||
};
|
||||
|
||||
m2::RectF const & arrowTexRect = arrowSymbol.GetTexRect();
|
||||
m2::PointF arrowHalfSize = m2::PointF(arrowSymbol.GetPixelSize()) * 0.5f;
|
||||
|
||||
Vertex arrowData[4]=
|
||||
{
|
||||
{ glsl::vec2(-arrowHalfSize.x, arrowHalfSize.y), glsl::ToVec2(arrowTexRect.LeftTop()) },
|
||||
{ glsl::vec2(-arrowHalfSize.x, -arrowHalfSize.y), glsl::ToVec2(arrowTexRect.LeftBottom()) },
|
||||
{ glsl::vec2( arrowHalfSize.x, arrowHalfSize.y), glsl::ToVec2(arrowTexRect.RightTop()) },
|
||||
{ glsl::vec2( arrowHalfSize.x, -arrowHalfSize.y), glsl::ToVec2(arrowTexRect.RightBottom())}
|
||||
};
|
||||
mng->GetSymbolRegion("current-position-obsolete", arrowGraySymbol);
|
||||
|
||||
m_arrow3d.SetSize(arrowSymbol.GetPixelSize().x, arrowSymbol.GetPixelSize().y);
|
||||
m_arrow3d.SetTexture(mng);
|
||||
|
||||
ASSERT(pointSymbol.GetTexture() == arrowSymbol.GetTexture(), ());
|
||||
ASSERT(pointSymbol.GetTexture() == arrowGraySymbol.GetTexture(), ());
|
||||
dp::GLState state(gpu::MY_POSITION_PROGRAM, dp::GLState::OverlayLayer);
|
||||
state.SetColorTexture(pointSymbol.GetTexture());
|
||||
|
||||
dp::TextureManager::SymbolRegion * symbols[kSymbolsCount] = { &pointSymbol, &arrowSymbol, &arrowGraySymbol };
|
||||
EMyPositionPart partIndices[kSymbolsCount] = { MY_POSITION_POINT, MY_POSITION_ARROW, MY_POSITION_ARROW_GRAY };
|
||||
{
|
||||
dp::Batcher batcher(2 * dp::Batcher::IndexPerQuad, 2 * dp::Batcher::VertexPerQuad);
|
||||
dp::Batcher batcher(kSymbolsCount * dp::Batcher::IndexPerQuad, kSymbolsCount * dp::Batcher::VertexPerQuad);
|
||||
dp::SessionGuard guard(batcher, [this](dp::GLState const & state, drape_ptr<dp::RenderBucket> && b)
|
||||
{
|
||||
drape_ptr<dp::RenderBucket> bucket = move(b);
|
||||
|
@ -213,20 +226,12 @@ void MyPosition::CachePointPosition(ref_ptr<dp::TextureManager> mng)
|
|||
m_nodes.emplace_back(state, bucket->MoveBuffer());
|
||||
});
|
||||
|
||||
dp::AttributeProvider pointProvider(1 /*stream count*/, dp::Batcher::VertexPerQuad);
|
||||
pointProvider.InitStream(0 /*stream index*/, GetBindingInfo(), make_ref(pointData));
|
||||
|
||||
dp::AttributeProvider arrowProvider(1 /*stream count*/, dp::Batcher::VertexPerQuad);
|
||||
arrowProvider.InitStream(0 /*stream index*/, GetBindingInfo(), make_ref(arrowData));
|
||||
|
||||
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.InsertTriangleStrip(state, make_ref(&pointProvider), nullptr);
|
||||
ASSERT(m_parts[MY_POSITION_POINT].first.IsValid(), ());
|
||||
|
||||
m_parts[MY_POSITION_ARROW].first = batcher.InsertTriangleStrip(state, make_ref(&arrowProvider), nullptr);
|
||||
ASSERT(m_parts[MY_POSITION_ARROW].first.IsValid(), ());
|
||||
int const partIndex = m_nodes.size();
|
||||
for (int i = 0; i < kSymbolsCount; i++)
|
||||
{
|
||||
m_parts[partIndices[i]].second = partIndex;
|
||||
CacheSymbol(*symbols[i], state, batcher, partIndices[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -234,9 +239,8 @@ void MyPosition::RenderPart(ref_ptr<dp::GpuProgramManager> mng,
|
|||
dp::UniformValuesStorage const & uniforms,
|
||||
MyPosition::EMyPositionPart part)
|
||||
{
|
||||
TPart const & accuracy = m_parts[part];
|
||||
RenderNode & node = m_nodes[accuracy.second];
|
||||
node.Render(mng, uniforms, accuracy.first);
|
||||
TPart const & p = m_parts[part];
|
||||
m_nodes[p.second].Render(mng, uniforms, p.first);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ public:
|
|||
void SetIsValidAzimuth(bool isValid);
|
||||
void SetAccuracy(float accuracy);
|
||||
void SetRoutingMode(bool routingMode);
|
||||
void SetPositionObsolete(bool obsolete);
|
||||
|
||||
void RenderAccuracy(ScreenBase const & screen,
|
||||
ref_ptr<dp::GpuProgramManager> mng,
|
||||
|
@ -39,25 +40,29 @@ private:
|
|||
void CacheAccuracySector(ref_ptr<dp::TextureManager> mng);
|
||||
void CachePointPosition(ref_ptr<dp::TextureManager> mng);
|
||||
|
||||
private:
|
||||
enum EMyPositionPart
|
||||
{
|
||||
// don't change order and values
|
||||
MY_POSITION_ACCURACY = 0,
|
||||
MY_POSITION_ARROW = 1,
|
||||
MY_POSITION_POINT = 2
|
||||
MY_POSITION_POINT = 2,
|
||||
MY_POSITION_ARROW_GRAY = 3
|
||||
};
|
||||
|
||||
void RenderPart(ref_ptr<dp::GpuProgramManager> mng,
|
||||
dp::UniformValuesStorage const & uniforms,
|
||||
EMyPositionPart part);
|
||||
|
||||
private:
|
||||
void CacheSymbol(dp::TextureManager::SymbolRegion const & symbol,
|
||||
dp::GLState const & state, dp::Batcher & batcher,
|
||||
EMyPositionPart part);
|
||||
|
||||
m2::PointF m_position;
|
||||
float m_azimuth;
|
||||
float m_accuracy;
|
||||
bool m_showAzimuth;
|
||||
bool m_isRoutingMode;
|
||||
bool m_obsoletePosition;
|
||||
|
||||
using TPart = pair<dp::IndicesRange, size_t>;
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ double const kMinSpeedThresholdMps = 1.0;
|
|||
double const kMaxPendingLocationTimeSec = 60.0;
|
||||
double const kMaxTimeInBackgroundSec = 60.0 * 60;
|
||||
double const kMaxNotFollowRoutingTimeSec = 10.0;
|
||||
double const kMaxUpdateLocationInvervalSec = 30.0;
|
||||
|
||||
int const kDoNotChangeZoom = -1;
|
||||
|
||||
|
@ -326,6 +327,7 @@ void MyPositionController::OnLocationUpdate(location::GpsInfo const & info, bool
|
|||
|
||||
m_isPositionAssigned = true;
|
||||
SetIsVisible(true);
|
||||
m_updateLocationTimer.Reset();
|
||||
}
|
||||
|
||||
void MyPositionController::LoseLocation()
|
||||
|
@ -399,6 +401,9 @@ void MyPositionController::Render(uint32_t renderMode, ScreenBase const & screen
|
|||
m_shape->SetAccuracy(m_errorRadius);
|
||||
m_shape->SetRoutingMode(IsInRouting());
|
||||
|
||||
double const updateInterval = m_updateLocationTimer.ElapsedSeconds();
|
||||
m_shape->SetPositionObsolete(updateInterval >= kMaxUpdateLocationInvervalSec);
|
||||
|
||||
if ((renderMode & RenderAccuracy) != 0)
|
||||
m_shape->RenderAccuracy(screen, mng, commonUniforms);
|
||||
|
||||
|
|
|
@ -144,6 +144,7 @@ private:
|
|||
my::Timer m_lastGPSBearing;
|
||||
my::Timer m_pendingTimer;
|
||||
my::Timer m_routingNotFollowTimer;
|
||||
my::Timer m_updateLocationTimer;
|
||||
|
||||
m2::RectD m_pixelRect;
|
||||
m2::PointD m_centerPixelPositionRouting;
|
||||
|
|
Loading…
Add table
Reference in a new issue