|
commit 00884f28e2610e266dc653a34b45da1af2613e31
Author: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
AuthorDate: Tue Nov 29 12:28:31 2022 +0100
Commit: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
CommitDate: Tue Nov 29 12:28:31 2022 +0100
Fix for issue [Cairo]: Arrows have a "gap" (#561)
The problem to fix is that the arrow drawn by draw_arrow1() in src/fl_symbols.cxx
displays a faint clear line between the stem and head of the arrow with the Cairo
graphics driver.
This occurs because draw_arrow1() draws the arrow in 2 steps (a rectangle +
a triangle) and the Cairo driver is configured to use antialiasing when filling
polygons. The antialiasing produces the faint line between stem and head.
Why does draw_arrow1() draw a rectangle + a triangle rather than a
7-vertex polygon? That's because the X11 graphics driver fails with its polygon-
drawing function when the polygon is also rotated: the polygon is drawn
empty.
We want to keep using antialiasing under Cairo for polygons because
the result is better with non horizontal/vertical polygon edges.
This implementation changes function draw_arrow1() which draws
the arrow as a 7-vertex filled polygon except when the graphics driver
returns false for its virtual member function can_fill_non_convex_polygon().
In that situation, draw_arrow1() draws, as before, a rectangle + a triangle.
The new, virtual member function can_fill_non_convex_polygon() returns
true except for the X11 graphics driver. Therefore, draw_arrow1() is effectively
unchanged under the X11 driver.
FL/Fl_Graphics_Driver.H | 2 ++
src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H | 1 +
src/drivers/Xlib/Fl_Xlib_Graphics_Driver_vertex.cxx | 4 ++++
src/fl_symbols.cxx | 11 +++++++++--
4 files changed, 16 insertions(+), 2 deletions(-)
diff --git FL/Fl_Graphics_Driver.H FL/Fl_Graphics_Driver.H
index 0f25756..e131a29 100644
--- FL/Fl_Graphics_Driver.H
+++ FL/Fl_Graphics_Driver.H
@@ -316,6 +316,8 @@ public:
virtual void fixloop();
virtual void end_polygon();
virtual void end_complex_polygon();
+ // default implementation is most probably enough
+ virtual bool can_fill_non_convex_polygon() { return true; }
virtual void gap();
virtual void circle(double x, double y, double r);
virtual void arc(double x, double y, double r, double start, double end);
diff --git src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H
index 899d398..016ace4 100644
--- src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H
+++ src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H
@@ -193,6 +193,7 @@ protected:
void end_loop();
void end_polygon();
void end_complex_polygon();
+ bool can_fill_non_convex_polygon();
void gap();
virtual void ellipse_unscaled(double xt, double yt, double rx, double ry);
virtual void arc_unscaled(int x, int y, int w, int h, double a1, double a2);
diff --git src/drivers/Xlib/Fl_Xlib_Graphics_Driver_vertex.cxx src/drivers/Xlib/Fl_Xlib_Graphics_Driver_vertex.cxx
index 3b43a36..1b6e7b4 100644
--- src/drivers/Xlib/Fl_Xlib_Graphics_Driver_vertex.cxx
+++ src/drivers/Xlib/Fl_Xlib_Graphics_Driver_vertex.cxx
@@ -76,6 +76,10 @@ void Fl_Xlib_Graphics_Driver::end_complex_polygon() {
if (n>2) XFillPolygon(fl_display, fl_window, gc_, short_point, n, 0, 0);
}
+bool Fl_Xlib_Graphics_Driver::can_fill_non_convex_polygon() {
+ return false;
+}
+
// shortcut the closed circles so they use XDrawArc:
// warning: these do not draw rotated ellipses correctly!
// See fl_arc.c for portable version.
diff --git src/fl_symbols.cxx src/fl_symbols.cxx
index 2f86c23..e6ebb41 100644
--- src/fl_symbols.cxx
+++ src/fl_symbols.cxx
@@ -238,8 +238,15 @@ static void draw_search(Fl_Color col)
static void draw_arrow1(Fl_Color col)
{
fl_color(col);
- BP; vv(-0.8,-0.4); vv(-0.8,0.4); vv(0.0,0.4); vv(0.0,-0.4); EP;
- BP; vv(0.0,0.8); vv(0.8,0.0); vv(0.0,-0.8); vv(0.0,-0.4); vv(0.0,0.4); EP;
+ if (fl_graphics_driver->can_fill_non_convex_polygon()) {
+ // draw the arrow as a 7-vertex filled polygon
+ BP; vv(-0.8,-0.4); vv(-0.8,0.4); vv(0.0,0.4); vv(0.0,0.8); vv(0.8,0.0);
+ vv(0.0,-0.8); vv(0.0,-0.4); EP;
+ } else {
+ // draw the arrow as a rectangle plus a triangle
+ BP; vv(-0.8,-0.4); vv(-0.8,0.4); vv(0.0,0.4); vv(0.0,-0.4); EP;
+ BP; vv(0.0,0.8); vv(0.8,0.0); vv(0.0,-0.8); vv(0.0,-0.4); vv(0.0,0.4); EP;
+ }
set_outline_color(col);
BC; vv(-0.8,-0.4); vv(-0.8,0.4); vv(0.0,0.4); vv(0.0,0.8); vv(0.8,0.0);
vv(0.0,-0.8); vv(0.0,-0.4); EC;
[ Direct Link to Message ] | |