Added new user event Move for scrolling the map by buttons.

This commit is contained in:
Daria Volvenkova 2019-03-07 20:17:31 +03:00 committed by Roman Kuznetsov
parent f9ed08034c
commit be152241df
6 changed files with 64 additions and 1 deletions

View file

@ -188,6 +188,11 @@ void DrapeEngine::Scale(double factor, m2::PointD const & pxPoint, bool isAnim)
AddUserEvent(make_unique_dp<ScaleEvent>(factor, pxPoint, isAnim));
}
void DrapeEngine::Move(double factorX, double factorY, bool isAnim)
{
AddUserEvent(make_unique_dp<MoveEvent>(factorX, factorY, isAnim));
}
void DrapeEngine::SetModelViewCenter(m2::PointD const & centerPt, int zoom, bool isAnim,
bool trackVisibleViewport)
{

View file

@ -126,6 +126,7 @@ public:
void AddTouchEvent(TouchEvent const & event);
void Scale(double factor, m2::PointD const & pxPoint, bool isAnim);
void Move(double factorX, double factorY, bool isAnim);
// If zoom == -1 then current zoom will not be changed.
void SetModelViewCenter(m2::PointD const & centerPt, int zoom, bool isAnim,

View file

@ -177,6 +177,13 @@ ScreenBase const & UserEventStream::ProcessEvents(bool & modelViewChanged, bool
TouchCancel(m_touches);
}
break;
case UserEvent::EventType::Move:
{
ref_ptr<MoveEvent> moveEvent = make_ref(e);
breakAnim = OnMove(moveEvent);
TouchCancel(m_touches);
}
break;
case UserEvent::EventType::Resize:
{
ref_ptr<ResizeEvent> resizeEvent = make_ref(e);
@ -360,6 +367,21 @@ bool UserEventStream::OnSetScale(ref_ptr<ScaleEvent> scaleEvent)
return true;
}
bool UserEventStream::OnMove(ref_ptr<MoveEvent> moveEvent)
{
double const factorX = moveEvent->GetFactorX();
double const factorY = moveEvent->GetFactorY();
ScreenBase screen;
GetTargetScreen(screen);
auto const & rect = screen.PixelRectIn3d();
screen.Move(factorX * rect.SizeX(), -factorY * rect.SizeY());
ShrinkAndScaleInto(screen, df::GetWorldRect());
return SetScreen(screen, moveEvent->IsAnim());
}
bool UserEventStream::OnSetAnyRect(ref_ptr<SetAnyRectEvent> anyRectEvent)
{
return SetRect(anyRectEvent->GetRect(), anyRectEvent->IsAnim(), anyRectEvent->FitInViewport());

View file

@ -40,7 +40,8 @@ public:
Rotate,
FollowAndRotate,
AutoPerspective,
VisibleViewport
VisibleViewport,
Move
};
virtual ~UserEvent() = default;
@ -134,6 +135,27 @@ private:
bool m_isAnim;
};
class MoveEvent : public UserEvent
{
public:
MoveEvent(double factorX, double factorY, bool isAnim)
: m_factorX(factorX)
, m_factorY(factorY)
, m_isAnim(isAnim)
{}
EventType GetType() const override { return UserEvent::EventType::Move; }
double GetFactorX() const { return m_factorX; }
double GetFactorY() const { return m_factorY; }
bool IsAnim() const { return m_isAnim; }
private:
double m_factorX;
double m_factorY;
bool m_isAnim;
};
class SetCenterEvent : public UserEvent
{
public:
@ -402,6 +424,7 @@ public:
private:
bool OnSetScale(ref_ptr<ScaleEvent> scaleEvent);
bool OnMove(ref_ptr<MoveEvent> moveEvent);
bool OnSetAnyRect(ref_ptr<SetAnyRectEvent> anyRectEvent);
bool OnSetRect(ref_ptr<SetRectEvent> rectEvent);
bool OnSetCenter(ref_ptr<SetCenterEvent> centerEvent);

View file

@ -1274,6 +1274,12 @@ void Framework::Scale(double factor, m2::PointD const & pxPoint, bool isAnim)
m_drapeEngine->Scale(factor, pxPoint, isAnim);
}
void Framework::Move(double factorX, double factorY, bool isAnim)
{
if (m_drapeEngine != nullptr)
m_drapeEngine->Move(factorX, factorY, isAnim);
}
void Framework::TouchEvent(df::TouchEvent const & touch)
{
if (m_drapeEngine != nullptr)

View file

@ -655,6 +655,12 @@ public:
void Scale(double factor, bool isAnim);
void Scale(double factor, m2::PointD const & pxPoint, bool isAnim);
/// Moves the viewport a distance of factorX * viewportWidth and factorY * viewportHeight.
/// E.g. factorX == 1.0 moves the map one screen size to the right, factorX == -0.5 moves the map
/// half screen size to the left, factorY == -2.0 moves the map two sizes down,
/// factorY = 1.5 moves the map one and a half size up.
void Move(double factorX, double factorY, bool isAnim);
void TouchEvent(df::TouchEvent const & touch);
//@}