void MainWindow::startWithValues(int aX, int aY, int tX, int tY) { int i,j; QPen linesPen(Qt::blue); sizeRectX = 500/aX; sizeRectY = 500/aY; numberOfRows = aY; numberOfColumns = aX; qreal sizeOfTableX = tX * sizeRectX; qreal sizeOfTableY = tY * sizeRectY; for (i=1; i < aX; i++) { p_scene->addLine(sizeRectX*i, 0, sizeRectX*i, 500, linesPen); } for (j=1; j < aY; j++) { p_scene->addLine(0, sizeRectY*j, 500, sizeRectY*j, linesPen); } QPixmap woodPix(QCoreApplication::applicationDirPath() + "/img/table.png"); if (woodPix.isNull()) { std::cout << "Ouverture de table.png échouée, ouverture de table.jpg" << std::endl; woodPix = QPixmap(QCoreApplication::applicationDirPath() + "/img/table.jpg"); } table = p_scene->addRect( (aX/2 - tX/2) * sizeRectX, (aY/2 - tY/2) * sizeRectY, sizeOfTableX, sizeOfTableY, QPen(), QBrush(woodPix)); this->show(); }
void LabyrinthParser::paintEvent(QPaintEvent *) { QPainter p(this); const QRect rounded(roundedRect()); p.drawImage(0, 0, __labyrint); const QPainterPath veil(([&rounded, this]()->QPainterPath{ QPainterPath viel; viel.addRect(QRectF(QPointF(0.0f, 0.0f), size())); QPainterPath rect; rect.addRect(rounded); viel -= rect; return viel; })()); static const QBrush vielTexture(QColor(0x40,0x80,0x99, 0x70)); p.fillPath(veil, vielTexture); QPen linesPen(QColor(0x00, 0x00, 0x60, 0x20)); p.setPen(linesPen); if (__sectorSize.height() > 0) { for (int i(0); i < rounded.height(); i += __sectorSize.height()) { p.drawLine(rounded.left(), i + rounded.top(), rounded.right(), i + rounded.top()); } } if (__sectorSize.width() > 0) { for (int i(0); i < rounded.width(); i += __sectorSize.width()) { p.drawLine(i + rounded.left(), rounded.bottom(), i + rounded.left(), rounded.top()); } } }
void CGUIView::Draw(QPainter* painter, double scale) { painter->setBrush(Qt::green); m_space->Draw(painter); /// Finding active planets CGUIPlanet* currPl; std::vector<CGUIPlanet* > activePlanets; foreach (currPl, m_planets) { if (currPl->IsActive()) { activePlanets.push_back(currPl); } } /// Connecting active planets with lines if (!activePlanets.empty()) { QPen linesPen(CGUIPlanet::GetColor(m_playerId), 1); painter->setPen(linesPen); unsigned int min_x(0), min_y(0); unsigned int max_x(0), max_y(0); unsigned int curr_x(0), curr_y(0); activePlanets.front()->GetPlanet()->GetPosition(min_x, min_y); activePlanets.front()->GetPlanet()->GetPosition(max_x, max_y); /// Find min and max koords of active planets to determine middle planet foreach (currPl, activePlanets) { currPl->GetPlanet()->GetPosition(curr_x, curr_y); if (curr_x < min_x) { min_x = curr_x; } else if (curr_x > max_x) { max_x = curr_x; } if (curr_y < min_y) { min_y = curr_y; } else if (curr_y > max_y) { max_y = curr_y; } }
void CBirchCtrl::OnPaint() { CPaintDC dc(this); // Device context for painting if (!m_birch) return; // Double-buffering CDC* pDCMem = new CDC; CBitmap* pOldBitmap = NULL; CBitmap bmpCanvas; CRect rFrame; GetClientRect( rFrame ); pDCMem->CreateCompatibleDC( &dc ); bmpCanvas.CreateCompatibleBitmap( &dc, rFrame.Width(), rFrame.Height() ); pOldBitmap = pDCMem->SelectObject( &bmpCanvas ); // START DRAW ------------------------------------------------- // If there is a bitmap loaded, use it // Otherwise, paint the background white pDCMem->FillSolidRect( rFrame, GetSysColor(COLOR_WINDOW) ); UINT nMode = pDCMem->SetBkMode( TRANSPARENT ); CFont* pOldFont = pDCMem->SelectObject( &m_Font ); CPen *pOldPen = pDCMem->GetCurrentPen(); CPen linesPen(PS_SOLID, 1, m_crConnectingLines), marksPen(PS_SOLID, 1, m_crConnectingLines); int iLastNodePos = m_iPadding - GetScrollPos( SB_VERT ); HTREENODE curTreeNode = m_birch->GetTopNode()->pFirstChild ; while (curTreeNode) { iLastNodePos = DrawNodesRecursive( pDCMem, curTreeNode, iLastNodePos+1, &linesPen, &marksPen, rFrame ); curTreeNode = curTreeNode->pNextSibling; } pDCMem->SelectObject(pOldPen); pDCMem->SelectObject( pOldFont ); pDCMem->SetBkMode( nMode ); // END DRAW ------------------------------------------------- dc.BitBlt( 0, 0, rFrame.Width(), rFrame.Height(), pDCMem, 0, 0, SRCCOPY ); pDCMem->SelectObject( pOldBitmap ); delete pDCMem; iLastNodePos+=GetScrollPos( SB_VERT ); // Has the total document height changed? if( iLastNodePos != m_iDocHeight ) { BOOL bInvalidate = ( ( m_iDocHeight < rFrame.Height() ) != ( iLastNodePos < rFrame.Height() ) ); m_iDocHeight = iLastNodePos; ResetScrollBar(); // If the scrollbar has just been hidden/shown, repaint if( bInvalidate ) Invalidate(); } }