You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
GIF Animation (open the image in full resolution in a new tab):
LibGfx Code:
voiddraw_rounded_rect(GUI::Painter &painter, const Gfx::Color &color, const Gfx::IntRect &rect, int rad, bool fill) {
auto path = Gfx::Path();
constfloat left = rect.left(), right = rect.right(), top = rect.top(), bottom = rect.bottom();
path.move_to({ left + rad, top });
path.line_to({ right - rad, top });
path.quadratic_bezier_curve_to({ right, top }, { right, top + rad });
path.line_to({ right, bottom - rad });
path.quadratic_bezier_curve_to({ right, bottom }, { right - rad, bottom });
path.line_to({ left + rad, bottom });
path.quadratic_bezier_curve_to({ left, bottom }, { left, bottom - rad });
path.line_to({ left, top + rad });
path.quadratic_bezier_curve_to({ left, top }, { left + rad, top });
path.close();
painter.fill_path(path, color, Gfx::Painter::WindingRule::EvenOdd);
}
Qt 5 Code:
voiddrawRoundedRect(QPainter &painter, const QColor &color, const QRect &rect, int rad, bool fill) {
int left = rect.left(), right = rect.right(), top = rect.top(), bottom = rect.bottom();
QPainterPath p;
p.moveTo(left + rad, top);
p.lineTo(right - rad, top);
p.quadTo(right, top, right, top + rad);
p.lineTo(right, bottom - rad);
p.quadTo(right, bottom, right - rad, bottom);
p.lineTo(left + rad, bottom);
p.quadTo(left, bottom, left, bottom - rad);
p.lineTo(left, top + rad);
p.quadTo(left, top, left + rad, top);
p.closeSubpath();
painter.fillPath(p, color);
}
The lines could probably be made more similar by tweaking the "can approximate bezier curve" tolerance.
However the fill seems to consistently draw an extra pixel on the outline, perhaps we're drawing a border somehow?
I think @SrimantaBarua made a new path-filling impl (see the TTF PR), perhaps try that one and see if it gets rid of these artifacts?
It seems that path with
quadratic_bezier_curve_to()
has some distortions compared to Qt 5, especially the fill. Maybe I'm using this method wrong?@alimpfard @linusg
GIF Animation (open the image in full resolution in a new tab):
LibGfx Code:
Qt 5 Code:
Sample Code: QuadBezierSampleCode.zip
The text was updated successfully, but these errors were encountered: