mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:48:14 +00:00
PixelPaint: Support panning and scaling the image we're working on :^)
ImageEditor now supports panning (Ctrl+MiddleMouse) and scaling (Wheel) the image. This took a lot of unpleasant coordinate math, but now it actually kinda works and feels awesome! :^)
This commit is contained in:
parent
58fa9c6e89
commit
bf9e190533
4 changed files with 159 additions and 26 deletions
|
@ -49,17 +49,14 @@ Image::Image(const Gfx::Size& size)
|
|||
{
|
||||
}
|
||||
|
||||
void Image::paint_into(GUI::Painter& painter, const Gfx::Rect& dest_rect, const Gfx::Rect& src_rect)
|
||||
void Image::paint_into(GUI::Painter& painter, const Gfx::Rect& dest_rect)
|
||||
{
|
||||
(void) src_rect;
|
||||
float scale = (float)dest_rect.width() / (float)rect().width();
|
||||
Gfx::PainterStateSaver saver(painter);
|
||||
painter.add_clip_rect(dest_rect);
|
||||
for (auto& layer : m_layers) {
|
||||
auto target = dest_rect.translated(layer.location());
|
||||
target.set_size(layer.size());
|
||||
#ifdef IMAGE_DEBUG
|
||||
dbg() << "Composite layer " << layer.name() << " target: " << target << ", layer.rect: " << layer.rect();
|
||||
#endif
|
||||
auto target = dest_rect.translated(layer.location().x() * scale, layer.location().y() * scale);
|
||||
target.set_size(layer.size().width() * scale, layer.size().height() * scale);
|
||||
painter.draw_scaled_bitmap(target, layer.bitmap(), layer.rect());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue