mirror of
https://bitbucket.org/mfeemster/fractorium.git
synced 2025-08-16 12:25:08 -04:00
22.21.4.2 4/19/2021
--User changes -Allow users to set the Exp value when using the Exp temporal filter type. -Set the default temporal filter type to be Box, which does not alter the palette values at all during animation. This is done to avoid confusion when using Gaussian or Exp which can produce darkened images. --Bug fixes -Sending a sequence to the final render dialog when the keyframes had non zero rotate and center Y values would produce off center animations when rendered. -Temporal filters were being unnecessarily recreated many times when rendering or generating sequences. -Exp filter was always treated like a Box filter. --Code changes -Add a new member function SaveCurrentAsXml(QString filename = "") to the controllers which is only used for testing. -Modernize some C++ code.
This commit is contained in:
@ -39,7 +39,7 @@ public:
|
||||
QColor Color() const;
|
||||
|
||||
protected:
|
||||
virtual void paintEvent(QPaintEvent* event) override;
|
||||
void paintEvent(QPaintEvent* event) override;
|
||||
|
||||
private:
|
||||
QPen m_Pen;
|
||||
|
@ -78,7 +78,7 @@ void ColorPickerWidget::resizeEvent(QResizeEvent* event)
|
||||
void ColorPickerWidget::OnColorViewerClicked()
|
||||
{
|
||||
m_ColorDialog->setCurrentColor(m_ColorPanel->Color());
|
||||
auto newColor = m_ColorDialog->getColor(m_ColorPanel->Color(), this);
|
||||
const auto newColor = m_ColorDialog->getColor(m_ColorPanel->Color(), this);
|
||||
SetColorPanelColor(newColor);
|
||||
}
|
||||
|
||||
|
@ -105,10 +105,10 @@ ColorTriangle::ColorTriangle(QWidget* parent)
|
||||
void ColorTriangle::Polish()
|
||||
{
|
||||
outerRadius = CalcOuterRadius();//Matt
|
||||
penWidth = (int)Floor(outerRadius / 50.0);
|
||||
ellipseSize = (int) Floor(outerRadius / 12.5);
|
||||
double cx = (double) contentsRect().center().x();
|
||||
double cy = (double) contentsRect().center().y();
|
||||
penWidth = static_cast<int>(Floor(outerRadius / 50.0));
|
||||
ellipseSize = static_cast<int>(Floor(outerRadius / 12.5));
|
||||
const auto cx = static_cast<double>(contentsRect().center().x());
|
||||
const auto cy = static_cast<double>(contentsRect().center().y());
|
||||
pa = QPointF(cx + (std::cos(a) * (outerRadius - (outerRadius / 5.0))),
|
||||
cy - (std::sin(a) * (outerRadius - (outerRadius / 5.0))));
|
||||
pb = QPointF(cx + (std::cos(b) * (outerRadius - (outerRadius / 5.0))),
|
||||
@ -147,7 +147,7 @@ int ColorTriangle::heightForWidth(int w) const
|
||||
void ColorTriangle::GenBackground()
|
||||
{
|
||||
// Find the inner radius of the hue donut.
|
||||
double innerRadius = outerRadius - outerRadius / 5;
|
||||
const auto innerRadius = outerRadius - outerRadius / 5.0;
|
||||
// Create an image of the same size as the contents rect.
|
||||
bg = QImage(contentsRect().size(), QImage::Format_RGB32);
|
||||
QPainter p(&bg);
|
||||
@ -162,15 +162,15 @@ void ColorTriangle::GenBackground()
|
||||
#if QT_VERSION < 0x040100
|
||||
color.setHsv(int(i * 360.0), 255, 255);
|
||||
#else
|
||||
color.setHsv(int(360.0 - (i * 360.0)), 255, 255);
|
||||
color.setHsv(static_cast<int>(360.0 - (i * 360.0)), 255, 255);
|
||||
#endif
|
||||
gradient.setColorAt(i, color);
|
||||
}
|
||||
|
||||
QRectF innerRadiusRect(bg.rect().center().x() - innerRadius, bg.rect().center().y() - innerRadius,
|
||||
innerRadius * 2 + 1, innerRadius * 2 + 1);
|
||||
QRectF outerRadiusRect(bg.rect().center().x() - outerRadius, bg.rect().center().y() - outerRadius,
|
||||
outerRadius * 2 + 1, outerRadius * 2 + 1);
|
||||
const QRectF innerRadiusRect(bg.rect().center().x() - innerRadius, bg.rect().center().y() - innerRadius,
|
||||
innerRadius * 2 + 1, innerRadius * 2 + 1);
|
||||
const QRectF outerRadiusRect(bg.rect().center().x() - outerRadius, bg.rect().center().y() - outerRadius,
|
||||
outerRadius * 2 + 1, outerRadius * 2 + 1);
|
||||
QPainterPath path;
|
||||
path.addEllipse(innerRadiusRect);
|
||||
path.addEllipse(outerRadiusRect);
|
||||
@ -178,15 +178,15 @@ void ColorTriangle::GenBackground()
|
||||
p.setClipPath(path);
|
||||
p.fillRect(bg.rect(), gradient);
|
||||
p.restore();
|
||||
double penThickness = bg.width() / 400.0;
|
||||
const auto penThickness = bg.width() / 400.0;
|
||||
|
||||
for (int f = 0; f <= 5760; f += 20)
|
||||
{
|
||||
int value = int((0.5 + std::cos(((f - 1800) / 5760.0) * TWOPI) / 2) * 255.0);
|
||||
color.setHsv(int((f / 5760.0) * 360.0), 128 + (255 - value) / 2, 255 - (255 - value) / 4);
|
||||
int value = static_cast<int>((0.5 + std::cos(((f - 1800) / 5760.0) * TWOPI) / 2) * 255.0);
|
||||
color.setHsv(static_cast<int>((f / 5760.0) * 360.0), 128 + (255 - value) / 2, 255 - (255 - value) / 4);
|
||||
p.setPen(QPen(color, penThickness));
|
||||
p.drawArc(innerRadiusRect, 1440 - f, 20);
|
||||
color.setHsv(int((f / 5760.0) * 360.0), 128 + value / 2, 255 - value / 4);
|
||||
color.setHsv(static_cast<int>((f / 5760.0) * 360.0), 128 + value / 2, 255 - value / 4);
|
||||
p.setPen(QPen(color, penThickness));
|
||||
p.drawArc(outerRadiusRect, 2880 - 1440 - f, 20);
|
||||
}
|
||||
@ -205,7 +205,7 @@ void ColorTriangle::mouseMoveEvent(QMouseEvent* e)
|
||||
if ((e->buttons() & Qt::LeftButton) == 0)
|
||||
return;
|
||||
|
||||
QPointF depos((double) e->pos().x(), (double) e->pos().y());
|
||||
const QPointF depos(static_cast<double>(e->pos().x()), static_cast<double>(e->pos().y()));
|
||||
bool newColor = false;
|
||||
|
||||
if (selMode == SelectingHue)
|
||||
@ -225,7 +225,7 @@ void ColorTriangle::mouseMoveEvent(QMouseEvent* e)
|
||||
|
||||
if (am < 0) am += TWOPI;
|
||||
|
||||
curHue = 360 - (int) (((am) * 360.0) / TWOPI);
|
||||
curHue = 360 - static_cast<int>(((am) * 360.0) / TWOPI);
|
||||
int h, s, v;
|
||||
curColor.getHsv(&h, &s, &v);
|
||||
|
||||
@ -235,8 +235,8 @@ void ColorTriangle::mouseMoveEvent(QMouseEvent* e)
|
||||
curColor.setHsv(curHue, s, v);
|
||||
}
|
||||
|
||||
double cx = (double) contentsRect().center().x();
|
||||
double cy = (double) contentsRect().center().y();
|
||||
const auto cx = static_cast<double>(contentsRect().center().x());
|
||||
const auto cy = static_cast<double>(contentsRect().center().y());
|
||||
pa = QPointF(cx + (std::cos(a) * (outerRadius - (outerRadius / 5.0))),
|
||||
cy - (std::sin(a) * (outerRadius - (outerRadius / 5.0))));
|
||||
pb = QPointF(cx + (std::cos(b) * (outerRadius - (outerRadius / 5.0))),
|
||||
@ -263,7 +263,7 @@ void ColorTriangle::mouseMoveEvent(QMouseEvent* e)
|
||||
if (p2->point.y() > p3->point.y()) swap(&p2, &p3);
|
||||
|
||||
selectorPos = MovePointToTriangle(depos.x(), depos.y(), aa, bb, cc);
|
||||
QColor col = ColorFromPoint(selectorPos);
|
||||
const auto col = ColorFromPoint(selectorPos);
|
||||
|
||||
if (col != curColor)
|
||||
{
|
||||
@ -297,8 +297,8 @@ void ColorTriangle::mousePressEvent(QMouseEvent* e)
|
||||
return;
|
||||
|
||||
//QMessageBox::information(NULL, "Gradient", "press");
|
||||
QPointF depos((double) e->pos().x(), (double) e->pos().y());
|
||||
double rad = RadiusAt(depos, contentsRect());
|
||||
const QPointF depos(static_cast<double>(e->pos().x()), static_cast<double>(e->pos().y()));
|
||||
const auto rad = RadiusAt(depos, contentsRect());
|
||||
bool newColor = false;
|
||||
|
||||
// As in mouseMoveEvent, either find the a,b,c angles or the
|
||||
@ -319,7 +319,7 @@ void ColorTriangle::mousePressEvent(QMouseEvent* e)
|
||||
|
||||
if (am < 0) am += TWOPI;
|
||||
|
||||
curHue = 360 - (int) ((am * 360.0) / TWOPI);
|
||||
curHue = 360 - static_cast<int>((am * 360.0) / TWOPI);
|
||||
int h, s, v;
|
||||
curColor.getHsv(&h, &s, &v);
|
||||
|
||||
@ -329,8 +329,8 @@ void ColorTriangle::mousePressEvent(QMouseEvent* e)
|
||||
curColor.setHsv(curHue, s, v);
|
||||
}
|
||||
|
||||
double cx = (double) contentsRect().center().x();
|
||||
double cy = (double) contentsRect().center().y();
|
||||
const auto cx = static_cast<double>(contentsRect().center().x());
|
||||
const auto cy = static_cast<double>(contentsRect().center().y());
|
||||
pa = QPointF(cx + (std::cos(a) * (outerRadius - (outerRadius / 5.0))),
|
||||
cy - (std::sin(a) * (outerRadius - (outerRadius / 5.0))));
|
||||
pb = QPointF(cx + (std::cos(b) * (outerRadius - (outerRadius / 5.0))),
|
||||
@ -360,7 +360,7 @@ void ColorTriangle::mousePressEvent(QMouseEvent* e)
|
||||
if (p2->point.y() > p3->point.y()) swap(&p2, &p3);
|
||||
|
||||
selectorPos = MovePointToTriangle(depos.x(), depos.y(), aa, bb, cc);
|
||||
QColor col = ColorFromPoint(selectorPos);
|
||||
const auto col = ColorFromPoint(selectorPos);
|
||||
|
||||
if (col != curColor)
|
||||
{
|
||||
@ -477,10 +477,10 @@ void ColorTriangle::keyPressEvent(QKeyEvent* e)
|
||||
void ColorTriangle::resizeEvent(QResizeEvent*)
|
||||
{
|
||||
outerRadius = CalcOuterRadius();//Matt
|
||||
penWidth = (int)Floor(outerRadius / 50.0);
|
||||
ellipseSize = (int)Floor(outerRadius / 12.5);
|
||||
double cx = (double) contentsRect().center().x();
|
||||
double cy = (double) contentsRect().center().y();
|
||||
penWidth = static_cast<int>(Floor(outerRadius / 50.0));
|
||||
ellipseSize = static_cast<int>(Floor(outerRadius / 12.5));
|
||||
const auto cx = static_cast<double>(contentsRect().center().x());
|
||||
const auto cy = static_cast<double>(contentsRect().center().y());
|
||||
pa = QPointF(cx + (std::cos(a) * (outerRadius - (outerRadius / 5.0))),
|
||||
cy - (std::sin(a) * (outerRadius - (outerRadius / 5.0))));
|
||||
pb = QPointF(cx + (std::cos(b) * (outerRadius - (outerRadius / 5.0))),
|
||||
@ -530,7 +530,7 @@ void ColorTriangle::paintEvent(QPaintEvent* e)
|
||||
QPainter painter(&pix);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
// Draw an outline of the triangle
|
||||
QColor halfAlpha(0, 0, 0, 128);
|
||||
const QColor halfAlpha(0, 0, 0, 128);
|
||||
painter.setPen(QPen(halfAlpha, 0));
|
||||
painter.drawLine(pa, pb);
|
||||
painter.drawLine(pb, pc);
|
||||
@ -543,8 +543,8 @@ void ColorTriangle::paintEvent(QPaintEvent* e)
|
||||
else
|
||||
painter.setPen(QPen(Qt::white, penWidth));
|
||||
|
||||
painter.drawEllipse((int) (pd.x() - ellipseSize / 2.0),
|
||||
(int) (pd.y() - ellipseSize / 2.0),
|
||||
painter.drawEllipse(static_cast<int>(pd.x() - ellipseSize / 2.0),
|
||||
static_cast<int>(pd.y() - ellipseSize / 2.0),
|
||||
ellipseSize, ellipseSize);
|
||||
curColor.getRgb(&ri, &gi, &bi);
|
||||
|
||||
@ -597,15 +597,15 @@ void ColorTriangle::DrawTrigon(QImage* buf, const QPointF& pa,
|
||||
if (p2->point.y() > p3->point.y()) swap(&p2, &p3);
|
||||
|
||||
// All the three y deltas are >= 0
|
||||
double p1p2ydist = p2->point.y() - p1->point.y();
|
||||
double p1p3ydist = p3->point.y() - p1->point.y();
|
||||
double p2p3ydist = p3->point.y() - p2->point.y();
|
||||
double p1p2xdist = p2->point.x() - p1->point.x();
|
||||
double p1p3xdist = p3->point.x() - p1->point.x();
|
||||
double p2p3xdist = p3->point.x() - p2->point.x();
|
||||
const auto p1p2ydist = p2->point.y() - p1->point.y();
|
||||
const auto p1p3ydist = p3->point.y() - p1->point.y();
|
||||
const auto p2p3ydist = p3->point.y() - p2->point.y();
|
||||
const auto p1p2xdist = p2->point.x() - p1->point.x();
|
||||
const auto p1p3xdist = p3->point.x() - p1->point.x();
|
||||
const auto p2p3xdist = p3->point.x() - p2->point.x();
|
||||
// The first x delta decides wether we have a lefty or a righty
|
||||
// trigon.
|
||||
bool lefty = p1p2xdist < 0;
|
||||
const auto lefty = p1p2xdist < 0;
|
||||
// Left and right colors and X values. The key in this map is the
|
||||
// y values. Our goal is to fill these structures with all the
|
||||
// information needed to do a single pass top-to-bottom,
|
||||
@ -614,10 +614,10 @@ void ColorTriangle::DrawTrigon(QImage* buf, const QPointF& pa,
|
||||
QVarLengthArray<DoubleColor, 2000> rightColors;
|
||||
QVarLengthArray<double, 2000> leftX;
|
||||
QVarLengthArray<double, 2000> rightX;
|
||||
leftColors.resize(int(Floor(p3->point.y() + 1)));
|
||||
rightColors.resize(int(Floor(p3->point.y() + 1)));
|
||||
leftX.resize(int(Floor(p3->point.y() + 1)));
|
||||
rightX.resize(int(Floor(p3->point.y() + 1)));
|
||||
leftColors.resize(static_cast<int>(Floor(p3->point.y() + 1)));
|
||||
rightColors.resize(static_cast<int>(Floor(p3->point.y() + 1)));
|
||||
leftX.resize(static_cast<int>(Floor(p3->point.y() + 1)));
|
||||
rightX.resize(static_cast<int>(Floor(p3->point.y() + 1)));
|
||||
// Scan longy - find all left and right colors and X-values for
|
||||
// the tallest edge (p1-p3).
|
||||
DoubleColor source;
|
||||
@ -634,8 +634,8 @@ void ColorTriangle::DrawTrigon(QImage* buf, const QPointF& pa,
|
||||
r = source.r;
|
||||
g = source.g;
|
||||
b = source.b;
|
||||
y1 = (int)Floor(p1->point.y());
|
||||
y2 = (int)Floor(p3->point.y());
|
||||
y1 = static_cast<int>(Floor(p1->point.y()));
|
||||
y2 = static_cast<int>(Floor(p3->point.y()));
|
||||
// Find slopes (notice that if the y dists are 0, we don't care
|
||||
// about the slopes)
|
||||
xdelta = p1p3ydist == 0.0 ? 0.0 : p1p3xdist / p1p3ydist;
|
||||
@ -672,8 +672,8 @@ void ColorTriangle::DrawTrigon(QImage* buf, const QPointF& pa,
|
||||
r = source.r;
|
||||
g = source.g;
|
||||
b = source.b;
|
||||
y1 = (int)Floor(p1->point.y());
|
||||
y2 = (int)Floor(p2->point.y());
|
||||
y1 = static_cast<int>(Floor(p1->point.y()));
|
||||
y2 = static_cast<int>(Floor(p2->point.y()));
|
||||
// Find slopes (notice that if the y dists are 0, we don't care
|
||||
// about the slopes)
|
||||
xdelta = p1p2ydist == 0.0 ? 0.0 : p1p2xdist / p1p2ydist;
|
||||
@ -709,8 +709,8 @@ void ColorTriangle::DrawTrigon(QImage* buf, const QPointF& pa,
|
||||
r = source.r;
|
||||
g = source.g;
|
||||
b = source.b;
|
||||
y1 = (int)Floor(p2->point.y());
|
||||
y2 = (int)Floor(p3->point.y());
|
||||
y1 = static_cast<int>(Floor(p2->point.y()));
|
||||
y2 = static_cast<int>(Floor(p3->point.y()));
|
||||
// Find slopes (notice that if the y dists are 0, we don't care
|
||||
// about the slopes)
|
||||
xdelta = p2p3ydist == 0.0 ? 0.0 : p2p3xdist / p2p3ydist;
|
||||
@ -740,34 +740,34 @@ void ColorTriangle::DrawTrigon(QImage* buf, const QPointF& pa,
|
||||
|
||||
// Inner loop. For each y in the left map of x-values, draw one
|
||||
// line from left to right.
|
||||
const int p3yfloor = int(Floor(p3->point.y()));
|
||||
const auto p3yfloor = static_cast<int>(Floor(p3->point.y()));
|
||||
|
||||
for (int y = int(Floor(p1->point.y())); y < p3yfloor; ++y)
|
||||
for (auto y = static_cast<int>(Floor(p1->point.y())); y < p3yfloor; ++y)
|
||||
{
|
||||
double lx = leftX[y];
|
||||
double rx = rightX[y];
|
||||
int lxi = (int)Floor(lx);
|
||||
int rxi = (int)Floor(rx);
|
||||
DoubleColor rc = rightColors[y];
|
||||
DoubleColor lc = leftColors[y];
|
||||
const auto lx = leftX[y];
|
||||
const auto rx = rightX[y];
|
||||
const auto lxi = static_cast<int>(Floor(lx));
|
||||
const auto rxi = static_cast<int>(Floor(rx));
|
||||
const auto rc = rightColors[y];
|
||||
const auto lc = leftColors[y];
|
||||
// if the xdist is 0, don't draw anything.
|
||||
double xdist = rx - lx;
|
||||
const auto xdist = rx - lx;
|
||||
|
||||
if (xdist != 0.0)
|
||||
{
|
||||
double r = lc.r;
|
||||
double g = lc.g;
|
||||
double b = lc.b;
|
||||
double rdelta = (rc.r - r) / xdist;
|
||||
double gdelta = (rc.g - g) / xdist;
|
||||
double bdelta = (rc.b - b) / xdist;
|
||||
QRgb* scanline = reinterpret_cast<QRgb*>(buf->scanLine(y));
|
||||
auto r = lc.r;
|
||||
auto g = lc.g;
|
||||
auto b = lc.b;
|
||||
const auto rdelta = (rc.r - r) / xdist;
|
||||
const auto gdelta = (rc.g - g) / xdist;
|
||||
const auto bdelta = (rc.b - b) / xdist;
|
||||
auto scanline = reinterpret_cast<QRgb*>(buf->scanLine(y));
|
||||
scanline += lxi;
|
||||
|
||||
// Inner loop 2. Draws the line from left to right.
|
||||
for (int i = lxi; i < rxi; ++i)
|
||||
for (auto i = lxi; i < rxi; ++i)
|
||||
{
|
||||
*scanline++ = qRgb((int) r, (int) g, (int) b);
|
||||
*scanline++ = qRgb(static_cast<int>(r), static_cast<int>(g), static_cast<int>(b));
|
||||
r += rdelta;
|
||||
g += gdelta;
|
||||
b += bdelta;
|
||||
@ -805,10 +805,10 @@ void ColorTriangle::Color(const QColor& col)
|
||||
|
||||
if (c > TWOPI) c -= TWOPI;
|
||||
|
||||
double cx = (double) contentsRect().center().x();
|
||||
double cy = (double) contentsRect().center().y();
|
||||
double innerRadius = outerRadius - (outerRadius / 5.0);
|
||||
double pointerRadius = outerRadius - (outerRadius / 10.0);
|
||||
const auto cx = static_cast<double>(contentsRect().center().x());
|
||||
const auto cy = static_cast<double>(contentsRect().center().y());
|
||||
const auto innerRadius = outerRadius - (outerRadius / 5.0);
|
||||
const auto pointerRadius = outerRadius - (outerRadius / 10.0);
|
||||
pa = QPointF(cx + (std::cos(a) * innerRadius), cy - (std::sin(a) * innerRadius));
|
||||
pb = QPointF(cx + (std::cos(b) * innerRadius), cy - (std::sin(b) * innerRadius));
|
||||
pc = QPointF(cx + (std::cos(c) * innerRadius), cy - (std::sin(c) * innerRadius));
|
||||
@ -829,7 +829,7 @@ QColor ColorTriangle::Color() const
|
||||
|
||||
double ColorTriangle::CalcOuterRadius() const
|
||||
{
|
||||
double rad = (std::min(contentsRect().width(), contentsRect().height()) - 1) / 2;
|
||||
auto rad = (std::min(contentsRect().width(), contentsRect().height()) - 1) / 2;
|
||||
rad -= 2;//Matt - a little extra because the top gets cut off without doing this.
|
||||
return rad;
|
||||
}
|
||||
@ -841,8 +841,8 @@ double ColorTriangle::CalcOuterRadius() const
|
||||
*/
|
||||
double ColorTriangle::RadiusAt(const QPointF& pos, const QRect& rect) const
|
||||
{
|
||||
double mousexdist = pos.x() - (double) rect.center().x();
|
||||
double mouseydist = pos.y() - (double) rect.center().y();
|
||||
const auto mousexdist = pos.x() - static_cast<double>(rect.center().x());
|
||||
const auto mouseydist = pos.y() - static_cast<double>(rect.center().y());
|
||||
return std::sqrt(mousexdist * mousexdist + mouseydist * mouseydist);
|
||||
}
|
||||
|
||||
@ -855,14 +855,14 @@ double ColorTriangle::RadiusAt(const QPointF& pos, const QRect& rect) const
|
||||
*/
|
||||
double ColorTriangle::AngleAt(const QPointF& pos, const QRect& rect) const
|
||||
{
|
||||
double mousexdist = pos.x() - (double) rect.center().x();
|
||||
double mouseydist = pos.y() - (double) rect.center().y();
|
||||
double mouserad = std::sqrt(mousexdist * mousexdist + mouseydist * mouseydist);
|
||||
const auto mousexdist = pos.x() - static_cast<double>(rect.center().x());
|
||||
const auto mouseydist = pos.y() - static_cast<double>(rect.center().y());
|
||||
const auto mouserad = std::sqrt(mousexdist * mousexdist + mouseydist * mouseydist);
|
||||
|
||||
if (mouserad == 0.0)
|
||||
return 0.0;
|
||||
|
||||
double angle = std::acos(mousexdist / mouserad);
|
||||
auto angle = std::acos(mousexdist / mouserad);
|
||||
|
||||
if (mouseydist >= 0)
|
||||
angle = TWOPI - angle;
|
||||
@ -1122,38 +1122,38 @@ QPointF ColorTriangle::MovePointToTriangle(double x, double y, const Vertex& a,
|
||||
// Let v1A be the vector from (x,y) to a.
|
||||
// Let v2A be the vector from a to b.
|
||||
// Find the angle alphaA between v1A and v2A.
|
||||
double v1xA = x - a.point.x();
|
||||
double v1yA = y - a.point.y();
|
||||
double v2xA = b.point.x() - a.point.x();
|
||||
double v2yA = b.point.y() - a.point.y();
|
||||
double vpA = vprod(v1xA, v1yA, v2xA, v2yA);
|
||||
double cosA = vpA / (vlen(v1xA, v1yA) * vlen(v2xA, v2yA));
|
||||
double alphaA = std::acos(cosA);
|
||||
const auto v1xA = x - a.point.x();
|
||||
const auto v1yA = y - a.point.y();
|
||||
const auto v2xA = b.point.x() - a.point.x();
|
||||
const auto v2yA = b.point.y() - a.point.y();
|
||||
const auto vpA = vprod(v1xA, v1yA, v2xA, v2yA);
|
||||
const auto cosA = vpA / (vlen(v1xA, v1yA) * vlen(v2xA, v2yA));
|
||||
const auto alphaA = std::acos(cosA);
|
||||
// Let v1B be the vector from x to b.
|
||||
// Let v2B be the vector from b to c.
|
||||
double v1xB = x - b.point.x();
|
||||
double v1yB = y - b.point.y();
|
||||
double v2xB = c.point.x() - b.point.x();
|
||||
double v2yB = c.point.y() - b.point.y();
|
||||
double vpB = vprod(v1xB, v1yB, v2xB, v2yB);
|
||||
double cosB = vpB / (vlen(v1xB, v1yB) * vlen(v2xB, v2yB));
|
||||
double alphaB = std::acos(cosB);
|
||||
const auto v1xB = x - b.point.x();
|
||||
const auto v1yB = y - b.point.y();
|
||||
const auto v2xB = c.point.x() - b.point.x();
|
||||
const auto v2yB = c.point.y() - b.point.y();
|
||||
const auto vpB = vprod(v1xB, v1yB, v2xB, v2yB);
|
||||
const auto cosB = vpB / (vlen(v1xB, v1yB) * vlen(v2xB, v2yB));
|
||||
const auto alphaB = std::acos(cosB);
|
||||
// Let v1C be the vector from x to c.
|
||||
// Let v2C be the vector from c back to a.
|
||||
double v1xC = x - c.point.x();
|
||||
double v1yC = y - c.point.y();
|
||||
double v2xC = a.point.x() - c.point.x();
|
||||
double v2yC = a.point.y() - c.point.y();
|
||||
double vpC = vprod(v1xC, v1yC, v2xC, v2yC);
|
||||
double cosC = vpC / (vlen(v1xC, v1yC) * vlen(v2xC, v2yC));
|
||||
double alphaC = std::acos(cosC);
|
||||
const auto v1xC = x - c.point.x();
|
||||
const auto v1yC = y - c.point.y();
|
||||
const auto v2xC = a.point.x() - c.point.x();
|
||||
const auto v2yC = a.point.y() - c.point.y();
|
||||
const auto vpC = vprod(v1xC, v1yC, v2xC, v2yC);
|
||||
const auto cosC = vpC / (vlen(v1xC, v1yC) * vlen(v2xC, v2yC));
|
||||
const auto alphaC = std::acos(cosC);
|
||||
// Find the radian angles between the (1,0) vector and the points
|
||||
// A, B, C and (x,y). Use this information to determine which of
|
||||
// the edges we should project (x,y) onto.
|
||||
double angleA = AngleAt(a.point, contentsRect());
|
||||
double angleB = AngleAt(b.point, contentsRect());
|
||||
double angleC = AngleAt(c.point, contentsRect());
|
||||
double angleP = AngleAt(QPointF(x, y), contentsRect());
|
||||
const auto angleA = AngleAt(a.point, contentsRect());
|
||||
const auto angleB = AngleAt(b.point, contentsRect());
|
||||
const auto angleC = AngleAt(c.point, contentsRect());
|
||||
const auto angleP = AngleAt(QPointF(x, y), contentsRect());
|
||||
|
||||
// If (x,y) is in the a-b area, project onto the a-b vector.
|
||||
if (angleBetweenAngles(angleP, angleA, angleB))
|
||||
@ -1162,10 +1162,10 @@ QPointF ColorTriangle::MovePointToTriangle(double x, double y, const Vertex& a,
|
||||
// the a-b vector with this distance and the angle between a-b
|
||||
// and a-(x,y) to determine the point of intersection of the
|
||||
// perpendicular projection from (x,y) onto a-b.
|
||||
double pdist = std::sqrt(qsqr(x - a.point.x()) + qsqr(y - a.point.y()));
|
||||
const auto pdist = std::sqrt(qsqr(x - a.point.x()) + qsqr(y - a.point.y()));
|
||||
// the length of all edges is always > 0
|
||||
double p0x = a.point.x() + ((b.point.x() - a.point.x()) / vlen(v2xB, v2yB)) * std::cos(alphaA) * pdist;
|
||||
double p0y = a.point.y() + ((b.point.y() - a.point.y()) / vlen(v2xB, v2yB)) * std::cos(alphaA) * pdist;
|
||||
const auto p0x = a.point.x() + ((b.point.x() - a.point.x()) / vlen(v2xB, v2yB)) * std::cos(alphaA) * pdist;
|
||||
const auto p0y = a.point.y() + ((b.point.y() - a.point.y()) / vlen(v2xB, v2yB)) * std::cos(alphaA) * pdist;
|
||||
|
||||
// If (x,y) is above the a-b line, which basically means it's
|
||||
// outside the triangle, then return its projection onto a-b.
|
||||
@ -1186,10 +1186,10 @@ QPointF ColorTriangle::MovePointToTriangle(double x, double y, const Vertex& a,
|
||||
else if (angleBetweenAngles(angleP, angleB, angleC))
|
||||
{
|
||||
// If (x,y) is in the b-c area, project onto the b-c vector.
|
||||
double pdist = std::sqrt(qsqr(x - b.point.x()) + qsqr(y - b.point.y()));
|
||||
const auto pdist = std::sqrt(qsqr(x - b.point.x()) + qsqr(y - b.point.y()));
|
||||
// the length of all edges is always > 0
|
||||
double p0x = b.point.x() + ((c.point.x() - b.point.x()) / vlen(v2xC, v2yC)) * std::cos(alphaB) * pdist;
|
||||
double p0y = b.point.y() + ((c.point.y() - b.point.y()) / vlen(v2xC, v2yC)) * std::cos(alphaB) * pdist;
|
||||
const auto p0x = b.point.x() + ((c.point.x() - b.point.x()) / vlen(v2xC, v2yC)) * std::cos(alphaB) * pdist;
|
||||
const auto p0y = b.point.y() + ((c.point.y() - b.point.y()) / vlen(v2xC, v2yC)) * std::cos(alphaB) * pdist;
|
||||
|
||||
if (pointAbovePoint(x, y, p0x, p0y, b.point.x(), b.point.y(), c.point.x(), c.point.y()))
|
||||
{
|
||||
@ -1206,14 +1206,14 @@ QPointF ColorTriangle::MovePointToTriangle(double x, double y, const Vertex& a,
|
||||
else if (angleBetweenAngles(angleP, angleC, angleA))
|
||||
{
|
||||
// If (x,y) is in the c-a area, project onto the c-a vector.
|
||||
double pdist = std::sqrt(qsqr(x - c.point.x()) + qsqr(y - c.point.y()));
|
||||
const auto pdist = std::sqrt(qsqr(x - c.point.x()) + qsqr(y - c.point.y()));
|
||||
// the length of all edges is always > 0
|
||||
double p0x = c.point.x() + ((a.point.x() - c.point.x()) / vlen(v2xA, v2yA)) * std::cos(alphaC) * pdist;
|
||||
double p0y = c.point.y() + ((a.point.y() - c.point.y()) / vlen(v2xA, v2yA)) * std::cos(alphaC) * pdist;
|
||||
const auto p0x = c.point.x() + ((a.point.x() - c.point.x()) / vlen(v2xA, v2yA)) * std::cos(alphaC) * pdist;
|
||||
const auto p0y = c.point.y() + ((a.point.y() - c.point.y()) / vlen(v2xA, v2yA)) * std::cos(alphaC) * pdist;
|
||||
|
||||
if (pointAbovePoint(x, y, p0x, p0y, c.point.x(), c.point.y(), a.point.x(), a.point.y()))
|
||||
{
|
||||
int n = pointInLine(p0x, p0y, c.point.x(), c.point.y(), a.point.x(), a.point.y());
|
||||
const auto n = pointInLine(p0x, p0y, c.point.x(), c.point.y(), a.point.x(), a.point.y());
|
||||
|
||||
if (n < 0)
|
||||
return c.point;
|
||||
@ -1251,37 +1251,37 @@ QPointF ColorTriangle::PointFromColor(const QColor& col) const
|
||||
return pc;
|
||||
|
||||
// Find the x and y slopes
|
||||
double ab_deltax = pb.x() - pa.x();
|
||||
double ab_deltay = pb.y() - pa.y();
|
||||
double bc_deltax = pc.x() - pb.x();
|
||||
double bc_deltay = pc.y() - pb.y();
|
||||
double ac_deltax = pc.x() - pa.x();
|
||||
double ac_deltay = pc.y() - pa.y();
|
||||
const auto ab_deltax = pb.x() - pa.x();
|
||||
const auto ab_deltay = pb.y() - pa.y();
|
||||
const auto bc_deltax = pc.x() - pb.x();
|
||||
const auto bc_deltay = pc.y() - pb.y();
|
||||
const auto ac_deltax = pc.x() - pa.x();
|
||||
const auto ac_deltay = pc.y() - pa.y();
|
||||
// Extract the h,s,v values of col.
|
||||
int hue, sat, val;
|
||||
col.getHsv(&hue, &sat, &val);
|
||||
// Find the line that passes through the triangle where the value
|
||||
// is equal to our color's value.
|
||||
double p1 = pa.x() + (ab_deltax * (double) (255 - val)) / 255.0;
|
||||
double q1 = pa.y() + (ab_deltay * (double) (255 - val)) / 255.0;
|
||||
double p2 = pb.x() + (bc_deltax * (double) val) / 255.0;
|
||||
double q2 = pb.y() + (bc_deltay * (double) val) / 255.0;
|
||||
const auto p1 = pa.x() + (ab_deltax * static_cast<double>(255 - val)) / 255.0;
|
||||
const auto q1 = pa.y() + (ab_deltay * static_cast<double>(255 - val)) / 255.0;
|
||||
const auto p2 = pb.x() + (bc_deltax * static_cast<double>(val)) / 255.0;
|
||||
const auto q2 = pb.y() + (bc_deltay * static_cast<double>(val)) / 255.0;
|
||||
// Find the line that passes through the triangle where the
|
||||
// saturation is equal to our color's value.
|
||||
double p3 = pa.x() + (ac_deltax * (double) (255 - sat)) / 255.0;
|
||||
double q3 = pa.y() + (ac_deltay * (double) (255 - sat)) / 255.0;
|
||||
double p4 = pb.x();
|
||||
double q4 = pb.y();
|
||||
const auto p3 = pa.x() + (ac_deltax * static_cast<double>(255 - sat)) / 255.0;
|
||||
const auto q3 = pa.y() + (ac_deltay * static_cast<double>(255 - sat)) / 255.0;
|
||||
const auto p4 = pb.x();
|
||||
const auto q4 = pb.y();
|
||||
// Find the intersection between these lines.
|
||||
double x = 0;
|
||||
double y = 0;
|
||||
auto x = 0;
|
||||
auto y = 0;
|
||||
|
||||
if (p1 != p2)
|
||||
{
|
||||
double a = (q2 - q1) / (p2 - p1);
|
||||
double c = (q4 - q3) / (p4 - p3);
|
||||
double b = q1 - a * p1;
|
||||
double d = q3 - c * p3;
|
||||
const auto a = (q2 - q1) / (p2 - p1);
|
||||
const auto c = (q4 - q3) / (p4 - p3);
|
||||
const auto b = q1 - a * p1;
|
||||
const auto d = q3 - c * p3;
|
||||
x = (d - b) / (a - c);
|
||||
y = a * x + b;
|
||||
}
|
||||
@ -1304,28 +1304,28 @@ QPointF ColorTriangle::PointFromColor(const QColor& col) const
|
||||
QColor ColorTriangle::ColorFromPoint(const QPointF& p) const
|
||||
{
|
||||
// Find the outer radius of the hue gradient.
|
||||
int outerRadius = CalcOuterRadius();//Matt//why is this local?
|
||||
const auto outerRadius = CalcOuterRadius();//Matt//why is this local?
|
||||
// Find the center coordinates
|
||||
double cx = (double) contentsRect().center().x();
|
||||
double cy = (double) contentsRect().center().y();
|
||||
const auto cx = static_cast<double>(contentsRect().center().x());
|
||||
const auto cy = static_cast<double>(contentsRect().center().y());
|
||||
// Find the a, b and c from their angles, the center of the rect
|
||||
// and the radius of the hue gradient donut.
|
||||
QPointF pa(cx + (std::cos(a) * (outerRadius - (outerRadius / 5.0))),
|
||||
cy - (std::sin(a) * (outerRadius - (outerRadius / 5.0))));
|
||||
QPointF pb(cx + (std::cos(b) * (outerRadius - (outerRadius / 5.0))),
|
||||
cy - (std::sin(b) * (outerRadius - (outerRadius / 5.0))));
|
||||
QPointF pc(cx + (std::cos(c) * (outerRadius - (outerRadius / 5.0))),
|
||||
cy - (std::sin(c) * (outerRadius - (outerRadius / 5.0))));
|
||||
const QPointF pa(cx + (std::cos(a) * (outerRadius - (outerRadius / 5.0))),
|
||||
cy - (std::sin(a) * (outerRadius - (outerRadius / 5.0))));
|
||||
const QPointF pb(cx + (std::cos(b) * (outerRadius - (outerRadius / 5.0))),
|
||||
cy - (std::sin(b) * (outerRadius - (outerRadius / 5.0))));
|
||||
const QPointF pc(cx + (std::cos(c) * (outerRadius - (outerRadius / 5.0))),
|
||||
cy - (std::sin(c) * (outerRadius - (outerRadius / 5.0))));
|
||||
// Find the hue value from the angle of the 'a' point.
|
||||
double angle = a - M_PI / 2.0;
|
||||
auto angle = a - M_PI / 2.0;
|
||||
|
||||
if (angle < 0) angle += TWOPI;
|
||||
|
||||
double hue = (360.0 * angle) / TWOPI;
|
||||
const auto hue = (360.0 * angle) / TWOPI;
|
||||
// Create the color of the 'a' corner point. We know that b is
|
||||
// black and c is white.
|
||||
QColor color;
|
||||
color.setHsv(360 - (int)Floor(hue), 255, 255);
|
||||
color.setHsv(360 - static_cast<int>(Floor(hue)), 255, 255);
|
||||
// See also drawTrigon(), which basically does exactly the same to
|
||||
// determine all colors in the trigon.
|
||||
Vertex aa(color, pa);
|
||||
@ -1344,22 +1344,22 @@ QColor ColorTriangle::ColorFromPoint(const QPointF& p) const
|
||||
|
||||
// Find the slopes of all edges in the trigon. All the three y
|
||||
// deltas here are positive because of the above sorting.
|
||||
double p1p2ydist = p2->point.y() - p1->point.y();
|
||||
double p1p3ydist = p3->point.y() - p1->point.y();
|
||||
double p2p3ydist = p3->point.y() - p2->point.y();
|
||||
double p1p2xdist = p2->point.x() - p1->point.x();
|
||||
double p1p3xdist = p3->point.x() - p1->point.x();
|
||||
double p2p3xdist = p3->point.x() - p2->point.x();
|
||||
const auto p1p2ydist = p2->point.y() - p1->point.y();
|
||||
const auto p1p3ydist = p3->point.y() - p1->point.y();
|
||||
const auto p2p3ydist = p3->point.y() - p2->point.y();
|
||||
const auto p1p2xdist = p2->point.x() - p1->point.x();
|
||||
const auto p1p3xdist = p3->point.x() - p1->point.x();
|
||||
const auto p2p3xdist = p3->point.x() - p2->point.x();
|
||||
// The first x delta decides wether we have a lefty or a righty
|
||||
// trigon. A lefty trigon has its tallest edge on the right hand
|
||||
// side of the trigon. The righty trigon has it on its left side.
|
||||
// This property determines wether the left or the right set of x
|
||||
// coordinates will be continuous.
|
||||
bool lefty = p1p2xdist < 0;
|
||||
const auto lefty = p1p2xdist < 0;
|
||||
// Find whether the selector's y is in the first or second shorty,
|
||||
// counting from the top and downwards. This is used to find the
|
||||
// color at the selector point.
|
||||
bool firstshorty = (p.y() >= p1->point.y() && p.y() < p2->point.y());
|
||||
const auto firstshorty = (p.y() >= p1->point.y() && p.y() < p2->point.y());
|
||||
// From the y value of the selector's position, find the left and
|
||||
// right x values.
|
||||
double leftx;
|
||||
@ -1554,9 +1554,9 @@ QColor ColorTriangle::ColorFromPoint(const QPointF& p) const
|
||||
// find the distances from the selector to each of these (saxdist
|
||||
// and saxdist2). These distances are used to find the color at
|
||||
// the selector.
|
||||
double xdist = rightx - leftx;
|
||||
double saxdist = p.x() - leftx;
|
||||
double saxdist2 = xdist - saxdist;
|
||||
const auto xdist = rightx - leftx;
|
||||
const auto saxdist = p.x() - leftx;
|
||||
const auto saxdist2 = xdist - saxdist;
|
||||
// Now determine the r,g,b values of the selector using a linear
|
||||
// approximation.
|
||||
double r, g, b;
|
||||
@ -1582,9 +1582,9 @@ QColor ColorTriangle::ColorFromPoint(const QPointF& p) const
|
||||
// Now floor the color components and fit them into proper
|
||||
// boundaries. This again is to compensate for the error caused by
|
||||
// loss of precision.
|
||||
int ri = (int)Floor(r);
|
||||
int gi = (int)Floor(g);
|
||||
int bi = (int)Floor(b);
|
||||
auto ri = static_cast<int>(Floor(r));
|
||||
auto gi = static_cast<int>(Floor(g));
|
||||
auto bi = static_cast<int>(Floor(b));
|
||||
|
||||
if (ri < 0) ri = 0;
|
||||
else if (ri > 255) ri = 255;
|
||||
|
@ -73,8 +73,8 @@ struct Vertex
|
||||
|
||||
Vertex(const DoubleColor& c, const QPointF& p) : color(c), point(p) {}
|
||||
Vertex(const QColor& c, const QPointF& p)
|
||||
: color(DoubleColor((double)c.red(), (double)c.green(),
|
||||
(double)c.blue())), point(p) {}
|
||||
: color(DoubleColor(static_cast<double>(c.red()), static_cast<double>(c.green()),
|
||||
static_cast<double>(c.blue()))), point(p) {}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@ -94,19 +94,19 @@ public:
|
||||
QColor Color() const;
|
||||
void Color(const QColor& col);
|
||||
|
||||
virtual int heightForWidth(int w) const override;
|
||||
virtual QSize sizeHint() const override;
|
||||
int heightForWidth(int w) const override;
|
||||
QSize sizeHint() const override;
|
||||
|
||||
Q_SIGNALS:
|
||||
void ColorChanged(const QColor& col);
|
||||
|
||||
protected:
|
||||
virtual void paintEvent(QPaintEvent*) override;
|
||||
virtual void mouseMoveEvent(QMouseEvent*) override;
|
||||
virtual void mousePressEvent(QMouseEvent*) override;
|
||||
virtual void mouseReleaseEvent(QMouseEvent*) override;
|
||||
virtual void keyPressEvent(QKeyEvent* e) override;
|
||||
virtual void resizeEvent(QResizeEvent*) override;
|
||||
void paintEvent(QPaintEvent*) override;
|
||||
void mouseMoveEvent(QMouseEvent*) override;
|
||||
void mousePressEvent(QMouseEvent*) override;
|
||||
void mouseReleaseEvent(QMouseEvent*) override;
|
||||
void keyPressEvent(QKeyEvent* e) override;
|
||||
void resizeEvent(QResizeEvent*) override;
|
||||
|
||||
private:
|
||||
void GenBackground();
|
||||
|
@ -102,10 +102,10 @@ public:
|
||||
TopArrow(int width, size_t index)
|
||||
{
|
||||
QPolygon area;
|
||||
int center = 10;
|
||||
int mid = width / 2;
|
||||
int left = center - mid;
|
||||
int right = center + mid;
|
||||
const auto center = 10;
|
||||
const auto mid = width / 2;
|
||||
const auto left = center - mid;
|
||||
const auto right = center + mid;
|
||||
area << QPoint(left, 0) << QPoint(right, 0) << QPoint(right, 10) << QPoint(center, 15) << QPoint(left, 10) << QPoint(left, 0);
|
||||
Area(area);
|
||||
m_Index = index;
|
||||
|
@ -138,8 +138,8 @@ void GradientColorsView::AddArrow(const QColor& color)
|
||||
}
|
||||
else if (m_Arrows.size() == 2)
|
||||
{
|
||||
auto b = m_Arrows.begin();
|
||||
auto rb = m_Arrows.rbegin();
|
||||
const auto b = m_Arrows.begin();
|
||||
const auto rb = m_Arrows.rbegin();
|
||||
position = std::abs((rb->first + b->first) / 2.0);
|
||||
|
||||
if (position == b->first)
|
||||
@ -151,7 +151,7 @@ void GradientColorsView::AddArrow(const QColor& color)
|
||||
{
|
||||
bool set = false;
|
||||
auto it = m_Arrows.begin();
|
||||
auto oneBeforeLast = Advance(m_Arrows.begin(), m_Arrows.size() - 1);
|
||||
const auto oneBeforeLast = Advance(m_Arrows.begin(), m_Arrows.size() - 1);
|
||||
|
||||
for (; it != oneBeforeLast; ++it)
|
||||
{
|
||||
@ -226,7 +226,7 @@ void GradientColorsView::InvertColors()
|
||||
for (auto& it : m_Arrows)
|
||||
{
|
||||
auto& arrow = it.second;
|
||||
auto col = arrow.Color();
|
||||
const auto col = arrow.Color();
|
||||
arrow.Color(QColor(255 - col.red(), 255 - col.green(), 255 - col.blue()));
|
||||
|
||||
if (arrow.Focus())
|
||||
@ -256,9 +256,9 @@ void GradientColorsView::RandomColors()
|
||||
for (auto& it : m_Arrows)
|
||||
it.second.Color(
|
||||
{
|
||||
int(QTIsaac<ISAAC_SIZE, ISAAC_INT>::LockedRand(256)),
|
||||
int(QTIsaac<ISAAC_SIZE, ISAAC_INT>::LockedRand(256)),
|
||||
int(QTIsaac<ISAAC_SIZE, ISAAC_INT>::LockedRand(256))
|
||||
static_cast<int>(QTIsaac<ISAAC_SIZE, ISAAC_INT>::LockedRand(256)),
|
||||
static_cast<int>(QTIsaac<ISAAC_SIZE, ISAAC_INT>::LockedRand(256)),
|
||||
static_cast<int>(QTIsaac<ISAAC_SIZE, ISAAC_INT>::LockedRand(256))
|
||||
});
|
||||
update();
|
||||
}
|
||||
@ -271,7 +271,8 @@ void GradientColorsView::DistributeColors()
|
||||
if (!m_Arrows.empty())
|
||||
{
|
||||
map<float, GradientArrow> arrows;
|
||||
float index = 0, inc = 1.0f / std::max<size_t>(size_t(1), m_Arrows.size() - 1);
|
||||
float index = 0;
|
||||
const auto inc = 1.0f / std::max<size_t>(size_t(1), m_Arrows.size() - 1);
|
||||
|
||||
for (auto it : m_Arrows)
|
||||
{
|
||||
@ -392,7 +393,7 @@ Palette<float>& GradientColorsView::GetPalette(int size)
|
||||
{
|
||||
if (!m_Arrows.empty())
|
||||
{
|
||||
QSize imageSize(size, 1);
|
||||
const QSize imageSize(size, 1);
|
||||
QImage image(imageSize, QImage::Format_ARGB32_Premultiplied);
|
||||
m_Palette.m_SourceColors.clear();
|
||||
QPainter painter(&image);
|
||||
@ -522,15 +523,15 @@ void GradientColorsView::paintEvent(QPaintEvent*)
|
||||
|
||||
if (!m_Arrows.empty())
|
||||
{
|
||||
QPoint gradStart = QPoint(m_ViewRect.topLeft().x(), m_ViewRect.bottomLeft().y() / 2);
|
||||
QPoint gradStop = QPoint(m_ViewRect.topRight().x(), m_ViewRect.bottomRight().y() / 2);
|
||||
const QPoint gradStart = QPoint(m_ViewRect.topLeft().x(), m_ViewRect.bottomLeft().y() / 2);
|
||||
const QPoint gradStop = QPoint(m_ViewRect.topRight().x(), m_ViewRect.bottomRight().y() / 2);
|
||||
QLinearGradient grad(gradStart, gradStop);
|
||||
float start = m_ViewRect.x();
|
||||
|
||||
for (auto& it : m_Arrows)
|
||||
{
|
||||
GradientArrow& arrow = it.second;
|
||||
auto offset = std::ceil(it.first * RectWidth());
|
||||
const auto offset = std::ceil(it.first * RectWidth());
|
||||
|
||||
if (Blend())
|
||||
{
|
||||
@ -543,8 +544,8 @@ void GradientColorsView::paintEvent(QPaintEvent*)
|
||||
}
|
||||
|
||||
QPolygon arrowPolygon = arrow.Area();
|
||||
int iPosX = offset,
|
||||
iPosY = m_ViewRect.height() + m_ViewRect.top() + 3;
|
||||
const auto iPosX = offset;
|
||||
const auto iPosY = m_ViewRect.height() + m_ViewRect.top() + 3;
|
||||
arrowPolygon.translate(iPosX, iPosY);
|
||||
QPainterPath paintPath;
|
||||
paintPath.addPolygon(arrowPolygon);
|
||||
@ -575,7 +576,7 @@ void GradientColorsView::paintEvent(QPaintEvent*)
|
||||
auto& topArrow = it.second.second;
|
||||
auto topArrowPolygon = topArrow.Area();
|
||||
topArrowPolygon.translate(it.second.first * RectWidth(), 0);
|
||||
auto topArrowRect = topArrowPolygon.boundingRect();
|
||||
const auto topArrowRect = topArrowPolygon.boundingRect();
|
||||
topArrowPaintPath.addPolygon(topArrowPolygon);
|
||||
painter.drawPath(topArrowPaintPath);//When using a separate painter, the sides aren't as thick.
|
||||
//Draw text inside of the arrow.
|
||||
@ -655,7 +656,7 @@ void GradientColorsView::mouseMoveEvent(QMouseEvent* e)
|
||||
if (!m_ArrowMoving && !m_ColorIndexArrowMoving) return;
|
||||
|
||||
size_t index = 0;
|
||||
qreal maxMove = 11.5 / RectWidth();
|
||||
const qreal maxMove = 11.5 / RectWidth();
|
||||
|
||||
if (m_ArrowMoving)
|
||||
{
|
||||
@ -665,18 +666,18 @@ void GradientColorsView::mouseMoveEvent(QMouseEvent* e)
|
||||
|
||||
if (arrow.Focus())
|
||||
{
|
||||
qreal lastPos = it->first;
|
||||
qreal start = m_DragStart.x();
|
||||
qreal end = RectWidth();
|
||||
qreal dPos = ((qreal)e->pos().x() - start) / end;
|
||||
qreal newPos = lastPos + dPos;
|
||||
const qreal lastPos = it->first;
|
||||
const qreal start = m_DragStart.x();
|
||||
const qreal end = RectWidth();
|
||||
const qreal dPos = ((qreal)e->pos().x() - start) / end;
|
||||
const qreal newPos = lastPos + dPos;
|
||||
|
||||
if ((lastPos + dPos > 1) || (lastPos + dPos < 0))
|
||||
return;
|
||||
|
||||
if (dPos < 0 && index > 0)
|
||||
{
|
||||
qreal posBefore = std::prev(it)->first;
|
||||
const qreal posBefore = std::prev(it)->first;
|
||||
|
||||
if ((lastPos - maxMove + dPos) <= posBefore)
|
||||
return;
|
||||
@ -684,7 +685,7 @@ void GradientColorsView::mouseMoveEvent(QMouseEvent* e)
|
||||
|
||||
if ((dPos > 0) && (index < (m_Arrows.size() - 1)))
|
||||
{
|
||||
qreal posAfter = std::next(it)->first;
|
||||
const qreal posAfter = std::next(it)->first;
|
||||
|
||||
if ((lastPos + maxMove + dPos) >= posAfter)
|
||||
return;
|
||||
@ -708,11 +709,11 @@ void GradientColorsView::mouseMoveEvent(QMouseEvent* e)
|
||||
|
||||
if (arrow.Focus())
|
||||
{
|
||||
qreal lastPos = it.second.first;
|
||||
qreal start = m_DragStart.x();
|
||||
qreal end = RectWidth();
|
||||
qreal dPos = ((qreal)e->pos().x() - start) / end;
|
||||
qreal newPos = lastPos + dPos;
|
||||
const qreal lastPos = it.second.first;
|
||||
const qreal start = m_DragStart.x();
|
||||
const qreal end = RectWidth();
|
||||
const qreal dPos = ((qreal)e->pos().x() - start) / end;
|
||||
const qreal newPos = lastPos + dPos;
|
||||
|
||||
if ((lastPos + dPos > 1) || (lastPos + dPos < 0))
|
||||
return;
|
||||
|
@ -64,12 +64,12 @@ Q_SIGNALS:
|
||||
void ColorIndexMove(size_t index, float value);
|
||||
|
||||
protected:
|
||||
virtual void paintEvent(QPaintEvent* e) override;
|
||||
virtual void mousePressEvent(QMouseEvent* e) override;
|
||||
virtual void mouseDoubleClickEvent(QMouseEvent* e) override;
|
||||
virtual void mouseMoveEvent(QMouseEvent* e) override;
|
||||
virtual void mouseReleaseEvent(QMouseEvent* e) override;
|
||||
virtual void resizeEvent(QResizeEvent*) override;
|
||||
void paintEvent(QPaintEvent* e) override;
|
||||
void mousePressEvent(QMouseEvent* e) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent* e) override;
|
||||
void mouseMoveEvent(QMouseEvent* e) override;
|
||||
void mouseReleaseEvent(QMouseEvent* e) override;
|
||||
void resizeEvent(QResizeEvent*) override;
|
||||
|
||||
private:
|
||||
int RectWidth();
|
||||
|
@ -58,7 +58,7 @@ PaletteEditor::PaletteEditor(QWidget* p) :
|
||||
ui->PaletteFilenameCombo->addItem(info.fileName());
|
||||
}
|
||||
|
||||
ui->PaletteFilenameCombo->model()->sort(0);
|
||||
ui->PaletteFilenameCombo->model()->sort(0);
|
||||
|
||||
if (ui->PaletteFilenameCombo->count() > 0)
|
||||
m_CurrentPaletteFilePath = ui->PaletteFilenameCombo->itemText(0).toStdString();
|
||||
@ -91,7 +91,7 @@ Palette<float>& PaletteEditor::GetPalette(int size)
|
||||
/// <param name="palette">The palette to assign</param>
|
||||
void PaletteEditor::SetPalette(const Palette<float>& palette)
|
||||
{
|
||||
auto combo = ui->PaletteFilenameCombo;
|
||||
const auto combo = ui->PaletteFilenameCombo;
|
||||
m_PaletteIndex = std::numeric_limits<int>::max();
|
||||
m_GradientColorView->SetPalette(palette);
|
||||
auto& arrows = m_GradientColorView->GetArrows();
|
||||
@ -241,7 +241,7 @@ void PaletteEditor::OnResetToDefaultButtonClicked()
|
||||
/// </summary>
|
||||
void PaletteEditor::OnCreatePaletteFromImageButtonClicked()
|
||||
{
|
||||
auto filenames = SetupOpenImagesDialog();
|
||||
const auto filenames = SetupOpenImagesDialog();
|
||||
|
||||
if (!filenames.empty())
|
||||
{
|
||||
@ -317,7 +317,7 @@ void PaletteEditor::OnSyncCheckBoxStateChanged(int state)
|
||||
/// <param name="state">Ignored</param>
|
||||
void PaletteEditor::OnBlendCheckBoxStateChanged(int state)
|
||||
{
|
||||
m_GradientColorView->Blend((bool)state);
|
||||
m_GradientColorView->Blend(static_cast<bool>(state));
|
||||
m_GradientColorView->update();
|
||||
EmitPaletteChanged();
|
||||
}
|
||||
@ -331,10 +331,10 @@ void PaletteEditor::OnPaletteFilenameComboChanged(const QString& text)
|
||||
{
|
||||
if (!text.isEmpty())//This occasionally seems to get called with an empty string for reasons unknown.
|
||||
{
|
||||
auto paletteTable = ui->PaletteListTable;
|
||||
const auto paletteTable = ui->PaletteListTable;
|
||||
m_CurrentPaletteFilePath = text.toStdString();
|
||||
::FillPaletteTable(text.toStdString(), paletteTable, m_PaletteList);
|
||||
auto fullname = m_PaletteList->GetFullPathFromFilename(m_CurrentPaletteFilePath);
|
||||
const auto fullname = m_PaletteList->GetFullPathFromFilename(m_CurrentPaletteFilePath);
|
||||
ui->PaletteFilenameCombo->setToolTip(QString::fromStdString(fullname));
|
||||
EnablePaletteFileControls();
|
||||
}
|
||||
@ -350,7 +350,7 @@ void PaletteEditor::OnPaletteCellClicked(int row, int col)
|
||||
{
|
||||
if (col == 1)
|
||||
{
|
||||
if (auto palette = m_PaletteList->GetPaletteByFilename(m_CurrentPaletteFilePath, row))
|
||||
if (const auto palette = m_PaletteList->GetPaletteByFilename(m_CurrentPaletteFilePath, row))
|
||||
{
|
||||
SetPalette(*palette);
|
||||
m_PaletteIndex = row;
|
||||
@ -368,7 +368,7 @@ void PaletteEditor::OnPaletteCellChanged(int row, int col)
|
||||
{
|
||||
if (col == 0)
|
||||
{
|
||||
if (auto palette = m_PaletteList->GetPaletteByFilename(m_CurrentPaletteFilePath, row))
|
||||
if (const auto palette = m_PaletteList->GetPaletteByFilename(m_CurrentPaletteFilePath, row))
|
||||
{
|
||||
if (!palette->m_SourceColors.empty())
|
||||
{
|
||||
@ -386,7 +386,7 @@ void PaletteEditor::OnPaletteCellChanged(int row, int col)
|
||||
/// </summary>
|
||||
void PaletteEditor::OnNewPaletteFileButtonClicked()
|
||||
{
|
||||
auto filename = EmberFile<float>::UniqueFilename(GetDefaultUserPath() + "/user-palettes.xml");
|
||||
const auto filename = EmberFile<float>::UniqueFilename(GetDefaultUserPath() + "/user-palettes.xml");
|
||||
|
||||
if (m_PaletteList->AddEmptyPaletteFile(filename.toStdString()))
|
||||
{
|
||||
@ -404,18 +404,18 @@ void PaletteEditor::OnNewPaletteFileButtonClicked()
|
||||
void PaletteEditor::OnCopyPaletteFileButtonClicked()
|
||||
{
|
||||
auto& paletteFiles = m_PaletteList->Palettes();
|
||||
auto qscurr = QString::fromStdString(m_CurrentPaletteFilePath);
|
||||
auto qfilename = EmberFile<float>::UniqueFilename(GetDefaultUserPath() + "/" + qscurr);
|
||||
auto filename = qfilename.toStdString();
|
||||
const auto qscurr = QString::fromStdString(m_CurrentPaletteFilePath);
|
||||
const auto qfilename = EmberFile<float>::UniqueFilename(GetDefaultUserPath() + "/" + qscurr);
|
||||
const auto filename = qfilename.toStdString();
|
||||
|
||||
if (m_PaletteList->GetPaletteListByFullPath(filename) == nullptr)//Ensure the new filename does not exist in the map.
|
||||
{
|
||||
//Get the list of palettes for the current filename, this will be added as a copy below.
|
||||
if (auto currentPaletteFile = m_PaletteList->GetPaletteListByFilename(m_CurrentPaletteFilePath))//Ensure the list of palettes was properly retrieved.
|
||||
if (const auto currentPaletteFile = m_PaletteList->GetPaletteListByFilename(m_CurrentPaletteFilePath))//Ensure the list of palettes was properly retrieved.
|
||||
{
|
||||
if (m_PaletteList->AddPaletteFile(filename, *currentPaletteFile))//Add the current vector of palettes to an entry with the new filename.
|
||||
{
|
||||
QFileInfo info(qfilename);
|
||||
const QFileInfo info(qfilename);
|
||||
ui->PaletteFilenameCombo->addItem(info.fileName());
|
||||
ui->PaletteFilenameCombo->setCurrentIndex(ui->PaletteFilenameCombo->count() - 1);
|
||||
}
|
||||
@ -435,7 +435,7 @@ void PaletteEditor::OnCopyPaletteFileButtonClicked()
|
||||
/// </summary>
|
||||
void PaletteEditor::OnAppendPaletteButtonClicked()
|
||||
{
|
||||
auto& pal = GetPalette(256);
|
||||
const auto& pal = GetPalette(256);
|
||||
m_PaletteList->AddPaletteToFile(m_CurrentPaletteFilePath, pal);
|
||||
::FillPaletteTable(m_CurrentPaletteFilePath, ui->PaletteListTable, m_PaletteList);
|
||||
m_PaletteIndex = ui->PaletteListTable->rowCount() - 1;
|
||||
@ -448,7 +448,7 @@ void PaletteEditor::OnAppendPaletteButtonClicked()
|
||||
/// </summary>
|
||||
void PaletteEditor::OnOverwritePaletteButtonClicked()
|
||||
{
|
||||
auto& pal = GetPalette(256);
|
||||
const auto& pal = GetPalette(256);
|
||||
m_PaletteList->Replace(m_CurrentPaletteFilePath, pal, m_PaletteIndex);
|
||||
::FillPaletteTable(m_CurrentPaletteFilePath, ui->PaletteListTable, m_PaletteList);
|
||||
emit PaletteFileChanged();
|
||||
@ -461,7 +461,7 @@ void PaletteEditor::OnOverwritePaletteButtonClicked()
|
||||
/// </summary>
|
||||
void PaletteEditor::OnDeletePaletteButtonClicked()
|
||||
{
|
||||
auto table = ui->PaletteListTable;
|
||||
const auto table = ui->PaletteListTable;
|
||||
|
||||
if (table->rowCount() > 1)
|
||||
{
|
||||
@ -520,7 +520,7 @@ void PaletteEditor::EmitColorIndexChanged(size_t index, float value)
|
||||
QStringList PaletteEditor::SetupOpenImagesDialog()
|
||||
{
|
||||
QStringList filenames;
|
||||
auto settings = FractoriumSettings::Instance();
|
||||
const auto settings = FractoriumSettings::Instance();
|
||||
#ifndef __APPLE__
|
||||
|
||||
if (!m_FileDialog)
|
||||
@ -547,19 +547,19 @@ QStringList PaletteEditor::SetupOpenImagesDialog()
|
||||
|
||||
if (!filenames.empty())
|
||||
{
|
||||
auto path = QFileInfo(filenames[0]).canonicalPath();
|
||||
const auto path = QFileInfo(filenames[0]).canonicalPath();
|
||||
m_FileDialog->setDirectory(path);
|
||||
settings->OpenPaletteImageFolder(path);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
auto filename = QFileDialog::getOpenFileName(this, tr("Open Image"), settings->OpenPaletteImageFolder(), tr("Image Files (*.jpg *.png)"));
|
||||
const auto filename = QFileDialog::getOpenFileName(this, tr("Open Image"), settings->OpenPaletteImageFolder(), tr("Image Files (*.jpg *.png)"));
|
||||
|
||||
if (filename.size() > 0)
|
||||
{
|
||||
filenames.append(filename);
|
||||
auto path = QFileInfo(filenames[0]).canonicalPath();
|
||||
const auto path = QFileInfo(filenames[0]).canonicalPath();
|
||||
settings->OpenPaletteImageFolder(path);
|
||||
}
|
||||
|
||||
@ -574,9 +574,9 @@ QStringList PaletteEditor::SetupOpenImagesDialog()
|
||||
/// <param name="color">The color to assign to the new arrow</param>
|
||||
void PaletteEditor::AddArrow(const QColor& color)
|
||||
{
|
||||
auto count = std::min<int>(std::abs(256 - m_GradientColorView->ArrowCount()), ui->ArrowsSpinBox->value());
|
||||
const auto count = std::min<int>(std::abs(256 - m_GradientColorView->ArrowCount()), ui->ArrowsSpinBox->value());
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
for (auto i = 0; i < count; i++)
|
||||
{
|
||||
m_GradientColorView->AddArrow(color);
|
||||
|
||||
@ -594,18 +594,18 @@ void PaletteEditor::AddArrow(const QColor& color)
|
||||
map<float, GradientArrow> PaletteEditor::GetRandomColorsFromImage(QString filename, int numPoints)
|
||||
{
|
||||
map<float, GradientArrow> colors;
|
||||
QTime time = QTime::currentTime();
|
||||
const auto time = QTime::currentTime();
|
||||
qsrand((uint)time.msec());
|
||||
QImage image(filename);
|
||||
const QImage image(filename);
|
||||
const qreal gSize = 512;
|
||||
float off = 0.0f, inc = 1.0f / std::max(1, numPoints - 1);
|
||||
QLinearGradient grad(QPoint(0, 0), QPoint(gSize, 1));
|
||||
|
||||
for (int i = 0; i < numPoints; i++)
|
||||
for (auto i = 0; i < numPoints; i++)
|
||||
{
|
||||
int x = QTIsaac<ISAAC_SIZE, ISAAC_INT>::LockedRand(image.width());
|
||||
int y = QTIsaac<ISAAC_SIZE, ISAAC_INT>::LockedRand(image.height());
|
||||
QRgb rgb = image.pixel(x, y);
|
||||
const auto x = QTIsaac<ISAAC_SIZE, ISAAC_INT>::LockedRand(image.width());
|
||||
const auto y = QTIsaac<ISAAC_SIZE, ISAAC_INT>::LockedRand(image.height());
|
||||
const auto rgb = image.pixel(x, y);
|
||||
GradientArrow arrow;
|
||||
arrow.Color(QColor::fromRgb(rgb));
|
||||
arrow.Focus(i == 0);
|
||||
@ -621,7 +621,7 @@ map<float, GradientArrow> PaletteEditor::GetRandomColorsFromImage(QString filena
|
||||
/// </summary>
|
||||
void PaletteEditor::EnablePaletteFileControls()
|
||||
{
|
||||
bool b = IsCurrentPaletteAndFileEditable();//Both the file and the current palette must be editable.
|
||||
const auto b = IsCurrentPaletteAndFileEditable();//Both the file and the current palette must be editable.
|
||||
ui->DeletePaletteButton->setEnabled(b);
|
||||
ui->CopyPaletteFileButton->setEnabled(b);
|
||||
ui->AppendPaletteButton->setEnabled(b);
|
||||
@ -633,8 +633,8 @@ void PaletteEditor::EnablePaletteFileControls()
|
||||
/// </summary>
|
||||
void PaletteEditor::EnablePaletteControls()
|
||||
{
|
||||
bool b = IsCurrentPaletteAndFileEditable();//Both the file and the current palette must be editable.
|
||||
auto& pal = GetPalette(256);
|
||||
const auto b = IsCurrentPaletteAndFileEditable();//Both the file and the current palette must be editable.
|
||||
const auto& pal = GetPalette(256);
|
||||
ui->DeletePaletteButton->setEnabled(b);
|
||||
ui->CopyPaletteFileButton->setEnabled(b);
|
||||
ui->AppendPaletteButton->setEnabled(b);
|
||||
|
Reference in New Issue
Block a user