Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrachytski <siarhei.rachytski@gmail.com>2012-06-02 21:29:57 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:39:20 +0300
commit9201356184df3585de78c4abb998e4c7248b9ca2 (patch)
treefe258e7660965ba52ab5153df94be06ea54280b6 /map/country_status_display.cpp
parent21b63475a7383bb2a0e4f0f0d57c3b5fb995fc27 (diff)
added CountryStatusDisplay GUI element and using it into InformationDisplay.
Diffstat (limited to 'map/country_status_display.cpp')
-rw-r--r--map/country_status_display.cpp238
1 files changed, 238 insertions, 0 deletions
diff --git a/map/country_status_display.cpp b/map/country_status_display.cpp
new file mode 100644
index 0000000000..daa7e3bef9
--- /dev/null
+++ b/map/country_status_display.cpp
@@ -0,0 +1,238 @@
+#include "country_status_display.hpp"
+
+#include "../gui/controller.hpp"
+
+#include "../std/bind.hpp"
+#include "../std/sstream.hpp"
+
+#include "../storage/storage.hpp"
+
+#include "../yg/overlay_renderer.hpp"
+
+void CountryStatusDisplay::cache()
+{
+ m_downloadButton->setIsVisible(false);
+
+ m_statusMsg->setIsVisible(false);
+
+ if (m_countryIdx != storage::TIndex())
+ {
+ switch (m_countryStatus)
+ {
+ case storage::EInQueue:
+ {
+ m_statusMsg->setIsVisible(true);
+
+ ostringstream out;
+ out << m_countryName << " is added to the\ndownloading queue";
+
+ m_statusMsg->setText(out.str());
+ }
+
+ break;
+ case storage::EDownloading:
+ {
+ m_statusMsg->setIsVisible(true);
+
+ ostringstream out;
+ out << "Downloading " << m_countryName << "(" << m_countryProgress.first * 100 / m_countryProgress.second << "%)";
+
+ m_statusMsg->setText(out.str());
+ }
+ break;
+ case storage::ENotDownloaded:
+ {
+ m_downloadButton->setIsVisible(true);
+ m_downloadButton->setText("Download " + m_countryName);
+ }
+ break;
+ case storage::EDownloadFailed:
+ {
+ m_downloadButton->setIsVisible(true);
+ m_downloadButton->setText("Try again");
+
+ ostringstream out;
+ out << "Downloading " << m_countryName << "\nhas failed.";
+
+ m_statusMsg->setIsVisible(true);
+ m_statusMsg->setText(out.str());
+
+ setPivot(pivot());
+ }
+ break;
+ default:
+ return;
+ }
+ }
+
+ /// element bound rect is possibly changed
+ setIsDirtyRect(true);
+}
+
+void CountryStatusDisplay::CountryStatusChanged(storage::TIndex const & idx)
+{
+ if (idx == m_countryIdx)
+ {
+ m_countryStatus = m_storage->CountryStatus(m_countryIdx);
+ setIsDirtyDrawing(true);
+ invalidate();
+ }
+}
+
+void CountryStatusDisplay::CountryProgress(storage::TIndex const & idx, pair<int64_t, int64_t> const & progress)
+{
+ if ((m_countryIdx == idx) && m_storage->CountryStatus(idx) == storage::EDownloading)
+ {
+ m_countryProgress = progress;
+ setIsDirtyDrawing(true);
+ invalidate();
+ }
+}
+
+CountryStatusDisplay::CountryStatusDisplay(Params const & p)
+ : gui::Element(p), m_storage(p.m_storage)
+{
+ m_slotID = m_storage->Subscribe(bind(&CountryStatusDisplay::CountryStatusChanged, this, _1),
+ bind(&CountryStatusDisplay::CountryProgress, this, _1, _2));
+
+ gui::Button::Params bp;
+
+ bp.m_depth = yg::maxDepth;
+ bp.m_width = 200;
+ bp.m_height = 40;
+ bp.m_pivot = m2::PointD(0, 0);
+ bp.m_position = yg::EPosCenter;
+ bp.m_text = "Download";
+
+ m_downloadButton.reset(new gui::Button(bp));
+ m_downloadButton->setOnClickListener(bind(&CountryStatusDisplay::DownloadCountry, this));
+ m_downloadButton->setIsVisible(false);
+ m_downloadButton->setPosition(yg::EPosCenter);
+ m_downloadButton->setFont(gui::Element::EActive, yg::FontDesc(16));
+ m_downloadButton->setFont(gui::Element::EPressed, yg::FontDesc(16));
+
+ gui::TextView::Params tp;
+ tp.m_depth = yg::maxDepth;
+ tp.m_pivot = m2::PointD(0, 0);
+ tp.m_text = "Downloading";
+
+ m_statusMsg.reset(new gui::TextView(tp));
+
+ m_statusMsg->setIsVisible(false);
+ m_statusMsg->setPosition(yg::EPosCenter);
+
+ m_statusMsg->setFont(gui::Element::EActive, yg::FontDesc(18));
+
+ m_countryIdx = storage::TIndex();
+ m_countryStatus = storage::EUnknown;
+}
+
+CountryStatusDisplay::~CountryStatusDisplay()
+{
+ m_storage->Unsubscribe(m_slotID);
+}
+
+void CountryStatusDisplay::DownloadCountry()
+{
+ m_storage->DownloadCountry(m_countryIdx);
+}
+
+void CountryStatusDisplay::setCountryName(string const & name)
+{
+ if (m_countryName != name)
+ {
+ m_countryIdx = m_storage->FindIndexByName(name);
+ m_countryStatus = m_storage->CountryStatus(m_countryIdx);
+ m_countryProgress = m_storage->CountrySizeInBytes(m_countryIdx);
+ m_countryName = name;
+ setIsDirtyDrawing(true);
+ invalidate();
+ }
+}
+
+void CountryStatusDisplay::draw(yg::gl::OverlayRenderer *r,
+ math::Matrix<double, 3, 3> const & m) const
+{
+ if (!isVisible())
+ return;
+
+ checkDirtyDrawing();
+
+// r->drawRectangle(roughBoundRect(), yg::Color(0, 0, 255, 64), yg::maxDepth);
+
+ if (m_downloadButton->isVisible())
+ m_downloadButton->draw(r, m);
+ if (m_statusMsg->isVisible())
+ m_statusMsg->draw(r, m);
+}
+
+vector<m2::AnyRectD> const & CountryStatusDisplay::boundRects() const
+{
+ checkDirtyDrawing();
+
+ if (isDirtyRect())
+ {
+ m_boundRects.clear();
+ m2::RectD r = m_downloadButton->roughBoundRect();
+ r.Add(m_statusMsg->roughBoundRect());
+ m_boundRects.push_back(m2::AnyRectD(r));
+ setIsDirtyRect(false);
+ }
+
+ return m_boundRects;
+}
+
+void CountryStatusDisplay::setController(gui::Controller *controller)
+{
+ Element::setController(controller);
+ m_statusMsg->setController(controller);
+ m_downloadButton->setController(controller);
+}
+void CountryStatusDisplay::setPivot(m2::PointD const & pv)
+{
+ if (m_countryStatus == storage::EDownloadFailed)
+ {
+ size_t buttonHeight = m_downloadButton->roughBoundRect().SizeY();
+ size_t statusHeight = m_statusMsg->roughBoundRect().SizeY();
+
+ size_t commonHeight = buttonHeight + statusHeight + 10 * visualScale();
+
+ m_downloadButton->setPivot(m2::PointD(pv.x, pv.y + commonHeight / 2 - buttonHeight / 2));
+ m_statusMsg->setPivot(m2::PointD(pv.x, pv.y - commonHeight / 2 + statusHeight / 2));
+ }
+ else
+ {
+ m_downloadButton->setPivot(pv);
+ m_statusMsg->setPivot(pv);
+ }
+
+ gui::Element::setPivot(pv);
+}
+
+bool CountryStatusDisplay::onTapStarted(m2::PointD const & pt)
+{
+ if (m_downloadButton->isVisible())
+ return m_downloadButton->onTapStarted(pt);
+ return false;
+}
+
+bool CountryStatusDisplay::onTapMoved(m2::PointD const & pt)
+{
+ if (m_downloadButton->isVisible())
+ return m_downloadButton->onTapMoved(pt);
+ return false;
+}
+
+bool CountryStatusDisplay::onTapEnded(m2::PointD const & pt)
+{
+ if (m_downloadButton->isVisible())
+ return m_downloadButton->onTapEnded(pt);
+ return false;
+}
+
+bool CountryStatusDisplay::onTapCancelled(m2::PointD const & pt)
+{
+ if (m_downloadButton->isVisible())
+ return m_downloadButton->onTapCancelled(pt);
+ return false;
+}