Updating screen on AddMap, RemoveMap(only when map's bound rect lies inside the current viewport).

This commit is contained in:
rachytski 2011-03-23 22:27:01 +02:00 committed by Alex Zolotarev
parent 00e3a285f8
commit c7bd270ac3
3 changed files with 30 additions and 4 deletions

View file

@ -143,7 +143,9 @@ class FrameWork
feature::DataHeader header;
header.Load(FilesContainerR(datFile).GetReader(HEADER_FILE_TAG));
m_model.AddWorldRect(header.GetBounds());
m2::RectD bounds = header.GetBounds();
m_model.AddWorldRect(bounds);
{
threads::MutexGuard lock(m_modelSyn);
m_model.AddMap(datFile);
@ -226,7 +228,8 @@ public:
// initializes model with locally downloaded maps
storage.Init(bind(&FrameWork::AddMap, this, _1),
bind(&FrameWork::RemoveMap, this, _1));
bind(&FrameWork::RemoveMap, this, _1),
bind(&FrameWork::RepaintRect, this, _1));
}
bool IsEmptyModel()
@ -519,6 +522,16 @@ public:
Invalidate();
}
void RepaintRect(m2::RectD const & rect)
{
threads::MutexGuard lock(*m_renderQueue.renderState().m_mutex.get());
m2::RectD pxRect(0, 0, m_renderQueue.renderState().m_surfaceWidth, m_renderQueue.renderState().m_surfaceHeight);
m2::RectD glbRect;
m_navigator.Screen().PtoG(pxRect, glbRect);
if (glbRect.Intersect(rect))
Repaint();
}
void CenterViewport(m2::PointD const & pt)
{
m_navigator.CenterViewport(pt);

View file

@ -3,8 +3,11 @@
#include "../base/logging.hpp"
#include "../base/string_utils.hpp"
#include "../indexer/data_header.hpp"
#include "../coding/file_writer.hpp"
#include "../coding/file_reader.hpp"
#include "../coding/file_container.hpp"
#include "../coding/strutil.hpp"
#include "../version/version.hpp"
@ -44,12 +47,13 @@ namespace storage
}
////////////////////////////////////////////////////////////////////////////
void Storage::Init(TAddMapFunction addFunc, TRemoveMapFunction removeFunc)
void Storage::Init(TAddMapFunction addFunc, TRemoveMapFunction removeFunc, TUpdateRectFunction updateRectFunc)
{
m_currentVersion = static_cast<uint32_t>(Version::BUILD);
m_addMap = addFunc;
m_removeMap = removeFunc;
m_updateRect = updateRectFunc;
// activate all downloaded maps
Platform & p = GetPlatform();
@ -270,10 +274,13 @@ namespace storage
}
}
m2::RectD bounds = country.Bounds();
// @TODO: Do not delete pieces which are used by other countries
DeactivateAndDeleteCountry(country, m_removeMap);
if (m_observerChange)
m_observerChange(index);
m_updateRect(bounds);
}
void Storage::ReInitCountries(bool forceReload)
@ -346,6 +353,10 @@ namespace storage
// activate downloaded map piece
string const datFile = GetPlatform().ReadPathForFile(FileFromUrl(url));
m_addMap(datFile);
feature::DataHeader header;
header.Load(FilesContainerR(datFile).GetReader(HEADER_FILE_TAG));
m_updateRect(header.GetBounds());
}
DownloadNextCountryFromQueue();
}

View file

@ -91,8 +91,10 @@ namespace storage
//@{
typedef boost::function<void (string const &)> TAddMapFunction;
typedef boost::function<void (string const &)> TRemoveMapFunction;
typedef boost::function<void (m2::RectD const & r)> TUpdateRectFunction;
TAddMapFunction m_addMap;
TRemoveMapFunction m_removeMap;
TUpdateRectFunction m_updateRect;
//@}
void DownloadNextCountryFromQueue();
@ -104,7 +106,7 @@ namespace storage
Storage() {}
/// Adds all locally downloaded maps to the model
void Init(TAddMapFunction addFunc, TRemoveMapFunction removeFunc);
void Init(TAddMapFunction addFunc, TRemoveMapFunction removeFunc, TUpdateRectFunction updateRectFunc);
/// @name Called from DownloadManager
//@{