added ShapeRenderer::drawRoundedRectangle.

This commit is contained in:
rachytski 2012-05-25 17:49:30 +04:00 committed by Alex Zolotarev
parent e545e14183
commit d2c12d6eb3
2 changed files with 76 additions and 0 deletions

View file

@ -154,5 +154,80 @@ namespace yg
style->m_pipelineID
);
}
void ShapeRenderer::drawRoundedRectangle(m2::RectD const & r, double rad, yg::Color const & c, double depth)
{
ResourceStyle const * style = skin()->fromID(skin()->mapColor(c));
if (style == 0)
{
LOG(LINFO, ("cannot map color"));
return;
}
shared_ptr<BaseTexture> texture = skin()->getPage(style->m_pipelineID)->texture();
if (!texture)
{
LOG(LDEBUG, ("returning as no texture is reserved"));
return;
}
m2::PointF texPt = texture->mapPixel(m2::RectF(style->m_texRect).Center());
vector<m2::PointD> seg00;
vector<m2::PointD> seg10;
vector<m2::PointD> seg11;
vector<m2::PointD> seg01;
approximateArc(m2::PointD(r.minX() + rad, r.minY() + rad),
math::pi,
3 * math::pi / 2,
rad,
seg00);
approximateArc(m2::PointD(r.minX() + rad, r.maxY() - rad),
math::pi / 2,
math::pi,
rad,
seg01);
approximateArc(m2::PointD(r.maxX() - rad, r.maxY() - rad),
0,
math::pi / 2,
rad,
seg11);
approximateArc(m2::PointD(r.maxX() - rad, r.minY() + rad),
3 * math::pi / 2,
math::pi * 2,
rad,
seg10);
vector<m2::PointF> pts;
for (unsigned i = 0; i < seg11.size(); ++i)
pts.push_back(m2::PointF(seg11[i]));
for (unsigned i = 0; i < seg01.size(); ++i)
pts.push_back(m2::PointF(seg01[i]));
for (unsigned i = 0; i < seg00.size(); ++i)
pts.push_back(m2::PointF(seg00[i]));
for (unsigned i = 0; i < seg10.size(); ++i)
pts.push_back(m2::PointF(seg10[i]));
addTexturedFanStrided(
&pts[0],
sizeof(m2::PointF),
&texPt,
0,
pts.size(),
depth,
style->m_pipelineID
);
}
}
}

View file

@ -23,6 +23,7 @@ namespace yg
void drawRectangle(m2::AnyRectD const & r, yg::Color const & c, double depth);
void drawRectangle(m2::RectD const & r, yg::Color const & c, double depth);
void drawRoundedRectangle(m2::RectD const & r, double rad, yg::Color const & c, double depth);
};
}
}