#pragma once #include "Planisphere.h" #include "../Axis/Axis.h" #include "../base/Plot_p.h" namespace YSG { struct PlanisphereData { QPointF mPos; int mRemainTimes{}; int maxTotalTimes{}; }; struct PlanisphereInputData : InputData { std::list mDataList; void clear() override { mDataList.clear(); } }; struct PlanisphereRenderState : RenderState, Planisphere_Prop { }; struct PlanispherePrivate : RenderData { D_Ptr(Planisphere) std::list dataList; QVector xs, ys; QVector fixedPoints; void update_FixedPoints() { PlanisphereRenderState *s = renderState(); fixedPoints.clear(); if(s->type == Planisphere_Type::Psk8) { double xS = s->IAxis->coordToPixel(s->IRange.lower, SRC::Render); double yS = s->QAxis->coordToPixel(s->QRange.lower, SRC::Render); double xL = s->IAxis->coordToPixel(s->IRange.upper, SRC::Render) - xS; double yL = s->QAxis->coordToPixel(s->QRange.upper, SRC::Render) - yS; double xSpace = xL/ 6.0; double ySpace = yL/ 6.0; double xLineSpace = xL / 4.0; double yLineSpace = yL / 4.0; fixedPoints.push_back({xS + 2 * xSpace, yS + 1 * ySpace}); fixedPoints.push_back({xS + 1 * xSpace, yS + 2 * ySpace}); fixedPoints.push_back({xS + 1 * xSpace, yS + 4 * ySpace}); fixedPoints.push_back({xS + 2 * xSpace, yS + 5 * ySpace}); fixedPoints.push_back({xS + 4 * xSpace, yS + 5 * ySpace}); fixedPoints.push_back({xS + 5 * xSpace, yS + 4 * ySpace}); fixedPoints.push_back({xS + 5 * xSpace, yS + 4 * ySpace}); fixedPoints.push_back({xS + 5 * xSpace, yS + 2 * ySpace}); fixedPoints.push_back({xS + 4 * xSpace, yS + 1 * ySpace}); xs.resize(5); ys.resize(5); double curX = xS, curY = yS; for(int i = 0; i < 5; ++i) { xs[i] = curX; curX += xLineSpace; ys[i] = curY; curY += yLineSpace; } } } void refresh() { for (auto it = dataList.begin(); it != dataList.end();) { if (--it->mRemainTimes == 0) dataList.erase(it++); else ++it; } } void prepareData() override { syncStatePipeline(); PlanisphereInputData *d = renderInputData(); PlanisphereRenderState *s = renderState(); int times = qMax(5, (s->continueMillisecond * q()->mPlot->d->mRefreshTimesPreSecond) / 1000); for(PlanisphereData& data : d->mDataList) { data.maxTotalTimes = times; data.mRemainTimes = times; } dataList.splice(dataList.end(), d->mDataList); clearRenderInput(); refresh(); } void draw(QPainter *painter) override { update_FixedPoints(); PlanisphereRenderState *s = renderState(); { double xS = xs.first(), xE = xs.last(); double yS = ys.first(), yE = ys.last(); QPen pen; pen.setStyle(Qt::DotLine); pen.setColor(Qt::white); painter->setPen(pen); for(double x : xs) painter->drawLine(QPointF(x, yS), QPointF(x, yE)); for(double y : ys) painter->drawLine(QPointF(xS, y), QPointF(xE, y)); } { painter->setPen(Qt::NoPen); for(PlanisphereData &data : dataList) { QColor c = s->pointColor; c.setAlphaF(c.alphaF() * data.mRemainTimes / data.maxTotalTimes); painter->setBrush(c); double centerX = s->IAxis->coordToPixel(data.mPos.x(), SRC::Render); double centerY = s->QAxis->coordToPixel(data.mPos.y(), SRC::Render); double radius = 2; painter->drawEllipse({centerX - radius, centerY - radius}, 2 * radius, 2 * radius); } } { painter->setPen(QPen(s->anchorColor, 2)); painter->setBrush(Qt::NoBrush); QVector &fixedPoints = this->fixedPoints; for (auto &point: fixedPoints) { int radius = 6; painter->drawLine(QPointF{point.x() - radius, point.y()}, {point.x() + radius, point.y()}); painter->drawLine(QPointF{point.x(), point.y() - radius}, {point.x(), point.y() + radius}); } } } void plotEvent(QEvent* event) override { if(event->type() == QEvent::Resize){ auto e = reinterpret_cast(event); } } }; }