1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:57:45 +00:00

LibGfx: Make Painter take the scale factor as constructor argument

I want to give Bitmap an intrinsic scale factor and this is a step
in that direction.

No behavior change.
This commit is contained in:
Nico Weber 2021-01-17 09:46:55 -05:00 committed by Andreas Kling
parent 7a0bc2fdb8
commit 1382bbfc57
4 changed files with 12 additions and 14 deletions

View file

@ -68,13 +68,16 @@ ALWAYS_INLINE Color get_pixel(const Gfx::Bitmap& bitmap, int x, int y)
return bitmap.get_pixel(x, y);
}
Painter::Painter(Gfx::Bitmap& bitmap)
Painter::Painter(Gfx::Bitmap& bitmap, int scale)
: m_target(bitmap)
{
ASSERT(bitmap.format() == Gfx::BitmapFormat::RGB32 || bitmap.format() == Gfx::BitmapFormat::RGBA32);
ASSERT(bitmap.width() % scale == 0);
ASSERT(bitmap.height() % scale == 0);
m_state_stack.append(State());
state().font = &FontDatabase::default_font();
state().clip_rect = { { 0, 0 }, bitmap.size() };
state().scale = scale;
m_clip_origin = state().clip_rect;
}

View file

@ -41,7 +41,7 @@ namespace Gfx {
class Painter {
public:
explicit Painter(Gfx::Bitmap&);
explicit Painter(Gfx::Bitmap&, int scale = 1);
~Painter();
enum class LineStyle {
@ -119,7 +119,6 @@ public:
void translate(int dx, int dy) { translate({ dx, dy }); }
void translate(const IntPoint& delta) { state().translation.move_by(delta * state().scale); }
void scale(int s) { state().scale *= s; }
Gfx::Bitmap* target() { return m_target.ptr(); }