void RectangleTest::access() { Rectanglei rect({34, 23}, {47, 30}); constexpr Rectanglei crect({34, 23}, {47, 30}); CORRADE_COMPARE(rect.bottomLeft(), Vector2i(34, 23)); CORRADE_COMPARE(rect.topRight(), Vector2i(47, 30)); CORRADE_COMPARE(rect.bottom(), 23); CORRADE_COMPARE(rect.top(), 30); CORRADE_COMPARE(rect.left(), 34); CORRADE_COMPARE(rect.right(), 47); CORRADE_COMPARE(rect.bottomLeft(), Vector2i(34, 23)); CORRADE_COMPARE(rect.topRight(), Vector2i(47, 30)); constexpr Int bottom = crect.bottom(); constexpr Int top = crect.top(); constexpr Int left = crect.left(); constexpr Int right = crect.right(); CORRADE_COMPARE(bottom, 23); CORRADE_COMPARE(top, 30); CORRADE_COMPARE(left, 34); CORRADE_COMPARE(right, 47); constexpr Vector2i bottomLeft = crect.bottomLeft(); constexpr Vector2i topRight = crect.topRight(); CORRADE_COMPARE(bottomLeft, Vector2i(34, 23)); CORRADE_COMPARE(topRight, Vector2i(47, 30)); CORRADE_COMPARE(rect.topLeft(), Vector2i(34, 30)); CORRADE_COMPARE(rect.bottomRight(), Vector2i(47, 23)); }
/** * Submits the image to the backing store, or commits it if no backing * store is available. * * @param image Image. * @param rect Rectangle for the image determined by an IAllocator. */ void submitImage(Image const &image, Rectanglei const &rect) { Rectanglei const noBorders = rect.shrunk(border); Rectanglei const withMargin = rect.expanded(margin); if (hasBacking()) { // The margin is cleared to transparent black. backing.fill(withMargin, Image::Color(0, 0, 0, 0)); if (border > 0) { if (flags.testFlag(WrapBordersInBackingStore)) { // Wrap using the source image (left, right, top, bottom edges). backing.drawPartial(image, Rectanglei(0, 0, border, image.height()), rect.topRight() + Vector2i(-border, border)); backing.drawPartial(image, Rectanglei(image.width() - border, 0, border, image.height()), rect.topLeft + Vector2i(0, border)); backing.drawPartial(image, Rectanglei(0, 0, image.width(), border), rect.bottomLeft() + Vector2i(border, -border)); backing.drawPartial(image, Rectanglei(0, image.height() - border, image.width(), border), rect.topLeft + Vector2i(border, 0)); } } backing.draw(image, noBorders.topLeft); //backing.toQImage().save(QString("backing-%1.png").arg(uint64_t(this))); markAsChanged(rect); } else { // No backing, must commit immediately. if (border > 0) { // Expand with borders (repeat edges). QImage const srcImg = image.toQImage(); int const sw = srcImg.width(); int const sh = srcImg.height(); QImage bordered(QSize(rect.width(), rect.height()), srcImg.format()); int const w = bordered.width(); int const h = bordered.height(); QPainter painter(&bordered); painter.setCompositionMode(QPainter::CompositionMode_Source); painter.fillRect(bordered.rect(), QColor(0, 0, 0, 0)); /// @todo This really only works for a border of 1 pixels. Should /// repeat the same outmost edge pixels for every border. -jk painter.drawImage(border, border, srcImg); painter.drawImage(border, 0, srcImg, 0, 0, sw, 1); // top painter.drawImage(border, h - 1, srcImg, 0, sh - 1, sw, 1); // bottom painter.drawImage(0, border, srcImg, 0, 0, 1, sh); // left painter.drawImage(w - 1, border, srcImg, sw - 1, 0, 1, sh); // right // Corners. painter.drawImage(0, 0, srcImg, 0, 0, 1, 1); painter.drawImage(w - 1, 0, srcImg, sw - 1, 0, 1, 1); painter.drawImage(0, h - 1, srcImg, 0, sh - 1, 1, 1); painter.drawImage(w - 1, h - 1, srcImg, sw - 1, sh - 1, 1, 1); self().commit(bordered, rect.topLeft); } else { self().commit(image, noBorders.topLeft); } } }