forked from organicmaps/organicmaps
Updating navigator's ScreenBase.
This commit is contained in:
parent
52f914b593
commit
01967d745c
6 changed files with 99 additions and 22 deletions
|
@ -11,8 +11,6 @@ void main()
|
|||
{
|
||||
|
||||
v_tcoord = a_tcoord;
|
||||
gl_Position.xy = a_pos;
|
||||
gl_Position.zw = vec2(0.0, 1.0);
|
||||
gl_Position = projection * translate * rotate * gl_Position;
|
||||
gl_Position = projection * translate * rotate * vec4(a_pos, 0.0, 1.0);
|
||||
}
|
||||
|
||||
|
|
|
@ -469,6 +469,7 @@ void FrontendRenderer::AcceptMessage(ref_ptr<Message> message)
|
|||
m_renderer3d->SetPlaneAngleX(msg->GetAngleX());
|
||||
m_useFramebuffer = true;
|
||||
m_3dModeChanged = true;
|
||||
AddUserEvent(Enable3dModeEvent(max(m_renderer3d->GetScaleX(), m_renderer3d->GetScaleY())));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -476,6 +477,7 @@ void FrontendRenderer::AcceptMessage(ref_ptr<Message> message)
|
|||
{
|
||||
m_useFramebuffer = false;
|
||||
m_3dModeChanged = true;
|
||||
AddUserEvent(Disable3dMode(false));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1154,28 +1156,19 @@ ScreenBase const & FrontendRenderer::ProcessEvents(bool & modelViewChanged, bool
|
|||
ScreenBase const & modelView = m_userEventStream.ProcessEvents(modelViewChanged, viewportChanged);
|
||||
gui::DrapeGui::Instance().SetInUserAction(m_userEventStream.IsInUserAction());
|
||||
|
||||
ScreenBase modelView2 = modelView;
|
||||
m_pixelRect = modelView.PixelRect();
|
||||
|
||||
modelViewChanged = modelViewChanged || m_3dModeChanged;
|
||||
viewportChanged = viewportChanged || m_3dModeChanged;
|
||||
if (m_useFramebuffer && modelViewChanged)
|
||||
{
|
||||
double scale = max(m_renderer3d->GetScaleX(), m_renderer3d->GetScaleY());
|
||||
|
||||
m2::RectD const & pxRect = modelView2.PixelRect();
|
||||
m2::RectI iRect(0, 0, (int)(pxRect.maxX() * scale), (int)(pxRect.maxY() * scale));
|
||||
|
||||
m2::AnyRectD const & gRect = modelView2.GlobalRect();
|
||||
double dyG = gRect.GetLocalRect().SizeY() * (scale - 1.0);
|
||||
modelView2.Scale(1.0 / scale);
|
||||
modelView2.MoveG(m2::PointD(0, -dyG / 2.0));
|
||||
|
||||
modelView2 = ScreenBase(iRect, modelView2.GlobalRect());
|
||||
}
|
||||
m_3dModeChanged = false;
|
||||
|
||||
return modelView2;
|
||||
if (m_useFramebuffer)
|
||||
{
|
||||
double scale = max(m_renderer3d->GetScaleX(), m_renderer3d->GetScaleY());
|
||||
m_pixelRect.setMaxX(pxRect.maxX() / scale);
|
||||
m_pixelRect.setMaxY(pxRect.maxY() / scale);
|
||||
}
|
||||
|
||||
return modelView;
|
||||
}
|
||||
|
||||
void FrontendRenderer::PrepareScene(ScreenBase const & modelView)
|
||||
|
|
|
@ -31,7 +31,9 @@ namespace df
|
|||
{
|
||||
|
||||
Navigator::Navigator()
|
||||
: m_InAction(false)
|
||||
: m_is3dMode(false)
|
||||
, m_scale3d(1.0)
|
||||
, m_InAction(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -510,6 +512,40 @@ bool Navigator::IsRotatingDuringScale() const
|
|||
return m_IsRotatingDuringScale;
|
||||
}
|
||||
|
||||
void Navigator::Enable3dMode(double scale)
|
||||
{
|
||||
ASSERT(!m_is3dMode, ());
|
||||
|
||||
m2::RectD const & pxRect = m_Screen.PixelRect();
|
||||
m2::RectI iRect(0, 0, (int)(pxRect.maxX() * scale + 0.5), (int)(pxRect.maxY() * scale + 0.5));
|
||||
|
||||
m2::AnyRectD const & gRect = m_Screen.GlobalRect();
|
||||
double dyG = gRect.GetLocalRect().SizeY() * (scale - 1.0);
|
||||
m_Screen.Scale(1.0 / scale);
|
||||
m_Screen.MoveG(m2::PointD(0, -dyG / 2.0));
|
||||
|
||||
m_Screen = ScreenBase(iRect, m_Screen.GlobalRect());
|
||||
m_is3dMode = true;
|
||||
m_scale3d = scale;
|
||||
}
|
||||
|
||||
void Navigator::Disable3dMode()
|
||||
{
|
||||
ASSERT(m_is3dMode, ());
|
||||
|
||||
m2::RectD const & pxRect = m_Screen.PixelRect();
|
||||
m2::RectI iRect(0, 0, (int)(pxRect.maxX() / m_scale3d + 0.5), (int)(pxRect.maxY() / m_scale3d + 0.5));
|
||||
|
||||
m2::AnyRectD const & gRect = m_Screen.GlobalRect();
|
||||
double dyG = gRect.GetLocalRect().SizeY() * (1.0 - 1.0 / m_scale3d);
|
||||
m_Screen.MoveG(m2::PointD(0, dyG / 2.0));
|
||||
m_Screen.Scale(m_scale3d);
|
||||
|
||||
|
||||
m_Screen = ScreenBase(iRect, m_Screen.GlobalRect());
|
||||
m_is3dMode = false;
|
||||
}
|
||||
|
||||
m2::AnyRectD ToRotated(Navigator const & navigator, m2::RectD const & rect)
|
||||
{
|
||||
double const dx = rect.SizeX();
|
||||
|
|
|
@ -47,6 +47,9 @@ public:
|
|||
void CalculateScale(m2::PointD const & pt, double factor, ScreenBase & screen);
|
||||
bool InAction() const;
|
||||
|
||||
void Enable3dMode(double scale);
|
||||
void Disable3dMode();
|
||||
|
||||
private:
|
||||
bool CheckMinScale(ScreenBase const & screen) const;
|
||||
bool CheckMaxScale(ScreenBase const & screen) const;
|
||||
|
@ -63,6 +66,10 @@ private:
|
|||
ScreenBase m_StartScreen;
|
||||
// Internal screen to do GtoP() and PtoG() calculations. It is always up to date with navigation.
|
||||
ScreenBase m_Screen;
|
||||
|
||||
bool m_is3dMode;
|
||||
double m_scale3d;
|
||||
|
||||
// Intial point for dragging and scaling.
|
||||
m2::PointD m_StartPt1;
|
||||
// Last point for dragging and scaling.
|
||||
|
|
|
@ -178,6 +178,12 @@ ScreenBase const & UserEventStream::ProcessEvents(bool & modelViewChange, bool &
|
|||
e.m_followAndRotate.m_isAnim);
|
||||
TouchCancel(m_touches);
|
||||
break;
|
||||
case UserEvent::EVENT_ENABLE_3D_MODE:
|
||||
Enable3dMode(e.m_enable3dMode.m_scale);
|
||||
break;
|
||||
case UserEvent::EVENT_DISABLE_3D_MODE:
|
||||
Disable3dMode();
|
||||
break;
|
||||
default:
|
||||
ASSERT(false, ());
|
||||
break;
|
||||
|
@ -351,6 +357,16 @@ bool UserEventStream::SetFollowAndRotate(m2::PointD const & userPos, m2::PointD
|
|||
return true;
|
||||
}
|
||||
|
||||
void UserEventStream::Enable3dMode(double scale)
|
||||
{
|
||||
m_navigator.Enable3dMode(scale);
|
||||
}
|
||||
|
||||
void UserEventStream::Disable3dMode()
|
||||
{
|
||||
m_navigator.Disable3dMode();
|
||||
}
|
||||
|
||||
void UserEventStream::ResetCurrentAnimation(bool finishAnimation)
|
||||
{
|
||||
if (m_animation)
|
||||
|
|
|
@ -144,6 +144,24 @@ struct FollowAndRotateEvent
|
|||
bool m_isAnim;
|
||||
};
|
||||
|
||||
struct Enable3dModeEvent
|
||||
{
|
||||
Enable3dModeEvent(double scale)
|
||||
: m_scale(scale)
|
||||
{}
|
||||
|
||||
double m_scale;
|
||||
};
|
||||
|
||||
struct Disable3dMode
|
||||
{
|
||||
Disable3dMode(bool isAnim)
|
||||
: m_isAnim(isAnim)
|
||||
{}
|
||||
|
||||
bool m_isAnim;
|
||||
};
|
||||
|
||||
struct RotateEvent
|
||||
{
|
||||
RotateEvent(double targetAzimut) : m_targetAzimut(targetAzimut) {}
|
||||
|
@ -170,7 +188,9 @@ struct UserEvent
|
|||
EVENT_SET_ANY_RECT,
|
||||
EVENT_RESIZE,
|
||||
EVENT_ROTATE,
|
||||
EVENT_FOLLOW_AND_ROTATE
|
||||
EVENT_FOLLOW_AND_ROTATE,
|
||||
EVENT_ENABLE_3D_MODE,
|
||||
EVENT_DISABLE_3D_MODE
|
||||
};
|
||||
|
||||
UserEvent(TouchEvent const & e) : m_type(EVENT_TOUCH) { m_touchEvent = e; }
|
||||
|
@ -181,6 +201,8 @@ struct UserEvent
|
|||
UserEvent(ResizeEvent const & e) : m_type(EVENT_RESIZE) { m_resize = e; }
|
||||
UserEvent(RotateEvent const & e) : m_type(EVENT_ROTATE) { m_rotate = e; }
|
||||
UserEvent(FollowAndRotateEvent const & e) : m_type(EVENT_FOLLOW_AND_ROTATE) { m_followAndRotate = e; }
|
||||
UserEvent(Enable3dModeEvent const & e) : m_type(EVENT_ENABLE_3D_MODE) { m_enable3dMode = e; }
|
||||
UserEvent(Disable3dMode const & e) : m_type(EVENT_DISABLE_3D_MODE) { m_disable3dMode = e; }
|
||||
|
||||
EEventType m_type;
|
||||
union
|
||||
|
@ -193,6 +215,8 @@ struct UserEvent
|
|||
ResizeEvent m_resize;
|
||||
RotateEvent m_rotate;
|
||||
FollowAndRotateEvent m_followAndRotate;
|
||||
Enable3dModeEvent m_enable3dMode;
|
||||
Disable3dMode m_disable3dMode;
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -262,6 +286,9 @@ private:
|
|||
bool SetFollowAndRotate(m2::PointD const & userPos, m2::PointD const & pixelPos,
|
||||
double azimuth, int preferredZoomLevel, bool isAnim);
|
||||
|
||||
void Enable3dMode(double scale);
|
||||
void Disable3dMode();
|
||||
|
||||
m2::AnyRectD GetCurrentRect() const;
|
||||
|
||||
bool ProcessTouch(TouchEvent const & touch);
|
||||
|
|
Loading…
Add table
Reference in a new issue