2020-01-18 08:38:21 +00:00
|
|
|
/*
|
2024-10-04 11:19:50 +00:00
|
|
|
* Copyright (c) 2018-2021, Andreas Kling <andreas@ladybird.org>
|
2020-01-18 08:38:21 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 08:38:21 +00:00
|
|
|
*/
|
|
|
|
|
2018-10-10 14:49:36 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-02-14 22:28:42 +00:00
|
|
|
#include <AK/Forward.h>
|
2023-03-08 19:49:00 +00:00
|
|
|
#include <AK/Memory.h>
|
2020-02-14 23:58:14 +00:00
|
|
|
#include <AK/NonnullRefPtr.h>
|
2020-02-14 20:41:10 +00:00
|
|
|
#include <AK/Vector.h>
|
|
|
|
#include <LibGfx/Color.h>
|
2020-02-14 22:28:42 +00:00
|
|
|
#include <LibGfx/Forward.h>
|
2024-06-05 08:25:10 +00:00
|
|
|
#include <LibGfx/LineStyle.h>
|
2023-01-15 22:15:24 +00:00
|
|
|
#include <LibGfx/PaintStyle.h>
|
2020-02-14 20:41:10 +00:00
|
|
|
#include <LibGfx/Point.h>
|
|
|
|
#include <LibGfx/Rect.h>
|
2024-06-05 08:10:38 +00:00
|
|
|
#include <LibGfx/ScalingMode.h>
|
2020-02-14 20:41:10 +00:00
|
|
|
#include <LibGfx/Size.h>
|
2024-06-05 08:21:28 +00:00
|
|
|
#include <LibGfx/WindingRule.h>
|
2023-01-15 22:15:24 +00:00
|
|
|
|
2020-02-06 10:56:38 +00:00
|
|
|
namespace Gfx {
|
|
|
|
|
2024-01-05 23:32:29 +00:00
|
|
|
ALWAYS_INLINE static Color color_for_format(BitmapFormat format, ARGB32 value)
|
|
|
|
{
|
|
|
|
switch (format) {
|
|
|
|
case BitmapFormat::BGRA8888:
|
|
|
|
return Color::from_argb(value);
|
|
|
|
case BitmapFormat::BGRx8888:
|
|
|
|
return Color::from_rgb(value);
|
|
|
|
// FIXME: Handle other formats
|
|
|
|
default:
|
|
|
|
VERIFY_NOT_REACHED();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-05 08:40:29 +00:00
|
|
|
class DeprecatedPainter {
|
2018-10-10 14:49:36 +00:00
|
|
|
public:
|
2024-07-05 08:40:29 +00:00
|
|
|
explicit DeprecatedPainter(Gfx::Bitmap&);
|
|
|
|
~DeprecatedPainter() = default;
|
2020-05-10 10:58:33 +00:00
|
|
|
|
2021-09-17 13:06:28 +00:00
|
|
|
void clear_rect(IntRect const&, Color);
|
|
|
|
void fill_rect(IntRect const&, Color);
|
2023-01-15 22:18:46 +00:00
|
|
|
void fill_rect(IntRect const&, PaintStyle const&);
|
2021-09-17 13:06:28 +00:00
|
|
|
void fill_rect_with_rounded_corners(IntRect const&, Color, int radius);
|
|
|
|
void fill_rect_with_rounded_corners(IntRect const&, Color, int top_left_radius, int top_right_radius, int bottom_right_radius, int bottom_left_radius);
|
|
|
|
void fill_ellipse(IntRect const&, Color);
|
|
|
|
void draw_rect(IntRect const&, Color, bool rough = false);
|
2022-12-06 20:27:44 +00:00
|
|
|
Optional<Color> get_pixel(IntPoint);
|
|
|
|
void draw_line(IntPoint, IntPoint, Color, int thickness = 1, LineStyle style = LineStyle::Solid, Color alternate_color = Color::Transparent);
|
|
|
|
void blit(IntPoint, Gfx::Bitmap const&, IntRect const& src_rect, float opacity = 1.0f, bool apply_alpha = true);
|
2023-07-29 18:33:53 +00:00
|
|
|
void blit_filtered(IntPoint, Gfx::Bitmap const&, IntRect const& src_rect, Function<Color(Color)> const&, bool apply_alpha = true);
|
2019-01-12 16:02:54 +00:00
|
|
|
|
2021-05-15 21:33:21 +00:00
|
|
|
enum class CornerOrientation {
|
|
|
|
TopLeft,
|
|
|
|
TopRight,
|
|
|
|
BottomRight,
|
|
|
|
BottomLeft
|
|
|
|
};
|
2021-09-17 13:06:28 +00:00
|
|
|
void fill_rounded_corner(IntRect const&, int radius, Color, CornerOrientation);
|
2021-05-15 21:33:21 +00:00
|
|
|
|
2022-12-06 20:57:07 +00:00
|
|
|
static void for_each_line_segment_on_bezier_curve(FloatPoint control_point, FloatPoint p1, FloatPoint p2, Function<void(FloatPoint, FloatPoint)>&);
|
|
|
|
static void for_each_line_segment_on_bezier_curve(FloatPoint control_point, FloatPoint p1, FloatPoint p2, Function<void(FloatPoint, FloatPoint)>&&);
|
2020-05-06 07:25:12 +00:00
|
|
|
|
2022-12-06 20:57:07 +00:00
|
|
|
static void for_each_line_segment_on_cubic_bezier_curve(FloatPoint control_point_0, FloatPoint control_point_1, FloatPoint p1, FloatPoint p2, Function<void(FloatPoint, FloatPoint)>&);
|
|
|
|
static void for_each_line_segment_on_cubic_bezier_curve(FloatPoint control_point_0, FloatPoint control_point_1, FloatPoint p1, FloatPoint p2, Function<void(FloatPoint, FloatPoint)>&&);
|
2021-09-17 14:12:30 +00:00
|
|
|
|
2024-08-08 08:22:03 +00:00
|
|
|
void stroke_path(DeprecatedPath const&, Color, int thickness);
|
2020-04-16 19:03:17 +00:00
|
|
|
|
2024-08-08 08:22:03 +00:00
|
|
|
void fill_path(DeprecatedPath const&, Color, WindingRule rule = WindingRule::Nonzero);
|
|
|
|
void fill_path(DeprecatedPath const&, PaintStyle const& paint_style, float opacity = 1.0f, WindingRule rule = WindingRule::Nonzero);
|
2020-05-06 07:25:12 +00:00
|
|
|
|
2021-09-17 13:06:28 +00:00
|
|
|
void add_clip_rect(IntRect const& rect);
|
2019-02-04 14:37:23 +00:00
|
|
|
|
2024-10-18 12:08:52 +00:00
|
|
|
void translate(int dx, int dy) { state().translation.translate_by({ dx, dy }); }
|
2019-03-07 12:13:25 +00:00
|
|
|
|
2022-10-01 12:04:05 +00:00
|
|
|
IntPoint translation() const { return state().translation; }
|
|
|
|
|
2024-06-05 08:43:00 +00:00
|
|
|
[[nodiscard]] Gfx::Bitmap& target() { return *m_target; }
|
2019-02-10 13:28:39 +00:00
|
|
|
|
2019-03-09 15:48:02 +00:00
|
|
|
void save() { m_state_stack.append(m_state_stack.last()); }
|
2019-06-05 16:22:11 +00:00
|
|
|
void restore()
|
|
|
|
{
|
2021-02-23 19:42:32 +00:00
|
|
|
VERIFY(m_state_stack.size() > 1);
|
2019-06-05 16:22:11 +00:00
|
|
|
m_state_stack.take_last();
|
|
|
|
}
|
2019-03-09 15:48:02 +00:00
|
|
|
|
2021-02-16 02:30:47 +00:00
|
|
|
IntRect clip_rect() const { return state().clip_rect; }
|
|
|
|
|
2019-03-28 16:19:56 +00:00
|
|
|
protected:
|
2023-03-11 16:50:54 +00:00
|
|
|
friend AntiAliasingPainter;
|
2023-05-31 18:02:00 +00:00
|
|
|
template<unsigned SamplesPerPixel>
|
|
|
|
friend class EdgeFlagPathRasterizer;
|
2023-01-10 01:07:06 +00:00
|
|
|
|
2024-06-05 06:17:28 +00:00
|
|
|
IntPoint to_physical(IntPoint p) const { return p.translated(translation()); }
|
2024-06-04 12:58:01 +00:00
|
|
|
void set_physical_pixel(u32& pixel, Color);
|
|
|
|
void fill_physical_scanline(int y, int x, int width, Color color);
|
2022-12-06 20:27:44 +00:00
|
|
|
void blit_with_opacity(IntPoint, Gfx::Bitmap const&, IntRect const& src_rect, float opacity, bool apply_alpha = true);
|
|
|
|
void draw_physical_pixel(IntPoint, Color, int thickness = 1);
|
2022-12-24 14:18:53 +00:00
|
|
|
void set_physical_pixel(IntPoint, Color color, bool blend);
|
2019-01-11 02:52:09 +00:00
|
|
|
|
2019-03-09 15:48:02 +00:00
|
|
|
struct State {
|
2021-05-03 14:37:05 +00:00
|
|
|
IntPoint translation;
|
2021-01-20 14:59:22 +00:00
|
|
|
IntRect clip_rect;
|
2019-03-09 15:48:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
State& state() { return m_state_stack.last(); }
|
2021-09-17 13:06:28 +00:00
|
|
|
State const& state() const { return m_state_stack.last(); }
|
2019-03-09 15:48:02 +00:00
|
|
|
|
2021-09-17 13:06:28 +00:00
|
|
|
void fill_physical_rect(IntRect const&, Color);
|
2021-05-03 14:37:05 +00:00
|
|
|
|
2020-02-06 10:56:38 +00:00
|
|
|
NonnullRefPtr<Gfx::Bitmap> m_target;
|
2019-04-20 12:02:19 +00:00
|
|
|
Vector<State, 4> m_state_stack;
|
2018-10-10 14:49:36 +00:00
|
|
|
};
|
2019-03-09 15:54:41 +00:00
|
|
|
|
2020-02-06 10:56:38 +00:00
|
|
|
}
|