mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 23:57:34 +00:00
LibGfx: Make it possible to apply an (integer) scale to a Painter
This adds a scale factor to Painter, which will be used for HighDPI support. It's also a step towards general affine transforms on Painters. All of Painter's public API takes logical coordinates, while some internals deal with physical coordinates now. If scale == 1, logical and physical coordinates are the same. For scale == 2, a 200x100 bitmap would be covered by a logical {0, 0, 100, 50} rect, while its physical size would be {0, 0, 200, 100}. Most of Painter's functions just assert that scale() == 1 is for now, but most functions called by WindowServer are updated to handle arbitrary (integer) scale. Also add a new Demo "LibGfxScaleDemo" that covers the converted functions and that can be used to iteratively add scaling support to more functions. To make Painter's interface deal with logical coordinates only, make translation() and clip_rect() non-public.
This commit is contained in:
parent
545b4879e4
commit
d551263b11
7 changed files with 288 additions and 73 deletions
|
@ -116,12 +116,10 @@ public:
|
|||
|
||||
void add_clip_rect(const IntRect& rect);
|
||||
void clear_clip_rect();
|
||||
IntRect clip_rect() const { return state().clip_rect; }
|
||||
|
||||
void translate(int dx, int dy) { state().translation.move_by(dx, dy); }
|
||||
void translate(const IntPoint& delta) { state().translation.move_by(delta); }
|
||||
|
||||
IntPoint translation() const { return state().translation; }
|
||||
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(); }
|
||||
|
||||
|
@ -133,23 +131,31 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
IntPoint translation() const { return state().translation; }
|
||||
IntRect to_physical(const IntRect& r) const { return (r * scale()).translated(translation()); }
|
||||
IntPoint to_physical(const IntPoint& p) const { return (p * scale()).translated(translation()); }
|
||||
int scale() const { return state().scale; }
|
||||
void set_pixel_with_draw_op(u32& pixel, const Color&);
|
||||
void fill_scanline_with_draw_op(int y, int x, int width, const Color& color);
|
||||
void fill_rect_with_draw_op(const IntRect&, Color);
|
||||
void blit_with_alpha(const IntPoint&, const Gfx::Bitmap&, const IntRect& src_rect);
|
||||
void blit_with_opacity(const IntPoint&, const Gfx::Bitmap&, const IntRect& src_rect, float opacity);
|
||||
void draw_pixel(const IntPoint&, Color, int thickness = 1);
|
||||
void draw_physical_pixel(const IntPoint&, Color, int thickness = 1);
|
||||
IntRect clip_rect() const { return state().clip_rect; }
|
||||
|
||||
struct State {
|
||||
const Font* font;
|
||||
IntPoint translation;
|
||||
IntRect clip_rect;
|
||||
int scale = 1;
|
||||
IntRect clip_rect; // In physical coordinates.
|
||||
DrawOp draw_op;
|
||||
};
|
||||
|
||||
State& state() { return m_state_stack.last(); }
|
||||
const State& state() const { return m_state_stack.last(); }
|
||||
|
||||
void fill_physical_rect(const IntRect&, Color);
|
||||
|
||||
IntRect m_clip_origin;
|
||||
NonnullRefPtr<Gfx::Bitmap> m_target;
|
||||
Vector<State, 4> m_state_stack;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue