diff options
author | Darafei Praliaskouski <komzpa@gmail.com> | 2013-01-22 19:03:05 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:49:05 +0300 |
commit | 0eec5d802a61173c5baf4e3a008f0280de6343a7 (patch) | |
tree | 377e97d3a707efb2d671d669a8bbc770a028edb9 | |
parent | b0e7e0ce61aaf6ae2df778f362efc3e1101f8f3e (diff) |
improved drawing priorities
-rw-r--r-- | graphics/composite_overlay_element.cpp | 4 | ||||
-rw-r--r-- | graphics/composite_overlay_element.hpp | 2 | ||||
-rw-r--r-- | graphics/overlay_element.cpp | 5 | ||||
-rw-r--r-- | graphics/overlay_element.hpp | 11 | ||||
-rw-r--r-- | graphics/overlay_renderer.cpp | 29 | ||||
-rw-r--r-- | graphics/overlay_renderer.hpp | 3 | ||||
-rw-r--r-- | graphics/path_text_element.cpp | 5 | ||||
-rw-r--r-- | graphics/path_text_element.hpp | 2 | ||||
-rw-r--r-- | graphics/straight_text_element.cpp | 16 | ||||
-rw-r--r-- | graphics/straight_text_element.hpp | 3 | ||||
-rw-r--r-- | graphics/symbol_element.cpp | 2 | ||||
-rw-r--r-- | gui/element.cpp | 2 | ||||
-rw-r--r-- | gui/element.hpp | 2 | ||||
-rw-r--r-- | map/drawer.cpp | 66 | ||||
-rw-r--r-- | map/feature_styler.cpp | 13 | ||||
-rw-r--r-- | map/proto_to_styles.cpp | 14 | ||||
-rw-r--r-- | map/proto_to_styles.hpp | 2 | ||||
-rw-r--r-- | map/ruler.cpp | 2 | ||||
-rw-r--r-- | map/ruler.hpp | 2 |
19 files changed, 124 insertions, 61 deletions
diff --git a/graphics/composite_overlay_element.cpp b/graphics/composite_overlay_element.cpp index 1c77938e02..05c1c85e64 100644 --- a/graphics/composite_overlay_element.cpp +++ b/graphics/composite_overlay_element.cpp @@ -48,9 +48,9 @@ namespace graphics m_elements[i]->draw(r, m); } - int CompositeOverlayElement::priority() const + double CompositeOverlayElement::priority() const { - int res = numeric_limits<int>::min(); + double res = numeric_limits<double>::min(); for (unsigned i = 0; i < m_elements.size(); ++i) res = max(res, m_elements[i]->priority()); diff --git a/graphics/composite_overlay_element.hpp b/graphics/composite_overlay_element.hpp index c73f2a48a8..2fba999fc9 100644 --- a/graphics/composite_overlay_element.hpp +++ b/graphics/composite_overlay_element.hpp @@ -26,7 +26,7 @@ namespace graphics void draw(OverlayRenderer * r, math::Matrix<double, 3, 3> const & m) const; - int priority() const; + double priority() const; void offset(m2::PointD const & offs); }; diff --git a/graphics/overlay_element.cpp b/graphics/overlay_element.cpp index 95de5ece43..21aa25cd8e 100644 --- a/graphics/overlay_element.cpp +++ b/graphics/overlay_element.cpp @@ -210,8 +210,9 @@ namespace graphics return false; } - int OverlayElement::priority() const + double OverlayElement::priority() const { - return m_depth * 1000; + return m_depth; } + } diff --git a/graphics/overlay_element.hpp b/graphics/overlay_element.hpp index ef6b14eefc..e49256adce 100644 --- a/graphics/overlay_element.hpp +++ b/graphics/overlay_element.hpp @@ -27,8 +27,7 @@ namespace graphics m2::PointD m_pivot; graphics::EPosition m_position; - double m_depth; - UserInfo m_userInfo; + double m_depth; bool m_isNeedRedraw; bool m_isFrozen; @@ -42,6 +41,8 @@ namespace graphics public: + UserInfo m_userInfo; + m2::PointD const tieRect(m2::RectD const & r, math::Matrix<double, 3, 3> const & m) const; struct Params @@ -61,7 +62,8 @@ namespace graphics /// PLEASE, REMEMBER THE REFERENCE!!! virtual vector<m2::AnyRectD> const & boundRects() const = 0; virtual void draw(OverlayRenderer * r, math::Matrix<double, 3, 3> const & m) const = 0; - virtual int priority() const; + + virtual double priority() const; m2::PointD const & pivot() const; virtual void setPivot(m2::PointD const & pv); @@ -94,6 +96,9 @@ namespace graphics bool isValid() const; void setIsValid(bool flag); + m2::PointD getOffset() const; + void setOffset(m2::PointD offset); + UserInfo const & userInfo() const; virtual bool hitTest(m2::PointD const & pt) const; diff --git a/graphics/overlay_renderer.cpp b/graphics/overlay_renderer.cpp index e30efae526..be259c882c 100644 --- a/graphics/overlay_renderer.cpp +++ b/graphics/overlay_renderer.cpp @@ -92,10 +92,27 @@ namespace graphics params.m_log2vis = log2vis; params.m_pivot = pt; params.m_position = pos; - params.m_glyphCache = glyphCache(); params.m_logText = strings::MakeUniString(utf8Text); params.m_doSplit = doSplit; params.m_useAllParts = false; + params.m_glyphCache = glyphCache(); + + shared_ptr<OverlayElement> oe(new StraightTextElement(params)); + + math::Matrix<double, 3, 3> id = math::Identity<double, 3>(); + + if (!m_overlay.get()) + oe->draw(this, id); + else + m_overlay->processOverlayElement(oe); + } + + void OverlayRenderer::drawTextEx(StraightTextElement::Params & params) + { + if (!m_drawTexts) + return; + + params.m_glyphCache = glyphCache(); shared_ptr<OverlayElement> oe(new StraightTextElement(params)); @@ -127,21 +144,15 @@ namespace graphics params.m_log2vis = log2vis; params.m_pivot = pt; params.m_position = pos; - params.m_glyphCache = glyphCache(); params.m_logText = strings::MakeUniString(text); params.m_auxLogText = strings::MakeUniString(secondaryText); params.m_doSplit = doSplit; params.m_useAllParts = false; - shared_ptr<OverlayElement> oe(new StraightTextElement(params)); + drawTextEx(params); + } - math::Matrix<double, 3, 3> id = math::Identity<double, 3>(); - if (!m_overlay.get()) - oe->draw(this, id); - else - m_overlay->processOverlayElement(oe); - } bool OverlayRenderer::drawPathText( FontDesc const & fontDesc, m2::PointD const * path, size_t s, string const & utf8Text, diff --git a/graphics/overlay_renderer.hpp b/graphics/overlay_renderer.hpp index 05aafdf5bb..d2347cbe21 100644 --- a/graphics/overlay_renderer.hpp +++ b/graphics/overlay_renderer.hpp @@ -6,6 +6,7 @@ #include "text_renderer.hpp" #include "overlay.hpp" #include "circle.hpp" +#include "straight_text_element.hpp" namespace graphics { @@ -52,6 +53,8 @@ namespace graphics bool log2vis, bool doSplit = false); + void drawTextEx(StraightTextElement::Params & params); + void drawTextEx(FontDesc const & primaryFont, FontDesc const & secondaryFont, m2::PointD const & pt, diff --git a/graphics/path_text_element.cpp b/graphics/path_text_element.cpp index 3af1f3dfb0..e07c7b9ecb 100644 --- a/graphics/path_text_element.cpp +++ b/graphics/path_text_element.cpp @@ -83,11 +83,6 @@ namespace graphics m_glyphLayout.setPivot(pivot); } - int PathTextElement::priority() const - { - return OverlayElement::priority() + m_fontDesc.m_size; - } - OverlayElement * PathTextElement::clone(math::Matrix<double, 3, 3> const & m) const { return new PathTextElement(*this, m); diff --git a/graphics/path_text_element.hpp b/graphics/path_text_element.hpp index 0287d38e39..3ebd522a59 100644 --- a/graphics/path_text_element.hpp +++ b/graphics/path_text_element.hpp @@ -30,7 +30,5 @@ namespace graphics void setPivot(m2::PointD const & pivot); OverlayElement * clone(math::Matrix<double, 3, 3> const & m) const; - - int priority() const; }; } diff --git a/graphics/straight_text_element.cpp b/graphics/straight_text_element.cpp index e016e0cbe5..0d358f5f8a 100644 --- a/graphics/straight_text_element.cpp +++ b/graphics/straight_text_element.cpp @@ -172,7 +172,6 @@ namespace graphics } } - double curShift = allElemHeight / 2; /// performing aligning of glyphLayouts as for the center position @@ -180,7 +179,7 @@ namespace graphics for (unsigned i = 0; i < m_glyphLayouts.size(); ++i) { double elemSize = m_glyphLayouts[i].boundRects().back().GetGlobalRect().SizeY(); - m_glyphLayouts[i].setPivot(m_glyphLayouts[i].pivot() + m2::PointD(0, -curShift + elemSize / 2)); + m_glyphLayouts[i].setPivot(m_glyphLayouts[i].pivot() + m2::PointD(0, -curShift + elemSize / 2) + p.m_offset); curShift -= elemSize; } @@ -259,10 +258,10 @@ namespace graphics if (isNeedRedraw()) c = graphics::Color(255, 0, 0, 64); - screen->drawRectangle(roughBoundRect(), graphics::Color(255, 255, 0, 64), graphics::maxDepth - 10); + screen->drawRectangle(roughBoundRect(), graphics::Color(255, 255, 0, 64), depth() - 0.2); for (unsigned i = 0 ; i < boundRects().size(); ++i) - screen->drawRectangle(boundRects()[i], c, graphics::maxDepth - 10); + screen->drawRectangle(boundRects()[i], c, depth() - 0.2); } if (!isNeedRedraw()) @@ -271,14 +270,14 @@ namespace graphics for (unsigned i = 0; i < m_glyphLayouts.size(); ++i) { if (m_glyphLayouts[i].fontDesc().m_isMasked) - drawTextImpl(m_glyphLayouts[i], screen, m, true, true, m_glyphLayouts[i].fontDesc(), graphics::maxDepth - 9); + drawTextImpl(m_glyphLayouts[i], screen, m, true, true, m_glyphLayouts[i].fontDesc(), depth() - 0.1); } for (unsigned i = 0; i < m_glyphLayouts.size(); ++i) { graphics::FontDesc fontDesc = m_glyphLayouts[i].fontDesc(); fontDesc.m_isMasked = false; - drawTextImpl(m_glyphLayouts[i], screen, m, true, true, fontDesc, graphics::maxDepth - 8); + drawTextImpl(m_glyphLayouts[i], screen, m, true, true, fontDesc, depth()); } } @@ -293,11 +292,6 @@ namespace graphics m_glyphLayouts[i].setPivot(m_glyphLayouts[i].pivot() + offs); } - int StraightTextElement::priority() const - { - return OverlayElement::priority() + m_fontDesc.m_size; - } - OverlayElement * StraightTextElement::clone(math::Matrix<double, 3, 3> const & m) const { return new StraightTextElement(*this, m); diff --git a/graphics/straight_text_element.hpp b/graphics/straight_text_element.hpp index 5084c70c46..d33f18e3d9 100644 --- a/graphics/straight_text_element.hpp +++ b/graphics/straight_text_element.hpp @@ -22,6 +22,7 @@ namespace graphics unsigned m_maxSymInRow; bool m_doSplit; bool m_useAllParts; + m2::PointD m_offset; string m_delimiters; Params(); }; @@ -33,8 +34,6 @@ namespace graphics void draw(OverlayRenderer * r, math::Matrix<double, 3, 3> const & m) const; - int priority() const; - void setPivot(m2::PointD const & pv); OverlayElement * clone(math::Matrix<double, 3, 3> const & m) const; diff --git a/graphics/symbol_element.cpp b/graphics/symbol_element.cpp index c13ab23822..e1a79ca839 100644 --- a/graphics/symbol_element.cpp +++ b/graphics/symbol_element.cpp @@ -83,7 +83,7 @@ namespace graphics r->drawStraightTexturedPolygon(pivot(), texRect.minX(), texRect.minY(), texRect.maxX(), texRect.maxY(), posPt.x, posPt.y, posPt.x + texRect.SizeX(), posPt.y + texRect.SizeY(), - graphics::maxDepth - 2, + depth(), res->m_pipelineID); } diff --git a/gui/element.cpp b/gui/element.cpp index 7e5f76a358..af5f84d2a1 100644 --- a/gui/element.cpp +++ b/gui/element.cpp @@ -92,7 +92,7 @@ namespace gui r->drawRectangle(boundRects()[i], color(state()), depth()); } - int Element::priority() const + double Element::priority() const { return 0; } diff --git a/gui/element.hpp b/gui/element.hpp index b87457e1e3..6af61b472f 100644 --- a/gui/element.hpp +++ b/gui/element.hpp @@ -69,7 +69,7 @@ namespace gui graphics::OverlayElement * clone(math::Matrix<double, 3, 3> const & m) const; void draw(graphics::OverlayRenderer * r, math::Matrix<double, 3, 3> const & m) const; - int priority() const; + double priority() const; virtual void cache(); /// this method is called upon renderPolicy destruction and should clean diff --git a/map/drawer.cpp b/map/drawer.cpp index 9a923f42f8..4cc5ef058e 100644 --- a/map/drawer.cpp +++ b/map/drawer.cpp @@ -9,6 +9,13 @@ #include "../graphics/defines.hpp" #include "../graphics/screen.hpp" #include "../graphics/resource_manager.hpp" +#include "../graphics/straight_text_element.hpp" + +#ifdef OMIM_PRODUCTION + #include "../indexer/drules_struct_lite.pb.h" +#else + #include "../indexer/drules_struct.pb.h" +#endif #include "../geometry/screenbase.hpp" @@ -224,26 +231,42 @@ bool Drawer::filter_text_size(rule_ptr_t pRule) const void Drawer::drawText(m2::PointD const & pt, di::DrawInfo const * pInfo, rule_ptr_t pRule, graphics::EPosition pos, double depth, FeatureID const & id) { - graphics::FontDesc font; - ConvertStyle(pRule->GetCaption(0), m_visualScale, font); - font.SetRank(pInfo->m_rank); + graphics::FontDesc primaryFont; + m2::PointD primaryOffset; + ConvertStyle(pRule->GetCaption(0), m_visualScale, primaryFont, primaryOffset); + primaryFont.SetRank(pInfo->m_rank); - graphics::FontDesc smallFont; + graphics::FontDesc secondaryFont; + m2::PointD secondaryOffset; if (pRule->GetCaption(1)) { - ConvertStyle(pRule->GetCaption(1), m_visualScale, smallFont); - smallFont.SetRank(pInfo->m_rank); + ConvertStyle(pRule->GetCaption(1), m_visualScale, secondaryFont, secondaryOffset); + secondaryFont.SetRank(pInfo->m_rank); } - m_pScreen->drawTextEx(font, smallFont, pt, pos, - pInfo->m_name, pInfo->m_secondaryName, - depth, true, true); + graphics::StraightTextElement::Params params; + params.m_depth = depth; + params.m_fontDesc = primaryFont; + params.m_auxFontDesc = secondaryFont; + params.m_offset = primaryOffset; + params.m_log2vis = true; + params.m_pivot = pt; + params.m_position = pos; + params.m_logText = strings::MakeUniString(pInfo->m_name); + params.m_auxLogText = strings::MakeUniString(pInfo->m_secondaryName); + params.m_doSplit = true; + params.m_useAllParts = false; + params.m_userInfo.m_mwmID = id.first; + params.m_userInfo.m_offset = id.second; + + m_pScreen->drawTextEx(params); } bool Drawer::drawPathText(di::PathInfo const & info, di::DrawInfo const * pInfo, rule_ptr_t pRule, double depth) { graphics::FontDesc font; - ConvertStyle(pRule->GetCaption(0), m_visualScale, font); + m2::PointD offset; + ConvertStyle(pRule->GetCaption(0), m_visualScale, font, offset); return m_pScreen->drawPathText(font, &info.m_path[0], @@ -334,7 +357,6 @@ void Drawer::Draw(di::DrawInfo const * pInfo, di::DrawRule const * rules, size_t if (!isCaption) { - double const sm = 2.0 * m_visualScale; // draw area if (isArea) @@ -347,7 +369,7 @@ void Drawer::Draw(di::DrawInfo const * pInfo, di::DrawRule const * rules, size_t if (isFill) drawArea(i->m_path, pRule, depth); else if (hasSym) - drawSymbol(i->GetCenter() + m2::PointD(0.0, sm), pRule, graphics::EPosUnder, depth, id); + drawSymbol(i->GetCenter(), pRule, graphics::EPosCenter, depth, id); } } @@ -355,22 +377,32 @@ void Drawer::Draw(di::DrawInfo const * pInfo, di::DrawRule const * rules, size_t if (!isPath && !isArea && ((pRule->GetType() & drule::node) != 0)) { if (hasSymbol) - drawSymbol(pInfo->m_point + m2::PointD(0.0, sm), pRule, graphics::EPosUnder, depth, id); + drawSymbol(pInfo->m_point, pRule, graphics::EPosCenter, depth, id); else if (isCircle) - drawCircle(pInfo->m_point + m2::PointD(0.0, sm), pRule, graphics::EPosUnder, depth, id); + drawCircle(pInfo->m_point, pRule, graphics::EPosCenter, depth, id); } } else { - if (!pInfo->m_name.empty()) + if (!pInfo->m_name.empty() && (pRule->GetCaption(0) != 0)) { bool isN = ((pRule->GetType() & drule::way) != 0); + graphics::EPosition textPosition = graphics::EPosCenter; + if (pRule->GetCaption(0)->has_offset_y()) + { + if (pRule->GetCaption(0)->offset_y() > 0) + textPosition = graphics::EPosUnder; + else + textPosition = graphics::EPosAbove; + } + + // draw area text if (isArea/* && isN*/) { for (list<di::AreaInfo>::const_iterator i = pInfo->m_areas.begin(); i != pInfo->m_areas.end(); ++i) - drawText(i->GetCenter(), pInfo, pRule, graphics::EPosCenter, depth, id); + drawText(i->GetCenter(), pInfo, pRule, textPosition, depth, id); } // draw way name @@ -383,7 +415,7 @@ void Drawer::Draw(di::DrawInfo const * pInfo, di::DrawRule const * rules, size_t // draw point text isN = ((pRule->GetType() & drule::node) != 0); if (!isPath && !isArea && isN) - drawText(pInfo->m_point, pInfo, pRule, graphics::EPosAbove, depth, id); + drawText(pInfo->m_point, pInfo, pRule, textPosition, depth, id); } } } diff --git a/map/feature_styler.cpp b/map/feature_styler.cpp index 2f2426dc4d..a28eaad188 100644 --- a/map/feature_styler.cpp +++ b/map/feature_styler.cpp @@ -88,9 +88,22 @@ namespace feature for (size_t i = 0; i < count; ++i) { double depth = keys[i].m_priority; + + if (layer != 0) depth = (layer * drule::layer_base_priority) + fmod(depth, drule::layer_base_priority); + if (keys[i].m_type == drule::symbol) + depth = 16000; + if (keys[i].m_type == drule::caption) + { + depth = 15000; + if (m_geometryType == GEOM_POINT) + depth = 15500; + } + if (keys[i].m_type == drule::pathtext) + depth = 17000; + if ((keys[i].m_type == drule::caption) || (keys[i].m_type == drule::symbol) || (keys[i].m_type == drule::circle) diff --git a/map/proto_to_styles.cpp b/map/proto_to_styles.cpp index a6202fa74e..0584c69c90 100644 --- a/map/proto_to_styles.cpp +++ b/map/proto_to_styles.cpp @@ -67,6 +67,9 @@ void ConvertStyle(LineDefProto const * pSrc, double scale, graphics::Pen::Info & case BEVELJOIN: dest.m_join = graphics::Pen::Info::EBevelJoin; break; + case NOJOIN: + dest.m_join = graphics::Pen::Info::ENoJoin; + break; default: break; } @@ -82,6 +85,9 @@ void ConvertStyle(LineDefProto const * pSrc, double scale, graphics::Pen::Info & case BUTTCAP: dest.m_cap = graphics::Pen::Info::EButtCap; break; + case SQUARECAP: + dest.m_cap = graphics::Pen::Info::ESquareCap; + break; default: break; } @@ -114,11 +120,17 @@ void ConvertStyle(CircleRuleProto const * pSrc, double scale, graphics::Circle:: } } -void ConvertStyle(CaptionDefProto const * pSrc, double scale, graphics::FontDesc & dest) +void ConvertStyle(CaptionDefProto const * pSrc, double scale, graphics::FontDesc & dest, m2::PointD & offset) { uint8_t const h = max(static_cast<int>(pSrc->height() * scale), static_cast<int>(8 * scale)); // replace 12 to 8 as it defined in drawing rules + offset = m2::PointD(0,0); + if (pSrc->has_offset_x()) + offset.x = pSrc->offset_x(); + if (pSrc->has_offset_y()) + offset.y = pSrc->offset_y(); + dest = graphics::FontDesc(h, ConvertColor(pSrc->color())); if (pSrc->has_stroke_color()) diff --git a/map/proto_to_styles.hpp b/map/proto_to_styles.hpp index 85f5c3ae42..ae6541fa0e 100644 --- a/map/proto_to_styles.hpp +++ b/map/proto_to_styles.hpp @@ -16,6 +16,6 @@ void ConvertStyle(LineDefProto const * pSrc, double scale, graphics::Pen::Info & void ConvertStyle(AreaRuleProto const * pSrc, graphics::Brush::Info & dest); void ConvertStyle(SymbolRuleProto const * pSrc, graphics::Icon::Info & dest); void ConvertStyle(CircleRuleProto const * pSrc, double scale, graphics::Circle::Info & dest); -void ConvertStyle(CaptionDefProto const * pSrc, double scale, graphics::FontDesc & dest); +void ConvertStyle(CaptionDefProto const * pSrc, double scale, graphics::FontDesc & dest, m2::PointD & offset); uint8_t GetFontSize(CaptionDefProto const * pSrc); diff --git a/map/ruler.cpp b/map/ruler.cpp index 5a9eae00eb..1deb41f7d2 100644 --- a/map/ruler.cpp +++ b/map/ruler.cpp @@ -303,7 +303,7 @@ void Ruler::draw(graphics::OverlayRenderer * s, math::Matrix<double, 3, 3> const } } -int Ruler::priority() const +double Ruler::priority() const { return 0; } diff --git a/map/ruler.hpp b/map/ruler.hpp index e6e7e2db5a..f6b03d97d4 100644 --- a/map/ruler.hpp +++ b/map/ruler.hpp @@ -80,6 +80,6 @@ public: void draw(graphics::OverlayRenderer * r, math::Matrix<double, 3, 3> const & m) const; - int priority() const; + double priority() const; graphics::OverlayElement * clone(math::Matrix<double, 3, 3> const & m) const; }; |