forked from organicmaps/organicmaps
[drape] country status logic
This commit is contained in:
parent
b2a14b8be3
commit
bd950780e2
26 changed files with 741 additions and 184 deletions
|
@ -138,6 +138,11 @@ void Trim(string & s)
|
|||
boost::trim(s);
|
||||
}
|
||||
|
||||
void Trim(string & s, char const * anyOf)
|
||||
{
|
||||
boost::trim_if(s, boost::is_any_of(anyOf));
|
||||
}
|
||||
|
||||
bool EqualNoCase(string const & s1, string const & s2)
|
||||
{
|
||||
return MakeLowerCase(s1) == MakeLowerCase(s2);
|
||||
|
|
|
@ -53,6 +53,7 @@ void AsciiToLower(string & s);
|
|||
// TODO(AlexZ): current boost impl uses default std::locale() to trim.
|
||||
// In general, it does not work for any unicode whitespace except ASCII U+0020 one.
|
||||
void Trim(string & s);
|
||||
void Trim(string & s, char const * anyOf);
|
||||
|
||||
void MakeLowerCaseInplace(string & s);
|
||||
string MakeLowerCase(string const & s);
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
#include "drape_frontend/backend_renderer.hpp"
|
||||
#include "drape_frontend/read_manager.hpp"
|
||||
#include "drape_frontend/batchers_pool.hpp"
|
||||
#include "drape_frontend/visual_params.hpp"
|
||||
#include "drape_frontend/map_shape.hpp"
|
||||
#include "drape_frontend/user_mark_shapes.hpp"
|
||||
|
||||
#include "drape_frontend/message_subclasses.hpp"
|
||||
#include "drape_frontend/read_manager.hpp"
|
||||
#include "drape_frontend/user_mark_shapes.hpp"
|
||||
#include "drape_frontend/visual_params.hpp"
|
||||
|
||||
#include "drape_gui/drape_gui.hpp"
|
||||
|
||||
#include "indexer/scales.hpp"
|
||||
|
||||
#include "drape/texture_manager.hpp"
|
||||
|
||||
|
@ -24,21 +27,36 @@ BackendRenderer::BackendRenderer(dp::RefPointer<ThreadsCommutator> commutator,
|
|||
MapDataProvider const & model)
|
||||
: BaseRenderer(ThreadsCommutator::ResourceUploadThread, commutator, oglcontextfactory)
|
||||
, m_model(model)
|
||||
, m_engineContext(commutator)
|
||||
, m_texturesManager(textureManager)
|
||||
, m_guiCacher("default")
|
||||
{
|
||||
m_batchersPool.Reset(new BatchersPool(ReadManager::ReadCount(), bind(&BackendRenderer::FlushGeometry, this, _1)));
|
||||
m_readManager.Reset(new ReadManager(m_engineContext, m_model));
|
||||
m_readManager.Reset(new ReadManager(commutator, m_model));
|
||||
|
||||
gui::DrapeGui::Instance().SetRecacheSlot([this](gui::Skin::ElementName elements)
|
||||
{
|
||||
m_commutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
|
||||
dp::MovePointer<Message>(new GuiRecacheMessage(elements)),
|
||||
MessagePriority::Normal);
|
||||
});
|
||||
|
||||
StartThread();
|
||||
}
|
||||
|
||||
BackendRenderer::~BackendRenderer()
|
||||
{
|
||||
gui::DrapeGui::Instance().ClearRecacheSlot();
|
||||
StopThread();
|
||||
}
|
||||
|
||||
void BackendRenderer::RecacheGui(gui::Skin::ElementName elements)
|
||||
{
|
||||
using TLayerRenderer = dp::TransferPointer<gui::LayerRenderer>;
|
||||
TLayerRenderer layerRenderer = m_guiCacher.Recache(elements, m_texturesManager);
|
||||
dp::TransferPointer<Message> outputMsg = dp::MovePointer<Message>(new GuiLayerRecachedMessage(layerRenderer));
|
||||
m_commutator->PostMessage(ThreadsCommutator::RenderThread, outputMsg, MessagePriority::High);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////
|
||||
// MessageAcceptor //
|
||||
/////////////////////////////////////////
|
||||
|
@ -52,6 +70,11 @@ void BackendRenderer::AcceptMessage(dp::RefPointer<Message> message)
|
|||
ScreenBase const & screen = msg->GetScreen();
|
||||
set<TileKey> const & tiles = msg->GetTiles();
|
||||
m_readManager->UpdateCoverage(screen, tiles);
|
||||
storage::TIndex cnt;
|
||||
if (!tiles.empty() && (*tiles.begin()).m_zoomLevel > scales::GetUpperWorldScale())
|
||||
cnt = m_model.FindCountry(screen.ClipRect().Center());
|
||||
|
||||
gui::DrapeGui::Instance().SetCountryIndex(cnt);
|
||||
break;
|
||||
}
|
||||
case Message::Resize:
|
||||
|
@ -59,10 +82,7 @@ void BackendRenderer::AcceptMessage(dp::RefPointer<Message> message)
|
|||
ResizeMessage * msg = df::CastMessage<ResizeMessage>(message);
|
||||
df::Viewport const & v = msg->GetViewport();
|
||||
m_guiCacher.Resize(v.GetWidth(), v.GetHeight());
|
||||
dp::TransferPointer<gui::LayerRenderer> layerRenderer =
|
||||
m_guiCacher.Recache(gui::Skin::AllElements, m_texturesManager);
|
||||
GuiLayerRecachedMessage * outputMsg = new GuiLayerRecachedMessage(layerRenderer);
|
||||
m_commutator->PostMessage(ThreadsCommutator::RenderThread, dp::MovePointer<df::Message>(outputMsg), MessagePriority::High);
|
||||
RecacheGui(gui::Skin::AllElements);
|
||||
break;
|
||||
}
|
||||
case Message::InvalidateReadManagerRect:
|
||||
|
@ -71,6 +91,9 @@ void BackendRenderer::AcceptMessage(dp::RefPointer<Message> message)
|
|||
m_readManager->Invalidate(msg->GetTilesForInvalidate());
|
||||
break;
|
||||
}
|
||||
case Message::GuiRecache:
|
||||
RecacheGui(CastMessage<GuiRecacheMessage>(message)->GetElements());
|
||||
break;
|
||||
case Message::TileReadStarted:
|
||||
m_batchersPool->ReserveBatcher(df::CastMessage<BaseTileMessage>(message)->GetKey());
|
||||
break;
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include "drape_frontend/base_renderer.hpp"
|
||||
#include "drape_frontend/engine_context.hpp"
|
||||
#include "drape_frontend/viewport.hpp"
|
||||
#include "drape_frontend/map_data_provider.hpp"
|
||||
#include "drape_frontend/viewport.hpp"
|
||||
|
||||
#include "drape_gui/layer_render.hpp"
|
||||
#include "drape/pointers.hpp"
|
||||
|
@ -33,9 +32,11 @@ public:
|
|||
|
||||
~BackendRenderer() override;
|
||||
|
||||
private:
|
||||
void RecacheGui(gui::Skin::ElementName elements);
|
||||
|
||||
private:
|
||||
MapDataProvider m_model;
|
||||
EngineContext m_engineContext;
|
||||
dp::MasterPointer<BatchersPool> m_batchersPool;
|
||||
dp::MasterPointer<ReadManager> m_readManager;
|
||||
dp::RefPointer<dp::TextureManager> m_texturesManager;
|
||||
|
|
|
@ -14,13 +14,10 @@
|
|||
namespace df
|
||||
{
|
||||
|
||||
DrapeEngine::DrapeEngine(dp::RefPointer<dp::OGLContextFactory> contextfactory,
|
||||
Viewport const & viewport,
|
||||
MapDataProvider const & model,
|
||||
double vs)
|
||||
: m_viewport(viewport)
|
||||
DrapeEngine::DrapeEngine(Params const & params)
|
||||
: m_viewport(params.m_viewport)
|
||||
{
|
||||
VisualParams::Init(vs, df::CalculateTileSize(m_viewport.GetWidth(), m_viewport.GetHeight()));
|
||||
VisualParams::Init(params.m_vs, df::CalculateTileSize(m_viewport.GetWidth(), m_viewport.GetHeight()));
|
||||
|
||||
gui::DrapeGui::TScaleFactorFn scaleFn = []
|
||||
{
|
||||
|
@ -31,20 +28,23 @@ DrapeEngine::DrapeEngine(dp::RefPointer<dp::OGLContextFactory> contextfactory,
|
|||
return GetDrawTileScale(screen);
|
||||
};
|
||||
|
||||
gui::DrapeGui::Instance().Init(scaleFn, gnLvlFn);
|
||||
gui::DrapeGui & guiSubsystem = gui::DrapeGui::Instance();
|
||||
guiSubsystem.Init(scaleFn, gnLvlFn);
|
||||
guiSubsystem.SetLocalizator(bind(&StringsBundle::GetString, params.m_stringsBundle.GetRaw(), _1));
|
||||
guiSubsystem.SetStorageAccessor(params.m_storageAccessor);
|
||||
|
||||
m_textureManager = dp::MasterPointer<dp::TextureManager>(new dp::TextureManager());
|
||||
m_threadCommutator = dp::MasterPointer<ThreadsCommutator>(new ThreadsCommutator());
|
||||
dp::RefPointer<ThreadsCommutator> commutatorRef = m_threadCommutator.GetRefPointer();
|
||||
|
||||
m_frontend = dp::MasterPointer<FrontendRenderer>(new FrontendRenderer(commutatorRef,
|
||||
contextfactory,
|
||||
params.m_factory,
|
||||
m_textureManager.GetRefPointer(),
|
||||
m_viewport));
|
||||
m_backend = dp::MasterPointer<BackendRenderer>(new BackendRenderer(commutatorRef,
|
||||
contextfactory,
|
||||
params.m_factory,
|
||||
m_textureManager.GetRefPointer(),
|
||||
model));
|
||||
params.m_model));
|
||||
}
|
||||
|
||||
DrapeEngine::~DrapeEngine()
|
||||
|
|
|
@ -9,7 +9,10 @@
|
|||
|
||||
#include "geometry/screenbase.hpp"
|
||||
|
||||
#include "base/strings_bundle.hpp"
|
||||
|
||||
namespace dp { class OGLContextFactory; }
|
||||
namespace gui { class StorageAccessor; }
|
||||
|
||||
namespace df
|
||||
{
|
||||
|
@ -21,10 +24,32 @@ class Viewport;
|
|||
class DrapeEngine
|
||||
{
|
||||
public:
|
||||
DrapeEngine(dp::RefPointer<dp::OGLContextFactory> oglcontextfactory,
|
||||
Viewport const & viewport,
|
||||
MapDataProvider const & model,
|
||||
double vs);
|
||||
struct Params
|
||||
{
|
||||
Params(dp::RefPointer<dp::OGLContextFactory> factory,
|
||||
dp::RefPointer<StringsBundle> stringBundle,
|
||||
dp::RefPointer<gui::StorageAccessor> storageAccessor,
|
||||
Viewport const & viewport,
|
||||
MapDataProvider const & model,
|
||||
double vs)
|
||||
: m_factory(factory)
|
||||
, m_stringsBundle(stringBundle)
|
||||
, m_storageAccessor(storageAccessor)
|
||||
, m_viewport(viewport)
|
||||
, m_model(model)
|
||||
, m_vs(vs)
|
||||
{
|
||||
}
|
||||
|
||||
dp::RefPointer<dp::OGLContextFactory> m_factory;
|
||||
dp::RefPointer<StringsBundle> m_stringsBundle;
|
||||
dp::RefPointer<gui::StorageAccessor> m_storageAccessor;
|
||||
Viewport m_viewport;
|
||||
MapDataProvider m_model;
|
||||
double m_vs = 1.0f;
|
||||
};
|
||||
|
||||
DrapeEngine(Params const & params);
|
||||
~DrapeEngine();
|
||||
|
||||
void Resize(int w, int h);
|
||||
|
|
|
@ -3,9 +3,12 @@
|
|||
namespace df
|
||||
{
|
||||
|
||||
MapDataProvider::MapDataProvider(TReadIDsFn const & idsReader, TReadFeaturesFn const & featureReader)
|
||||
MapDataProvider::MapDataProvider(TReadIDsFn const & idsReader,
|
||||
TReadFeaturesFn const & featureReader,
|
||||
TResolveCountryFn const & countryResolver)
|
||||
: m_featureReader(featureReader)
|
||||
, m_idsReader(idsReader)
|
||||
, m_countryResolver(countryResolver)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -19,4 +22,9 @@ void MapDataProvider::ReadFeatures(TReadFeatureCallback const & fn, vector<Featu
|
|||
m_featureReader(fn, ids);
|
||||
}
|
||||
|
||||
storage::TIndex MapDataProvider::FindCountry(m2::PointF const & pt)
|
||||
{
|
||||
return m_countryResolver(pt);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include "indexer/feature.hpp"
|
||||
#include "storage/index.hpp"
|
||||
#include "storage/storage_defines.hpp"
|
||||
|
||||
#include "indexer/feature.hpp"
|
||||
#include "geometry/rect2d.hpp"
|
||||
|
||||
#include "std/function.hpp"
|
||||
|
@ -12,19 +14,25 @@ namespace df
|
|||
class MapDataProvider
|
||||
{
|
||||
public:
|
||||
typedef function<void (FeatureID const &)> TReadIdCallback;
|
||||
typedef function<void (FeatureType const &)> TReadFeatureCallback;
|
||||
typedef function<void (TReadFeatureCallback const & , vector<FeatureID> const &)> TReadFeaturesFn;
|
||||
typedef function<void (TReadIdCallback const & , m2::RectD const &, int)> TReadIDsFn;
|
||||
using TReadIdCallback = function<void (FeatureID const &)>;
|
||||
using TReadFeatureCallback = function<void (FeatureType const &)>;
|
||||
using TReadFeaturesFn = function<void (TReadFeatureCallback const & , vector<FeatureID> const &)>;
|
||||
using TReadIDsFn = function<void (TReadIdCallback const & , m2::RectD const &, int)>;
|
||||
using TResolveCountryFn = function<storage::TIndex (m2::PointF const &)>;
|
||||
|
||||
MapDataProvider(TReadIDsFn const & idsReader, TReadFeaturesFn const & featureReader);
|
||||
MapDataProvider(TReadIDsFn const & idsReader,
|
||||
TReadFeaturesFn const & featureReader,
|
||||
TResolveCountryFn const & countryResolver);
|
||||
|
||||
void ReadFeaturesID(TReadIdCallback const & fn, m2::RectD const & r, int scale) const;
|
||||
void ReadFeatures(TReadFeatureCallback const & fn, vector<FeatureID> const & ids) const;
|
||||
|
||||
storage::TIndex FindCountry(m2::PointF const & pt);
|
||||
|
||||
private:
|
||||
TReadFeaturesFn m_featureReader;
|
||||
TReadIDsFn m_idsReader;
|
||||
TResolveCountryFn m_countryResolver;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ public:
|
|||
ChangeUserMarkLayerVisibility,
|
||||
UpdateUserMarkLayer,
|
||||
GuiLayerRecached,
|
||||
GuiRecache,
|
||||
StopRendering
|
||||
};
|
||||
|
||||
|
|
|
@ -5,11 +5,12 @@
|
|||
#include "drape_frontend/tile_key.hpp"
|
||||
#include "drape_frontend/user_marks_provider.hpp"
|
||||
|
||||
#include "drape_gui/layer_render.hpp"
|
||||
|
||||
#include "geometry/rect2d.hpp"
|
||||
#include "geometry/screenbase.hpp"
|
||||
|
||||
#include "drape_gui/layer_render.hpp"
|
||||
#include "drape_gui/skin.hpp"
|
||||
|
||||
#include "drape/glstate.hpp"
|
||||
#include "drape/pointers.hpp"
|
||||
#include "drape/render_bucket.hpp"
|
||||
|
@ -231,6 +232,24 @@ private:
|
|||
dp::TransferPointer<gui::LayerRenderer> m_renderer;
|
||||
};
|
||||
|
||||
class GuiRecacheMessage : public Message
|
||||
{
|
||||
public:
|
||||
GuiRecacheMessage(gui::Skin::ElementName elements)
|
||||
: m_elements(elements)
|
||||
{
|
||||
}
|
||||
|
||||
Type GetType() const override { return Message::GuiRecache;}
|
||||
gui::Skin::ElementName GetElements() const
|
||||
{
|
||||
return m_elements;
|
||||
}
|
||||
|
||||
private:
|
||||
gui::Skin::ElementName m_elements;
|
||||
};
|
||||
|
||||
class StopRenderingMessage : public Message
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -19,7 +19,7 @@ class CountryStatusHandle : public Handle
|
|||
typedef Handle TBase;
|
||||
|
||||
public:
|
||||
CountryStatusHandle(int state, dp::Anchor anchor, m2::PointF const & size)
|
||||
CountryStatusHandle(CountryStatusHelper::ECountryState const state, dp::Anchor anchor, m2::PointF const & size)
|
||||
: Handle(anchor, m2::PointF::Zero(), size), m_state(state)
|
||||
{
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
int m_state;
|
||||
CountryStatusHelper::ECountryState m_state;
|
||||
};
|
||||
|
||||
class CountryProgressHandle : public MutableLabelHandle
|
||||
|
@ -39,7 +39,7 @@ class CountryProgressHandle : public MutableLabelHandle
|
|||
using TBase = MutableLabelHandle;
|
||||
|
||||
public:
|
||||
CountryProgressHandle(dp::Anchor anchor, int state)
|
||||
CountryProgressHandle(dp::Anchor anchor, CountryStatusHelper::ECountryState const state)
|
||||
: MutableLabelHandle(anchor, m2::PointF::Zero()), m_state(state)
|
||||
{
|
||||
}
|
||||
|
@ -69,19 +69,20 @@ protected:
|
|||
string const & GetContent() const override { return m_value; }
|
||||
|
||||
private:
|
||||
int m_state;
|
||||
CountryStatusHelper::ECountryState m_state;
|
||||
bool m_contentDirty;
|
||||
string m_value;
|
||||
};
|
||||
|
||||
dp::TransferPointer<dp::OverlayHandle> CreateHandle(int state, dp::Anchor anchor,
|
||||
dp::TransferPointer<dp::OverlayHandle> CreateHandle(CountryStatusHelper::ECountryState const state,
|
||||
dp::Anchor anchor,
|
||||
m2::PointF const & size)
|
||||
{
|
||||
return dp::MovePointer<dp::OverlayHandle>(new CountryStatusHandle(state, anchor, size));
|
||||
}
|
||||
|
||||
void DrawLabelControl(string const & text, dp::Anchor anchor, dp::Batcher::TFlushFn const & flushFn,
|
||||
dp::RefPointer<dp::TextureManager> mng, int state)
|
||||
dp::RefPointer<dp::TextureManager> mng, CountryStatusHelper::ECountryState state)
|
||||
{
|
||||
StaticLabel::LabelResult result;
|
||||
StaticLabel::CacheStaticText(text, "\n", anchor, dp::FontDecl(dp::Color::Black(), 18), mng,
|
||||
|
@ -103,7 +104,7 @@ void DrawLabelControl(string const & text, dp::Anchor anchor, dp::Batcher::TFlus
|
|||
}
|
||||
|
||||
void DrawProgressControl(dp::Anchor anchor, dp::Batcher::TFlushFn const & flushFn,
|
||||
dp::RefPointer<dp::TextureManager> mng, int state)
|
||||
dp::RefPointer<dp::TextureManager> mng, CountryStatusHelper::ECountryState state)
|
||||
{
|
||||
MutableLabelDrawer::Params params;
|
||||
CountryStatusHelper & helper = DrapeGui::GetCountryStatusHelper();
|
||||
|
@ -123,44 +124,48 @@ void DrawProgressControl(dp::Anchor anchor, dp::Batcher::TFlushFn const & flushF
|
|||
|
||||
dp::TransferPointer<ShapeRenderer> CountryStatus::Draw(dp::RefPointer<dp::TextureManager> tex) const
|
||||
{
|
||||
CountryStatusHelper & helper = DrapeGui::GetCountryStatusHelper();
|
||||
if (helper.GetComponentCount() == 0)
|
||||
return dp::MovePointer<ShapeRenderer>(nullptr);
|
||||
|
||||
CountryStatusHelper::ECountryState const state = helper.GetState();
|
||||
ASSERT(state != CountryStatusHelper::COUNTRY_STATE_LOADED, ());
|
||||
|
||||
dp::MasterPointer<ShapeRenderer> renderer(new ShapeRenderer());
|
||||
dp::Batcher::TFlushFn flushFn = bind(&ShapeRenderer::AddShape, renderer.GetRaw(), _1, _2);
|
||||
|
||||
CountryStatusHelper & helper = DrapeGui::GetCountryStatusHelper();
|
||||
int const state = helper.GetState();
|
||||
|
||||
for (size_t i = 0; i < helper.GetComponentCount(); ++i)
|
||||
{
|
||||
CountryStatusHelper::Control const & control = helper.GetControl(i);
|
||||
switch (control.m_type)
|
||||
{
|
||||
case CountryStatusHelper::Button:
|
||||
{
|
||||
Button::THandleCreator handleCreator = bind(&CreateHandle, state, _1, _2);
|
||||
ShapeControl shapeControl;
|
||||
Button::Params params;
|
||||
params.m_anchor = m_position.m_anchor;
|
||||
params.m_label = control.m_label;
|
||||
params.m_labelFont = dp::FontDecl(dp::Color::White(), 16);
|
||||
params.m_minWidth = 300;
|
||||
params.m_maxWidth = 600;
|
||||
params.m_margin = 5.0f * DrapeGui::Instance().GetScaleFactor();
|
||||
params.m_bodyHandleCreator = handleCreator;
|
||||
params.m_labelHandleCreator = handleCreator;
|
||||
case CountryStatusHelper::CONTROL_TYPE_BUTTON:
|
||||
{
|
||||
Button::THandleCreator handleCreator = bind(&CreateHandle, state, _1, _2);
|
||||
ShapeControl shapeControl;
|
||||
Button::Params params;
|
||||
params.m_anchor = m_position.m_anchor;
|
||||
params.m_label = control.m_label;
|
||||
params.m_labelFont = dp::FontDecl(dp::Color::White(), 16);
|
||||
params.m_minWidth = 300;
|
||||
params.m_maxWidth = 600;
|
||||
params.m_margin = 5.0f * DrapeGui::Instance().GetScaleFactor();
|
||||
params.m_bodyHandleCreator = handleCreator;
|
||||
params.m_labelHandleCreator = handleCreator;
|
||||
|
||||
Button::Draw(params, shapeControl, tex);
|
||||
renderer->AddShapeControl(move(shapeControl));
|
||||
}
|
||||
break;
|
||||
case CountryStatusHelper::Label:
|
||||
DrawLabelControl(control.m_label, m_position.m_anchor, flushFn, tex, state);
|
||||
break;
|
||||
case CountryStatusHelper::Progress:
|
||||
DrawProgressControl(m_position.m_anchor, flushFn, tex, state);
|
||||
break;
|
||||
default:
|
||||
ASSERT(false, ());
|
||||
break;
|
||||
Button::Draw(params, shapeControl, tex);
|
||||
renderer->AddShapeControl(move(shapeControl));
|
||||
}
|
||||
break;
|
||||
case CountryStatusHelper::CONTROL_TYPE_LABEL:
|
||||
DrawLabelControl(control.m_label, m_position.m_anchor, flushFn, tex, state);
|
||||
break;
|
||||
case CountryStatusHelper::CONTROL_TYPE_PROGRESS:
|
||||
DrawProgressControl(m_position.m_anchor, flushFn, tex, state);
|
||||
break;
|
||||
default:
|
||||
ASSERT(false, ());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,17 +1,125 @@
|
|||
#include "country_status_helper.hpp"
|
||||
#include "drape_gui.hpp"
|
||||
|
||||
#include "../storage/index.hpp"
|
||||
|
||||
#include "../base/stl_add.hpp"
|
||||
#include "../base/string_utils.hpp"
|
||||
#include "../base/string_format.hpp"
|
||||
|
||||
namespace gui
|
||||
{
|
||||
CountryStatusHelper::CountryStatusHelper()
|
||||
|
||||
namespace
|
||||
{
|
||||
// TODO UVR
|
||||
m_controls.push_back(Control{"Belarus", Label});
|
||||
m_controls.push_back(Control{"Download map\n70MB", Button});
|
||||
m_controls.push_back(Control{"Download map + routing\n70MB", Button});
|
||||
m_controls.push_back(Control{"", Progress});
|
||||
|
||||
CountryStatusHelper::Control MakeLabel(string const & text)
|
||||
{
|
||||
return { text, CountryStatusHelper::CONTROL_TYPE_LABEL, CountryStatusHelper::BUTTON_TYPE_NOT_BUTTON };
|
||||
}
|
||||
|
||||
CountryStatusHelper::Control MakeButton(string const & text, CountryStatusHelper::EButtonType type)
|
||||
{
|
||||
return { text, CountryStatusHelper::CONTROL_TYPE_BUTTON, type };
|
||||
}
|
||||
|
||||
CountryStatusHelper::Control MakeProgress()
|
||||
{
|
||||
return { "", CountryStatusHelper::CONTROL_TYPE_PROGRESS, CountryStatusHelper::BUTTON_TYPE_NOT_BUTTON };
|
||||
}
|
||||
|
||||
string GetLocalizedString(string const & id)
|
||||
{
|
||||
return DrapeGui::Instance().GetLocalizedString(id);
|
||||
}
|
||||
|
||||
void FormatMapSize(uint64_t sizeInBytes, string & units, size_t & sizeToDownload)
|
||||
{
|
||||
int const mbInBytes = 1024 * 1024;
|
||||
int const kbInBytes = 1024;
|
||||
if (sizeInBytes > mbInBytes)
|
||||
{
|
||||
sizeToDownload = (sizeInBytes + (mbInBytes >> 1)) / mbInBytes;
|
||||
units = "MB";
|
||||
}
|
||||
else if (sizeInBytes > kbInBytes)
|
||||
{
|
||||
sizeToDownload = (sizeInBytes + (kbInBytes >> 1)) / kbInBytes;
|
||||
units = "KB";
|
||||
}
|
||||
else
|
||||
{
|
||||
sizeToDownload = sizeInBytes;
|
||||
units = "B";
|
||||
}
|
||||
}
|
||||
|
||||
char const * DownloadMapButtonID = "country_status_download";
|
||||
char const * DownloadMapRoutingButtonID = "country_status_download_routing";
|
||||
char const * TryAgainButtonID = "try_again";
|
||||
char const * DownloadingLabelID = "country_status_downloading";
|
||||
char const * DownloadingFailedID = "country_status_download_failed";
|
||||
char const * InQueueID = "country_status_added_to_queue";
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
CountryStatusHelper::CountryStatusHelper()
|
||||
: m_state(COUNTRY_STATE_LOADED)
|
||||
{
|
||||
}
|
||||
|
||||
void CountryStatusHelper::SetStorageAccessor(dp::RefPointer<StorageAccessor> accessor)
|
||||
{
|
||||
m_accessor = accessor;
|
||||
}
|
||||
|
||||
void CountryStatusHelper::SetCountryIndex(storage::TIndex const & index)
|
||||
{
|
||||
ASSERT(!m_accessor.IsNull(), ());
|
||||
if (m_accessor->GetCountryIndex() == index)
|
||||
return;
|
||||
|
||||
CountryStatusHelper::ECountryState state = CountryStatusHelper::COUNTRY_STATE_LOADED;
|
||||
m_accessor->SetCountryIndex(index);
|
||||
switch(m_accessor->GetCountryStatus())
|
||||
{
|
||||
case storage::TStatus::ENotDownloaded:
|
||||
state = CountryStatusHelper::COUNTRY_STATE_EMPTY;
|
||||
break;
|
||||
case storage::TStatus::EDownloading:
|
||||
state = CountryStatusHelper::COUNTRY_STATE_LOADING;
|
||||
break;
|
||||
case storage::TStatus::EInQueue:
|
||||
state = CountryStatusHelper::COUNTRY_STATE_IN_QUEUE;
|
||||
break;
|
||||
case storage::TStatus::EDownloadFailed:
|
||||
case storage::TStatus::EOutOfMemFailed:
|
||||
state = CountryStatusHelper::COUNTRY_STATE_FAILED;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
SetState(state);
|
||||
}
|
||||
|
||||
void CountryStatusHelper::SetState(ECountryState state)
|
||||
{
|
||||
m_state = state;
|
||||
FillControlsForState();
|
||||
DrapeGui::Instance().EmitRecacheSignal(Skin::CountryStatus);
|
||||
}
|
||||
|
||||
CountryStatusHelper::ECountryState CountryStatusHelper::GetState() const
|
||||
{
|
||||
return m_state;
|
||||
}
|
||||
|
||||
bool CountryStatusHelper::IsVisibleForState(ECountryState state) const
|
||||
{
|
||||
return m_state != COUNTRY_STATE_LOADED && m_state == state;
|
||||
}
|
||||
|
||||
size_t CountryStatusHelper::GetComponentCount() const { return m_controls.size(); }
|
||||
|
@ -34,29 +142,108 @@ void CountryStatusHelper::GetProgressInfo(string & alphabet, size_t & maxLength)
|
|||
|
||||
string CountryStatusHelper::GetProgressValue() const
|
||||
{
|
||||
// TODO UVR
|
||||
static int value = 0;
|
||||
static int counter = 0;
|
||||
if (counter >= 60)
|
||||
return strings::to_string(m_accessor->GetDownloadProgress()) + "%";
|
||||
}
|
||||
|
||||
void CountryStatusHelper::FillControlsForState()
|
||||
{
|
||||
m_controls.clear();
|
||||
switch (m_state)
|
||||
{
|
||||
value++;
|
||||
counter = 0;
|
||||
case COUNTRY_STATE_EMPTY:
|
||||
FillControlsForEmpty();
|
||||
break;
|
||||
case COUNTRY_STATE_LOADING:
|
||||
FillControlsForLoading();
|
||||
break;
|
||||
case COUNTRY_STATE_IN_QUEUE:
|
||||
FillControlsForInQueue();
|
||||
break;
|
||||
case COUNTRY_STATE_FAILED:
|
||||
FillControlsForFailed();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
counter++;
|
||||
|
||||
return strings::to_string(value) + "%";
|
||||
}
|
||||
|
||||
int CountryStatusHelper::GetState() const
|
||||
void CountryStatusHelper::FillControlsForEmpty()
|
||||
{
|
||||
// TODO UVR
|
||||
return 0;
|
||||
ASSERT(m_controls.empty(), ());
|
||||
m_controls.push_back(MakeLabel(m_accessor->GetCurrentCountryName()));
|
||||
m_controls.push_back(MakeButton(FormatDownloadMap(), BUTTON_TYPE_MAP));
|
||||
m_controls.push_back(MakeButton(FormatDownloadMapRouting(), BUTTON_TYPE_MAP_ROUTING));
|
||||
}
|
||||
|
||||
bool CountryStatusHelper::IsVisibleForState(int state) const
|
||||
void CountryStatusHelper::FillControlsForLoading()
|
||||
{
|
||||
// TODO UVR
|
||||
return state != 0;
|
||||
ASSERT(m_controls.empty(), ());
|
||||
string text = GetLocalizedString(DownloadingLabelID);
|
||||
size_t firstPos = text.find('^');
|
||||
size_t secondPos = text.find('^', firstPos + 1);
|
||||
|
||||
ASSERT(firstPos != string::npos, ());
|
||||
ASSERT(secondPos != string::npos, ());
|
||||
if (firstPos != 0)
|
||||
{
|
||||
string firstLabel = text.substr(0, firstPos);
|
||||
strings::Trim(firstLabel, "\n ");
|
||||
m_controls.push_back(MakeLabel(firstLabel));
|
||||
}
|
||||
|
||||
m_controls.push_back(MakeLabel(m_accessor->GetCurrentCountryName()));
|
||||
m_controls.push_back(MakeProgress());
|
||||
|
||||
if (secondPos + 1 < text.size())
|
||||
{
|
||||
string secondLabel = text.substr(secondPos + 1);
|
||||
strings::Trim(secondLabel , "\n ");
|
||||
m_controls.push_back(MakeLabel(secondLabel ));
|
||||
}
|
||||
}
|
||||
|
||||
void CountryStatusHelper::FillControlsForInQueue()
|
||||
{
|
||||
ASSERT(m_controls.empty(), ());
|
||||
m_controls.push_back(MakeLabel(FormatInQueueMap()));
|
||||
}
|
||||
|
||||
void CountryStatusHelper::FillControlsForFailed()
|
||||
{
|
||||
ASSERT(m_controls.empty(), ());
|
||||
m_controls.push_back(MakeLabel(FormatFailed()));
|
||||
m_controls.push_back(MakeButton(FormatTryAgain(), BUTTON_TRY_AGAIN));
|
||||
}
|
||||
|
||||
string CountryStatusHelper::FormatDownloadMap()
|
||||
{
|
||||
size_t size;
|
||||
string units;
|
||||
FormatMapSize(m_accessor->GetMapSize(), units, size);
|
||||
return strings::Format(GetLocalizedString(DownloadMapButtonID), size, units);
|
||||
}
|
||||
|
||||
string CountryStatusHelper::FormatDownloadMapRouting()
|
||||
{
|
||||
size_t size;
|
||||
string units;
|
||||
FormatMapSize(m_accessor->GetMapSize() + m_accessor->GetRoutingSize(), units, size);
|
||||
return strings::Format(GetLocalizedString(DownloadMapRoutingButtonID), size, units);
|
||||
}
|
||||
|
||||
string CountryStatusHelper::FormatInQueueMap()
|
||||
{
|
||||
return strings::Format(GetLocalizedString(InQueueID), m_accessor->GetCurrentCountryName());
|
||||
}
|
||||
|
||||
string CountryStatusHelper::FormatFailed()
|
||||
{
|
||||
return strings::Format(GetLocalizedString(DownloadingFailedID), m_accessor->GetCurrentCountryName());
|
||||
}
|
||||
|
||||
string CountryStatusHelper::FormatTryAgain()
|
||||
{
|
||||
return GetLocalizedString(TryAgainButtonID);
|
||||
}
|
||||
|
||||
} // namespace gui
|
||||
|
|
|
@ -1,28 +1,62 @@
|
|||
#pragma once
|
||||
|
||||
#include "../drape/pointers.hpp"
|
||||
|
||||
#include "../base/buffer_vector.hpp"
|
||||
|
||||
#include "../std/string.hpp"
|
||||
#include "../std/unique_ptr.hpp"
|
||||
|
||||
namespace storage { struct TIndex; }
|
||||
|
||||
namespace gui
|
||||
{
|
||||
|
||||
class StorageAccessor;
|
||||
|
||||
class CountryStatusHelper
|
||||
{
|
||||
public:
|
||||
enum ControlType
|
||||
enum ECountryState
|
||||
{
|
||||
Label,
|
||||
Button,
|
||||
Progress
|
||||
COUNTRY_STATE_EMPTY,
|
||||
COUNTRY_STATE_LOADED,
|
||||
COUNTRY_STATE_LOADING,
|
||||
COUNTRY_STATE_IN_QUEUE,
|
||||
COUNTRY_STATE_FAILED
|
||||
};
|
||||
|
||||
enum EControlType
|
||||
{
|
||||
CONTROL_TYPE_LABEL,
|
||||
CONTROL_TYPE_BUTTON,
|
||||
CONTROL_TYPE_PROGRESS
|
||||
};
|
||||
|
||||
enum EButtonType
|
||||
{
|
||||
BUTTON_TYPE_NOT_BUTTON,
|
||||
BUTTON_TYPE_MAP,
|
||||
BUTTON_TYPE_MAP_ROUTING,
|
||||
BUTTON_TRY_AGAIN
|
||||
};
|
||||
|
||||
struct Control
|
||||
{
|
||||
string m_label;
|
||||
ControlType m_type;
|
||||
EControlType m_type;
|
||||
EButtonType m_buttonType;
|
||||
};
|
||||
|
||||
CountryStatusHelper();
|
||||
|
||||
void SetStorageAccessor(dp::RefPointer<StorageAccessor> accessor);
|
||||
void SetCountryIndex(storage::TIndex const & index);
|
||||
|
||||
void SetState(ECountryState state);
|
||||
ECountryState GetState() const;
|
||||
bool IsVisibleForState(ECountryState state) const;
|
||||
|
||||
size_t GetComponentCount() const;
|
||||
Control const & GetControl(size_t index) const;
|
||||
static float GetControlMargin();
|
||||
|
@ -30,11 +64,23 @@ public:
|
|||
static void GetProgressInfo(string & alphabet, size_t & maxLength);
|
||||
string GetProgressValue() const;
|
||||
|
||||
int GetState() const;
|
||||
bool IsVisibleForState(int state) const;
|
||||
private:
|
||||
void FillControlsForState();
|
||||
void FillControlsForEmpty();
|
||||
void FillControlsForLoading();
|
||||
void FillControlsForInQueue();
|
||||
void FillControlsForFailed();
|
||||
|
||||
string FormatDownloadMap();
|
||||
string FormatDownloadMapRouting();
|
||||
string FormatInQueueMap();
|
||||
string FormatFailed();
|
||||
string FormatTryAgain();
|
||||
|
||||
private:
|
||||
ECountryState m_state;
|
||||
buffer_vector<Control, 4> m_controls;
|
||||
dp::RefPointer<StorageAccessor> m_accessor;
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
|
|
|
@ -7,10 +7,19 @@
|
|||
namespace gui
|
||||
{
|
||||
|
||||
void StorageAccessor::SetStatusChangedCallback(TSlotFn const & fn)
|
||||
{
|
||||
m_statusChanged = fn;
|
||||
}
|
||||
|
||||
struct DrapeGui::Impl
|
||||
{
|
||||
DrapeGui::TScaleFactorFn m_scaleFn;
|
||||
DrapeGui::TGeneralizationLevelFn m_gnLvlFn;
|
||||
DrapeGui::TLocalizeStringFn m_localizeFn;
|
||||
|
||||
DrapeGui::TRecacheSlot m_recacheSlot;
|
||||
|
||||
RulerHelper m_rulerHelper;
|
||||
CountryStatusHelper m_countryHelper;
|
||||
};
|
||||
|
@ -39,6 +48,12 @@ void DrapeGui::Init(TScaleFactorFn const & scaleFn, TGeneralizationLevelFn const
|
|||
m_impl->m_gnLvlFn = gnLvlFn;
|
||||
}
|
||||
|
||||
void DrapeGui::SetLocalizator(const DrapeGui::TLocalizeStringFn & fn)
|
||||
{
|
||||
ASSERT(m_impl != nullptr, ());
|
||||
m_impl->m_localizeFn = fn;
|
||||
}
|
||||
|
||||
double DrapeGui::GetScaleFactor()
|
||||
{
|
||||
ASSERT(m_impl != nullptr, ());
|
||||
|
@ -51,6 +66,48 @@ int DrapeGui::GetGeneralization(ScreenBase const & screen)
|
|||
return m_impl->m_gnLvlFn(screen);
|
||||
}
|
||||
|
||||
void DrapeGui::SetRecacheSlot(DrapeGui::TRecacheSlot const & fn)
|
||||
{
|
||||
ASSERT(m_impl != nullptr, ());
|
||||
m_impl->m_recacheSlot = fn;
|
||||
}
|
||||
|
||||
void DrapeGui::EmitRecacheSignal(Skin::ElementName elements)
|
||||
{
|
||||
ASSERT(m_impl != nullptr, ());
|
||||
if (m_impl->m_recacheSlot)
|
||||
m_impl->m_recacheSlot(elements);
|
||||
}
|
||||
|
||||
void DrapeGui::ClearRecacheSlot()
|
||||
{
|
||||
SetRecacheSlot(TRecacheSlot());
|
||||
}
|
||||
|
||||
string DrapeGui::GetLocalizedString(string const & stringID) const
|
||||
{
|
||||
ASSERT(m_impl != nullptr, ());
|
||||
ASSERT(m_impl->m_localizeFn != nullptr, ());
|
||||
return m_impl->m_localizeFn(stringID);
|
||||
}
|
||||
|
||||
void DrapeGui::SetStorageAccessor(dp::RefPointer<StorageAccessor> accessor)
|
||||
{
|
||||
ASSERT(m_impl != nullptr, ());
|
||||
accessor->SetStatusChangedCallback([this]
|
||||
{
|
||||
SendRecacheSignal(Skin::CountryStatus);
|
||||
});
|
||||
|
||||
CountryStatusHelper & cntHelpet = GetCountryStatusHelperImpl();
|
||||
cntHelpet.SetStorageAccessor(accessor);
|
||||
}
|
||||
|
||||
void DrapeGui::SetCountryIndex(storage::TIndex const & index)
|
||||
{
|
||||
GetCountryStatusHelperImpl().SetCountryIndex(index);
|
||||
}
|
||||
|
||||
RulerHelper & DrapeGui::GetRulerHelperImpl()
|
||||
{
|
||||
ASSERT(m_impl != nullptr, ());
|
||||
|
@ -62,4 +119,12 @@ CountryStatusHelper & DrapeGui::GetCountryStatusHelperImpl()
|
|||
ASSERT(m_impl != nullptr, ());
|
||||
return m_impl->m_countryHelper;
|
||||
}
|
||||
|
||||
void DrapeGui::SendRecacheSignal(Skin::ElementName elemetns)
|
||||
{
|
||||
ASSERT(m_impl != nullptr, ());
|
||||
if (m_impl->m_recacheSlot)
|
||||
m_impl->m_recacheSlot(elemetns);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include "skin.hpp"
|
||||
|
||||
#include "../storage/index.hpp"
|
||||
#include "../storage/storage_defines.hpp"
|
||||
|
||||
#include "../drape/pointers.hpp"
|
||||
|
||||
#include "../std/function.hpp"
|
||||
#include "../std/unique_ptr.hpp"
|
||||
|
||||
|
@ -7,28 +14,63 @@ class ScreenBase;
|
|||
|
||||
namespace gui
|
||||
{
|
||||
|
||||
class RulerHelper;
|
||||
class CountryStatusHelper;
|
||||
|
||||
class StorageAccessor
|
||||
{
|
||||
public:
|
||||
using TSlotFn = function<void (void)>;
|
||||
|
||||
virtual ~StorageAccessor() {}
|
||||
virtual string GetCurrentCountryName() const = 0;
|
||||
virtual size_t GetMapSize() const = 0;
|
||||
virtual size_t GetRoutingSize() const = 0;
|
||||
virtual size_t GetDownloadProgress() const = 0;
|
||||
|
||||
virtual void SetCountryIndex(storage::TIndex const & index) = 0;
|
||||
virtual storage::TIndex GetCountryIndex() const = 0;
|
||||
virtual storage::TStatus GetCountryStatus() const = 0;
|
||||
|
||||
void SetStatusChangedCallback(TSlotFn const & fn);
|
||||
|
||||
protected:
|
||||
TSlotFn m_statusChanged;
|
||||
};
|
||||
|
||||
class DrapeGui
|
||||
{
|
||||
public:
|
||||
|
||||
typedef function<double ()> TScaleFactorFn;
|
||||
typedef function<int (ScreenBase const &)> TGeneralizationLevelFn;
|
||||
using TRecacheSlot = function<void (Skin::ElementName)>;
|
||||
using TScaleFactorFn = function<double ()>;
|
||||
using TGeneralizationLevelFn = function<int (ScreenBase const &)>;
|
||||
using TLocalizeStringFn = function<string (string const &)>;
|
||||
|
||||
static DrapeGui & Instance();
|
||||
static RulerHelper & GetRulerHelper();
|
||||
static CountryStatusHelper & GetCountryStatusHelper();
|
||||
|
||||
void Init(TScaleFactorFn const & scaleFn, TGeneralizationLevelFn const & gnLvlFn);
|
||||
void SetLocalizator(TLocalizeStringFn const & fn);
|
||||
void SetStorageAccessor(dp::RefPointer<gui::StorageAccessor> accessor);
|
||||
|
||||
void SetCountryIndex(storage::TIndex const & index);
|
||||
|
||||
double GetScaleFactor();
|
||||
int GetGeneralization(ScreenBase const & screen);
|
||||
string GetLocalizedString(string const & stringID) const;
|
||||
|
||||
void SetRecacheSlot(TRecacheSlot const & fn);
|
||||
void EmitRecacheSignal(Skin::ElementName elements);
|
||||
void ClearRecacheSlot();
|
||||
|
||||
private:
|
||||
RulerHelper & GetRulerHelperImpl();
|
||||
CountryStatusHelper & GetCountryStatusHelperImpl();
|
||||
|
||||
void SendRecacheSignal(Skin::ElementName elements);
|
||||
|
||||
private:
|
||||
struct Impl;
|
||||
unique_ptr<Impl> m_impl;
|
||||
|
|
|
@ -156,23 +156,23 @@ void StaticLabel::CacheStaticText(string const & text, char const * delim,
|
|||
float textRatio = font.m_size * DrapeGui::Instance().GetScaleFactor() / BASE_GLYPH_HEIGHT;
|
||||
|
||||
buffer_vector<float, 4> lineLengths;
|
||||
lineLengths.resize(buffers.size());
|
||||
lineLengths.reserve(buffers.size());
|
||||
|
||||
buffer_vector<size_t, 4> ranges;
|
||||
ranges.reserve(buffers.size());
|
||||
|
||||
float fullHeight = 0.0;
|
||||
float prevLineHeight = 0.0;
|
||||
float firstLineHeight = 0.0;
|
||||
|
||||
buffer_vector<Vertex, 128> & rb = result.m_buffer;
|
||||
|
||||
for (size_t i = 0; i < buffers.size(); ++i)
|
||||
for (int i = static_cast<int>(buffers.size()) - 1; i >= 0; --i)
|
||||
{
|
||||
dp::TextureManager::TGlyphsBuffer & regions = buffers[i];
|
||||
float & currentLineLength = lineLengths[i];
|
||||
lineLengths.push_back(0.0f);
|
||||
float & currentLineLength = lineLengths.back();
|
||||
|
||||
float depth = 0.0;
|
||||
glsl::vec2 pen(0.0, prevLineHeight);
|
||||
glsl::vec2 pen(0.0, -fullHeight);
|
||||
prevLineHeight = 0.0;
|
||||
for (size_t j = 0; j < regions.size(); ++j)
|
||||
{
|
||||
|
@ -202,19 +202,16 @@ void StaticLabel::CacheStaticText(string const & text, char const * delim,
|
|||
|
||||
ranges.push_back(rb.size());
|
||||
|
||||
if (i == 0)
|
||||
firstLineHeight = prevLineHeight;
|
||||
|
||||
fullHeight += prevLineHeight;
|
||||
}
|
||||
|
||||
float const halfHeight = fullHeight / 2.0f;
|
||||
float const halfHeight = 0.5f * fullHeight;
|
||||
|
||||
float yOffset = firstLineHeight - fullHeight / 2.0f;
|
||||
float yOffset = halfHeight;
|
||||
if (anchor & dp::Top)
|
||||
yOffset = firstLineHeight;
|
||||
yOffset = fullHeight;
|
||||
else if (anchor & dp::Bottom)
|
||||
yOffset -= halfHeight;
|
||||
yOffset = 0.0f;
|
||||
|
||||
size_t startIndex = 0;
|
||||
for (size_t i = 0; i < ranges.size(); ++i)
|
||||
|
|
|
@ -89,6 +89,9 @@ void LayerRenderer::DestroyRenderers()
|
|||
void LayerRenderer::AddShapeRenderer(Skin::ElementName name,
|
||||
dp::TransferPointer<ShapeRenderer> shape)
|
||||
{
|
||||
if (shape.IsNull())
|
||||
return;
|
||||
|
||||
VERIFY(m_renderers.insert(make_pair(name, dp::MasterPointer<ShapeRenderer>(shape))).second, ());
|
||||
}
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ public:
|
|||
void RetryDownloading(TGroup const & group, int position);
|
||||
void RetryDownloading(TIndex const & index);
|
||||
|
||||
///@{ For CountryStatusDisplay only
|
||||
///@{ For CountryStatus only
|
||||
TIndex const & GetCoreIndex(TGroup const & group, int position) const;
|
||||
string const GetFormatedCountryName(TIndex const & index) const;
|
||||
///@}
|
||||
|
@ -95,15 +95,16 @@ public:
|
|||
|
||||
void ShowMap(TGroup const & group, int position);
|
||||
|
||||
/// @param[in] Sorted vector of current .mwm files.
|
||||
using TLocalFilePtr = shared_ptr<platform::LocalCountryFile>;
|
||||
void Init(vector<TLocalFilePtr> const & files);
|
||||
void Clear();
|
||||
|
||||
private:
|
||||
friend class CountryTree;
|
||||
Storage const & GetStorage() const;
|
||||
Storage & GetStorage();
|
||||
|
||||
using TLocalFilePtr = shared_ptr<platform::LocalCountryFile>;
|
||||
void Init(vector<TLocalFilePtr> const & files);
|
||||
void Clear();
|
||||
|
||||
void ShowMap(TIndex const & index);
|
||||
|
||||
void StatusChangedCallback(TIndex const & index);
|
||||
|
|
|
@ -40,9 +40,9 @@ inline TIndex GetIndexParent(TIndex const & index)
|
|||
return parent;
|
||||
}
|
||||
|
||||
CountryTree::CountryTree(Framework & framework)
|
||||
CountryTree::CountryTree(shared_ptr<ActiveMapsLayout> activeMaps)
|
||||
{
|
||||
m_layout.reset(new ActiveMapsLayout(framework));
|
||||
m_layout = activeMaps;
|
||||
ConnectToCoreStorage();
|
||||
}
|
||||
|
||||
|
@ -65,19 +65,6 @@ CountryTree & CountryTree::operator=(CountryTree const & other)
|
|||
return *this;
|
||||
}
|
||||
|
||||
void CountryTree::Init(vector<ActiveMapsLayout::TLocalFilePtr> const & maps)
|
||||
{
|
||||
ASSERT(IsValid(), ());
|
||||
m_layout->Init(maps);
|
||||
}
|
||||
|
||||
void CountryTree::Clear()
|
||||
{
|
||||
ASSERT(IsValid(), ());
|
||||
ResetRoot();
|
||||
m_layout->Clear();
|
||||
}
|
||||
|
||||
ActiveMapsLayout & CountryTree::GetActiveMapLayout()
|
||||
{
|
||||
ASSERT(IsValid(), ());
|
||||
|
|
|
@ -31,17 +31,13 @@ public:
|
|||
};
|
||||
|
||||
CountryTree() = default;
|
||||
explicit CountryTree(Framework & framework);
|
||||
explicit CountryTree(shared_ptr<ActiveMapsLayout> activeMaps);
|
||||
|
||||
CountryTree(CountryTree const & other) = delete;
|
||||
~CountryTree();
|
||||
|
||||
CountryTree & operator=(CountryTree const & other);
|
||||
|
||||
/// @param[in] Sorted vector of current .mwm files.
|
||||
void Init(vector<ActiveMapsLayout::TLocalFilePtr> const & maps);
|
||||
void Clear();
|
||||
|
||||
ActiveMapsLayout & GetActiveMapLayout();
|
||||
ActiveMapsLayout const & GetActiveMapLayout() const;
|
||||
|
||||
|
@ -96,7 +92,7 @@ private:
|
|||
|
||||
private:
|
||||
int m_subscribeSlotID = 0;
|
||||
mutable shared_ptr<ActiveMapsLayout> m_layout;
|
||||
shared_ptr<ActiveMapsLayout> m_layout;
|
||||
|
||||
buffer_vector<TIndex, 16> m_levelItems;
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "map/geourl_process.hpp"
|
||||
#include "map/ge0_parser.hpp"
|
||||
#include "map/storage_bridge.hpp"
|
||||
|
||||
#include "defines.hpp"
|
||||
|
||||
|
@ -165,7 +166,6 @@ Framework::Framework()
|
|||
m_queryMaxScaleMode(false),
|
||||
m_width(0),
|
||||
m_height(0),
|
||||
m_countryTree(*this),
|
||||
m_animController(new anim::Controller),
|
||||
m_informationDisplay(this),
|
||||
m_bmManager(*this),
|
||||
|
@ -173,6 +173,10 @@ Framework::Framework()
|
|||
m_fixedSearchResults(0),
|
||||
m_locationChangedSlotID(-1)
|
||||
{
|
||||
m_activeMaps.reset(new ActiveMapsLayout(*this));
|
||||
m_globalCntTree = storage::CountryTree(m_activeMaps);
|
||||
m_storageAccessor.Reset(new StorageBridge(m_activeMaps));
|
||||
|
||||
// Restore map style before classificator loading
|
||||
int mapStyle = MapStyleLight;
|
||||
if (!Settings::Get(kMapStyleKey, mapStyle))
|
||||
|
@ -1360,22 +1364,35 @@ bool Framework::GetDistanceAndAzimut(m2::PointD const & point,
|
|||
|
||||
void Framework::CreateDrapeEngine(dp::RefPointer<dp::OGLContextFactory> contextFactory, float vs, int w, int h)
|
||||
{
|
||||
typedef df::MapDataProvider::TReadIDsFn TReadIDsFn;
|
||||
typedef df::MapDataProvider::TReadFeaturesFn TReadFeaturesFn;
|
||||
typedef df::MapDataProvider::TReadIdCallback TReadIdCallback;
|
||||
typedef df::MapDataProvider::TReadFeatureCallback TReadFeatureCallback;
|
||||
using TReadIDsFn = df::MapDataProvider::TReadIDsFn;
|
||||
using TReadFeaturesFn = df::MapDataProvider::TReadFeaturesFn;
|
||||
using TReadIdCallback = df::MapDataProvider::TReadIdCallback;
|
||||
using TReadFeatureCallback = df::MapDataProvider::TReadFeatureCallback;
|
||||
using TResolveCountryFn = df::MapDataProvider::TResolveCountryFn;
|
||||
|
||||
TReadIDsFn idReadFn = [this](TReadIdCallback const & fn, m2::RectD const & r, int scale)
|
||||
TReadIDsFn idReadFn = [this](TReadIdCallback const & fn, m2::RectD const & r, int scale) -> void
|
||||
{
|
||||
m_model.ForEachFeatureID(r, fn, scale);
|
||||
};
|
||||
|
||||
TReadFeaturesFn featureReadFn = [this](TReadFeatureCallback const & fn, vector<FeatureID> const & ids)
|
||||
TReadFeaturesFn featureReadFn = [this](TReadFeatureCallback const & fn, vector<FeatureID> const & ids) -> void
|
||||
{
|
||||
m_model.ReadFeatures(fn, ids);
|
||||
};
|
||||
|
||||
m_drapeEngine.Reset(new df::DrapeEngine(contextFactory, df::Viewport(0, 0, w, h), df::MapDataProvider(idReadFn, featureReadFn), vs));
|
||||
TResolveCountryFn resolveCountry = [this](m2::PointF const & pt) -> TIndex
|
||||
{
|
||||
return GetCountryIndex(m2::PointD(pt));
|
||||
};
|
||||
|
||||
df::DrapeEngine::Params p(contextFactory,
|
||||
dp::MakeStackRefPointer(&m_stringsBundle),
|
||||
m_storageAccessor.GetRefPointer(),
|
||||
df::Viewport(0, 0, w, h),
|
||||
df::MapDataProvider(idReadFn, featureReadFn, resolveCountry),
|
||||
vs);
|
||||
|
||||
m_drapeEngine.Reset(new df::DrapeEngine(p));
|
||||
OnSize(w, h);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,24 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
#include "map/active_maps_layout.hpp"
|
||||
#include "map/animator.hpp"
|
||||
#include "map/bookmark.hpp"
|
||||
#include "map/bookmark_manager.hpp"
|
||||
#include "map/country_tree.hpp"
|
||||
#include "map/events.hpp"
|
||||
#include "drape/oglcontextfactory.hpp"
|
||||
#include "drape_frontend/drape_engine.hpp"
|
||||
#include "map/feature_vec_model.hpp"
|
||||
#include "map/information_display.hpp"
|
||||
#include "map/location_state.hpp"
|
||||
#include "map/navigator.hpp"
|
||||
#include "map/animator.hpp"
|
||||
|
||||
#include "map/api_mark_container.hpp"
|
||||
#include "map/api_mark_point.hpp"
|
||||
#include "map/bookmark.hpp"
|
||||
#include "map/bookmark_manager.hpp"
|
||||
#include "map/pin_click_manager.hpp"
|
||||
|
||||
#include "map/mwm_url.hpp"
|
||||
#include "map/move_screen_task.hpp"
|
||||
#include "map/mwm_url.hpp"
|
||||
#include "map/navigator.hpp"
|
||||
#include "map/pin_click_manager.hpp"
|
||||
#include "map/routing_session.hpp"
|
||||
#include "map/track.hpp"
|
||||
#include "map/country_tree.hpp"
|
||||
|
||||
#include "drape_frontend/drape_engine.hpp"
|
||||
#include "drape/oglcontextfactory.hpp"
|
||||
|
||||
#include "indexer/data_header.hpp"
|
||||
#include "indexer/map_style.hpp"
|
||||
|
@ -59,6 +58,8 @@ class CountryInfoGetter;
|
|||
namespace anim { class Controller; }
|
||||
namespace routing { namespace turns{ class Settings; } }
|
||||
|
||||
namespace gui { class StorageAccessor; }
|
||||
|
||||
/// Uncomment line to make fixed position settings and
|
||||
/// build version for screenshots.
|
||||
//#define FIXED_LOCATION
|
||||
|
@ -105,6 +106,7 @@ protected:
|
|||
|
||||
typedef vector<BookmarkCategory *>::iterator CategoryIter;
|
||||
|
||||
dp::MasterPointer<gui::StorageAccessor> m_storageAccessor;
|
||||
dp::MasterPointer<df::DrapeEngine> m_drapeEngine;
|
||||
|
||||
double m_startForegroundTime;
|
||||
|
@ -117,7 +119,8 @@ protected:
|
|||
void StopLocationFollow();
|
||||
|
||||
storage::Storage m_storage;
|
||||
storage::CountryTree m_countryTree;
|
||||
shared_ptr<storage::ActiveMapsLayout> m_activeMaps;
|
||||
storage::CountryTree m_globalCntTree;
|
||||
unique_ptr<anim::Controller> m_animController;
|
||||
InformationDisplay m_informationDisplay;
|
||||
|
||||
|
@ -237,7 +240,8 @@ public:
|
|||
inline m2::PointD GtoP(m2::PointD const & p) const { return m_navigator.GtoP(p); }
|
||||
|
||||
storage::Storage & Storage() { return m_storage; }
|
||||
storage::CountryTree & GetCountryTree() { return m_countryTree; }
|
||||
shared_ptr<storage::ActiveMapsLayout> & GetActiveMaps() { return m_activeMaps; }
|
||||
storage::CountryTree & GetCountryTree() { return m_globalCntTree; }
|
||||
|
||||
/// @name GPS location updates routine.
|
||||
//@{
|
||||
|
|
13
map/map.pro
13
map/map.pro
|
@ -20,6 +20,7 @@ HEADERS += \
|
|||
change_viewport_task.hpp \
|
||||
compass_arrow.hpp \
|
||||
country_tree.hpp \
|
||||
events.hpp \
|
||||
feature_vec_model.hpp \
|
||||
framework.hpp \
|
||||
ge0_parser.hpp \
|
||||
|
@ -29,15 +30,16 @@ HEADERS += \
|
|||
move_screen_task.hpp \
|
||||
mwm_url.hpp \
|
||||
navigator.hpp \
|
||||
navigator_utils.hpp \
|
||||
pin_click_manager.hpp \
|
||||
rotate_screen_task.hpp \
|
||||
route_track.hpp \
|
||||
routing_session.hpp \
|
||||
storage_bridge.hpp \
|
||||
track.hpp \
|
||||
user_mark.hpp \
|
||||
user_mark_container.hpp \
|
||||
|
||||
SOURCES += \
|
||||
../api/src/c/api-client.c \
|
||||
../api/src/c/api-client.c \
|
||||
active_maps_layout.cpp \
|
||||
address_finder.cpp \
|
||||
alfa_animation_task.cpp \
|
||||
|
@ -57,9 +59,10 @@ SOURCES += \
|
|||
move_screen_task.cpp \
|
||||
mwm_url.cpp \
|
||||
navigator.cpp \
|
||||
navigator_utils.cpp \
|
||||
pin_click_manager.cpp \
|
||||
rotate_screen_task.cpp \
|
||||
route_track.cpp \
|
||||
routing_session.cpp \
|
||||
storage_bridge.cpp \
|
||||
track.cpp \
|
||||
user_mark_container.cpp \
|
||||
|
||||
|
|
86
map/storage_bridge.cpp
Normal file
86
map/storage_bridge.cpp
Normal file
|
@ -0,0 +1,86 @@
|
|||
#include "storage_bridge.hpp"
|
||||
|
||||
using namespace storage;
|
||||
|
||||
StorageBridge::StorageBridge(shared_ptr<storage::ActiveMapsLayout> activeMaps)
|
||||
: m_activeMaps(activeMaps)
|
||||
{
|
||||
}
|
||||
|
||||
string StorageBridge::GetCurrentCountryName() const
|
||||
{
|
||||
ASSERT(m_currentIndex != TIndex(), ());
|
||||
return m_activeMaps->GetFormatedCountryName(m_currentIndex);
|
||||
}
|
||||
|
||||
size_t StorageBridge::GetMapSize() const
|
||||
{
|
||||
ASSERT(m_currentIndex != TIndex(), ());
|
||||
return m_activeMaps->GetRemoteCountrySizes(m_currentIndex).first;
|
||||
}
|
||||
|
||||
size_t StorageBridge::GetRoutingSize() const
|
||||
{
|
||||
ASSERT(m_currentIndex != TIndex(), ());
|
||||
return m_activeMaps->GetRemoteCountrySizes(m_currentIndex).second;
|
||||
}
|
||||
|
||||
size_t StorageBridge::GetDownloadProgress() const
|
||||
{
|
||||
if (m_progress.second == 0)
|
||||
return 0;
|
||||
|
||||
return m_progress.first * 100 / m_progress.second;
|
||||
}
|
||||
|
||||
void StorageBridge::SetCountryIndex(storage::TIndex const & index)
|
||||
{
|
||||
m_currentIndex = index;
|
||||
}
|
||||
|
||||
storage::TIndex StorageBridge::GetCountryIndex() const
|
||||
{
|
||||
return m_currentIndex;
|
||||
}
|
||||
|
||||
storage::TStatus StorageBridge::GetCountryStatus() const
|
||||
{
|
||||
if (m_currentIndex == TIndex())
|
||||
return TStatus::EOnDisk;
|
||||
|
||||
return m_activeMaps->GetCountryStatus(m_currentIndex);
|
||||
}
|
||||
|
||||
void StorageBridge::CountryGroupChanged(ActiveMapsLayout::TGroup const & oldGroup, int oldPosition,
|
||||
ActiveMapsLayout::TGroup const & newGroup, int newPosition)
|
||||
{
|
||||
UNUSED_VALUE(oldGroup);
|
||||
UNUSED_VALUE(oldPosition);
|
||||
UNUSED_VALUE(newGroup);
|
||||
UNUSED_VALUE(newPosition);
|
||||
}
|
||||
|
||||
void StorageBridge::CountryStatusChanged(ActiveMapsLayout::TGroup const & group, int position,
|
||||
TStatus const & oldStatus, TStatus const & newStatus)
|
||||
{
|
||||
UNUSED_VALUE(oldStatus);
|
||||
UNUSED_VALUE(newStatus);
|
||||
if (m_activeMaps->GetCoreIndex(group, position) == m_currentIndex && m_statusChanged)
|
||||
m_statusChanged();
|
||||
}
|
||||
|
||||
void StorageBridge::CountryOptionsChanged(ActiveMapsLayout::TGroup const & group, int position,
|
||||
TMapOptions const & oldOpt, TMapOptions const & newOpt)
|
||||
{
|
||||
UNUSED_VALUE(group);
|
||||
UNUSED_VALUE(position);
|
||||
UNUSED_VALUE(oldOpt);
|
||||
UNUSED_VALUE(newOpt);
|
||||
}
|
||||
|
||||
void StorageBridge::DownloadingProgressUpdate(ActiveMapsLayout::TGroup const & group, int position,
|
||||
LocalAndRemoteSizeT const & progress)
|
||||
{
|
||||
if (m_activeMaps->GetCoreIndex(group, position) == m_currentIndex)
|
||||
m_progress = progress;
|
||||
}
|
38
map/storage_bridge.hpp
Normal file
38
map/storage_bridge.hpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
#pragma once
|
||||
|
||||
#include "active_maps_layout.hpp"
|
||||
|
||||
#include "../drape_gui/drape_gui.hpp"
|
||||
|
||||
#include "../storage/index.hpp"
|
||||
#include "../storage/storage_defines.hpp"
|
||||
|
||||
class StorageBridge : public gui::StorageAccessor
|
||||
, public storage::ActiveMapsLayout::ActiveMapsListener
|
||||
{
|
||||
public:
|
||||
StorageBridge(shared_ptr<storage::ActiveMapsLayout> activeMaps);
|
||||
|
||||
string GetCurrentCountryName() const override;
|
||||
size_t GetMapSize() const override;
|
||||
size_t GetRoutingSize() const override;
|
||||
size_t GetDownloadProgress() const override;
|
||||
|
||||
void SetCountryIndex(storage::TIndex const & index) override;
|
||||
storage::TIndex GetCountryIndex() const override;
|
||||
storage::TStatus GetCountryStatus() const override;
|
||||
|
||||
void CountryGroupChanged(storage::ActiveMapsLayout::TGroup const & oldGroup, int oldPosition,
|
||||
storage::ActiveMapsLayout::TGroup const & newGroup, int newPosition) override;
|
||||
void CountryStatusChanged(storage::ActiveMapsLayout::TGroup const & group, int position,
|
||||
storage::TStatus const & oldStatus, storage::TStatus const & newStatus) override;
|
||||
void CountryOptionsChanged(storage::ActiveMapsLayout::TGroup const & group, int position,
|
||||
storage::TMapOptions const & oldOpt, storage::TMapOptions const & newOpt) override;
|
||||
void DownloadingProgressUpdate(storage::ActiveMapsLayout::TGroup const & group, int position,
|
||||
storage::LocalAndRemoteSizeT const & progress) override;
|
||||
|
||||
private:
|
||||
storage::TIndex m_currentIndex;
|
||||
shared_ptr<storage::ActiveMapsLayout> m_activeMaps;
|
||||
storage::LocalAndRemoteSizeT m_progress;
|
||||
};
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include "qt/slider_ctrl.hpp"
|
||||
|
||||
#include "map/country_status_display.hpp"
|
||||
#include "drape_frontend/visual_params.hpp"
|
||||
|
||||
#include "render/render_policy.hpp"
|
||||
|
@ -56,19 +55,9 @@ namespace qt
|
|||
manager.ConnectUserMarkListener(bind(&DrawWidget::OnActivateMark, this, _1));
|
||||
manager.ConnectDismissListener(&DummyDismiss);
|
||||
|
||||
///@TODO UVR
|
||||
//m_framework->GetCountryStatusDisplay()->SetDownloadCountryListener([this] (storage::TIndex const & idx, int opt)
|
||||
//{
|
||||
// storage::ActiveMapsLayout & layout = m_framework->GetCountryTree().GetActiveMapLayout();
|
||||
// if (opt == -1)
|
||||
// layout.RetryDownloading(idx);
|
||||
// else
|
||||
// layout.DownloadMap(idx, static_cast<storage::TMapOptions>(opt));
|
||||
//});
|
||||
|
||||
//m_framework->SetRouteBuildingListener([] (routing::IRouter::ResultCode, vector<storage::TIndex> const &)
|
||||
//{
|
||||
//});
|
||||
m_framework->SetRouteBuildingListener([] (routing::IRouter::ResultCode, vector<storage::TIndex> const &)
|
||||
{
|
||||
});
|
||||
}
|
||||
|
||||
DrawWidget::~DrawWidget()
|
||||
|
|
Loading…
Add table
Reference in a new issue