void paintFoliation(const balazs::Foliation& foliation, QPainter &painter, int folW, int folH) { painter.save(); painter.setPen(Qt::SolidLine); painter.drawRect(0, 0, folW, folH); for(std::size_t i = 0; i < foliation.numIntervals(); i++){ double singularityHeight = heightOfSingularity(foliation, i, folH); QPointF topPoint(folW * foliation.topDivPoints()[i], 0); QPointF middlePoint(folW * foliation.topDivPoints()[i], singularityHeight); QPointF bottomPoint(folW * foliation.topDivPoints()[i], folH); painter.setPen(Qt::SolidLine); painter.drawLine(topPoint, middlePoint); painter.setPen(Qt::DotLine); painter.drawLine(bottomPoint, middlePoint); painter.save(); painter.setPen(QPen(Qt::black, 4)); painter.drawPoint(middlePoint); painter.restore(); } painter.setPen(Qt::DashLine); for(std::size_t i = 0; i < foliation.numIntervals(); i++){ QPointF topPoint(folW * foliation.bottomDivPoints()[i], folH); QPointF bottomPoint(folW * foliation.bottomDivPoints()[i], 1.05 * folH); painter.drawLine(topPoint, bottomPoint); } painter.restore(); }
void XProcessTablePrivate::drawColumnLines(QPainter *painter) { painter->save(); painter->setPen(XPT::Color::ColumnLineColor); qreal initX = 0; for(int index = 0;index < _allColumnWidth.size();index++) { initX += _allColumnWidth.at(index); QPointF topPoint(initX,0); QPointF bottomPoint(initX,height()); painter->drawLine(topPoint,bottomPoint); } painter->restore(); }
void WTFWidget::drawInnerArrow(QPainter& painter) { if(_innerPercent == 0) return; QRect rect = this->contentsRect(); QPoint center = rect.center(); painter.save(); painter.translate(center); painter.rotate(90 * _innerPercent); QColor arrowColor = QColor::fromRgb(0xff,0xff,0xff,0xff * _innerPercent); QPen pen = QPen(arrowColor); pen.setWidth(2); painter.setPen(pen); int left = - CIRCLE_INNER_RADIUS; int top = - CIRCLE_INNER_RADIUS; QRect arcRect = QRect(left,top,CIRCLE_INNER_RADIUS * 2, CIRCLE_INNER_RADIUS * 2); painter.drawArc(arcRect,90 * 16,270 * 16); // start draw arrow qreal arrowBorderLen = 8; QPainterPath path; QPoint topPoint(0, - CIRCLE_INNER_RADIUS - arrowBorderLen/2); path.moveTo(topPoint); qreal distance = (arrowBorderLen / 2) / qTan(qDegreesToRadians((double)30)); QPoint rightPoint(distance,-CIRCLE_INNER_RADIUS); path.lineTo(rightPoint); QPoint bottomPoint(0, - CIRCLE_INNER_RADIUS + arrowBorderLen/2); path.lineTo(bottomPoint); path.closeSubpath(); painter.fillPath(path,QBrush(arrowColor)); painter.translate(-center.x(),-center.y()); painter.restore(); }
void CVxDisplayArea::DrawGrid(QPainter& painter,int iW, int iH) { float fW = 1.0 * iW/m_iCol; float fH = 1.0 * iH/(m_iRow + 1); //画竖直线。 float fStartX = 0; for ( int i = 0; i < m_iCol; i ++ ) { QPoint topPoint(fStartX, 0); QPoint bottomPoint(fStartX,iH); painter.drawLine(topPoint,bottomPoint); QString strDegree = QString("E ") + QString::number(120)+ GetDegreeStr() + QString::number(15.001) + GetMinuteStr(); painter.drawText(fStartX + 5, 15, strDegree); fStartX += fW; } //画竖直线。 float fStartY = 0; for ( int i = 0; i < m_iRow + 1 + 1; i ++ )//多画最底下一条和副显示区域之间的横线。 { QPoint LeftPoint(0, fStartY); QPoint RightPoint(iW,fStartY); painter.drawLine(LeftPoint,RightPoint); if ( i < m_iRow) { QString strDegree = QString("N ") + QString::number(120)+ GetDegreeStr() + QString::number(15.001) + GetMinuteStr(); painter.drawText( 5, fStartY + fH - 10, strDegree); } fStartY += fH; } }
JFPoint JTimerObj::outputPoint(int n, JLinkObj& link) { if (!n) return rightPoint(n, link, 0, 1); return bottomPoint(n, link, 1, OUT_LAST-1); }
void RenderMathMLRoot::paint(PaintInfo& info, const LayoutPoint& paintOffset) { RenderMathMLBlock::paint(info, paintOffset); if (info.context->paintingDisabled()) return; IntPoint adjustedPaintOffset = roundedIntPoint(paintOffset + location() + contentBoxRect().location()); int startX = adjustedPaintOffset.x(); int frontWidth = lroundf(gFrontWidthEms * style()->fontSize()); int overbarWidth = roundToInt(contentLogicalWidth()) + m_overbarLeftPointShift; int baseHeight = roundToInt(contentLogicalHeight()); int rootPad = lroundf(gSpaceAboveEms * style()->fontSize()); adjustedPaintOffset.setY(adjustedPaintOffset.y() - rootPad); float radicalDipLeftPointYPos = (index() ? gRootRadicalDipLeftPointYPos : gSqrtRadicalDipLeftPointYPos) * baseHeight; FloatPoint overbarLeftPoint(startX - m_overbarLeftPointShift, adjustedPaintOffset.y()); FloatPoint bottomPoint(startX - gRadicalBottomPointXFront * frontWidth, adjustedPaintOffset.y() + baseHeight + gRadicalBottomPointLower); FloatPoint dipLeftPoint(startX - gRadicalDipLeftPointXFront * frontWidth, adjustedPaintOffset.y() + radicalDipLeftPointYPos); FloatPoint leftEnd(startX - frontWidth, dipLeftPoint.y() + gRadicalLeftEndYShiftEms * style()->fontSize()); GraphicsContextStateSaver stateSaver(*info.context); info.context->setStrokeThickness(gRadicalLineThicknessEms * style()->fontSize()); info.context->setStrokeStyle(SolidStroke); info.context->setStrokeColor(style()->visitedDependentColor(CSSPropertyColor), ColorSpaceDeviceRGB); info.context->setLineJoin(MiterJoin); info.context->setMiterLimit(style()->fontSize()); Path root; root.moveTo(FloatPoint(overbarLeftPoint.x() + overbarWidth, adjustedPaintOffset.y())); // draw top root.addLineTo(overbarLeftPoint); // draw from top left corner to bottom point of radical root.addLineTo(bottomPoint); // draw from bottom point to top of left part of radical base "dip" root.addLineTo(dipLeftPoint); // draw to end root.addLineTo(leftEnd); info.context->strokePath(root); GraphicsContextStateSaver maskStateSaver(*info.context); // Build a mask to draw the thick part of the root. Path mask; mask.moveTo(overbarLeftPoint); mask.addLineTo(bottomPoint); mask.addLineTo(dipLeftPoint); mask.addLineTo(FloatPoint(2 * dipLeftPoint.x() - leftEnd.x(), 2 * dipLeftPoint.y() - leftEnd.y())); info.context->clip(mask); // Draw the thick part of the root. info.context->setStrokeThickness(gRadicalThickLineThicknessEms * style()->fontSize()); info.context->setLineCap(SquareCap); Path line; line.moveTo(bottomPoint); line.addLineTo(dipLeftPoint); info.context->strokePath(line); }
void MyPrimitive::GenerateSphere(float a_fRadius, int a_nSubdivisions, vector3 a_v3Color) { ////Sets minimum and maximum of subdivisions //if (a_nSubdivisions < 1) //{ // GenerateCube(a_fRadius * 2, a_v3Color); // return; //} //if (a_nSubdivisions > 6) // a_nSubdivisions = 6; Release(); Init(); //Your code starts here vector3 topPoint(0.00f, a_fRadius, 0.00f); vector3 bottomPoint(0.00f, -a_fRadius, 0.00f); std::vector<std::vector<vector3>> spherePoints; //holds all other vertices on the sphere //add the middle ring of vertices; if the number of subdivisions is even, there are two middle rings if (a_nSubdivisions % 2 == 0) { std::vector<vector3> topMiddleRing; for (int x = 0; x < a_nSubdivisions; x++) { //calculate vertex positions float angle = ((2 * PI) / a_nSubdivisions) * x; float x_Value = a_fRadius * sin(angle); float z_Value = a_fRadius * cos(angle); topMiddleRing.push_back(vector3(x_Value, a_fRadius / (2 * a_nSubdivisions), z_Value)); } std::vector<vector3> bottomMiddleRing; for (int x = 0; x < a_nSubdivisions; x++) { //calculate vertex positions float angle = ((2 * PI) / a_nSubdivisions) * x; float x_Value = a_fRadius * sin(angle); float z_Value = a_fRadius * cos(angle); bottomMiddleRing.push_back(vector3(x_Value, -a_fRadius / (2 * a_nSubdivisions), z_Value)); } spherePoints.push_back(topMiddleRing); spherePoints.push_back(bottomMiddleRing); } else { std::vector<vector3> middleRing; for (int x = 0; x < a_nSubdivisions; x++) { //calculate vertex positions float angle = ((2 * PI) / a_nSubdivisions) * x; float x_Value = a_fRadius * sin(angle); float z_Value = a_fRadius * cos(angle); middleRing.push_back(vector3(x_Value, 0.00f, z_Value)); } spherePoints.push_back(middleRing); } //add more rings to the sphere equal to the number of subdivisions minus existing rings //rings can be added in pairs moving away from the middle ring/rings in both directions, //so the loop will run half the number of times int existingRings = spherePoints.size(); for (int x = 0; x < (a_nSubdivisions - existingRings)/ 2; x++) { std::vector<vector3> upperRing; std::vector<vector3> lowerRing; //get an adjusted radius for this pair of rings float adjustedRadius = (a_fRadius / ((a_nSubdivisions / 2) + 1)) * ((a_nSubdivisions / 2) - x); for (int y = 0; y < a_nSubdivisions; y++) { //calculate vertex positions float angle = ((2 * PI) / a_nSubdivisions) * y; float x_Value = adjustedRadius * sin(angle); float z_Value = adjustedRadius * cos(angle); upperRing.push_back(vector3(x_Value, a_fRadius - adjustedRadius, z_Value)); lowerRing.push_back(vector3(x_Value, -a_fRadius + adjustedRadius, z_Value)); } spherePoints.push_back(upperRing); spherePoints.push_back(lowerRing); } //draw quads around the sphere moving away from the middle ring/rings if (a_nSubdivisions % 2 == 0) { //draw middle ring of quads for (int x = 0; x < spherePoints[0].size(); x++) { if (x != spherePoints[0].size() - 1) { AddQuad(spherePoints[1][x], spherePoints[1][x + 1], spherePoints[0][x], spherePoints[0][x + 1]); } else { AddQuad(spherePoints[1][x], spherePoints[1][0], spherePoints[0][x], spherePoints[0][0]); } } //draw more rings of quads for (int x = 0; x < spherePoints.size() - 2; x++) { if (x % 2 == 0) { for (int y = 0; y < spherePoints[x].size(); y++) { if (y != spherePoints[x].size() - 1) { AddQuad(spherePoints[x][y], spherePoints[x][y + 1], spherePoints[x + 2][y], spherePoints[x + 2][y + 1]); } else { AddQuad(spherePoints[x][y], spherePoints[x][0], spherePoints[x + 2][y], spherePoints[x + 2][0]); } } } else { for (int y = 0; y < spherePoints[x].size(); y++) { if (y != spherePoints[x].size() - 1) { AddQuad(spherePoints[x + 2][y], spherePoints[x + 2][y + 1], spherePoints[x][y], spherePoints[x][y + 1]); } else { AddQuad(spherePoints[x + 2][y], spherePoints[x + 2][0], spherePoints[x][y], spherePoints[x][0]); } } } } } else { } //draw the tris for the top and bottom for (int x = 0; x < spherePoints[spherePoints.size() - 1].size(); x++) { AddVertexPosition(bottomPoint); if (x == spherePoints[spherePoints.size() - 1].size() - 1) { AddVertexPosition(spherePoints[spherePoints.size() - 1][0]); } else { AddVertexPosition(spherePoints[spherePoints.size() - 1][x + 1]); } AddVertexPosition(spherePoints[spherePoints.size() - 1][x]); } for (int x = 0; x < spherePoints[spherePoints.size() - 2].size(); x++) { AddVertexPosition(spherePoints[spherePoints.size() - 2][x]); if (x == spherePoints[spherePoints.size() - 2].size() - 1) { AddVertexPosition(spherePoints[spherePoints.size() - 2][0]); } else { AddVertexPosition(spherePoints[spherePoints.size() - 2][x + 1]); } AddVertexPosition(topPoint); } //float fValue = 0.5f; ////3--2 ////| | ////0--1 //vector3 point0(-fValue, -fValue, fValue); //0 //vector3 point1(fValue, -fValue, fValue); //1 //vector3 point2(fValue, fValue, fValue); //2 //vector3 point3(-fValue, fValue, fValue); //3 //AddQuad(point0, point1, point3, point2); //Your code ends here CompileObject(a_v3Color); }
JFPoint J1DSliderObj::outputPoint(int n, JLinkObj& link) { if (type == HORIZONTAL) return rightPoint(n, link, 0, 1); return bottomPoint(n, link, 0, 1); }