void GraphicPencil::draw(CDC* pDC) { CPen pen; int jump = this->points.GetCount() / 100 + 2; if (this->graphic_type == BRUSH) { jump = 1; } pen.CreatePen(this->pattern, this->thickness, this->color); pDC->SelectObject(pen); if (this->isEnd == FALSE || this->type() == GraphicType::PENCIL) { pDC->Polyline(this->points.GetData(), this->points.GetCount()); } else { Graphics g(pDC->GetSafeHdc()); Pen gpen(Color(GetRValue(this->color), GetGValue(this->color), GetBValue(this->color)), (float)this->thickness); gpen.SetLineJoin(LineJoinRound); int count = points.GetCount(); PointF* cp = new PointF[count]; for (int i = 0; i < count; i++) { cp[i].X = (Gdiplus::REAL)points[i].x; cp[i].Y = (Gdiplus::REAL)points[i].y; } g.DrawCurve(&gpen, cp, count); delete[] cp; } pen.DeleteObject(); if (isSelect) { pDC->SelectObject(this->gray_pen); for (int i = 0; i < this->points.GetCount(); i += jump) { if (this->pointSelect[i] == TRUE || this->allSelect) { pDC->SelectObject(this->black_brush); } else { pDC->SelectObject(this->white_brush); } pDC->Rectangle(this->points[i].x - this->radius, this->points[i].y - this->radius, this->points[i].x + this->radius, this->points[i].y + this->radius); } } }
void JumpingCubeWindow::drawLines(QPainter *qp) { QPen pen(Qt::black, 2, Qt::SolidLine); QPen rpen(Qt::red, 2, Qt::SolidLine); QPen gpen(Qt::green, 2, Qt::SolidLine); qp->setPen(pen); //qp->drawLine(20, 40, 250, 40); int winWidth = this->size().rwidth(); int winHeight = this->size().rheight(); float cellwidth = winWidth/boardWidth; float cellheight = winHeight/boardHeight; for (int x=0;x<boardWidth;x++){ float xp = x*cellwidth; qp->drawLine(xp, 0, xp, winHeight); } for (int y=0;y<boardHeight;y++){ float yp = y*cellheight; qp->drawLine(0, yp, winWidth, yp); } for (int x=0;x<boardWidth;x++){ float xp = x*cellwidth; for (int y=0;y<boardHeight;y++){ float yp = y*cellheight; float drawRad = board[x][y]*10; if (boardOwner[x][y] == 0)qp->setPen(rpen); else if (boardOwner[x][y] == 1)qp->setPen(gpen); if (board[x][y] == getNumSides(x,y) and false) qp->drawRect(xp+cellwidth/2-drawRad/2, yp+cellheight/2-drawRad/2, drawRad, drawRad); else { if (board[x][y] %2 == 0) qp->drawRect( xp+cellwidth/2-drawRad/2, yp+cellheight/2-drawRad/2, drawRad, drawRad); else qp->drawEllipse(xp+cellwidth/2-drawRad/2, yp+cellheight/2-drawRad/2, drawRad, drawRad); //else // qp->drawEllipse(xp+cellwidth/2-drawRad/2, yp+cellheight/2-drawRad/2, drawRad, drawRad); } std::stringstream ss; ss << boardOwner[x][y]; qp->drawText(xp,yp,ss.str().data()); qp->setPen(pen); } } /* pen.setStyle(Qt::DashLine); qp->setPen(pen); qp->drawLine(20, 80, 250, 80); pen.setStyle(Qt::DashDotLine); qp->setPen(pen); qp->drawLine(20, 120, 250, 120); pen.setStyle(Qt::DotLine); qp->setPen(pen); qp->drawLine(20, 160, 250, 160); pen.setStyle(Qt::DashDotDotLine); qp->setPen(pen); qp->drawLine(20, 200, 250, 200); QVector<qreal> dashes; qreal space = 4; dashes << 1 << space << 5 << space; pen.setStyle(Qt::CustomDashLine); pen.setDashPattern(dashes); qp->setPen(pen); qp->drawLine(20, 240, 250, 240); */ }