GLPainter: DrawGL

git-svn-id: svn://ultimatepp.org/upp/trunk@12405 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2018-10-23 18:43:37 +00:00
parent 463a0fbdb2
commit cd779c9fba
4 changed files with 62 additions and 22 deletions

View file

@ -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<Vector<Pointf>>& 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<Vector<Pointf>> 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);
}
};

View file

@ -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<Vector<Pointf>>& 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<double> dash = { 18, 6 };
static Vector<double> dot = { 3, 3 };
static Vector<double> dashdot = { 9, 6, 3, 6 };
static Vector<double> dashdotdot = { 9, 3, 3, 3, 3, 3 };
Vector<double>& d = *decode(width, PEN_DASH, &dash,
PEN_DOT, &dot,
PEN_DASHDOT, &dashdot,
&dashdotdot);
Vector<Vector<Pointf>> 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<Vector<Pointf>> 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<Vector<Pointf>>& 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);
}
}

View file

@ -175,7 +175,7 @@ template <typename Src>
void GLPolylines(GLVertexData& data, const Src& polygon);
void DashPolyline(Vector<Vector<Pointf>>& polyline, const Vector<Pointf>& line,
const Vector<double>& pattern, double distance);
const Vector<double>& 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<Vector<Pointf>>& 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<Vector<Pointf>>& poly, const Point *pp, const Point *end);
void ApplyDash(Vector<Vector<Pointf>>& polyline, int& width);
public:
void Init(Size sz, double alpha = 1);

View file

@ -61,7 +61,7 @@ void GLDrawPolylines(const GLContext2D& dd, Pointf at, const GLVertexData& mesh,
}
void DashPolyline(Vector<Vector<Pointf>>& polyline, const Vector<Pointf>& line,
const Vector<double>& pattern, double distance = 0)
const Vector<double>& pattern, double distance)
{
struct LineStore : LinearPathConsumer {
Vector<Vector<Pointf>>& polyline;