Skip to content

Commit

Permalink
Minor tapEvent refactoring: reused already defined struct.
Browse files Browse the repository at this point in the history
  • Loading branch information
biodranik authored and syershov committed Mar 23, 2016
1 parent ddb15b9 commit b7b0892
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 43 deletions.
6 changes: 3 additions & 3 deletions drape_frontend/drape_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ DrapeEngine::DrapeEngine(Params && params)
make_ref(m_textureManager), m_viewport,
bind(&DrapeEngine::ModelViewChanged, this, _1),
params.m_model.GetIsCountryLoadedFn(),
bind(&DrapeEngine::TapEvent, this, _1, _2, _3, _4),
bind(&DrapeEngine::TapEvent, this, _1),
bind(&DrapeEngine::UserPositionChanged, this, _1),
bind(&DrapeEngine::MyPositionModeChanged, this, _1),
mode, make_ref(m_requestedTiles), params.m_allow3dBuildings);
Expand Down Expand Up @@ -235,12 +235,12 @@ void DrapeEngine::MyPositionModeChanged(location::EMyPositionMode mode)
});
}

void DrapeEngine::TapEvent(m2::PointD const & pxPoint, bool isLong, bool isMyPosition, FeatureID const & feature)
void DrapeEngine::TapEvent(TapInfo const & tapInfo)
{
GetPlatform().RunOnGuiThread([=]()
{
if (m_tapListener)
m_tapListener(pxPoint, isLong, isMyPosition, feature);
m_tapListener(tapInfo);
});
}

Expand Down
2 changes: 1 addition & 1 deletion drape_frontend/drape_engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class DrapeEngine
void ModelViewChangedGuiThread(ScreenBase const & screen);

void MyPositionModeChanged(location::EMyPositionMode mode);
void TapEvent(m2::PointD const & pxPoint, bool isLong, bool isMyPosition, FeatureID const & feature);
void TapEvent(TapInfo const & tapInfo);
void UserPositionChanged(m2::PointD const & position);

void ResizeImpl(int w, int h);
Expand Down
2 changes: 1 addition & 1 deletion drape_frontend/frontend_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ void FrontendRenderer::OnTap(m2::PointD const & pt, bool isLongTap)
isMyPosition = selectRect.IsPointInside(pt);
}

m_tapEventInfoFn(pt, isLongTap, isMyPosition, GetVisiblePOI(selectRect));
m_tapEventInfoFn({pt, isLongTap, isMyPosition, GetVisiblePOI(selectRect)});
}

void FrontendRenderer::OnForceTap(m2::PointD const & pt)
Expand Down
9 changes: 4 additions & 5 deletions drape_frontend/frontend_renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ class TransparentLayer;
struct TapInfo
{
m2::PointD const m_pixelPoint;
bool m_isLong;

bool m_isMyPositionTapped;
FeatureID m_featureTapped;
bool const m_isLong;
bool const m_isMyPositionTapped;
FeatureID const m_featureTapped;
};

class FrontendRenderer : public BaseRenderer
Expand All @@ -67,7 +66,7 @@ class FrontendRenderer : public BaseRenderer
public:
using TModelViewChanged = function<void (ScreenBase const & screen)>;
using TIsCountryLoaded = TIsCountryLoaded;
using TTapEventInfoFn = function<void (m2::PointD const & pxPoint, bool isLong, bool isMyPosition, FeatureID const & id)>;
using TTapEventInfoFn = function<void (TapInfo const &)>;
using TUserPositionChangedFn = function<void (m2::PointD const & pt)>;

struct Params : BaseRenderer::Params
Expand Down
46 changes: 23 additions & 23 deletions map/framework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,7 @@ void Framework::CreateDrapeEngine(ref_ptr<dp::OGLContextFactory> contextFactory,
if (GetDrawScale() <= scales::GetUpperWorldScale())
m_autoDownloadingOn = true;
});
m_drapeEngine->SetTapEventInfoListener(bind(&Framework::OnTapEvent, this, _1, _2, _3, _4));
m_drapeEngine->SetTapEventInfoListener(bind(&Framework::OnTapEvent, this, _1));
m_drapeEngine->SetUserPositionListener(bind(&Framework::OnUserPositionChanged, this, _1));
OnSize(params.m_surfaceWidth, params.m_surfaceHeight);

