mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +00:00
LibGfx: Add BitmapPaintStyle
This is a simple paint style for filling a path with a bitmap.
This commit is contained in:
parent
5faa0014f2
commit
064ca625df
Notes:
sideshowbarker
2024-07-18 22:57:59 +09:00
Author: https://github.com/MacDue Commit: https://github.com/SerenityOS/serenity/commit/064ca625df Pull-request: https://github.com/SerenityOS/serenity/pull/18212 Reviewed-by: https://github.com/Lubrsi Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/linusg
1 changed files with 27 additions and 0 deletions
|
@ -12,6 +12,7 @@
|
|||
#include <AK/RefCounted.h>
|
||||
#include <AK/RefPtr.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibGfx/Bitmap.h>
|
||||
#include <LibGfx/Color.h>
|
||||
#include <LibGfx/Forward.h>
|
||||
#include <LibGfx/Gradients.h>
|
||||
|
@ -59,6 +60,32 @@ private:
|
|||
Color m_color;
|
||||
};
|
||||
|
||||
class BitmapPaintStyle : public PaintStyle {
|
||||
public:
|
||||
static ErrorOr<NonnullRefPtr<BitmapPaintStyle>> create(Bitmap const& bitmap, IntPoint offset = {})
|
||||
{
|
||||
return adopt_nonnull_ref_or_enomem(new (nothrow) BitmapPaintStyle(bitmap, offset));
|
||||
}
|
||||
|
||||
virtual Color sample_color(IntPoint point) const override
|
||||
{
|
||||
point += m_offset;
|
||||
if (m_bitmap->rect().contains(point))
|
||||
return m_bitmap->get_pixel(point);
|
||||
return Color();
|
||||
}
|
||||
|
||||
private:
|
||||
BitmapPaintStyle(Bitmap const& bitmap, IntPoint offset)
|
||||
: m_bitmap(bitmap)
|
||||
, m_offset(offset)
|
||||
{
|
||||
}
|
||||
|
||||
NonnullRefPtr<Bitmap const> m_bitmap;
|
||||
IntPoint m_offset;
|
||||
};
|
||||
|
||||
class GradientPaintStyle : public PaintStyle {
|
||||
public:
|
||||
ErrorOr<void> add_color_stop(float position, Color color, Optional<float> transition_hint = {})
|
||||
|
|
Loading…
Reference in a new issue