forked from organicmaps/organicmaps-tmp
improved drawing priorities
This commit is contained in:
parent
b0e7e0ce61
commit
0eec5d802a
19 changed files with 125 additions and 62 deletions
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -210,8 +210,9 @@ namespace graphics
|
|||
return false;
|
||||
}
|
||||
|
||||
int OverlayElement::priority() const
|
||||
double OverlayElement::priority() const
|
||||
{
|
||||
return m_depth * 1000;
|
||||
return m_depth;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,22 +144,16 @@ 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));
|
||||
|
||||
math::Matrix<double, 3, 3> id = math::Identity<double, 3>();
|
||||
|
||||
if (!m_overlay.get())
|
||||
oe->draw(this, id);
|
||||
else
|
||||
m_overlay->processOverlayElement(oe);
|
||||
drawTextEx(params);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool OverlayRenderer::drawPathText(
|
||||
FontDesc const & fontDesc, m2::PointD const * path, size_t s, string const & utf8Text,
|
||||
double fullLength, double pathOffset, graphics::EPosition pos, double depth)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ namespace gui
|
|||
r->drawRectangle(boundRects()[i], color(state()), depth());
|
||||
}
|
||||
|
||||
int Element::priority() const
|
||||
double Element::priority() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue