forked from organicmaps/organicmaps
check balloon position (graphics::EPosition) dependent on balloon position on the screen.
animate screen to move when not all balloon on the screen
This commit is contained in:
parent
0b1a84735b
commit
d69bd26e8b
2 changed files with 84 additions and 2 deletions
|
@ -7,6 +7,7 @@
|
|||
#include "../anim/value_interpolation.hpp"
|
||||
|
||||
#define POPUP_PADDING 23
|
||||
#define ANIM_PADDING 8
|
||||
|
||||
class BookmarkBalloon::BalloonAnimTask : public anim::Task
|
||||
{
|
||||
|
@ -85,10 +86,80 @@ private:
|
|||
|
||||
BookmarkBalloon::BookmarkBalloon(Params const & p)
|
||||
: Balloon(p),
|
||||
m_isPositionChecked(true),
|
||||
m_framework(p.m_framework)
|
||||
{
|
||||
}
|
||||
|
||||
void BookmarkBalloon::setIsPositionChecked(bool isChecked)
|
||||
{
|
||||
m_isPositionChecked = isChecked;
|
||||
}
|
||||
|
||||
bool BookmarkBalloon::isPositionChecked() const
|
||||
{
|
||||
return m_isPositionChecked;
|
||||
}
|
||||
|
||||
bool BookmarkBalloon::checkPosition()
|
||||
{
|
||||
if (isPositionChecked())
|
||||
return false;
|
||||
|
||||
setIsPositionChecked(true);
|
||||
|
||||
bool result = false;
|
||||
|
||||
bool needLayout = false;
|
||||
m2::RectD balloonRect = roughBoundRect();
|
||||
if (balloonRect.minX() < 0)
|
||||
{
|
||||
setPosition(graphics::EPosLeft);
|
||||
needLayout = true;
|
||||
}
|
||||
if (m_framework->GetNavigator().Screen().GetWidth() < balloonRect.maxX())
|
||||
{
|
||||
setPosition(graphics::EPosRight);
|
||||
needLayout = true;
|
||||
}
|
||||
|
||||
if (needLayout)
|
||||
layout();
|
||||
|
||||
ScreenBase const & screen = m_framework->GetNavigator().Screen();
|
||||
|
||||
m2::PointD globalOrg = screen.GetOrg();
|
||||
m2::PointD pixelOrg = screen.GtoP(globalOrg);
|
||||
|
||||
double k = visualScale();
|
||||
balloonRect = roughBoundRect();
|
||||
if (balloonRect.minX() < 0)
|
||||
{
|
||||
pixelOrg.x += (balloonRect.minX() - ANIM_PADDING * k);
|
||||
result = true;
|
||||
}
|
||||
else if (balloonRect.maxX() > screen.GetWidth())
|
||||
{
|
||||
pixelOrg.x += (balloonRect.maxX() - screen.GetWidth() + ANIM_PADDING * k);
|
||||
result = true;
|
||||
}
|
||||
|
||||
if (balloonRect.minY() < 0)
|
||||
{
|
||||
pixelOrg.y += (balloonRect.minY() - ANIM_PADDING * k);
|
||||
result = true;
|
||||
}
|
||||
else if (balloonRect.maxY() > screen.GetHeight())
|
||||
{
|
||||
pixelOrg.y += (balloonRect.maxY() - screen.GetHeight() + ANIM_PADDING * k);
|
||||
result = true;
|
||||
}
|
||||
|
||||
m_framework->GetAnimator().MoveScreen(globalOrg, screen.PtoG(pixelOrg), 0.5);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void BookmarkBalloon::update()
|
||||
{
|
||||
Balloon::update();
|
||||
|
@ -98,6 +169,9 @@ void BookmarkBalloon::update()
|
|||
newPivot.y -= POPUP_PADDING * visualScale();
|
||||
setPivot(newPivot);
|
||||
|
||||
if (checkPosition())
|
||||
setIsDirtyLayout(true);
|
||||
|
||||
if (m_currentAnimTask)
|
||||
{
|
||||
m_balloonScale = m_currentAnimTask->GetScale();
|
||||
|
@ -153,6 +227,9 @@ void BookmarkBalloon::cancelTask()
|
|||
|
||||
void BookmarkBalloon::showAnimated()
|
||||
{
|
||||
setPosition(graphics::EPosCenter);
|
||||
setIsPositionChecked(false);
|
||||
|
||||
animTaskEnded(0);
|
||||
setIsVisible(true);
|
||||
}
|
||||
|
|
|
@ -14,9 +14,14 @@ private:
|
|||
shared_ptr<BalloonAnimTask> m_currentAnimTask;
|
||||
|
||||
m2::PointD m_glbPivot;
|
||||
Framework const * m_framework;
|
||||
Framework * m_framework;
|
||||
string m_bmkName;
|
||||
string m_bmkType;
|
||||
bool m_isPositionChecked;
|
||||
|
||||
void setIsPositionChecked(bool isChecked);
|
||||
bool isPositionChecked() const;
|
||||
bool checkPosition();
|
||||
|
||||
void createTask(double startScale, double endScale,
|
||||
double startOffset, double endOffset,
|
||||
|
@ -32,7 +37,7 @@ public:
|
|||
|
||||
struct Params : public base_t::Params
|
||||
{
|
||||
Framework const * m_framework;
|
||||
Framework * m_framework;
|
||||
};
|
||||
|
||||
BookmarkBalloon(Params const & p);
|
||||
|
|
Loading…
Add table
Reference in a new issue