Expand All @@ -1448,15 +1448,6 @@ void Framework::CreateDrapeEngine(ref_ptr<dp::OGLContextFactory> contextFactory,

InvalidateUserMarks();

// In case of the engine reinitialization simulate the last tap to show selection mark.
if (m_lastTapEvent != nullptr)
{
UserMark const * mark = OnTapEventImpl(m_lastTapEvent->m_pxPoint, m_lastTapEvent->m_isLong,
m_lastTapEvent->m_isMyPosition, m_lastTapEvent->m_feature);
if (mark != nullptr)
ActivateUserMark(mark, true);
}

#ifdef OMIM_OS_ANDROID
// In case of the engine reinitialization recover compass and location data
// for correct my position state.
Expand All @@ -1478,6 +1469,19 @@ void Framework::CreateDrapeEngine(ref_ptr<dp::OGLContextFactory> contextFactory,

if (m_connectToGpsTrack)
GpsTracker::Instance().Connect(bind(&Framework::OnUpdateGpsTrackPointsCallback, this, _1, _2));

// In case of the engine reinitialization simulate the last tap to show selection mark.
SimulateLastTapEventIfNeeded();
}

void Framework::SimulateLastTapEventIfNeeded()
{
if (m_lastTapEvent)
{
UserMark const * mark = OnTapEventImpl(*m_lastTapEvent);
if (mark)
ActivateUserMark(mark, true);
}
}

ref_ptr<df::DrapeEngine> Framework::GetDrapeEngine()
Expand Down Expand Up @@ -1890,20 +1894,15 @@ void Framework::InvalidateUserMarks()
}
}

void Framework::OnTapEvent(m2::PointD pxPoint, bool isLong, bool isMyPosition, FeatureID const & fid)
void Framework::OnTapEvent(df::TapInfo const & tapInfo)
{
// Back up last tap event to recover selection in case of Drape reinitialization.
if (!m_lastTapEvent)
m_lastTapEvent = make_unique<TapEventData>();
m_lastTapEvent->m_pxPoint = pxPoint;
m_lastTapEvent->m_isLong = isLong;
m_lastTapEvent->m_isMyPosition = isMyPosition;
m_lastTapEvent->m_feature = fid;
m_lastTapEvent.reset(new df::TapInfo(tapInfo));

UserMark const * mark = OnTapEventImpl(pxPoint, isLong, isMyPosition, fid);
UserMark const * mark = OnTapEventImpl(tapInfo);

{
alohalytics::TStringMap details {{"isLongPress", isLong ? "1" : "0"}};
alohalytics::TStringMap details {{"isLongPress", tapInfo.m_isLong ? "1" : "0"}};
if (mark)
mark->FillLogEvent(details);
alohalytics::Stats::Instance().LogEvent("$GetUserMark", details);
Expand All @@ -1918,11 +1917,11 @@ void Framework::InvalidateRendering()
m_drapeEngine->Invalidate();
}

UserMark const * Framework::OnTapEventImpl(m2::PointD pxPoint, bool isLong, bool isMyPosition, FeatureID const & fid)
UserMark const * Framework::OnTapEventImpl(const df::TapInfo & tapInfo)
{
m2::PointD const pxPoint2d = m_currentModelView.P3dtoP(pxPoint);
m2::PointD const pxPoint2d = m_currentModelView.P3dtoP(tapInfo.m_pixelPoint);

if (isMyPosition)
if (tapInfo.m_isMyPositionTapped)
return UserMarkContainer::UserMarkForMyPostion();

df::VisualParams const & vp = df::VisualParams::Instance();
Expand All @@ -1943,6 +1942,7 @@ UserMark const * Framework::OnTapEventImpl(m2::PointD pxPoint, bool isLong, bool
return (type == UserMarkType::BOOKMARK_MARK ? bmSearchRect : rect);
});

FeatureID const & fid = tapInfo.m_featureTapped;
if (mark != nullptr)
{
// TODO(AlexZ): Refactor out together with UserMarks.
Expand All @@ -1966,7 +1966,7 @@ UserMark const * Framework::OnTapEventImpl(m2::PointD pxPoint, bool isLong, bool
mercatorPivot = feature::GetCenter(*feature);
needMark = true;
}
else if (isLong)
else if (tapInfo.m_isLong)
{
mercatorPivot = m_currentModelView.PtoG(pxPoint2d);
// TODO(AlexZ): Should we change mercatorPivot to found feature's center?
Expand Down
15 changes: 5 additions & 10 deletions map/framework.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,21 +283,16 @@ class Framework
void InvalidateRendering();

private:
struct TapEventData
{
m2::PointD m_pxPoint;
bool m_isLong;
bool m_isMyPosition;
FeatureID m_feature;
};
unique_ptr<TapEventData> m_lastTapEvent;
/// UI callback is called when tap event is "restored" after Drape engine restart.
void SimulateLastTapEventIfNeeded();
unique_ptr<df::TapInfo> m_lastTapEvent;
#ifdef OMIM_OS_ANDROID
unique_ptr<location::CompassInfo> m_lastCompassInfo;
unique_ptr<location::GpsInfo> m_lastGPSInfo;
#endif

void OnTapEvent(m2::PointD pxPoint, bool isLong, bool isMyPosition, FeatureID const & feature);
UserMark const * OnTapEventImpl(m2::PointD pxPoint, bool isLong, bool isMyPosition, FeatureID const & feature);
void OnTapEvent(df::TapInfo const & tapInfo);
UserMark const * OnTapEventImpl(df::TapInfo const & tapInfo);
//@}

TActivateCallbackFn m_activateUserMarkFn;
Expand Down

0 comments on commit b7b0892

Please sign in to comment.