From 8aade1efab87c57cd90aca32aee009fcbe7fbde4 Mon Sep 17 00:00:00 2001 From: ExMix Date: Thu, 5 Mar 2015 15:02:07 +0300 Subject: [PATCH] [drape] move some files to resolve denepdencies --- drape/drape_common.pri | 2 + drape/drape_global.hpp | 17 + drape/drape_tests/drape_tests.pro | 3 +- .../drape_tests}/fribidi_tests.cpp | 3 +- .../fribidi.hpp => drape/fribidi.cpp | 4 +- drape/fribidi.hpp | 12 + drape_frontend/apply_feature_functors.cpp | 10 +- drape_frontend/drape_frontend.pro | 1 - .../drape_frontend_tests.pro | 3 +- drape_frontend/shape_view_params.hpp | 21 +- drape_frontend/text_layout.cpp | 3 +- drape_frontend/text_shape.cpp | 3 +- drape_frontend/text_shape.hpp | 2 +- drape_head/drape_head.pro | 2 +- indexer/indexer_tests/indexer_tests.pro | 1 + map/information_display.cpp | 1 - map/map.pro | 2 - map/ruler.cpp | 619 ------------------ map/ruler.hpp | 106 --- 19 files changed, 50 insertions(+), 765 deletions(-) rename {drape_frontend/drape_frontend_tests => drape/drape_tests}/fribidi_tests.cpp (91%) rename drape_frontend/fribidi.hpp => drape/fribidi.cpp (82%) create mode 100644 drape/fribidi.hpp delete mode 100644 map/ruler.cpp delete mode 100644 map/ruler.hpp diff --git a/drape/drape_common.pri b/drape/drape_common.pri index f08aad14cd..10270df72b 100644 --- a/drape/drape_common.pri +++ b/drape/drape_common.pri @@ -43,6 +43,7 @@ SOURCES += \ $$DRAPE_DIR/utils/vertex_decl.cpp \ $$DRAPE_DIR/utils/projection.cpp \ $$DRAPE_DIR/utils/gpu_mem_tracker.cpp \ + $$DRAPE_DIR/fribidi.cpp HEADERS += \ $$ROOT_DIR/3party/sdf_image/sdf_image.h \ @@ -92,3 +93,4 @@ HEADERS += \ $$DRAPE_DIR/utils/vertex_decl.hpp \ $$DRAPE_DIR/utils/projection.hpp \ $$DRAPE_DIR/utils/gpu_mem_tracker.hpp \ + $$DRAPE_DIR/fribidi.hpp diff --git a/drape/drape_global.hpp b/drape/drape_global.hpp index f9be7fd035..193a7c8732 100644 --- a/drape/drape_global.hpp +++ b/drape/drape_global.hpp @@ -1,5 +1,7 @@ #pragma once +#include "color.hpp" + namespace dp { @@ -38,4 +40,19 @@ enum LineJoin RoundJoin = 1, }; +struct FontDecl +{ + FontDecl() = default; + FontDecl(Color const & color, float size, Color const & outlineColor = Color::Transparent()) + : m_color(color) + , m_outlineColor(outlineColor) + , m_size(size) + { + } + + Color m_color = Color::Transparent(); + Color m_outlineColor = Color::Transparent(); + float m_size = 0; +}; + } diff --git a/drape/drape_tests/drape_tests.pro b/drape/drape_tests/drape_tests.pro index e71a26affa..f8c85faecb 100644 --- a/drape/drape_tests/drape_tests.pro +++ b/drape/drape_tests/drape_tests.pro @@ -4,7 +4,7 @@ CONFIG -= app_bundle TEMPLATE = app DEFINES += OGL_TEST_ENABLED GTEST_DONT_DEFINE_TEST COMPILER_TESTS -DEPENDENCIES = qt_tstfrm platform coding base gmock freetype expat tomcrypt +DEPENDENCIES = qt_tstfrm platform coding base gmock freetype fribidi expat tomcrypt ROOT_DIR = ../.. SHADER_COMPILE_ARGS = $$PWD/../shaders shader_index.txt shader_def include($$ROOT_DIR/common.pri) @@ -36,6 +36,7 @@ SOURCES += \ glyph_packer_test.cpp \ font_texture_tests.cpp \ img.cpp \ + fribidi_tests.cpp HEADERS += \ glmock_functions.hpp \ diff --git a/drape_frontend/drape_frontend_tests/fribidi_tests.cpp b/drape/drape_tests/fribidi_tests.cpp similarity index 91% rename from drape_frontend/drape_frontend_tests/fribidi_tests.cpp rename to drape/drape_tests/fribidi_tests.cpp index ac3e2a9464..4dd39af892 100644 --- a/drape_frontend/drape_frontend_tests/fribidi_tests.cpp +++ b/drape/drape_tests/fribidi_tests.cpp @@ -1,7 +1,8 @@ #include "base/SRC_FIRST.hpp" #include "testing/testing.hpp" -#include "drape_frontend/fribidi.hpp" +#include "drape/fribidi.hpp" + UNIT_TEST(FribidiDirection) { diff --git a/drape_frontend/fribidi.hpp b/drape/fribidi.cpp similarity index 82% rename from drape_frontend/fribidi.hpp rename to drape/fribidi.cpp index 184912fc24..49de159c02 100644 --- a/drape_frontend/fribidi.hpp +++ b/drape/fribidi.cpp @@ -1,5 +1,3 @@ -#pragma once - #include "base/string_utils.hpp" #include "3party/fribidi/lib/fribidi.h" @@ -7,7 +5,7 @@ namespace fribidi { -strings::UniString log2vis(strings::UniString const & str) +strings::UniString log2vis(const strings::UniString & str) { size_t const count = str.size(); if (count == 0) diff --git a/drape/fribidi.hpp b/drape/fribidi.hpp new file mode 100644 index 0000000000..6f5a8e0928 --- /dev/null +++ b/drape/fribidi.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include "../base/string_utils.hpp" + +#include "../3party/fribidi/lib/fribidi.h" + +namespace fribidi +{ + +strings::UniString log2vis(strings::UniString const & str); + +} diff --git a/drape_frontend/apply_feature_functors.cpp b/drape_frontend/apply_feature_functors.cpp index 69b6943b31..c68e4a292a 100644 --- a/drape_frontend/apply_feature_functors.cpp +++ b/drape_frontend/apply_feature_functors.cpp @@ -76,7 +76,7 @@ void Extract(::LineDefProto const * lineRule, } } -void CaptionDefProtoToFontDecl(CaptionDefProto const * capRule, df::FontDecl ¶ms) +void CaptionDefProtoToFontDecl(CaptionDefProto const * capRule, dp::FontDecl ¶ms) { params.m_color = ToDrapeColor(capRule->color()); params.m_size = max(8.0, capRule->height() * df::VisualParams::Instance().GetVisualScale()); @@ -122,7 +122,7 @@ void BaseApplyFeature::ExtractCaptionParams(CaptionDefProto const * primaryProto double depth, TextViewParams & params) const { - FontDecl decl; + dp::FontDecl decl; CaptionDefProtoToFontDecl(primaryProto, decl); params.m_anchor = GetAnchor(primaryProto); @@ -133,7 +133,7 @@ void BaseApplyFeature::ExtractCaptionParams(CaptionDefProto const * primaryProto if (secondaryProto) { - FontDecl auxDecl; + dp::FontDecl auxDecl; CaptionDefProtoToFontDecl(secondaryProto, auxDecl); params.m_secondaryText = m_captions.GetAuxText(); @@ -300,7 +300,7 @@ void ApplyLineFeature::ProcessRule(Stylist::rule_wrapper_t const & rule) if (pCaptionRule != NULL && pCaptionRule->height() > 2 && !m_captions.GetPathName().empty() && isWay) { - FontDecl fontDecl; + dp::FontDecl fontDecl; CaptionDefProtoToFontDecl(pCaptionRule, fontDecl); PathTextViewParams params; @@ -360,7 +360,7 @@ void ApplyLineFeature::Finish() viewParams.m_anchor = dp::Center; viewParams.m_featureID = FeatureID(); viewParams.m_primaryText = roadNumber; - viewParams.m_primaryTextFont = FontDecl(dp::Color::RoadNumberOutline(), textHeight, dp::Color::White()); + viewParams.m_primaryTextFont = dp::FontDecl(dp::Color::RoadNumberOutline(), textHeight, dp::Color::White()); m2::Spline::iterator it = m_spline.CreateIterator(); while (!it.BeginAgain()) diff --git a/drape_frontend/drape_frontend.pro b/drape_frontend/drape_frontend.pro index a0183c5e5a..870394452b 100644 --- a/drape_frontend/drape_frontend.pro +++ b/drape_frontend/drape_frontend.pro @@ -72,7 +72,6 @@ HEADERS += \ text_shape.hpp \ path_text_shape.hpp \ path_symbol_shape.hpp \ - fribidi.hpp \ text_layout.hpp \ intrusive_vector.hpp \ map_data_provider.hpp \ diff --git a/drape_frontend/drape_frontend_tests/drape_frontend_tests.pro b/drape_frontend/drape_frontend_tests/drape_frontend_tests.pro index ed8b75e58a..d93a63f41a 100644 --- a/drape_frontend/drape_frontend_tests/drape_frontend_tests.pro +++ b/drape_frontend/drape_frontend_tests/drape_frontend_tests.pro @@ -4,7 +4,7 @@ CONFIG += console warn_on CONFIG -= app_bundle TEMPLATE = app -DEPENDENCIES = drape_frontend coding platform drape base fribidi expat +DEPENDENCIES = drape_frontend coding platform drape base expat ROOT_DIR = ../.. include($$ROOT_DIR/common.pri) @@ -16,5 +16,4 @@ macx-* { SOURCES += \ ../../testing/testingmain.cpp \ memory_feature_index_tests.cpp \ - fribidi_tests.cpp \ object_pool_tests.cpp \ diff --git a/drape_frontend/shape_view_params.hpp b/drape_frontend/shape_view_params.hpp index 182e2ef676..fbd19e81bf 100644 --- a/drape_frontend/shape_view_params.hpp +++ b/drape_frontend/shape_view_params.hpp @@ -49,34 +49,19 @@ struct LineViewParams : CommonViewParams float m_baseGtoPScale; }; -struct FontDecl -{ - FontDecl() = default; - FontDecl(dp::Color const & color, float size, dp::Color const & outlineColor = dp::Color::Transparent()) - : m_color(color) - , m_outlineColor(outlineColor) - , m_size(size) - { - } - - dp::Color m_color = dp::Color::Transparent(); - dp::Color m_outlineColor = dp::Color::Transparent(); - float m_size = 0; -}; - struct TextViewParams : CommonViewParams { FeatureID m_featureID; - FontDecl m_primaryTextFont; + dp::FontDecl m_primaryTextFont; string m_primaryText; - FontDecl m_secondaryTextFont; + dp::FontDecl m_secondaryTextFont; string m_secondaryText; dp::Anchor m_anchor; }; struct PathTextViewParams : CommonViewParams { - FontDecl m_textFont; + dp::FontDecl m_textFont; string m_text; float m_baseGtoPScale; }; diff --git a/drape_frontend/text_layout.cpp b/drape_frontend/text_layout.cpp index 3b66ad7702..5964e3a869 100644 --- a/drape_frontend/text_layout.cpp +++ b/drape_frontend/text_layout.cpp @@ -1,8 +1,7 @@ #include "drape_frontend/text_layout.hpp" -#include "drape_frontend/fribidi.hpp" +#include "drape/fribidi.hpp" #include "drape/glsl_func.hpp" - #include "drape/overlay_handle.hpp" #include "std/numeric.hpp" diff --git a/drape_frontend/text_shape.cpp b/drape_frontend/text_shape.cpp index 2da4abf3e5..b30662a9b0 100644 --- a/drape_frontend/text_shape.cpp +++ b/drape_frontend/text_shape.cpp @@ -114,7 +114,7 @@ void TextShape::Draw(dp::RefPointer batcher, dp::RefPointer batcher, dp::RefPointer textures) const @@ -133,7 +133,6 @@ void TextShape::DrawSubString(StraightTextLayout const & layout, dynamicBuffer); dp::GLState state(gpu::TEXT_PROGRAM, dp::GLState::OverlayLayer); - state.SetBlending(dp::Blending(true)); ASSERT(color.GetTexture() == outline.GetTexture(), ()); state.SetColorTexture(color.GetTexture()); state.SetMaskTexture(layout.GetMaskTexture()); diff --git a/drape_frontend/text_shape.hpp b/drape_frontend/text_shape.hpp index 2978abd716..27aedaded3 100644 --- a/drape_frontend/text_shape.hpp +++ b/drape_frontend/text_shape.hpp @@ -18,7 +18,7 @@ public: void Draw(dp::RefPointer batcher, dp::RefPointer textures) const; private: - void DrawSubString(StraightTextLayout const & layout, df::FontDecl const & font, + void DrawSubString(StraightTextLayout const & layout, dp::FontDecl const & font, glsl::vec2 const & baseOffset, dp::RefPointer batcher, dp::RefPointer textures) const; diff --git a/drape_head/drape_head.pro b/drape_head/drape_head.pro index af680d973f..920b0ffec8 100644 --- a/drape_head/drape_head.pro +++ b/drape_head/drape_head.pro @@ -1,6 +1,6 @@ # Head project for drape develop and debuging ROOT_DIR = .. -DEPENDENCIES = map render drape_frontend anim drape indexer platform geometry coding base \ +DEPENDENCIES = map drape_frontend drape_gui anim drape indexer platform geometry coding base \ freetype expat protobuf jansson fribidi tomcrypt include($$ROOT_DIR/common.pri) diff --git a/indexer/indexer_tests/indexer_tests.pro b/indexer/indexer_tests/indexer_tests.pro index fa2b705834..d96eb346cc 100644 --- a/indexer/indexer_tests/indexer_tests.pro +++ b/indexer/indexer_tests/indexer_tests.pro @@ -37,3 +37,4 @@ SOURCES += \ test_polylines.cpp \ test_type.cpp \ visibility_test.cpp \ + measurement_tests.cpp \ diff --git a/map/information_display.cpp b/map/information_display.cpp index bebee28b39..876303bf82 100644 --- a/map/information_display.cpp +++ b/map/information_display.cpp @@ -2,7 +2,6 @@ #include "map/country_status_display.hpp" #include "map/compass_arrow.hpp" #include "map/framework.hpp" -#include "map/ruler.hpp" #include "map/alfa_animation_task.hpp" #include "anim/task.hpp" diff --git a/map/map.pro b/map/map.pro index 90a6a5170a..5c24938be1 100644 --- a/map/map.pro +++ b/map/map.pro @@ -33,7 +33,6 @@ HEADERS += \ navigator_utils.hpp \ pin_click_manager.hpp \ rotate_screen_task.hpp \ - ruler.hpp \ track.hpp \ user_mark.hpp \ user_mark_container.hpp \ @@ -63,7 +62,6 @@ SOURCES += \ navigator_utils.cpp \ pin_click_manager.cpp \ rotate_screen_task.cpp \ - ruler.cpp \ track.cpp \ user_mark.cpp \ user_mark_container.cpp \ diff --git a/map/ruler.cpp b/map/ruler.cpp deleted file mode 100644 index e539d3eb97..0000000000 --- a/map/ruler.cpp +++ /dev/null @@ -1,619 +0,0 @@ -#include "map/ruler.hpp" -#include "map/framework.hpp" -#include "map/alfa_animation_task.hpp" - -#include "anim/controller.hpp" - -#include "platform/measurement_utils.hpp" -#include "platform/settings.hpp" - -#include "indexer/mercator.hpp" - -#include "geometry/transformations.hpp" - -#include "base/string_utils.hpp" - -namespace -{ - static const int RulerHeight = 2; - static const int MinPixelWidth = 60; - static const int MinMetersWidth = 10; - static const int MaxMetersWidth = 1000000; - static const int CacheLength = 500; - - static const int MinUnitValue = -1; - static const int MaxUnitValue = numeric_limits::max() - 1; - static const int InvalidUnitValue = MaxUnitValue + 1; - - static const int TextOffsetFromRuler = 3; - - struct UnitValue - { - char const * m_s; - int m_i; - }; - - UnitValue g_arrFeets[] = { - { "10 ft", 10 }, - { "20 ft", 20 }, - { "50 ft", 50 }, - { "100 ft", 100 }, - { "200 ft", 200 }, - { "0.1 mi", 528 }, - { "0.2 mi", 528 * 2 }, - { "0.5 mi", 528 * 5 }, - { "1 mi", 5280 }, - { "2 mi", 2 * 5280 }, - { "5 mi", 5 * 5280 }, - { "10 mi", 10 * 5280 }, - { "20 mi", 20 * 5280 }, - { "50 mi", 50 * 5280 }, - { "100 mi", 100 * 5280 }, - { "200 mi", 200 * 5280 }, - { "500 mi", 500 * 5280 } - }; - - UnitValue g_arrMetres[] = { - { "1 m", 1 }, - { "2 m", 2 }, - { "5 m", 5 }, - { "10 m", 10 }, - { "20 m", 20 }, - { "50 m", 50 }, - { "100 m", 100 }, - { "200 m", 200 }, - { "500 m", 500 }, - { "1 km", 1000 }, - { "2 km", 2000 }, - { "5 km", 5000 }, - { "10 km", 10000 }, - { "20 km", 20000 }, - { "50 km", 50000 }, - { "100 km", 100000 }, - { "200 km", 200000 }, - { "500 km", 500000 }, - { "1000 km", 1000000 } - }; - - double identity(double val) - { - return val; - } -} - -// ========================================================= // -Ruler::RulerFrame::RulerFrame(Framework & f, const Ruler::RulerFrame::frame_end_fn & fn, double depth) - : m_f(f) - , m_textLengthInPx(0) - , m_scale(0.0) - , m_depth(depth) - , m_callback(fn) -{ -} - - -Ruler::RulerFrame::RulerFrame(const Ruler::RulerFrame & other, const Ruler::RulerFrame::frame_end_fn & fn) - : m_f(other.m_f) -{ - m_textLengthInPx = other.m_textLengthInPx; - m_scale = other.m_scale; - m_depth = other.m_depth; - m_orgPt = other.m_orgPt; - m_callback = fn; - - HideAnimate(false); -} - -Ruler::RulerFrame::~RulerFrame() -{ - if (m_frameAnim) - { - m_frameAnim->Cancel(); - m_frameAnim.reset(); - } - - Purge(); -} - -bool Ruler::RulerFrame::IsValid() const -{ - return false; -} - -///@TODO UVR -//void Ruler::RulerFrame::Cache(const string & text, FontDesc const & f) -//{ -// gui::Controller * controller = m_f.GetGuiController(); -// Screen * cs = controller->GetCacheScreen(); -// double const k = m_f.GetVisualScale(); - -// // Create solid line DL. -// if (m_dl == NULL) -// { -// m_dl.reset(cs->createDisplayList()); - -// cs->beginFrame(); -// cs->setDisplayList(m_dl.get()); -// cs->applyVarAlfaStates(); - -// m2::PointD coords[] = -// { -// /* 3*/ m2::PointD(0.0, -RulerHeight * k), -// /* 4*/ m2::PointD(0.0, 0.0), -// /*14*/ m2::PointD(CacheLength, -RulerHeight * k), -// /*15*/ m2::PointD(CacheLength, 0.0 * k), -// }; - -// Brush::Info const brushInfo(f.m_color); -// Resource const * brushRes = cs->fromID(cs->mapInfo(brushInfo)); -// m2::PointF const brushCenter = cs->pipeline(brushRes->m_pipelineID).texture()->mapPixel(brushRes->m_texRect.Center()); - -// m2::PointF normal(0.0, 0.0); -// cs->addTexturedStripStrided(coords , sizeof(m2::PointD), -// &normal, 0, -// &brushCenter, 0, ARRAY_SIZE(coords), -// m_depth, brushRes->m_pipelineID); - -// cs->setDisplayList(0); -// cs->applyStates(); -// cs->endFrame(); -// } - -// // Create text DL. - -// ASSERT(!text.empty(), ()); - -// { -// m_textDL.reset(); -// m_textDL.reset(cs->createDisplayList()); - -// cs->beginFrame(); -// cs->setDisplayList(m_textDL.get()); -// cs->applyVarAlfaStates(); - -// strings::UniString uniString = strings::MakeUniString(text); -// size_t length = uniString.size(); -// buffer_vector infos(length, Glyph::Info()); -// buffer_vector resInfos(length, NULL); -// buffer_vector ids(length, 0); -// buffer_vector glyphRes(length, NULL); - -// for (size_t i = 0; i < uniString.size(); ++i) -// { -// infos[i] = Glyph::Info(GlyphKey(uniString[i], f.m_size, false, f.m_color), -// controller->GetGlyphCache()); - -// resInfos[i] = &infos[i]; -// } - -// if (cs->mapInfo(resInfos.data(), ids.data(), infos.size())) -// { -// for (size_t i = 0; i < ids.size(); ++i) -// { -// Resource const * res = cs->fromID(ids[i]); -// glyphRes[i] = res; -// } - -// int32_t pipelineID = glyphRes[0]->m_pipelineID; -// shared_ptr texture = cs->pipeline(pipelineID).texture(); -// double lengthFromStart = 0.0; - -// buffer_vector coords; -// buffer_vector normals; -// buffer_vector texCoords; - -// for (size_t i = 0; i < uniString.size(); ++i) -// { -// double baseX = lengthFromStart; -// coords.push_back(m2::PointD(baseX, 0.0)); -// coords.push_back(m2::PointD(baseX, 0.0)); -// coords.push_back(m2::PointD(baseX, 0.0)); - -// coords.push_back(m2::PointD(baseX, 0.0)); -// coords.push_back(m2::PointD(baseX, 0.0)); -// coords.push_back(m2::PointD(baseX, 0.0)); - -// m2::RectI resourceRect(glyphRes[i]->m_texRect); -// resourceRect.Inflate(-1, -1); -// double w = resourceRect.SizeX(); -// double h = resourceRect.SizeY(); -// lengthFromStart += infos[i].m_metrics.m_xAdvance; - -// normals.push_back(m2::PointF(0.0, 0.0)); -// normals.push_back(m2::PointF(0.0, -h)); -// normals.push_back(m2::PointF(w , 0.0)); - -// normals.push_back(m2::PointF(w , 0.0)); -// normals.push_back(m2::PointF(0.0, -h)); -// normals.push_back(m2::PointF(w , -h)); - -// texCoords.push_back(texture->mapPixel(m2::PointF(resourceRect.minX(), resourceRect.maxY()))); -// texCoords.push_back(texture->mapPixel(m2::PointF(resourceRect.minX(), resourceRect.minY()))); -// texCoords.push_back(texture->mapPixel(m2::PointF(resourceRect.maxX(), resourceRect.maxY()))); - -// texCoords.push_back(texture->mapPixel(m2::PointF(resourceRect.maxX(), resourceRect.maxY()))); -// texCoords.push_back(texture->mapPixel(m2::PointF(resourceRect.minX(), resourceRect.minY()))); -// texCoords.push_back(texture->mapPixel(m2::PointF(resourceRect.maxX(), resourceRect.minY()))); -// } - -// m_textLengthInPx = lengthFromStart; -// cs->addTexturedListStrided(coords.data(), sizeof(m2::PointF), -// normals.data(), sizeof(m2::PointF), -// texCoords.data(), sizeof(m2::PointF), -// coords.size(), m_depth, pipelineID); -// } - -// cs->setDisplayList(0); -// cs->endFrame(); -// } -//} - -void Ruler::RulerFrame::Purge() -{ -} - -bool Ruler::RulerFrame::IsHidingAnim() const -{ - ASSERT(m_frameAnim != NULL, ()); - AlfaAnimationTask * a = static_cast(m_frameAnim.get()); - return a->IsHiding(); -} - -bool Ruler::RulerFrame::IsAnimActive() const -{ - return m_frameAnim != NULL; -} - -void Ruler::RulerFrame::SetScale(double scale) -{ - m_scale = scale; -} - -double Ruler::RulerFrame::GetScale() const -{ - return m_scale; -} - -void Ruler::RulerFrame::SetOrgPoint(const m2::PointD & org) -{ - m_orgPt = org; -} - -const m2::PointD &Ruler::RulerFrame::GetOrgPoint() const -{ - return m_orgPt; -} - -void Ruler::RulerFrame::ShowAnimate(bool needPause) -{ - double offset = (needPause == true) ? 0.07 : 0.0; - CreateAnim(IsAnimActive() ? GetCurrentAlfa() : 0.1, 1.0, 0.2, offset, true); -} - -void Ruler::RulerFrame::HideAnimate(bool needPause) -{ - double offset = (needPause == true) ? 1.0 : 0.0; - double timeInterval = (needPause == true) ? 0.3 : 0.15; - CreateAnim(1.0, 0.0, timeInterval, offset, false); -} - -///@TODO UVR -//void Ruler::RulerFrame::Draw(OverlayRenderer * r, const math::Matrix & m) -//{ -// ASSERT(m_dl, ()); -// ASSERT(m_textDL, ()); - -// UniformsHolder holder; -// holder.insertValue(ETransparency, GetCurrentAlfa()); - -// r->drawDisplayList(m_dl.get(), math::Shift( -// math::Scale(m, m2::PointD(m_scale, 1.0)), -// m_orgPt), &holder); - -// double const yOffset = -(2 + TextOffsetFromRuler * m_f.GetVisualScale()); -// r->drawDisplayList(m_textDL.get(), -// math::Shift(m, m_orgPt + m2::PointF(CacheLength * m_scale - m_textLengthInPx, yOffset)), -// &holder); -//} - -void Ruler::RulerFrame::CreateAnim(double startAlfa, double endAlfa, double timeInterval, double timeOffset, bool isVisibleAtEnd) -{ - anim::Controller * animController = m_f.GetAnimController(); - if (animController == NULL) - return; - - if (m_frameAnim) - m_frameAnim->Cancel(); - - m_frameAnim.reset(new AlfaAnimationTask(startAlfa, endAlfa, timeInterval, timeOffset, &m_f)); - m_frameAnim->AddCallback(anim::Task::EEnded, bind(&RulerFrame::AnimEnded, this, isVisibleAtEnd)); - animController->AddTask(m_frameAnim); -} - -float Ruler::RulerFrame::GetCurrentAlfa() -{ - if (m_frameAnim) - { - AlfaAnimationTask * a = static_cast(m_frameAnim.get()); - return a->GetCurrentAlfa(); - } - - return 1.0; -} - -void Ruler::RulerFrame::AnimEnded(bool isVisible) -{ - if (m_frameAnim != NULL) - { - m_frameAnim.reset(); - m_callback(isVisible, this); - } -} -// ========================================================= // - -double Ruler::CalcMetresDiff(double value) -{ - UnitValue * arrU = g_arrMetres; - int count = ARRAY_SIZE(g_arrMetres); - - typedef double (*ConversionFn)(double); - ConversionFn conversionFn = &identity; - - switch (m_currSystem) - { - default: - ASSERT_EQUAL ( m_currSystem, 0, () ); - break; - - case 1: - arrU = g_arrFeets; - count = ARRAY_SIZE(g_arrFeets); - conversionFn = &MeasurementUtils::MetersToFeet; - break; - } - - int prevUnitRange = m_currentRangeIndex; - string s; - double result = 0.0; - double v = conversionFn(value); - if (arrU[0].m_i > v) - { - m_currentRangeIndex = MinUnitValue; - s = string("< ") + arrU[0].m_s; - result = MinMetersWidth - 1.0; - } - else if (arrU[count-1].m_i <= v) - { - m_currentRangeIndex = MaxUnitValue; - s = string("> ") + arrU[count-1].m_s; - result = MaxMetersWidth + 1.0; - } - else - for (int i = 0; i < count; ++i) - { - if (arrU[i].m_i > v) - { - m_currentRangeIndex = i; - result = arrU[i].m_i / conversionFn(1.0); - s = arrU[i].m_s; - break; - } - } - - if (m_currentRangeIndex != prevUnitRange) - UpdateText(s); - return result; -} - -Ruler::Params::Params() - : m_framework(0) -{} - -Ruler::Ruler(Params const & p) - : m_currentRangeIndex(InvalidUnitValue), - m_currSystem(0), - m_framework(p.m_framework) -{ - ///@TODO UVR - //setIsVisible(false); -} - -void Ruler::AnimateShow() -{ - ///@TODO UVR -// RulerFrame * frame = GetMainFrame(); -// if (!isVisible() && (!frame->IsAnimActive() || frame->IsHidingAnim())) -// { -// setIsVisible(true); -// frame->ShowAnimate(false); -// m_framework->Invalidate(); -// } -// else if (isVisible() && (frame->IsAnimActive() && frame->IsHidingAnim())) -// { -// frame->ShowAnimate(false); -// m_framework->Invalidate(); -// } -} - -void Ruler::AnimateHide() -{ - ///@TODO UVR -// RulerFrame * frame = GetMainFrame(); -// if (isVisible() && (!frame->IsAnimActive() || !frame->IsHidingAnim())) -// { -// frame->HideAnimate(true); -// m_framework->Invalidate(); -// } -} - -void Ruler::layout() -{ - Settings::Units units = Settings::Metric; - Settings::Get("Units", units); - - int prevCurrSystem = m_currSystem; - switch (units) - { - default: - ASSERT_EQUAL ( units, Settings::Metric, () ); - m_currSystem = 0; - break; - case Settings::Foot: - m_currSystem = 1; - break; - } - - if (prevCurrSystem != m_currSystem) - m_currentRangeIndex = InvalidUnitValue; - - update(); -} - -void Ruler::UpdateText(const string & text) -{ - ///@TODO UVR -// RulerFrame * frame = GetMainFrame(); -// if (frame->IsAnimActive() && frame->IsHidingAnim()) -// return; - -// if (frame->IsValid()) -// m_animFrame.reset(new RulerFrame(*frame, bind(&Ruler::AnimFrameAnimEnded, this, _1, _2))); - -// frame->Cache(text, font(EActive)); -// if (isVisible()) -// frame->ShowAnimate(true); -} - -void Ruler::MainFrameAnimEnded(bool isVisible, RulerFrame * frame) -{ - ///@TODO UVR -// setIsVisible(isVisible); -// ASSERT(GetMainFrame() == frame, ()); -} - -void Ruler::AnimFrameAnimEnded(bool /*isVisible*/, RulerFrame * frame) -{ - ASSERT_EQUAL(m_animFrame.get(), frame, ()); - m_animFrame.reset(); -} - -Ruler::RulerFrame * Ruler::GetMainFrame() -{ - ///@TODO UVR -// if (!m_mainFrame) -// m_mainFrame.reset(new RulerFrame(*m_framework, bind(&Ruler::MainFrameAnimEnded, this, _1, _2), depth())); -// return m_mainFrame.get(); - return nullptr; -} - -Ruler::RulerFrame * Ruler::GetMainFrame() const -{ - ASSERT(m_mainFrame, ()); - return m_mainFrame.get(); -} - -void Ruler::purge() -{ - m_currentRangeIndex = InvalidUnitValue; - - m_mainFrame.reset(); - m_animFrame.reset(); - - ///@TODO UVR - //setIsVisible(false); -} - -void Ruler::update() -{ - ///@TODO UVR -// double const k = visualScale(); - -// ScreenBase const & screen = m_framework->GetNavigator().Screen(); - -// int const rulerHeight = my::rounds(RulerHeight * k); -// int const minPxWidth = my::rounds(MinPixelWidth * k); - -// // pivot() here is the down right point of the ruler. -// // Get global points of ruler and distance according to minPxWidth. - -// m2::PointD pt1 = screen.PtoG(pivot()); -// m2::PointD pt0 = screen.PtoG(pivot() - m2::PointD(minPxWidth, 0)); - -// double const distanceInMetres = MercatorBounds::DistanceOnEarth(pt0, pt1); - -// // convert metres to units for calculating m_metresDiff -// double metersDiff = CalcMetresDiff(distanceInMetres); - -// bool const higherThanMax = metersDiff > MaxMetersWidth; -// bool const lessThanMin = metersDiff < MinMetersWidth; - -// // Calculate width of the ruler in pixels. -// double scalerWidthInPx = minPxWidth; - -// if (higherThanMax) -// scalerWidthInPx = minPxWidth * 3 / 2; -// else if (!lessThanMin) -// { -// // Here we need to convert metres to pixels according to angle -// // (in global coordinates) of the ruler. - -// double const a = ang::AngleTo(pt1, pt0); -// pt0 = MercatorBounds::GetSmPoint(pt1, cos(a) * metersDiff, sin(a) * metersDiff); - -// scalerWidthInPx = my::rounds(pivot().Length(screen.GtoP(pt0))); -// } - -// m2::PointD orgPt = pivot() + m2::PointD(-scalerWidthInPx / 2, rulerHeight / 2); - -// if (position() & EPosLeft) -// orgPt.x -= scalerWidthInPx / 2; - -// if (position() & EPosRight) -// orgPt.x += scalerWidthInPx / 2; - -// if (position() & EPosAbove) -// orgPt.y -= rulerHeight / 2; - -// if (position() & EPosUnder) -// orgPt.y += rulerHeight / 2; - -// RulerFrame * frame = GetMainFrame(); -// frame->SetScale(scalerWidthInPx / CacheLength); -// frame->SetOrgPoint(orgPt); -} - -m2::RectD Ruler::GetBoundRect() const -{ - ///@TODO UVR -// FontDesc const & f = font(EActive); -// RulerFrame * frame = GetMainFrame(); -// m2::PointD const org = frame->GetOrgPoint(); -// m2::PointD const size = m2::PointD(CacheLength * frame->GetScale(), f.m_size * 2); -// return m2::RectD(org - m2::PointD(size.x, 0.0), org + m2::PointD(0.0, size.y)); - return m2::RectD(); -} - -void Ruler::cache() -{ - (void)GetMainFrame(); - update(); -} - -///@TODO UVR -//void Ruler::draw(OverlayRenderer * s, math::Matrix const & m) const -//{ -// if (isVisible()) -// { -// checkDirtyLayout(); - -// RulerFrame * frame = GetMainFrame(); -// frame->Draw(s, m); -// if (m_animFrame) -// m_animFrame->Draw(s, m); -// } -//} - -int Ruler::GetTextOffsetFromLine() const -{ - return TextOffsetFromRuler; -} diff --git a/map/ruler.hpp b/map/ruler.hpp deleted file mode 100644 index 8881e0a0f9..0000000000 --- a/map/ruler.hpp +++ /dev/null @@ -1,106 +0,0 @@ -#pragma once - -#include "geometry/point2d.hpp" -#include "geometry/rect2d.hpp" - -#include "std/shared_ptr.hpp" -#include "std/unique_ptr.hpp" -#include "std/function.hpp" - - -namespace anim -{ - class Task; -} - -class Framework; - - -class Ruler -{ - class RulerFrame - { - public: - typedef function frame_end_fn; - - RulerFrame(Framework & f, - frame_end_fn const & fn, - double depth); - - RulerFrame(RulerFrame const & other, const frame_end_fn & fn); - ~RulerFrame(); - - bool IsValid() const; - - void Purge(); - bool IsHidingAnim() const; - bool IsAnimActive() const; - void SetScale(double scale); - double GetScale() const; - void SetOrgPoint(m2::PointD const & org); - m2::PointD const & GetOrgPoint() const; - - void ShowAnimate(bool needPause); - void HideAnimate(bool needPause); - - private: - void CreateAnim(double startAlfa, double endAlfa, - double timeInterval, double timeOffset, - bool isVisibleAtEnd); - float GetCurrentAlfa(); - void AnimEnded(bool isVisible); - - private: - Framework & m_f; - - int m_textLengthInPx; - double m_scale; - double m_depth; - m2::PointD m_orgPt; - frame_end_fn m_callback; - - shared_ptr m_frameAnim; - }; - -private: - int m_currentRangeIndex; - int m_currSystem; - double CalcMetresDiff(double value); - void UpdateText(const string & text); - - void MainFrameAnimEnded(bool isVisible, RulerFrame * frame); - void AnimFrameAnimEnded(bool isVisible, RulerFrame * frame); - - RulerFrame * GetMainFrame(); - RulerFrame * GetMainFrame() const; - - unique_ptr m_mainFrame; - unique_ptr m_animFrame; - - Framework * m_framework; - -public: - - struct Params - { - Framework * m_framework; - Params(); - }; - - Ruler(Params const & p); - - void AnimateShow(); - void AnimateHide(); - - /// @name Override from graphics::OverlayElement and gui::Element. - //@{ - virtual m2::RectD GetBoundRect() const; - - void update(); - void layout(); - void cache(); - void purge(); - //@} - - int GetTextOffsetFromLine() const; -};