ClearRect::ClearRect(Cel* cel, const gfx::Rect& bounds) { ASSERT(cel); Image* image = cel->image(); if (!image) return; m_offsetX = bounds.x - cel->x(); m_offsetY = bounds.y - cel->y(); gfx::Rect bounds2 = image->bounds().createIntersection( gfx::Rect( m_offsetX, m_offsetY, bounds.w, bounds.h)); if (bounds.isEmpty()) return; m_dstImage.reset(new WithImage(image)); Doc* doc = static_cast<Doc*>(cel->document()); m_bgcolor = doc->bgColor(cel->layer()); m_copy.reset(crop_image(image, bounds2.x, bounds2.y, bounds2.w, bounds2.h, m_bgcolor)); }
ClearMask::ClearMask(Cel* cel) : WithCel(cel) { Doc* doc = static_cast<Doc*>(cel->document()); // If the mask is empty or is not visible then we have to clear the // entire image in the cel. if (!doc->isMaskVisible()) { m_seq.add(new cmd::ClearCel(cel)); return; } Image* image = cel->image(); assert(image); if (!image) return; Mask* mask = doc->mask(); m_offset = mask->bounds().origin() - cel->position(); gfx::Rect bounds = image->bounds().createIntersection( gfx::Rect( m_offset.x, m_offset.y, mask->bounds().w, mask->bounds().h)); if (bounds.isEmpty()) return; m_dstImage.reset(new WithImage(image)); m_bgcolor = doc->bgColor(cel->layer()); m_boundsX = bounds.x; m_boundsY = bounds.y; m_copy.reset(crop_image(image, bounds.x, bounds.y, bounds.w, bounds.h, m_bgcolor)); }