bool FloatRoundedRect::xInterceptsAtY(float y, float& minXIntercept, float& maxXIntercept) const { if (y < rect().y() || y > rect().maxY()) return false; if (!isRounded()) { minXIntercept = rect().x(); maxXIntercept = rect().maxX(); return true; } const FloatRect& topLeftRect = topLeftCorner(); const FloatRect& bottomLeftRect = bottomLeftCorner(); if (!topLeftRect.isEmpty() && y >= topLeftRect.y() && y < topLeftRect.maxY()) minXIntercept = topLeftRect.maxX() - cornerRectIntercept(topLeftRect.maxY() - y, topLeftRect); else if (!bottomLeftRect.isEmpty() && y >= bottomLeftRect.y() && y <= bottomLeftRect.maxY()) minXIntercept = bottomLeftRect.maxX() - cornerRectIntercept(y - bottomLeftRect.y(), bottomLeftRect); else minXIntercept = m_rect.x(); const FloatRect& topRightRect = topRightCorner(); const FloatRect& bottomRightRect = bottomRightCorner(); if (!topRightRect.isEmpty() && y >= topRightRect.y() && y <= topRightRect.maxY()) maxXIntercept = topRightRect.x() + cornerRectIntercept(topRightRect.maxY() - y, topRightRect); else if (!bottomRightRect.isEmpty() && y >= bottomRightRect.y() && y <= bottomRightRect.maxY()) maxXIntercept = bottomRightRect.x() + cornerRectIntercept(y - bottomRightRect.y(), bottomRightRect); else maxXIntercept = m_rect.maxX(); return true; }
template<typename MatrixType> void corners(const MatrixType& m) { typedef typename MatrixType::Index Index; Index rows = m.rows(); Index cols = m.cols(); Index r = internal::random<Index>(1,rows); Index c = internal::random<Index>(1,cols); MatrixType matrix = MatrixType::Random(rows,cols); const MatrixType const_matrix = MatrixType::Random(rows,cols); COMPARE_CORNER(topLeftCorner(r,c), block(0,0,r,c)); COMPARE_CORNER(topRightCorner(r,c), block(0,cols-c,r,c)); COMPARE_CORNER(bottomLeftCorner(r,c), block(rows-r,0,r,c)); COMPARE_CORNER(bottomRightCorner(r,c), block(rows-r,cols-c,r,c)); Index sr = internal::random<Index>(1,rows) - 1; Index nr = internal::random<Index>(1,rows-sr); Index sc = internal::random<Index>(1,cols) - 1; Index nc = internal::random<Index>(1,cols-sc); COMPARE_CORNER(topRows(r), block(0,0,r,cols)); COMPARE_CORNER(middleRows(sr,nr), block(sr,0,nr,cols)); COMPARE_CORNER(bottomRows(r), block(rows-r,0,r,cols)); COMPARE_CORNER(leftCols(c), block(0,0,rows,c)); COMPARE_CORNER(middleCols(sc,nc), block(0,sc,rows,nc)); COMPARE_CORNER(rightCols(c), block(0,cols-c,rows,c)); }
/////////////// // TOP RIGHT // /////////////// sf::Vector2f Fonction::topRightCorner(const sf::Sprite& sprite) { return topRightCorner(sprite.getGlobalBounds()); }
void UIWidget::drawImage(const Rect& screenCoords) { if(!m_imageTexture || !screenCoords.isValid()) return; // cache vertex buffers if(m_imageCachedScreenCoords != screenCoords || m_imageMustRecache) { m_imageCoordsBuffer.clear(); m_imageCachedScreenCoords = screenCoords; m_imageMustRecache = false; Rect drawRect = screenCoords; drawRect.translate(m_imageRect.topLeft()); if(m_imageRect.isValid()) drawRect.resize(m_imageRect.size()); Rect clipRect = m_imageClipRect.isValid() ? m_imageClipRect : Rect(0, 0, m_imageTexture->getSize()); if(!m_imageBordered) { if(m_imageFixedRatio) { Size textureSize = m_imageTexture->getSize(); Size textureClipSize = drawRect.size(); textureClipSize.scale(textureSize, Fw::KeepAspectRatio); Point texCoordsOffset; if(textureSize.height() > textureClipSize.height()) texCoordsOffset.y = (textureSize.height() - textureClipSize.height())/2; else if(textureSize.width() > textureClipSize.width()) texCoordsOffset.x = (textureSize.width() - textureClipSize.width())/2; Rect textureClipRect(texCoordsOffset, textureClipSize); m_imageCoordsBuffer.addRect(drawRect, textureClipRect); } else { if(m_imageRepeated) m_imageCoordsBuffer.addRepeatedRects(drawRect, clipRect); else m_imageCoordsBuffer.addRect(drawRect, clipRect); } } else { int top = m_imageBorder.top; int bottom = m_imageBorder.bottom; int left = m_imageBorder.left; int right = m_imageBorder.right; // calculates border coords const Rect clip = clipRect; Rect leftBorder(clip.left(), clip.top() + top, left, clip.height() - top - bottom); Rect rightBorder(clip.right() - right + 1, clip.top() + top, right, clip.height() - top - bottom); Rect topBorder(clip.left() + left, clip.top(), clip.width() - right - left, top); Rect bottomBorder(clip.left() + left, clip.bottom() - bottom + 1, clip.width() - right - left, bottom); Rect topLeftCorner(clip.left(), clip.top(), left, top); Rect topRightCorner(clip.right() - right + 1, clip.top(), right, top); Rect bottomLeftCorner(clip.left(), clip.bottom() - bottom + 1, left, bottom); Rect bottomRightCorner(clip.right() - right + 1, clip.bottom() - bottom + 1, right, bottom); Rect center(clip.left() + left, clip.top() + top, clip.width() - right - left, clip.height() - top - bottom); Size bordersSize(leftBorder.width() + rightBorder.width(), topBorder.height() + bottomBorder.height()); Size centerSize = drawRect.size() - bordersSize; Rect rectCoords; // first the center if(centerSize.area() > 0) { rectCoords = Rect(drawRect.left() + leftBorder.width(), drawRect.top() + topBorder.height(), centerSize); m_imageCoordsBuffer.addRepeatedRects(rectCoords, center); } // top left corner rectCoords = Rect(drawRect.topLeft(), topLeftCorner.size()); m_imageCoordsBuffer.addRepeatedRects(rectCoords, topLeftCorner); // top rectCoords = Rect(drawRect.left() + topLeftCorner.width(), drawRect.topLeft().y, centerSize.width(), topBorder.height()); m_imageCoordsBuffer.addRepeatedRects(rectCoords, topBorder); // top right corner rectCoords = Rect(drawRect.left() + topLeftCorner.width() + centerSize.width(), drawRect.top(), topRightCorner.size()); m_imageCoordsBuffer.addRepeatedRects(rectCoords, topRightCorner); // left rectCoords = Rect(drawRect.left(), drawRect.top() + topLeftCorner.height(), leftBorder.width(), centerSize.height()); m_imageCoordsBuffer.addRepeatedRects(rectCoords, leftBorder); // right rectCoords = Rect(drawRect.left() + leftBorder.width() + centerSize.width(), drawRect.top() + topRightCorner.height(), rightBorder.width(), centerSize.height()); m_imageCoordsBuffer.addRepeatedRects(rectCoords, rightBorder); // bottom left corner rectCoords = Rect(drawRect.left(), drawRect.top() + topLeftCorner.height() + centerSize.height(), bottomLeftCorner.size()); m_imageCoordsBuffer.addRepeatedRects(rectCoords, bottomLeftCorner); // bottom rectCoords = Rect(drawRect.left() + bottomLeftCorner.width(), drawRect.top() + topBorder.height() + centerSize.height(), centerSize.width(), bottomBorder.height()); m_imageCoordsBuffer.addRepeatedRects(rectCoords, bottomBorder); // bottom right corner rectCoords = Rect(drawRect.left() + bottomLeftCorner.width() + centerSize.width(), drawRect.top() + topRightCorner.height() + centerSize.height(), bottomRightCorner.size()); m_imageCoordsBuffer.addRepeatedRects(rectCoords, bottomRightCorner); } } // smooth is now enabled by default for all textures //m_imageTexture->setSmooth(m_imageSmooth); g_painter->setColor(m_imageColor); g_painter->drawTextureCoords(m_imageCoordsBuffer, m_imageTexture); }