On my position click, added function for communication with listeners

This commit is contained in:
Kirill Zhdanovich 2013-02-12 16:59:33 +03:00 committed by Alex Zolotarev
parent 1613f63ca5
commit 181a26c313
2 changed files with 60 additions and 27 deletions

View file

@ -444,7 +444,7 @@ namespace location
bool State::roughHitTest(m2::PointD const & pt) const
{
return false;
return hitTest(pt);
}
bool State::hitTest(m2::PointD const & pt) const
@ -453,7 +453,9 @@ namespace location
// return false;
// double radius = m_arrowHeight * m_controller->GetVisualScale();
// return m_hasCompass && (pt.SquareLength(pivot()) <= my::sq(radius));
return false;
m2::PointD const pxPosition = m_framework->GetNavigator().GtoP(Position());
double const pxErrorRadius = pxPosition.Length(m_framework->GetNavigator().GtoP(Position() + m2::PointD(m_errorRadius, 0.0)));
return pt.Length(pxPosition) <= pxErrorRadius;
}
void State::CheckCompassRotation()
@ -647,35 +649,57 @@ namespace location
bool State::onTapEnded(m2::PointD const & pt)
{
if (!m_framework->GetNavigator().DoSupportRotation())
return false;
CallOnPositionClickListeners(pt);
return false;
// if (!m_framework->GetNavigator().DoSupportRotation())
// return false;
anim::Controller::Guard guard(m_framework->GetAnimController());
// anim::Controller::Guard guard(m_framework->GetAnimController());
switch (state())
{
case EActive:
if (m_hasCompass)
{
if (!IsCentered())
AnimateToPositionAndEnqueueFollowing();
else
StartCompassFollowing();
}
break;
// switch (state())
// {
// case EActive:
// if (m_hasCompass)
// {
// if (!IsCentered())
// AnimateToPositionAndEnqueueFollowing();
// else
// StartCompassFollowing();
// }
// break;
case EPressed:
StopCompassFollowing();
break;
// case EPressed:
// StopCompassFollowing();
// break;
default:
/// @todo Need to check other states?
/// - do nothing, then write comment;
/// - place ASSERT, if other states are impossible;
break;
};
// default:
// /// @todo Need to check other states?
// /// - do nothing, then write comment;
// /// - place ASSERT, if other states are impossible;
// break;
// };
invalidate();
return true;
// invalidate();
// return true;
}
void State::CallOnPositionClickListeners(m2::PointD const & point)
{
for (TOnPositionClickListeners::const_iterator it = m_onPositionClickListeners.begin();
it != m_onPositionClickListeners.end();
++it)
it->second(point);
}
int State::AddOnPositionClickListener(TOnPositionClickListener const & listner)
{
int slotID = m_currentSlotID++;
m_onPositionClickListeners[slotID] = listner;
return slotID;
}
void State::RemoveOnPositionClickListener(int listnerID)
{
m_onPositionClickListeners.erase(listnerID);
}
}

View file

@ -51,6 +51,7 @@ namespace location
public:
typedef function<void(int)> TCompassStatusListener;
typedef function<void(m2::PointD const &)> TOnPositionClickListener;
private:
@ -113,6 +114,11 @@ namespace location
TCompassStatusListeners m_compassStatusListeners;
int m_currentSlotID;
typedef map<int, TOnPositionClickListener> TOnPositionClickListeners;
TOnPositionClickListeners m_onPositionClickListeners;
void CallOnPositionClickListeners(m2::PointD const & point);
void CallCompassStatusListeners(ECompassProcessMode mode);
double ComputeMoveSpeed(m2::PointD const & globalPt0,
@ -156,6 +162,9 @@ namespace location
int AddCompassStatusListener(TCompassStatusListener const & l);
void RemoveCompassStatusListener(int slotID);
int AddOnPositionClickListener(TOnPositionClickListener const & listner);
void RemoveOnPositionClickListener(int listnerID);
void SetIsCentered(bool flag);
bool IsCentered() const;