mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-23 17:52:26 -05:00
LibDraw: Add draw_ellipse_intersecting function
This functon will draw an ellipse which is intersecting the corners of the rect given. It is a very naive implementation, taking 200 samples of points around the ellipse, and drawing straight lines between each of these points. The ellipses look good enough to me though!
This commit is contained in:
parent
0b3a868729
commit
123b5c9d34
Notes:
sideshowbarker
2024-07-19 10:38:36 +09:00
Author: https://github.com/shannonbooth Commit: https://github.com/SerenityOS/serenity/commit/123b5c9d34b Pull-request: https://github.com/SerenityOS/serenity/pull/924
2 changed files with 19 additions and 0 deletions
|
@ -140,6 +140,24 @@ void Painter::fill_rect_with_gradient(const Rect& a_rect, Color gradient_start,
|
|||
}
|
||||
}
|
||||
|
||||
void Painter::draw_ellipse_intersecting(const Rect& rect, Color color, int thickness)
|
||||
{
|
||||
constexpr int number_samples = 100; // FIXME: dynamically work out the number of samples based upon the rect size
|
||||
double increment = M_PI / number_samples;
|
||||
|
||||
auto ellipse_x = [&](double theta) -> int {
|
||||
return (cos(theta) * rect.width() / sqrt(2)) + rect.center().x();
|
||||
};
|
||||
|
||||
auto ellipse_y = [&](double theta) -> int {
|
||||
return (sin(theta) * rect.height() / sqrt(2)) + rect.center().y();
|
||||
};
|
||||
|
||||
for (float theta = 0; theta < 2 * M_PI; theta += increment) {
|
||||
draw_line({ ellipse_x(theta), ellipse_y(theta) }, { ellipse_x(theta + increment), ellipse_y(theta + increment) }, color, thickness);
|
||||
}
|
||||
}
|
||||
|
||||
void Painter::draw_rect(const Rect& a_rect, Color color, bool rough)
|
||||
{
|
||||
Rect rect = a_rect.translated(translation());
|
||||
|
|
|
@ -25,6 +25,7 @@ public:
|
|||
void draw_rect(const Rect&, Color, bool rough = false);
|
||||
void draw_bitmap(const Point&, const CharacterBitmap&, Color = Color());
|
||||
void draw_bitmap(const Point&, const GlyphBitmap&, Color = Color());
|
||||
void draw_ellipse_intersecting(const Rect&, Color, int thickness = 1);
|
||||
void set_pixel(const Point&, Color);
|
||||
void draw_line(const Point&, const Point&, Color, int thickness = 1, bool dotted = false);
|
||||
void draw_scaled_bitmap(const Rect& dst_rect, const GraphicsBitmap&, const Rect& src_rect);
|
||||
|
|
Loading…
Add table
Reference in a new issue