diff --git a/map/framework.cpp b/map/framework.cpp index a96ad52408..22bae3b7da 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -186,6 +186,11 @@ CountryStatusDisplay * Framework::GetCountryStatusDisplay() const return m_informationDisplay.countryStatusDisplay().get(); } +void Framework::SetWidgetPivot(InformationDisplay::WidgetType widget, m2::PointD const & pivot) +{ + m_informationDisplay.SetWidgetPivot(widget, pivot); +} + void Framework::GetMaps(vector & maps) const { Platform & pl = GetPlatform(); @@ -783,7 +788,7 @@ void Framework::OnSize(int w, int h) // if gui controller not initialized, than we work in mode "Without gui" // and no need to set gui layout. We will not render it. if (m_guiController->GetCacheScreen()) - m_informationDisplay.setDisplayRect(m2::RectI(0, 0, w, h)); + m_informationDisplay.SetWidgetPivotsByDefault(w, h); m_renderPolicy->OnSize(w, h); } #else diff --git a/map/framework.hpp b/map/framework.hpp index 6a907d8c7b..52634ff86b 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -283,6 +283,22 @@ public: CountryStatusDisplay * GetCountryStatusDisplay() const; ScalesProcessor & GetScalesProcessor() { return m_scales; } + /*! + * \brief SetWidgetPivot() places widgets on the screen. + * \param widget is a widget ID. + * \param pivot is a pivot point of a widget in framebuffer coordinates. + * That means pivot points are measured in pixels. + * \note The default pivot points of the widgets on the map are set by + * InformationDisplay::SetWidgetPivotsByDefault() method. If you decide + * to change the default behavior by calling the method + * you should take into account that SetWidgetPivot() shall be called: + * - on the start of the program; + * - when the screen orientation is changed; + * - when the screen size is changed; + * A caller of Framework::OnSize() is a good place for it. + */ + void SetWidgetPivot(InformationDisplay::WidgetType widget, m2::PointD const & pivot); + /// Safe function to get current visual scale. /// Call it when you need do calculate pixel rect (not matter if m_renderPolicy == 0). /// @return 1.0 if m_renderPolicy == 0 (possible for Android). diff --git a/map/information_display.cpp b/map/information_display.cpp index 845c76086c..714400cb89 100644 --- a/map/information_display.cpp +++ b/map/information_display.cpp @@ -157,12 +157,14 @@ void InformationDisplay::setController(gui::Controller * controller) m_framework->GetAnimController()->AddTask(task); } -void InformationDisplay::setDisplayRect(m2::RectI const & rect) +void InformationDisplay::SetWidgetPivotsByDefault(int screenWidth, int screenHeight) { double rulerOffsX = RULLER_X_OFFSET; double rulerOffsY = RULLER_Y_OFFSET; double compassOffsX = COMPASS_X_OFFSET; double compassOffsY = COMPASS_Y_OFFSET; + m2::RectI const rect = m2::RectI(0, 0, screenWidth, screenHeight); + #ifdef OMIM_OS_ANDROID if (GetPlatform().IsTablet()) { @@ -282,3 +284,33 @@ void InformationDisplay::ResetRouteMatchingInfo() { m_locationState->ResetRouteMatchingInfo(); } + +void InformationDisplay::SetWidgetPivot(WidgetType widget, m2::PointD const & pivot) +{ + ASSERT(m_ruler, ()); + switch(widget) + { + case WidgetType::Ruler: + if (m_ruler) + m_ruler->setPivot(pivot); + return; + case WidgetType::CopyrightLabel: + if (m_copyrightLabel) + m_copyrightLabel->setPivot(pivot); + return; + case WidgetType::CountryStatusDisplay: + if (m_countryStatusDisplay) + m_countryStatusDisplay->setPivot(pivot); + return; + case WidgetType::CompassArrow: + if (m_compassArrow) + m_compassArrow->setPivot(pivot); + return; + case WidgetType::DebugLable: + if (m_debugLabel) + m_debugLabel->setPivot(pivot); + return; + default: + ASSERT(false, ()); + } +} diff --git a/map/information_display.hpp b/map/information_display.hpp index 9b695f87b3..273cebaa6e 100644 --- a/map/information_display.hpp +++ b/map/information_display.hpp @@ -58,12 +58,23 @@ class InformationDisplay void InitCopyright(Framework * fw); public: + enum class WidgetType { + Ruler = 0, + CopyrightLabel, + CountryStatusDisplay, + CompassArrow, + DebugLable + }; InformationDisplay(Framework * framework); void setController(gui::Controller * controller); - - void setDisplayRect(m2::RectI const & rect); + /*! + * \brief SetWidgetPivotsByDefault sets the default pivot points for all the widgets on the map. + * The pivot points can be overridden by a call of SetWidgetPivot() + * after Framework::OnSize() call. + */ + void SetWidgetPivotsByDefault(int screenWidth, int screenHeight); void setVisualScale(double visualScale); bool isCopyrightActive() const; @@ -88,4 +99,6 @@ public: shared_ptr const & countryStatusDisplay() const; void ResetRouteMatchingInfo(); + + void SetWidgetPivot(WidgetType widget, m2::PointD const & pivot); };