forked from organicmaps/organicmaps
changes to CompassArrow according to code review.
This commit is contained in:
parent
155a2cdd41
commit
e19ff2ec3a
3 changed files with 31 additions and 44 deletions
|
@ -1,6 +1,6 @@
|
|||
#include "compass_arrow.hpp"
|
||||
|
||||
#include "framework.hpp"
|
||||
#include "rotate_screen_task.hpp"
|
||||
|
||||
#include "../anim/controller.hpp"
|
||||
|
||||
|
@ -25,11 +25,9 @@ CompassArrow::CompassArrow(Params const & p)
|
|||
m_angle = 0;
|
||||
}
|
||||
|
||||
void CompassArrow::setAngle(double angle)
|
||||
void CompassArrow::SetAngle(double angle)
|
||||
{
|
||||
m_angle = angle;
|
||||
m_drawM = math::Shift(math::Rotate(math::Identity<double, 3>(), m_angle), pivot() * visualScale());
|
||||
|
||||
setIsDirtyRect(true);
|
||||
}
|
||||
|
||||
|
@ -39,11 +37,10 @@ vector<m2::AnyRectD> const & CompassArrow::boundRects() const
|
|||
{
|
||||
double k = visualScale();
|
||||
|
||||
m2::PointD pv = pivot() * k;
|
||||
double halfW = m_arrowWidth / 2.0 * k;
|
||||
double halfH = m_arrowHeight / 2.0 * k;
|
||||
|
||||
m_boundRects[0] = m2::AnyRectD(pv,
|
||||
m_boundRects[0] = m2::AnyRectD(pivot(),
|
||||
-math::pi / 2 + m_angle,
|
||||
m2::RectD(-halfW, -halfH, halfW, halfH));
|
||||
|
||||
|
@ -59,7 +56,14 @@ void CompassArrow::draw(yg::gl::OverlayRenderer * r,
|
|||
if (isVisible())
|
||||
{
|
||||
checkDirtyDrawing();
|
||||
m_displayList->draw(m_drawM * m);
|
||||
|
||||
math::Matrix<double, 3, 3> drawM = math::Shift(
|
||||
math::Rotate(
|
||||
math::Identity<double, 3>(),
|
||||
m_angle),
|
||||
pivot());
|
||||
|
||||
m_displayList->draw(drawM * m);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,8 +111,6 @@ void CompassArrow::cache()
|
|||
|
||||
cacheScreen->drawPath(outlinePts, sizeof(outlinePts) / sizeof(m2::PointD), 0, cacheScreen->skin()->mapPenInfo(outlinePenInfo), depth());
|
||||
|
||||
m_drawM = math::Shift(math::Rotate(math::Identity<double, 3>(), m_angle), pivot() * k);
|
||||
|
||||
cacheScreen->setDisplayList(0);
|
||||
cacheScreen->endFrame();
|
||||
|
||||
|
@ -121,15 +123,6 @@ void CompassArrow::purge()
|
|||
m_displayList.reset();
|
||||
}
|
||||
|
||||
void CompassArrow::StopAnimation()
|
||||
{
|
||||
if (m_rotateScreenTask
|
||||
&& !m_rotateScreenTask->IsEnded()
|
||||
&& !m_rotateScreenTask->IsCancelled())
|
||||
m_rotateScreenTask->Cancel();
|
||||
m_rotateScreenTask.reset();
|
||||
}
|
||||
|
||||
bool CompassArrow::onTapEnded(m2::PointD const & pt)
|
||||
{
|
||||
anim::Controller * animController = m_framework->GetAnimController();
|
||||
|
@ -150,8 +143,13 @@ bool CompassArrow::onTapEnded(m2::PointD const & pt)
|
|||
return true;
|
||||
}
|
||||
|
||||
unsigned CompassArrow::GetArrowHeight() const
|
||||
{
|
||||
return m_arrowHeight;
|
||||
}
|
||||
|
||||
bool CompassArrow::hitTest(m2::PointD const & pt) const
|
||||
{
|
||||
double rad = max(m_arrowWidth / 2, m_arrowHeight / 2);
|
||||
return pt.Length(pivot() * visualScale()) < rad * visualScale();
|
||||
return pt.Length(pivot()) < rad * visualScale();
|
||||
}
|
||||
|
|
|
@ -3,20 +3,12 @@
|
|||
#include "../gui/element.hpp"
|
||||
|
||||
#include "../yg/color.hpp"
|
||||
#include "../yg/display_list.hpp"
|
||||
|
||||
#include "../geometry/any_rect2d.hpp"
|
||||
|
||||
#include "../std/shared_ptr.hpp"
|
||||
#include "../std/scoped_ptr.hpp"
|
||||
|
||||
namespace yg
|
||||
{
|
||||
namespace gl
|
||||
{
|
||||
class DisplayList;
|
||||
}
|
||||
}
|
||||
|
||||
class RotateScreenTask;
|
||||
class Framework;
|
||||
|
||||
/// Compass Arrow, which shows up when the screen is rotated,
|
||||
|
@ -33,19 +25,10 @@ private:
|
|||
yg::Color m_southColor;
|
||||
double m_angle;
|
||||
|
||||
/// @todo It's a scoped_ptr. You don't pass it outside the class.
|
||||
shared_ptr<yg::gl::DisplayList> m_displayList;
|
||||
|
||||
/// @todo Am I missed something? Where does this ptr initialized?
|
||||
shared_ptr<RotateScreenTask> m_rotateScreenTask;
|
||||
scoped_ptr<yg::gl::DisplayList> m_displayList;
|
||||
|
||||
mutable vector<m2::AnyRectD> m_boundRects;
|
||||
|
||||
/// @todo I don't think that it's a good idea to store matrix as state of the class.
|
||||
/// Just calculate it in the needed plase (draw()). Otherwise you should not forget
|
||||
/// to recalculate it. Now it depends on pivot(), but what happens when pivot is changed?
|
||||
math::Matrix<double, 3, 3> m_drawM;
|
||||
|
||||
Framework * m_framework;
|
||||
|
||||
void cache();
|
||||
|
@ -64,7 +47,9 @@ public:
|
|||
|
||||
CompassArrow(Params const & p);
|
||||
|
||||
void setAngle(double angle);
|
||||
void SetAngle(double angle);
|
||||
|
||||
unsigned GetArrowHeight() const;
|
||||
|
||||
vector<m2::AnyRectD> const & boundRects() const;
|
||||
void draw(yg::gl::OverlayRenderer * r, math::Matrix<double, 3, 3> const & m) const;
|
||||
|
@ -72,6 +57,4 @@ public:
|
|||
bool onTapEnded(m2::PointD const & pt);
|
||||
|
||||
bool hitTest(m2::PointD const & pt) const;
|
||||
|
||||
void StopAnimation();
|
||||
};
|
||||
|
|
|
@ -46,7 +46,7 @@ InformationDisplay::InformationDisplay(Framework * framework)
|
|||
cap.m_depth = yg::maxDepth;
|
||||
cap.m_arrowHeight = 60;
|
||||
cap.m_arrowWidth = 20;
|
||||
cap.m_pivot = m2::PointD(10 + cap.m_arrowHeight / 2, 10 + cap.m_arrowHeight / 2);
|
||||
cap.m_pivot = m2::PointD(0, 0);
|
||||
cap.m_northColor = yg::Color(255, 0, 0, 255);
|
||||
cap.m_southColor = yg::Color(255, 255, 255, 255);
|
||||
cap.m_framework = framework;
|
||||
|
@ -101,6 +101,12 @@ void InformationDisplay::setScreen(ScreenBase const & screen)
|
|||
m2::PointD pt = m2::PointD(pxRect.SizeX() / 2, pxRect.SizeY() / 2) - m2::PointD(0, m_bottomShift * m_visualScale);
|
||||
m_countryStatusDisplay->setPivot(pt);
|
||||
}
|
||||
|
||||
double k = m_controller->GetVisualScale();
|
||||
unsigned arrowHeight = m_compassArrow->GetArrowHeight();
|
||||
|
||||
m_compassArrow->setPivot(m2::PointD(10 + arrowHeight / 2,
|
||||
10 + arrowHeight / 2) * k);
|
||||
}
|
||||
|
||||
void InformationDisplay::setBottomShift(double bottomShift)
|
||||
|
@ -393,7 +399,7 @@ void InformationDisplay::enableCompassArrow(bool doEnable)
|
|||
|
||||
void InformationDisplay::setCompassArrowAngle(double angle)
|
||||
{
|
||||
m_compassArrow->setAngle(angle);
|
||||
m_compassArrow->SetAngle(angle);
|
||||
}
|
||||
|
||||
void InformationDisplay::enableCountryStatusDisplay(bool doEnable)
|
||||
|
|
Loading…
Add table
Reference in a new issue