From 01b44f4c343c8695928622d4d1cb3baebb068552 Mon Sep 17 00:00:00 2001 From: rachytski Date: Tue, 15 Jan 2013 12:35:51 +0300 Subject: [PATCH] implemented PathRenderer::drawSymbolPath and added tests for it. --- graphics/graphics_tests/screengl_test.cpp | 65 ++++++++++++++++++++++- graphics/path_renderer.cpp | 59 +++++++++++++++++++- 2 files changed, 122 insertions(+), 2 deletions(-) diff --git a/graphics/graphics_tests/screengl_test.cpp b/graphics/graphics_tests/screengl_test.cpp index ae61a39914..8c0debaf87 100644 --- a/graphics/graphics_tests/screengl_test.cpp +++ b/graphics/graphics_tests/screengl_test.cpp @@ -99,6 +99,17 @@ namespace m_depthes.push_back(depth); } + void AddTest(vector const & pts, + graphics::Pen::Info const & info, + double depth, + double pathOffset) + { + m_pathes.push_back(pts); + m_pathOffsets.push_back(pathOffset); + m_depthes.push_back(depth); + m_penInfos.push_back(info); + } + std::vector & GetTestPoints(size_t i) { return m_pathes[i]; @@ -587,6 +598,57 @@ namespace } }; + struct TestDrawPathSymbol : TestDrawPathBase + { + typedef TestDrawPathBase base_t; + + void Init() + { + base_t::Init(); + + m_drawAxis = true; + + vector pts; + + graphics::Pen::Info info; + graphics::Pen::Info info1; + + info.m_icon.m_name = "theatre"; + info.m_step = 15; + + pts.clear(); + pts.push_back(m2::PointD(100, 100)); + pts.push_back(m2::PointD(200, 100)); + + AddTest(pts, info, graphics::maxDepth, 0); + + pts.clear(); + pts.push_back(m2::PointD(100, 200)); + pts.push_back(m2::PointD(200, 200)); + + AddTest(pts, info, graphics::maxDepth, 30); + + pts.clear(); + pts.push_back(m2::PointD(100, 300)); + pts.push_back(m2::PointD(200, 300)); + + vector pat; + + pat.push_back(20); + pat.push_back(20); + + info1 = graphics::Pen::Info(graphics::Color(0, 0, 0, 255), 20, &pat[0], pat.size()); + AddTest(pts, info1, graphics::maxDepth, 30); + + pts.clear(); + pts.push_back(m2::PointD(300, 100)); + pts.push_back(m2::PointD(400, 160)); + pts.push_back(m2::PointD(300, 240)); + + AddTest(pts, info, graphics::maxDepth, 0); + } + }; + struct TestDrawPoly { void DoDraw(shared_ptr p) @@ -1433,7 +1495,8 @@ namespace UNIT_TEST_GL(TestDrawPathJoin); UNIT_TEST_GL(TestDrawPathSolid1PX); UNIT_TEST_GL(TestDrawPathSolid2PX);*/ - UNIT_TEST_GL(TestDrawPathSolid); +// UNIT_TEST_GL(TestDrawPathSolid); + UNIT_TEST_GL(TestDrawPathSymbol); /*UNIT_TEST_GL(TestDrawOverlappedSymbolWithText); UNIT_TEST_GL(TestDrawAnyRect); UNIT_TEST_GL(TestDrawSector); diff --git a/graphics/path_renderer.cpp b/graphics/path_renderer.cpp index 20f3e1090e..3688a6bc16 100644 --- a/graphics/path_renderer.cpp +++ b/graphics/path_renderer.cpp @@ -2,6 +2,7 @@ #include "resource.hpp" #include "pen.hpp" #include "resource_cache.hpp" +#include "path_view.hpp" #include "opengl/base_texture.hpp" @@ -54,7 +55,63 @@ namespace graphics void PathRenderer::drawSymbolPath(m2::PointD const * pts, size_t ptsCount, double offset, Pen const * pen, double depth) { - LOG(LINFO, ("drawSymbolPath is unimplemented. symbolName=", pen->m_info.m_symbol)); + PathView pv(pts, ptsCount); + + PathPoint pt = pv.front(); + + pt = pv.offsetPoint(pt, offset); + + m2::RectU texRect = pen->m_texRect; + texRect.Inflate(-1, -1); + + double const w = texRect.SizeX(); + double const h = texRect.SizeY(); + + double const hw = w / 2.0; + double const hh = h / 2.0; + + shared_ptr tex = pipeline(pen->m_pipelineID).texture(); + + while (true) + { + PivotPoint pvPt = pv.findPivotPoint(pt, hw - 1, 0); + + if (pvPt.m_pp.m_i == -1) + break; + + ang::AngleD ang = pvPt.m_angle; + + m2::PointD pts[4]; + + pts[0] = pvPt.m_pp.m_pt.Move(-hw, ang.sin(), ang.cos()); + pts[0] = pts[0].Move(hh + 1, -ang.cos(), ang.sin()); + + pts[1] = pts[0].Move(w, ang.sin(), ang.cos()); + pts[2] = pts[0].Move(-h, -ang.cos(), ang.sin()); + pts[3] = pts[2].Move(w, ang.sin(), ang.cos()); + + m2::PointF texPts[4] = + { + tex->mapPixel(m2::PointF(texRect.minX(), texRect.minY())), + tex->mapPixel(m2::PointF(texRect.maxX(), texRect.minY())), + tex->mapPixel(m2::PointF(texRect.minX(), texRect.maxY())), + tex->mapPixel(m2::PointF(texRect.maxX(), texRect.maxY())) + }; + + m2::PointF normal(0, 0); + + addTexturedStripStrided(pts, sizeof(m2::PointD), + &normal, 0, + texPts, sizeof(m2::PointF), + 4, + depth, + pen->m_pipelineID); + + pt = pv.offsetPoint(pvPt.m_pp, pen->m_info.m_step); + + if (pt.m_i == -1) + break; + } } void PathRenderer::drawStipplePath(m2::PointD const * points, size_t pointsCount, double offset, Pen const * pen, double depth)