diff --git a/drape_frontend/color_constants.cpp b/drape_frontend/color_constants.cpp index 97fd648e0d..070670cc13 100644 --- a/drape_frontend/color_constants.cpp +++ b/drape_frontend/color_constants.cpp @@ -26,6 +26,8 @@ unordered_map> kColorConstants = { TrackCarSpeed, dp::Color(21, 121, 244, 255) }, { TrackPlaneSpeed, dp::Color(10, 196, 255, 255) }, { TrackUnknownDistance, dp::Color(97, 97, 97, 255) }, + { DownloadCancelButton, dp::Color(0, 0, 0, 112) }, + { DownloadCancelButtonPressed, dp::Color(0, 0, 0, 184) }, } }, { MapStyleDark, @@ -44,6 +46,8 @@ unordered_map> kColorConstants = { TrackCarSpeed, dp::Color(255, 202, 40, 255) }, { TrackPlaneSpeed, dp::Color(255, 245, 160, 255) }, { TrackUnknownDistance, dp::Color(150, 150, 150, 255) }, + { DownloadCancelButton, dp::Color(255, 255, 255, 178) }, + { DownloadCancelButtonPressed, dp::Color(255, 255, 255, 77) }, } }, }; diff --git a/drape_frontend/color_constants.hpp b/drape_frontend/color_constants.hpp index 4f6e8d45a8..d2bfe7043b 100644 --- a/drape_frontend/color_constants.hpp +++ b/drape_frontend/color_constants.hpp @@ -22,7 +22,9 @@ enum ColorConstant TrackHumanSpeed, TrackCarSpeed, TrackPlaneSpeed, - TrackUnknownDistance + TrackUnknownDistance, + DownloadCancelButton, + DownloadCancelButtonPressed }; dp::Color GetColorConstant(MapStyle style, ColorConstant constant); diff --git a/drape_frontend/drape_engine.cpp b/drape_frontend/drape_engine.cpp index f1b7befd93..c305b20a9e 100644 --- a/drape_frontend/drape_engine.cpp +++ b/drape_frontend/drape_engine.cpp @@ -45,6 +45,7 @@ DrapeEngine::DrapeEngine(Params && params) ConnectDownloadFn(gui::CountryStatusHelper::BUTTON_TYPE_MAP, params.m_model.GetDownloadMapHandler()); ConnectDownloadFn(gui::CountryStatusHelper::BUTTON_TRY_AGAIN, params.m_model.GetDownloadRetryHandler()); + ConnectDownloadFn(gui::CountryStatusHelper::BUTTON_CANCEL, params.m_model.GetDownloadCancelHandler()); m_textureManager = make_unique_dp(); m_threadCommutator = make_unique_dp(); diff --git a/drape_frontend/gui/button.cpp b/drape_frontend/gui/button.cpp index 4584d118c3..9490dc6747 100644 --- a/drape_frontend/gui/button.cpp +++ b/drape_frontend/gui/button.cpp @@ -70,9 +70,9 @@ uint32_t BuildCorner(vector & vertices, } -ButtonHandle::ButtonHandle(dp::Anchor anchor, m2::PointF const & size, +ButtonHandle::ButtonHandle(uint32_t id, dp::Anchor anchor, m2::PointF const & size, dp::Color const & color, dp::Color const & pressedColor) - : TBase(anchor, m2::PointF::Zero(), size) + : TBase(id, anchor, m2::PointF::Zero(), size) , m_isInPressedState(false) , m_color(color) , m_pressedColor(pressedColor) diff --git a/drape_frontend/gui/button.hpp b/drape_frontend/gui/button.hpp index 087cc676dd..bf9d90e4ef 100644 --- a/drape_frontend/gui/button.hpp +++ b/drape_frontend/gui/button.hpp @@ -14,7 +14,7 @@ class ButtonHandle : public TappableHandle typedef TappableHandle TBase; public: - ButtonHandle(dp::Anchor anchor, m2::PointF const & size, + ButtonHandle(uint32_t id, dp::Anchor anchor, m2::PointF const & size, dp::Color const & color, dp::Color const & pressedColor); void OnTapBegin() override; diff --git a/drape_frontend/gui/compass.cpp b/drape_frontend/gui/compass.cpp index 4b29591119..8accaae6ee 100644 --- a/drape_frontend/gui/compass.cpp +++ b/drape_frontend/gui/compass.cpp @@ -33,8 +33,9 @@ namespace double const VisibleEndAngle = my::DegToRad(355.0); public: - CompassHandle(m2::PointF const & pivot, m2::PointF const & size, Shape::TTapHandler const & tapHandler) - : TappableHandle(dp::Center, pivot, size) + CompassHandle(uint32_t id, m2::PointF const & pivot, m2::PointF const & size, + Shape::TTapHandler const & tapHandler) + : TappableHandle(id, dp::Center, pivot, size) , m_tapHandler(tapHandler) , m_animation(false, 0.25) { @@ -126,7 +127,9 @@ drape_ptr Compass::Draw(m2::PointF & compassSize, ref_ptr handle = make_unique_dp(m_position.m_pixelPivot, compassSize, tapHandler); + drape_ptr handle = make_unique_dp(EGuiHandle::GuiHandleCompass, + m_position.m_pixelPivot, + compassSize, tapHandler); drape_ptr renderer = make_unique_dp(); dp::Batcher batcher(dp::Batcher::IndexPerQuad, dp::Batcher::VertexPerQuad); diff --git a/drape_frontend/gui/copyright_label.cpp b/drape_frontend/gui/copyright_label.cpp index 81d405c706..1f768080b4 100644 --- a/drape_frontend/gui/copyright_label.cpp +++ b/drape_frontend/gui/copyright_label.cpp @@ -23,10 +23,10 @@ namespace using TBase = StaticLabelHandle; public: - CopyrightHandle(ref_ptr textureManager, + CopyrightHandle(uint32_t id, ref_ptr textureManager, dp::Anchor anchor, m2::PointF const & pivot, m2::PointF const & size, TAlphabet const & alphabet) - : TBase(textureManager, anchor, pivot, size, alphabet) + : TBase(id, textureManager, anchor, pivot, size, alphabet) { SetIsVisible(true); } @@ -77,7 +77,8 @@ drape_ptr CopyrightLabel::Draw(m2::PointF & size, ref_ptr handle = make_unique_dp(tex, m_position.m_anchor, + drape_ptr handle = make_unique_dp(EGuiHandle::GuiHandleCopyright, + tex, m_position.m_anchor, m_position.m_pixelPivot, size, result.m_alphabet); diff --git a/drape_frontend/gui/country_status.cpp b/drape_frontend/gui/country_status.cpp index cc11b1133b..06f8aed055 100644 --- a/drape_frontend/gui/country_status.cpp +++ b/drape_frontend/gui/country_status.cpp @@ -24,11 +24,11 @@ class CountryStatusButtonHandle : public ButtonHandle using TBase = ButtonHandle; public: - CountryStatusButtonHandle(CountryStatusHelper::ECountryState const state, + CountryStatusButtonHandle(uint32_t id, CountryStatusHelper::ECountryState const state, Shape::TTapHandler const & tapHandler, dp::Anchor anchor, m2::PointF const & size, dp::Color const & color, dp::Color const & pressedColor) - : TBase(anchor, size, color, pressedColor) + : TBase(id, anchor, size, color, pressedColor) , m_state(state) , m_tapHandler(tapHandler) {} @@ -55,11 +55,11 @@ class CountryStatusLabelHandle : public StaticLabelHandle using TBase = StaticLabelHandle; public: - CountryStatusLabelHandle(CountryStatusHelper::ECountryState const state, + CountryStatusLabelHandle(uint32_t id, CountryStatusHelper::ECountryState const state, ref_ptr textureManager, dp::Anchor anchor, m2::PointF const & size, TAlphabet const & alphabet) - : TBase(textureManager, anchor, m2::PointF::Zero(), size, alphabet) + : TBase(id, textureManager, anchor, m2::PointF::Zero(), size, alphabet) , m_state(state) {} @@ -78,9 +78,10 @@ class CountryProgressHandle : public MutableLabelHandle using TBase = MutableLabelHandle; public: - CountryProgressHandle(dp::Anchor anchor, CountryStatusHelper::ECountryState const state, + CountryProgressHandle(uint32_t id, dp::Anchor anchor, + CountryStatusHelper::ECountryState const state, ref_ptr textures) - : TBase(anchor, m2::PointF::Zero(), textures), m_state(state) + : TBase(id, anchor, m2::PointF::Zero(), textures), m_state(state) {} bool Update(ScreenBase const & screen) override @@ -97,20 +98,27 @@ private: CountryStatusHelper::ECountryState m_state; }; -drape_ptr CreateButtonHandle(CountryStatusHelper::ECountryState const state, +struct ButtonData +{ + Button::Params m_params; + StaticLabel::LabelResult m_label; + CountryStatusHelper::EButtonType m_type; +}; + +drape_ptr CreateButtonHandle(uint32_t id, CountryStatusHelper::ECountryState const state, Shape::TTapHandler const & tapHandler, dp::Color const & color, dp::Color const & pressedColor, dp::Anchor anchor, m2::PointF const & size) { - return make_unique_dp(state, tapHandler, anchor, size, color, pressedColor); + return make_unique_dp(id, state, tapHandler, anchor, size, color, pressedColor); } -drape_ptr CreateLabelHandle(CountryStatusHelper::ECountryState const state, +drape_ptr CreateLabelHandle(uint32_t id, CountryStatusHelper::ECountryState const state, ref_ptr textureManager, dp::Anchor anchor, m2::PointF const & size, TAlphabet const & alphabet) { - return make_unique_dp(state, textureManager, anchor, size, alphabet); + return make_unique_dp(id, state, textureManager, anchor, size, alphabet); } void DrawLabelControl(string const & text, dp::Anchor anchor, dp::Batcher::TFlushFn const & flushFn, @@ -130,7 +138,8 @@ void DrawLabelControl(string const & text, dp::Anchor anchor, dp::Batcher::TFlus dp::Batcher batcher(indexCount, vertexCount); dp::SessionGuard guard(batcher, flushFn); m2::PointF size(result.m_boundRect.SizeX(), result.m_boundRect.SizeY()); - drape_ptr handle = make_unique_dp(state, mng, anchor, size, result.m_alphabet); + drape_ptr handle = make_unique_dp(EGuiHandle::GuiHandleCountryLabel, + state, mng, anchor, size, result.m_alphabet); batcher.InsertListOfStrip(result.m_state, make_ref(&provider), move(handle), dp::Batcher::VertexPerQuad); } @@ -148,7 +157,7 @@ void DrawProgressControl(dp::Anchor anchor, dp::Batcher::TFlushFn const & flushF params.m_font = dp::FontDecl(textColor, 18); params.m_handleCreator = [state, mng](dp::Anchor anchor, m2::PointF const & /*pivot*/) { - return make_unique_dp(anchor, state, mng); + return make_unique_dp(EGuiHandle::GuiHandleCountryProgress, anchor, state, mng); }; MutableLabelDrawer::Draw(params, mng, flushFn); @@ -198,10 +207,10 @@ drape_ptr CountryStatus::Draw(ref_ptr tex, }); // Preprocess buttons. - vector> buttons; + vector buttons; float const kMinButtonWidth = 400; float maxButtonWidth = kMinButtonWidth; - buttons.reserve(2); + buttons.reserve(3); ForEachComponent(helper, CountryStatusHelper::CONTROL_TYPE_BUTTON, [this, &buttons, &state, &tex, &buttonHandlers, &maxButtonWidth](CountryStatusHelper::Control const & control) @@ -219,25 +228,60 @@ drape_ptr CountryStatus::Draw(ref_ptr tex, MapStyle const style = GetStyleReader().GetCurrentStyle(); auto color = df::GetColorConstant(style, df::DownloadButton); auto pressedColor = df::GetColorConstant(style, df::DownloadButtonPressed); + if (control.m_buttonType == CountryStatusHelper::BUTTON_CANCEL) + { + color = df::GetColorConstant(style, df::DownloadCancelButton); + pressedColor = df::GetColorConstant(style, df::DownloadCancelButtonPressed); + } + + uint32_t buttonHandleId = 0; + uint32_t buttonLabelHandleId = 0; + if (control.m_buttonType == CountryStatusHelper::BUTTON_TYPE_MAP) + { + buttonHandleId = EGuiHandle::GuiHandleDownloadButton; + buttonLabelHandleId = EGuiHandle::GuiHandleDownloadButtonLabel; + } + else if (control.m_buttonType == CountryStatusHelper::BUTTON_TRY_AGAIN) + { + buttonHandleId = EGuiHandle::GuiHandleRetryButton; + buttonLabelHandleId = EGuiHandle::GuiHandleRetryButtonLabel; + } + else if (control.m_buttonType == CountryStatusHelper::BUTTON_CANCEL) + { + buttonHandleId = EGuiHandle::GuiHandleCancelButton; + buttonLabelHandleId = EGuiHandle::GuiHandleCancelButtonLabel; + } + else + { + ASSERT(false, ("Unknown button")); + } + auto const buttonHandlerIt = buttonHandlers.find(control.m_buttonType); Shape::TTapHandler buttonHandler = (buttonHandlerIt != buttonHandlers.end() ? buttonHandlerIt->second : nullptr); - params.m_bodyHandleCreator = bind(&CreateButtonHandle, state, buttonHandler, color, pressedColor, _1, _2); - params.m_labelHandleCreator = bind(&CreateLabelHandle, state, tex, _1, _2, _3); + params.m_bodyHandleCreator = bind(&CreateButtonHandle, buttonHandleId, state, buttonHandler, color, pressedColor, _1, _2); + params.m_labelHandleCreator = bind(&CreateLabelHandle, buttonLabelHandleId, state, tex, _1, _2, _3); auto label = Button::PreprocessLabel(params, tex); float const buttonWidth = label.m_boundRect.SizeX(); if (buttonWidth > maxButtonWidth) maxButtonWidth = buttonWidth; - buttons.emplace_back(make_pair(move(params), move(label))); + ButtonData data; + data.m_params = move(params); + data.m_label = move(label); + data.m_type = control.m_buttonType; + buttons.emplace_back(move(data)); }); // Create buttons. for (size_t i = 0; i < buttons.size(); i++) { - buttons[i].first.m_width = maxButtonWidth; + if (buttons[i].m_type == CountryStatusHelper::BUTTON_CANCEL) + continue; + + buttons[i].m_params.m_width = maxButtonWidth; ShapeControl shapeControl; - Button::Draw(buttons[i].first, shapeControl, buttons[i].second); + Button::Draw(buttons[i].m_params, shapeControl, buttons[i].m_label); renderer->AddShapeControl(move(shapeControl)); } @@ -248,6 +292,19 @@ drape_ptr CountryStatus::Draw(ref_ptr tex, DrawProgressControl(m_position.m_anchor, flushFn, tex, state); }); + // Create cancel buttons. + for (size_t i = 0; i < buttons.size(); i++) + { + if (buttons[i].m_type == CountryStatusHelper::BUTTON_CANCEL) + { + buttons[i].m_params.m_width = maxButtonWidth; + ShapeControl shapeControl; + Button::Draw(buttons[i].m_params, shapeControl, buttons[i].m_label); + renderer->AddShapeControl(move(shapeControl)); + break; + } + } + buffer_vector heights; float totalHeight = 0.0f; diff --git a/drape_frontend/gui/country_status_helper.cpp b/drape_frontend/gui/country_status_helper.cpp index f2a20c4b79..d326d694a6 100644 --- a/drape_frontend/gui/country_status_helper.cpp +++ b/drape_frontend/gui/country_status_helper.cpp @@ -56,6 +56,7 @@ void FormatMapSize(uint64_t sizeInBytes, string & units, size_t & sizeToDownload char const * DownloadMapButtonID = "country_status_download"; char const * TryAgainButtonID = "try_again"; +char const * DownloadCancelButtonID = "country_download_cancel"; char const * DownloadingLabelID = "country_status_downloading"; char const * DownloadingFailedID = "country_status_download_failed"; char const * InQueueID = "country_status_added_to_queue"; @@ -202,6 +203,8 @@ void CountryStatusHelper::FillControlsForLoading() strings::Trim(secondLabel , "\n "); m_controls.push_back(MakeLabel(secondLabel)); } + + m_controls.push_back(MakeButton(FormatCancel(), BUTTON_CANCEL)); } void CountryStatusHelper::FillControlsForInQueue() @@ -240,4 +243,10 @@ string CountryStatusHelper::FormatTryAgain() return GetLocalizedString(TryAgainButtonID); } +string CountryStatusHelper::FormatCancel() +{ + //TODO: Uncomment after adding localization for country_download_cancel + return "Cancel";//GetLocalizedString(DownloadCancelButtonID); +} + } // namespace gui diff --git a/drape_frontend/gui/country_status_helper.hpp b/drape_frontend/gui/country_status_helper.hpp index cad9ee38e3..0a755851bc 100644 --- a/drape_frontend/gui/country_status_helper.hpp +++ b/drape_frontend/gui/country_status_helper.hpp @@ -45,7 +45,8 @@ public: { BUTTON_TYPE_NOT_BUTTON, BUTTON_TYPE_MAP, - BUTTON_TRY_AGAIN + BUTTON_TRY_AGAIN, + BUTTON_CANCEL }; struct Control @@ -86,6 +87,7 @@ private: string FormatInQueueMap(); string FormatFailed(); string FormatTryAgain(); + string FormatCancel(); void SetState(ECountryState state); diff --git a/drape_frontend/gui/gui_text.cpp b/drape_frontend/gui/gui_text.cpp index b6eebf9781..c876b0b14b 100644 --- a/drape_frontend/gui/gui_text.cpp +++ b/drape_frontend/gui/gui_text.cpp @@ -439,16 +439,16 @@ m2::PointF MutableLabel::GetAvarageSize() const return m2::PointF(w, h); } -MutableLabelHandle::MutableLabelHandle(dp::Anchor anchor, m2::PointF const & pivot) - : TBase(anchor, pivot, m2::PointF::Zero()) +MutableLabelHandle::MutableLabelHandle(uint32_t id, dp::Anchor anchor, m2::PointF const & pivot) + : TBase(id, anchor, pivot, m2::PointF::Zero()) , m_textView(make_unique_dp(anchor)) , m_isContentDirty(true) , m_glyphsReady(false) {} -MutableLabelHandle::MutableLabelHandle(dp::Anchor anchor, m2::PointF const & pivot, +MutableLabelHandle::MutableLabelHandle(uint32_t id, dp::Anchor anchor, m2::PointF const & pivot, ref_ptr textures) - : TBase(anchor, pivot, m2::PointF::Zero()) + : TBase(id, anchor, pivot, m2::PointF::Zero()) , m_textView(make_unique_dp(anchor)) , m_isContentDirty(true) , m_textureManager(textures) @@ -570,11 +570,11 @@ m2::PointF MutableLabelDrawer::Draw(Params const & params, ref_ptr textureManager, +StaticLabelHandle::StaticLabelHandle(uint32_t id, ref_ptr textureManager, dp::Anchor anchor, m2::PointF const & pivot, m2::PointF const & size, TAlphabet const & alphabet) - : TBase(anchor, pivot, size) + : TBase(id, anchor, pivot, size) , m_alphabet(alphabet.begin(), alphabet.end()) , m_textureManager(textureManager) , m_glyphsReady(false) diff --git a/drape_frontend/gui/gui_text.hpp b/drape_frontend/gui/gui_text.hpp index 55e1d94973..92fc5318d3 100644 --- a/drape_frontend/gui/gui_text.hpp +++ b/drape_frontend/gui/gui_text.hpp @@ -145,9 +145,9 @@ class MutableLabelHandle : public Handle using TBase = Handle; public: - MutableLabelHandle(dp::Anchor anchor, m2::PointF const & pivot); + MutableLabelHandle(uint32_t id, dp::Anchor anchor, m2::PointF const & pivot); - MutableLabelHandle(dp::Anchor anchor, m2::PointF const & pivot, + MutableLabelHandle(uint32_t id, dp::Anchor anchor, m2::PointF const & pivot, ref_ptr textures); void GetAttributeMutation(ref_ptr mutator, @@ -197,7 +197,7 @@ class StaticLabelHandle : public Handle using TBase = Handle; public: - StaticLabelHandle(ref_ptr textureManager, + StaticLabelHandle(uint32_t id, ref_ptr textureManager, dp::Anchor anchor, m2::PointF const & pivot, m2::PointF const & size, TAlphabet const & alphabet); diff --git a/drape_frontend/gui/layer_render.cpp b/drape_frontend/gui/layer_render.cpp index a8b41ae455..3caebb911e 100644 --- a/drape_frontend/gui/layer_render.cpp +++ b/drape_frontend/gui/layer_render.cpp @@ -40,16 +40,21 @@ void LayerRenderer::Render(ref_ptr mng, ScreenBase const void LayerRenderer::Merge(ref_ptr other) { + bool activeOverlayFound = false; for (TRenderers::value_type & r : other->m_renderers) { TRenderers::iterator it = m_renderers.find(r.first); if (it != m_renderers.end()) { + auto newActiveOverlay = r.second->FindHandle(m_activeOverlayId); + bool const updateActive = (m_activeOverlay != nullptr && newActiveOverlay != nullptr); it->second = move(r.second); - if (m_activeOverlay != nullptr && m_activeOverlayWidget == r.first) + if (!activeOverlayFound && updateActive) { - m_activeOverlay->OnTapEnd(); - m_activeOverlay = nullptr; + activeOverlayFound = true; + m_activeOverlay = newActiveOverlay; + if (m_activeOverlay != nullptr) + m_activeOverlay->OnTapBegin(); } } else @@ -58,6 +63,9 @@ void LayerRenderer::Merge(ref_ptr other) } } + if (!activeOverlayFound) + m_activeOverlay = nullptr; + other->m_renderers.clear(); } @@ -91,7 +99,7 @@ bool LayerRenderer::OnTouchDown(m2::RectD const & touchArea) m_activeOverlay = r.second->ProcessTapEvent(touchArea); if (m_activeOverlay != nullptr) { - m_activeOverlayWidget = r.first; + m_activeOverlayId = m_activeOverlay->GetFeatureID(); m_activeOverlay->OnTapBegin(); return true; } @@ -109,6 +117,7 @@ void LayerRenderer::OnTouchUp(m2::RectD const & touchArea) m_activeOverlay->OnTapEnd(); m_activeOverlay = nullptr; + m_activeOverlayId = FeatureID(); } } @@ -119,6 +128,7 @@ void LayerRenderer::OnTouchCancel(m2::RectD const & touchArea) { m_activeOverlay->OnTapEnd(); m_activeOverlay = nullptr; + m_activeOverlayId = FeatureID(); } } @@ -129,8 +139,8 @@ class ScaleLabelHandle : public MutableLabelHandle { using TBase = MutableLabelHandle; public: - ScaleLabelHandle(ref_ptr textures) - : TBase(dp::LeftBottom, m2::PointF::Zero(), textures) + ScaleLabelHandle(uint32_t id, ref_ptr textures) + : TBase(id, dp::LeftBottom, m2::PointF::Zero(), textures) , m_scale(0) { SetIsVisible(true); @@ -201,6 +211,7 @@ drape_ptr LayerCacher::RecacheCountryStatus(ref_ptrAddShapeRenderer(WIDGET_COUNTRY_STATUS, countryStatus.Draw(textures, handlers)); @@ -252,7 +263,7 @@ m2::PointF LayerCacher::CacheScaleLabel(Position const & position, ref_ptr(textures); + return make_unique_dp(EGuiHandle::GuiHandleScaleLabel, textures); }; drape_ptr scaleRenderer = make_unique_dp(); diff --git a/drape_frontend/gui/layer_render.hpp b/drape_frontend/gui/layer_render.hpp index 7d27dbb600..4126f77c2a 100644 --- a/drape_frontend/gui/layer_render.hpp +++ b/drape_frontend/gui/layer_render.hpp @@ -46,7 +46,7 @@ private: TRenderers m_renderers; ref_ptr m_activeOverlay; - EWidget m_activeOverlayWidget = EWidget::WIDGET_RULER; + FeatureID m_activeOverlayId; }; class LayerCacher diff --git a/drape_frontend/gui/ruler.cpp b/drape_frontend/gui/ruler.cpp index bd16d3fefd..541ccb8733 100644 --- a/drape_frontend/gui/ruler.cpp +++ b/drape_frontend/gui/ruler.cpp @@ -47,8 +47,8 @@ template class BaseRulerHandle : public TBase { public: - BaseRulerHandle(dp::Anchor anchor, m2::PointF const & pivot, bool isAppearing) - : TBase(anchor, pivot) + BaseRulerHandle(uint32_t id, dp::Anchor anchor, m2::PointF const & pivot, bool isAppearing) + : TBase(id, anchor, pivot) , m_isAppearing(isAppearing) , m_isVisibleAtEnd(true) , m_animation(false, 0.4) @@ -110,8 +110,8 @@ class RulerHandle : public BaseRulerHandle using TBase = BaseRulerHandle; public: - RulerHandle(dp::Anchor anchor, m2::PointF const & pivot, bool appearing) - : TBase(anchor, pivot, appearing) + RulerHandle(uint32_t id, dp::Anchor anchor, m2::PointF const & pivot, bool appearing) + : TBase(id, anchor, pivot, appearing) {} private: @@ -133,9 +133,9 @@ class RulerTextHandle : public BaseRulerHandle using TBase = BaseRulerHandle; public: - RulerTextHandle(dp::Anchor anchor, m2::PointF const & pivot, bool isAppearing, - ref_ptr textures) - : TBase(anchor, pivot, isAppearing) + RulerTextHandle(uint32_t id, dp::Anchor anchor, m2::PointF const & pivot, + bool isAppearing, ref_ptr textures) + : TBase(id, anchor, pivot, isAppearing) , m_firstUpdate(true) { SetTextureManager(textures); @@ -224,7 +224,8 @@ void Ruler::DrawRuler(m2::PointF & size, ShapeControl & control, ref_ptr(m_position.m_anchor, m_position.m_pixelPivot, isAppearing)); + make_unique_dp(EGuiHandle::GuiHandleRuler, m_position.m_anchor, + m_position.m_pixelPivot, isAppearing)); } } @@ -244,7 +245,7 @@ void Ruler::DrawText(m2::PointF & size, ShapeControl & control, ref_ptr(anchor, pivot, isAppearing, tex); + return make_unique_dp(EGuiHandle::GuiHandleRulerLabel, anchor, pivot, isAppearing, tex); }; m2::PointF textSize = MutableLabelDrawer::Draw(params, tex, bind(&ShapeControl::AddShape, &control, _1, _2)); diff --git a/drape_frontend/gui/shape.cpp b/drape_frontend/gui/shape.cpp index cd0f28bdce..610bf4c73c 100644 --- a/drape_frontend/gui/shape.cpp +++ b/drape_frontend/gui/shape.cpp @@ -9,8 +9,9 @@ namespace gui { -Handle::Handle(dp::Anchor anchor, const m2::PointF & pivot, const m2::PointF & size) - : dp::OverlayHandle(FeatureID(), anchor, 0, false) + +Handle::Handle(uint32_t id, dp::Anchor anchor, const m2::PointF & pivot, const m2::PointF & size) + : dp::OverlayHandle(FeatureID(MwmSet::MwmId(), id), anchor, 0, false) , m_pivot(glsl::ToVec2(pivot)), m_size(size) { } @@ -168,6 +169,18 @@ ref_ptr ShapeRenderer::ProcessTapEvent(m2::RectD const & touchArea) return resultHandle; } +ref_ptr ShapeRenderer::FindHandle(FeatureID const & id) +{ + ref_ptr resultHandle = nullptr; + ForEachShapeInfo([&resultHandle, &id](ShapeControl::ShapeInfo & shapeInfo) + { + if (shapeInfo.m_handle->GetFeatureID() == id) + resultHandle = make_ref(shapeInfo.m_handle); + }); + + return resultHandle; +} + ShapeControl::ShapeInfo::ShapeInfo(dp::GLState const & state, drape_ptr && buffer, drape_ptr && handle) diff --git a/drape_frontend/gui/shape.hpp b/drape_frontend/gui/shape.hpp index 98d5f517f6..2b32f0ede7 100644 --- a/drape_frontend/gui/shape.hpp +++ b/drape_frontend/gui/shape.hpp @@ -16,7 +16,7 @@ namespace gui class Handle : public dp::OverlayHandle { public: - Handle(dp::Anchor anchor, m2::PointF const & pivot, m2::PointF const & size = m2::PointF::Zero()); + Handle(uint32_t id, dp::Anchor anchor, m2::PointF const & pivot, m2::PointF const & size = m2::PointF::Zero()); dp::UniformValuesStorage const & GetUniforms() const { return m_uniforms; } @@ -43,8 +43,8 @@ protected: class TappableHandle : public Handle { public: - TappableHandle(dp::Anchor anchor, m2::PointF const & pivot, m2::PointF const & size) - : Handle(anchor, pivot, size) + TappableHandle(uint32_t id, dp::Anchor anchor, m2::PointF const & pivot, m2::PointF const & size) + : Handle(id, anchor, pivot, size) {} bool IsTapped(m2::RectD const & touchArea) const override; @@ -92,6 +92,7 @@ public: void SetPivot(m2::PointF const & pivot); ref_ptr ProcessTapEvent(m2::RectD const & touchArea); + ref_ptr FindHandle(FeatureID const & id); private: friend void ArrangeShapes(ref_ptr, diff --git a/drape_frontend/gui/skin.hpp b/drape_frontend/gui/skin.hpp index d49a369858..b756863c95 100644 --- a/drape_frontend/gui/skin.hpp +++ b/drape_frontend/gui/skin.hpp @@ -19,6 +19,23 @@ enum EWidget WIDGET_COUNTRY_STATUS = 0x8000 }; +enum EGuiHandle +{ + GuiHandleScaleLabel, + GuiHandleCopyright, + GuiHandleCompass, + GuiHandleRuler, + GuiHandleRulerLabel, + GuiHandleCountryLabel, + GuiHandleCountryProgress, + GuiHandleDownloadButton, + GuiHandleDownloadButtonLabel, + GuiHandleRetryButton, + GuiHandleRetryButtonLabel, + GuiHandleCancelButton, + GuiHandleCancelButtonLabel +}; + struct Position { Position() : m_pixelPivot(m2::PointF::Zero()), m_anchor(dp::Center) {} diff --git a/drape_frontend/map_data_provider.cpp b/drape_frontend/map_data_provider.cpp index efce03a4ba..96ad0344a4 100644 --- a/drape_frontend/map_data_provider.cpp +++ b/drape_frontend/map_data_provider.cpp @@ -9,13 +9,15 @@ MapDataProvider::MapDataProvider(TReadIDsFn const & idsReader, TIsCountryLoadedFn const & isCountryLoadedFn, TIsCountryLoadedByNameFn const & isCountryLoadedByNameFn, TDownloadFn const & downloadMapHandler, - TDownloadFn const & downloadRetryHandler) + TDownloadFn const & downloadRetryHandler, + TDownloadFn const & downloadCancelHandler) : m_featureReader(featureReader) , m_idsReader(idsReader) , m_countryIndexUpdater(countryIndexUpdater) , m_isCountryLoadedFn(isCountryLoadedFn) , m_downloadMapHandler(downloadMapHandler) , m_downloadRetryHandler(downloadRetryHandler) + , m_downloadCancelHandler(downloadCancelHandler) , m_isCountryLoadedByNameFn(isCountryLoadedByNameFn) { } @@ -50,4 +52,9 @@ MapDataProvider::TDownloadFn const & MapDataProvider::GetDownloadRetryHandler() return m_downloadRetryHandler; } +MapDataProvider::TDownloadFn const & MapDataProvider::GetDownloadCancelHandler() const +{ + return m_downloadCancelHandler; +} + } diff --git a/drape_frontend/map_data_provider.hpp b/drape_frontend/map_data_provider.hpp index 043638f7e1..50beb6bca9 100644 --- a/drape_frontend/map_data_provider.hpp +++ b/drape_frontend/map_data_provider.hpp @@ -28,7 +28,8 @@ public: TIsCountryLoadedFn const & isCountryLoadedFn, TIsCountryLoadedByNameFn const & isCountryLoadedByNameFn, TDownloadFn const & downloadMapHandler, - TDownloadFn const & downloadRetryHandler); + TDownloadFn const & downloadRetryHandler, + TDownloadFn const & downloadCancelHandler); void ReadFeaturesID(TReadCallback const & fn, m2::RectD const & r, int scale) const; void ReadFeatures(TReadCallback const & fn, vector const & ids) const; @@ -38,6 +39,7 @@ public: TDownloadFn const & GetDownloadMapHandler() const; TDownloadFn const & GetDownloadRetryHandler() const; + TDownloadFn const & GetDownloadCancelHandler() const; private: TReadFeaturesFn m_featureReader; @@ -46,6 +48,7 @@ private: TIsCountryLoadedFn m_isCountryLoadedFn; TDownloadFn m_downloadMapHandler; TDownloadFn m_downloadRetryHandler; + TDownloadFn m_downloadCancelHandler; public: TIsCountryLoadedByNameFn m_isCountryLoadedByNameFn; diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm index f6bcd6ea76..5864b349a1 100644 --- a/iphone/Maps/Classes/MapViewController.mm +++ b/iphone/Maps/Classes/MapViewController.mm @@ -588,6 +588,19 @@ NSString * const kAuthorizationSegue = @"Map2AuthorizationSegue"; } }); + f.SetDownloadCancelListener([self, &f](storage::TIndex const & idx) + { + ActiveMapsLayout & layout = f.GetCountryTree().GetActiveMapLayout(); + layout.CancelDownloading(idx); + }); + + f.SetAutoDownloadListener([self, &f](storage::TIndex const & idx) + { + //TODO: check wifi, migration, settings, whatever and download or not download + ActiveMapsLayout & layout = f.GetCountryTree().GetActiveMapLayout(); + layout.DownloadMap(idx, MapOptions::Map); + }); + f.SetRouteBuildingListener([self, &f](routing::IRouter::ResultCode code, vector const & absentCountries, vector const & absentRoutes) { dispatch_async(dispatch_get_main_queue(), [=] diff --git a/map/framework.cpp b/map/framework.cpp index 7dd0503f27..9088e658a2 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -910,6 +910,16 @@ void Framework::SetDownloadCountryListener(TDownloadCountryListener const & list m_downloadCountryListener = listener; } +void Framework::SetDownloadCancelListener(TDownloadCancelListener const & listener) +{ + m_downloadCancelListener = listener; +} + +void Framework::SetAutoDownloadListener(TAutoDownloadListener const & listener) +{ + m_autoDownloadListener = listener; +} + void Framework::OnDownloadMapCallback(storage::TIndex const & countryIndex) { if (m_downloadCountryListener != nullptr) @@ -918,14 +928,6 @@ void Framework::OnDownloadMapCallback(storage::TIndex const & countryIndex) m_activeMaps->DownloadMap(countryIndex, MapOptions::Map); } -void Framework::OnDownloadMapRoutingCallback(storage::TIndex const & countryIndex) -{ - if (m_downloadCountryListener != nullptr) - m_downloadCountryListener(countryIndex, static_cast(MapOptions::MapWithCarRouting)); - else - m_activeMaps->DownloadMap(countryIndex, MapOptions::MapWithCarRouting); -} - void Framework::OnDownloadRetryCallback(storage::TIndex const & countryIndex) { if (m_downloadCountryListener != nullptr) @@ -934,6 +936,17 @@ void Framework::OnDownloadRetryCallback(storage::TIndex const & countryIndex) m_activeMaps->RetryDownloading(countryIndex); } +void Framework::OnDownloadCancelCallback(storage::TIndex const & countryIndex) +{ + // Any cancel leads to disable auto-downloading. + m_autoDownloadingOn = false; + + if (m_downloadCancelListener != nullptr) + m_downloadCancelListener(countryIndex); + else + m_activeMaps->CancelDownloading(countryIndex); +} + void Framework::OnUpdateCountryIndex(storage::TIndex const & currentIndex, m2::PointF const & pt) { storage::TIndex newCountryIndex = GetCountryIndex(m2::PointD(pt)); @@ -944,7 +957,16 @@ void Framework::OnUpdateCountryIndex(storage::TIndex const & currentIndex, m2::P } if (currentIndex != newCountryIndex) + { + // Enable auto-downloading after return from the world map. + if (!currentIndex.IsValid()) + m_autoDownloadingOn = true; + + if (m_autoDownloadingOn && m_autoDownloadListener != nullptr) + m_autoDownloadListener(newCountryIndex); + UpdateCountryInfo(newCountryIndex, true /* isCurrentCountry */); + } } void Framework::UpdateCountryInfo(storage::TIndex const & countryIndex, bool isCurrentCountry) @@ -1392,6 +1414,11 @@ void Framework::CreateDrapeEngine(ref_ptr contextFactory, GetPlatform().RunOnGuiThread(bind(&Framework::OnDownloadRetryCallback, this, countryIndex)); }; + TDownloadFn downloadCancelFn = [this](storage::TIndex const & countryIndex) + { + GetPlatform().RunOnGuiThread(bind(&Framework::OnDownloadCancelCallback, this, countryIndex)); + }; + bool allow3d; bool allow3dBuildings; Load3dMode(allow3d, allow3dBuildings); @@ -1401,7 +1428,7 @@ void Framework::CreateDrapeEngine(ref_ptr contextFactory, df::Viewport(0, 0, params.m_surfaceWidth, params.m_surfaceHeight), df::MapDataProvider(idReadFn, featureReadFn, updateCountryIndex, isCountryLoadedFn, isCountryLoadedByNameFn, - downloadMapFn, downloadRetryFn), + downloadMapFn, downloadRetryFn, downloadCancelFn), params.m_visualScale, move(params.m_widgetsInitInfo), make_pair(params.m_initialMyPositionState, params.m_hasMyPositionState), diff --git a/map/framework.hpp b/map/framework.hpp index 3b976828e7..57d57cf505 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -98,6 +98,8 @@ class Framework protected: using TDrapeFunction = function; using TDownloadCountryListener = function; + using TDownloadCancelListener = function; + using TAutoDownloadListener = function; StringsBundle m_stringsBundle; @@ -124,6 +126,9 @@ protected: double m_startForegroundTime; TDownloadCountryListener m_downloadCountryListener; + TDownloadCancelListener m_downloadCancelListener; + TAutoDownloadListener m_autoDownloadListener; + bool m_autoDownloadingOn = true; storage::Storage m_storage; shared_ptr m_activeMaps; @@ -193,6 +198,8 @@ public: void DownloadCountry(storage::TIndex const & index, MapOptions opt); void SetDownloadCountryListener(TDownloadCountryListener const & listener); + void SetDownloadCancelListener(TDownloadCancelListener const & listener); + void SetAutoDownloadListener(TAutoDownloadListener const & listener); storage::TStatus GetCountryStatus(storage::TIndex const & index) const; string GetCountryName(storage::TIndex const & index) const; @@ -353,8 +360,8 @@ private: void FillSearchResultsMarks(search::Results const & results); void OnDownloadMapCallback(storage::TIndex const & countryIndex); - void OnDownloadMapRoutingCallback(storage::TIndex const & countryIndex); void OnDownloadRetryCallback(storage::TIndex const & countryIndex); + void OnDownloadCancelCallback(storage::TIndex const & countryIndex); void OnUpdateCountryIndex(storage::TIndex const & currentIndex, m2::PointF const & pt); void UpdateCountryInfo(storage::TIndex const & countryIndex, bool isCurrentCountry);