void CheckersBoard::drawBoard(){ bool indent = false; int xStart; // Dark wood colour // SDL_SetRenderDrawColor( gRenderer, 0x55, 0x27, 0x00, 0xFF ); for(int y=0;y<SCREEN_HEIGHT;y+=BUTTON_HEIGHT){ if (indent) { xStart = BUTTON_WIDTH; indent = false; } else{ xStart = 0; indent = true; } for(int x=xStart;x<SCREEN_WIDTH;x+=2*BUTTON_WIDTH){ SDL_Rect redRect = {x, y, BUTTON_WIDTH, BUTTON_HEIGHT}; SDL_RenderFillRect( gRenderer, &redRect); } } drawHighlights(); }
void HighlightScrollBarOverlay::paintEvent(QPaintEvent *paintEvent) { QWidget::paintEvent(paintEvent); updateCache(); if (m_highlightCache.isEmpty()) return; QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing, false); const QRect &gRect = overlayRect(); const QRect &hRect = handleRect(); const int marginX = 3; const int marginH = -2 * marginX + 1; const QRect aboveHandleRect = QRect(gRect.x() + marginX, gRect.y(), gRect.width() + marginH, hRect.y() - gRect.y()); const QRect handleRect = QRect(gRect.x() + marginX, hRect.y(), gRect.width() + marginH, hRect.height()); const QRect belowHandleRect = QRect(gRect.x() + marginX, hRect.y() + hRect.height(), gRect.width() + marginH, gRect.height() - hRect.height() + gRect.y() - hRect.y()); const int aboveValue = m_scrollBar->value(); const int belowValue = m_scrollBar->maximum() - m_scrollBar->value(); const int sizeDocAbove = aboveValue * int(m_highlightController->lineHeight()); const int sizeDocBelow = belowValue * int(m_highlightController->lineHeight()); const int sizeDocVisible = int(m_highlightController->visibleRange()); const int scrollBarBackgroundHeight = aboveHandleRect.height() + belowHandleRect.height(); const int sizeDocInvisible = sizeDocAbove + sizeDocBelow; const double backgroundRatio = sizeDocInvisible ? ((double)scrollBarBackgroundHeight / sizeDocInvisible) : 0; if (aboveValue) { drawHighlights(&painter, 0, sizeDocAbove, backgroundRatio, 0, aboveHandleRect); } if (belowValue) { // This is the hypothetical handle height if the handle would // be stretched using the background ratio. const double handleVirtualHeight = sizeDocVisible * backgroundRatio; // Skip the doc above and visible part. const int offset = qRound(aboveHandleRect.height() + handleVirtualHeight); drawHighlights(&painter, sizeDocAbove + sizeDocVisible, sizeDocBelow, backgroundRatio, offset, belowHandleRect); } const double handleRatio = sizeDocVisible ? ((double)handleRect.height() / sizeDocVisible) : 0; // This is the hypothetical handle position if the background would // be stretched using the handle ratio. const double aboveVirtualHeight = sizeDocAbove * handleRatio; // This is the accurate handle position (double) const double accurateHandlePos = sizeDocAbove * backgroundRatio; // The correction between handle position (int) and accurate position (double) const double correction = aboveHandleRect.height() - accurateHandlePos; // Skip the doc above and apply correction const int offset = qRound(aboveVirtualHeight + correction); drawHighlights(&painter, sizeDocAbove, sizeDocVisible, handleRatio, offset, handleRect); }