diff --git a/bazaar/GLPainter/Arc.cpp b/bazaar/GLPainter/Arc.cpp index 75e1aa8f7..3c009f709 100644 --- a/bazaar/GLPainter/Arc.cpp +++ b/bazaar/GLPainter/Arc.cpp @@ -2,7 +2,7 @@ namespace Upp { -void GLDrawArc(const GLContext2D& dd, const Rectf& rc, Pointf start, Pointf end, int width, Color color, double alpha) +void GLArc(Vector>& line, const Rectf& rc, Pointf start, Pointf end) { if(rc.Width() <= 0 || rc.Height() <= 0) return; @@ -10,18 +10,16 @@ void GLDrawArc(const GLContext2D& dd, const Rectf& rc, Pointf start, Pointf end, Pointf center = Pointf(rc.TopLeft()) + radius; double ang1 = Direction((Pointf(start) - center) / radius); double ang2 = Direction((Pointf(end) - center) / radius); + if(ang1 < 0) + ang1 += M_2PI; + if(ang2 < 0) + ang2 += M_2PI; if(ang1 > ang2) Swap(ang1, ang2); - Vector> line; line.Add(); - for(double a = ang1; a <= ang2 + M_PI / 200; a += M_PI / 200) { + for(double a = ang1; a <= ang2 + M_PI / 200; a += M_PI / 200) line.Top().Add(radius * Polar(min(a, ang2)) + center); - } - - GLVertexData l; - GLPolylines(l, line); - GLDrawPolylines(dd, Pointf(0, 0), l, Sizef(1, 1), width, color, alpha); } }; \ No newline at end of file diff --git a/bazaar/GLPainter/DrawGL.cpp b/bazaar/GLPainter/DrawGL.cpp index aa09f9626..405fc21f0 100644 --- a/bazaar/GLPainter/DrawGL.cpp +++ b/bazaar/GLPainter/DrawGL.cpp @@ -139,14 +139,33 @@ void DrawGL::DrawTextOp(int x, int y, int angle, const wchar *text, Font font, C GLDrawText(dd, Offset(x, y), angle * M_2PI / 3600, text, font, ink, n, dx); } -void DrawGL::DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color) +void DrawGL::ApplyDash(Vector>& polyline, int& width) { - // TODO... -} + if(width == 0) + width = 1; + if(width > 0) + return; + if(width == PEN_NULL) { + width = 0; + return; + } -void DrawGL::DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor) -{ - GLDrawEllipse(dd, Offset(r.CenterPoint()), Sizef(r.GetSize()) / 2, color, pen, pencolor); + static Vector dash = { 18, 6 }; + static Vector dot = { 3, 3 }; + static Vector dashdot = { 9, 6, 3, 6 }; + static Vector dashdotdot = { 9, 3, 3, 3, 3, 3 }; + + Vector& d = *decode(width, PEN_DASH, &dash, + PEN_DOT, &dot, + PEN_DASHDOT, &dashdot, + &dashdotdot); + + Vector> r; + for(auto& l : polyline) + DashPolyline(r, l, d); + + polyline = pick(r); + width = 1; } void DrawGL::DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color) @@ -155,10 +174,29 @@ void DrawGL::DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color) poly.Add().Add(Offset(x1, y1)); poly.Top().Add(Offset(x2, y2)); + ApplyDash(poly, width); + GLVertexData data; GLPolylines(data, poly); - GLDrawPolylines(dd, Pointf(0, 0), data, Sizef(1, 1), max(width, 1), color); + if(width > 0) + GLDrawPolylines(dd, Pointf(0, 0), data, Sizef(1, 1), width, color); +} + +void DrawGL::DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color) +{ + Vector> poly; + GLArc(poly, rc, start, end); + ApplyDash(poly, width); + GLVertexData data; + GLPolylines(data, poly); + if(width > 0) + GLDrawPolylines(dd, Pointf(0, 0), data, Sizef(1, 1), width, color); +} + +void DrawGL::DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor) +{ + GLDrawEllipse(dd, Offset(r.CenterPoint()), Sizef(r.GetSize()) / 2, color, pen, pencolor); } void DrawGL::DoPath(Vector>& poly, const Point *pp, const Point *end) @@ -180,8 +218,10 @@ void DrawGL::DrawPolyPolylineOp(const Point *vertices, int vertex_count, const i } GLVertexData data; + ApplyDash(poly, width); GLPolylines(data, poly); - GLDrawPolylines(dd, Pointf(0, 0), data, Sizef(1, 1), max(width, 1), color); + if(width > 0) + GLDrawPolylines(dd, Pointf(0, 0), data, Sizef(1, 1), width, color); } void DrawGL::DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count, const int *subpolygon_counts, int scc, @@ -208,8 +248,10 @@ void DrawGL::DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count, cons GLVertexData data; for(auto& pl : poly) pl.Add(pl[0]); + ApplyDash(poly, width); GLPolylines(data, poly); - GLDrawPolylines(dd, Pointf(0, 0), data, Sizef(1, 1), max(width, 1), outline); + if(width > 0) + GLDrawPolylines(dd, Pointf(0, 0), data, Sizef(1, 1), width, outline); } } diff --git a/bazaar/GLPainter/GLPainter.h b/bazaar/GLPainter/GLPainter.h index 9f30d5222..45122408c 100644 --- a/bazaar/GLPainter/GLPainter.h +++ b/bazaar/GLPainter/GLPainter.h @@ -175,7 +175,7 @@ template void GLPolylines(GLVertexData& data, const Src& polygon); void DashPolyline(Vector>& polyline, const Vector& line, - const Vector& pattern, double distance); + const Vector& pattern, double distance = 0); void GLDrawPolylines(const GLContext2D& dd, Pointf at, const GLVertexData& mesh, Sizef scale, double width, Color color, double alpha = 1); @@ -184,14 +184,13 @@ void GLDrawStencil(Color color, double alpha); void GLDrawEllipse(const GLContext2D& dd, Pointf center, Sizef radius, Color fill_color, double width = 0, Color line_color = Null, double alpha = 1); -void GLDrawArc(const GLContext2D& dd, const Rectf& rc, Pointf start, Pointf end, int width, - Color color, double alpha = 1); - GLTexture GetGlyphGLTextureCached(double angle, int chr, Font font, Color color); void GLDrawText(const GLContext2D& dd, Pointf pos, double angle, const wchar *text, Font font, Color ink, int n = -1, const int *dx = NULL, double alpha = 1); +void GLArc(Vector>& line, const Rectf& rc, Pointf start, Pointf end); + #include "GLPainter.hpp" class DrawGL : public Draw { @@ -235,6 +234,7 @@ private: Rectf Offset(int x, int y, Size sz); void SyncScissor(); void DoPath(Vector>& poly, const Point *pp, const Point *end); + void ApplyDash(Vector>& polyline, int& width); public: void Init(Size sz, double alpha = 1); diff --git a/bazaar/GLPainter/Line.cpp b/bazaar/GLPainter/Line.cpp index 5f0646887..cdb8e3df0 100644 --- a/bazaar/GLPainter/Line.cpp +++ b/bazaar/GLPainter/Line.cpp @@ -61,7 +61,7 @@ void GLDrawPolylines(const GLContext2D& dd, Pointf at, const GLVertexData& mesh, } void DashPolyline(Vector>& polyline, const Vector& line, - const Vector& pattern, double distance = 0) + const Vector& pattern, double distance) { struct LineStore : LinearPathConsumer { Vector>& polyline;