From 1108a6f37dc9c96b66c3ceaf1d4b292637639f97 Mon Sep 17 00:00:00 2001 From: Evil-Spirit Date: Sun, 17 Jul 2016 20:46:38 +0600 Subject: [PATCH] Use Canvas::Stroke, not Canvas::Fill, for drawing a point. Our points are more like fat lines than actual quads, in that they are scale-invariant. --- src/drawentity.cpp | 22 ++++++++++++---------- src/export.cpp | 2 +- src/render/render.cpp | 8 ++++---- src/render/render.h | 8 ++++---- src/render/render2d.cpp | 14 +++++++++++--- src/render/rendergl1.cpp | 14 +++++++++++--- 6 files changed, 43 insertions(+), 25 deletions(-) diff --git a/src/drawentity.cpp b/src/drawentity.cpp index 7e3cf089..47e632ce 100644 --- a/src/drawentity.cpp +++ b/src/drawentity.cpp @@ -496,11 +496,12 @@ void Entity::Draw(DrawAs how, Canvas *canvas) { } Canvas::hStroke hcs = canvas->GetStroke(stroke); - Canvas::Fill fill = {}; - fill.layer = stroke.layer; - fill.zIndex = IsPoint() ? 5 : 0; - fill.color = stroke.color; - Canvas::hFill hcf = canvas->GetFill(fill); + Canvas::Stroke pointStroke = {}; + pointStroke.layer = stroke.layer; + pointStroke.zIndex = IsPoint() ? zIndex + 1 : 0; + pointStroke.color = stroke.color; + pointStroke.width = 7.0; + Canvas::hStroke hcsPoint = canvas->GetStroke(pointStroke); switch(type) { case Type::POINT_N_COPY: @@ -528,14 +529,15 @@ void Entity::Draw(DrawAs how, Canvas *canvas) { free = pu->free || pv->free; } if(free) { - Canvas::Fill fillAnalyze = fill; - fillAnalyze.color = Style::Color(Style::ANALYZE); - Canvas::hFill hcfAnalyze = canvas->GetFill(fillAnalyze); + Canvas::Stroke analyzeStroke = pointStroke; + analyzeStroke.color = Style::Color(Style::ANALYZE); + analyzeStroke.width = 14.0; + Canvas::hStroke hcsAnalyze = canvas->GetStroke(analyzeStroke); - canvas->DrawPoint(PointGetNum(), 7.0, hcfAnalyze); + canvas->DrawPoint(PointGetNum(), hcsAnalyze); } - canvas->DrawPoint(PointGetNum(), 3.5, hcf); + canvas->DrawPoint(PointGetNum(), hcsPoint); return; } diff --git a/src/export.cpp b/src/export.cpp index f95d1970..c7306d09 100644 --- a/src/export.cpp +++ b/src/export.cpp @@ -143,7 +143,7 @@ public: void DrawOutlines(const SOutlineList &ol, hStroke hcs, DrawOutlinesAs drawAs) override { ssassert(false, "Not implemented"); } - void DrawPoint(const Vector &o, double d, hFill hcf) override { + void DrawPoint(const Vector &o, hStroke hcs) override { ssassert(false, "Not implemented"); } void DrawPolygon(const SPolygon &p, hFill hcf) override { diff --git a/src/render/render.cpp b/src/render/render.cpp index e44a1e0e..e080e403 100644 --- a/src/render/render.cpp +++ b/src/render/render.cpp @@ -346,10 +346,10 @@ void ObjectPicker::DrawQuad(const Vector &a, const Vector &b, const Vector &c, c DoQuad(a, b, c, d, fill->zIndex); } -void ObjectPicker::DrawPoint(const Vector &o, double s, hFill hcf) { - Fill *fill = fills.FindById(hcf); - double distance = point.DistanceTo(camera.ProjectPoint(o)) - s / 2; - DoCompare(distance, fill->zIndex); +void ObjectPicker::DrawPoint(const Vector &o, Canvas::hStroke hcs) { + Stroke *stroke = strokes.FindById(hcs); + double distance = point.DistanceTo(camera.ProjectPoint(o)) - stroke->width / 2; + DoCompare(distance, stroke->zIndex); } void ObjectPicker::DrawPolygon(const SPolygon &p, hFill hcf) { diff --git a/src/render/render.h b/src/render/render.h index 87fb0218..77092763 100644 --- a/src/render/render.h +++ b/src/render/render.h @@ -140,7 +140,7 @@ public: virtual void DrawQuad(const Vector &a, const Vector &b, const Vector &c, const Vector &d, hFill hcf) = 0; - virtual void DrawPoint(const Vector &o, double d, hFill hcf) = 0; + virtual void DrawPoint(const Vector &o, hStroke hcs) = 0; virtual void DrawPolygon(const SPolygon &p, hFill hcf) = 0; virtual void DrawMesh(const SMesh &m, hFill hcfFront, hFill hcfBack = {}, hStroke hcsTriangles = {}) = 0; @@ -196,7 +196,7 @@ public: void DrawQuad(const Vector &a, const Vector &b, const Vector &c, const Vector &d, hFill hcf) override; - void DrawPoint(const Vector &o, double s, hFill hcf) override; + void DrawPoint(const Vector &o, hStroke hcs) override; void DrawPolygon(const SPolygon &p, hFill hcf) override; void DrawMesh(const SMesh &m, hFill hcfFront, hFill hcfBack, hStroke hcsTriangles) override; void DrawFaces(const SMesh &m, const std::vector &faces, hFill hcf) override; @@ -244,7 +244,7 @@ public: void DrawQuad(const Vector &a, const Vector &b, const Vector &c, const Vector &d, hFill hcf) override; - void DrawPoint(const Vector &o, double s, hFill hcf) override; + void DrawPoint(const Vector &o, hStroke hcs) override; void DrawPolygon(const SPolygon &p, hFill hcf) override; void DrawMesh(const SMesh &m, hFill hcfFront, hFill hcfBack, hStroke hcsTriangles) override; void DrawFaces(const SMesh &m, const std::vector &faces, hFill hcf) override; @@ -347,7 +347,7 @@ public: void DrawQuad(const Vector &a, const Vector &b, const Vector &c, const Vector &d, hFill hcf) override; - void DrawPoint(const Vector &o, double s, hFill hcf) override; + void DrawPoint(const Vector &o, hStroke hcs) override; void DrawPolygon(const SPolygon &p, hFill hcf) override; void DrawMesh(const SMesh &m, hFill hcfFront, hFill hcfBack, hStroke hcsTriangles) override; void DrawFaces(const SMesh &m, const std::vector &faces, hFill hcf) override; diff --git a/src/render/render2d.cpp b/src/render/render2d.cpp index 6ce1c009..729f8eb9 100644 --- a/src/render/render2d.cpp +++ b/src/render/render2d.cpp @@ -104,9 +104,17 @@ void SurfaceRenderer::DrawQuad(const Vector &a, const Vector &b, const Vector &c mesh.AddTriangle(meta, ta, td, tc); } -void SurfaceRenderer::DrawPoint(const Vector &o, double s, hFill hcf) { - Vector u = camera.projRight.ScaledBy(1 / camera.scale * s), - v = camera.projUp.ScaledBy(1 / camera.scale * s); +void SurfaceRenderer::DrawPoint(const Vector &o, Canvas::hStroke hcs) { + Stroke *stroke = strokes.FindById(hcs); + + Fill fill = {}; + fill.layer = stroke->layer; + fill.zIndex = stroke->zIndex; + fill.color = stroke->color; + hFill hcf = GetFill(fill); + + Vector u = camera.projRight.ScaledBy(stroke->width/2.0/camera.scale), + v = camera.projUp.ScaledBy(stroke->width/2.0/camera.scale); DrawQuad(o.Minus(u).Minus(v), o.Minus(u).Plus(v), o.Plus(u).Plus(v), o.Plus(u).Minus(v), hcf); } diff --git a/src/render/rendergl1.cpp b/src/render/rendergl1.cpp index b2ea4809..e467ea9b 100644 --- a/src/render/rendergl1.cpp +++ b/src/render/rendergl1.cpp @@ -501,9 +501,17 @@ void OpenGl1Renderer::DrawQuad(const Vector &a, const Vector &b, const Vector &c ssglVertex3v(d); } -void OpenGl1Renderer::DrawPoint(const Vector &o, double s, hFill hcf) { - Vector r = camera.projRight.ScaledBy(s/camera.scale); - Vector u = camera.projUp.ScaledBy(s/camera.scale); +void OpenGl1Renderer::DrawPoint(const Vector &o, Canvas::hStroke hcs) { + Stroke *stroke = SelectStroke(hcs); + + Canvas::Fill fill = {}; + fill.layer = stroke->layer; + fill.zIndex = stroke->zIndex; + fill.color = stroke->color; + hFill hcf = GetFill(fill); + + Vector r = camera.projRight.ScaledBy(stroke->width/2.0/camera.scale); + Vector u = camera.projUp.ScaledBy(stroke->width/2.0/camera.scale); Vector a = o.Plus (r).Plus (u), b = o.Plus (r).Minus(u), c = o.Minus(r).Minus(u),