Clean up rotation functions

This commit is contained in:
GriffinR 2022-10-13 15:14:53 -04:00 committed by Marcus Huderle
parent ad5eea2293
commit 47f6723bd2
4 changed files with 33 additions and 26 deletions

View file

@ -44,15 +44,15 @@ public:
Q_INVOKABLE int getOpacity(int layer = 0); Q_INVOKABLE int getOpacity(int layer = 0);
Q_INVOKABLE void setOpacity(int opacity, int layer); Q_INVOKABLE void setOpacity(int opacity, int layer);
Q_INVOKABLE void setOpacity(int opacity); Q_INVOKABLE void setOpacity(int opacity);
Q_INVOKABLE int getHorizontalScale(int layer); Q_INVOKABLE int getHorizontalScale(int layer = 0);
Q_INVOKABLE int getVerticalScale(int layer); Q_INVOKABLE int getVerticalScale(int layer = 0);
Q_INVOKABLE void setHorizontalScale(int scale, int layer); Q_INVOKABLE void setHorizontalScale(int scale, int layer);
Q_INVOKABLE void setHorizontalScale(int scale); Q_INVOKABLE void setHorizontalScale(int scale);
Q_INVOKABLE void setVerticalScale(int scale, int layer); Q_INVOKABLE void setVerticalScale(int scale, int layer);
Q_INVOKABLE void setVerticalScale(int scale); Q_INVOKABLE void setVerticalScale(int scale);
Q_INVOKABLE int getRotation(int layer); Q_INVOKABLE int getAngle(int layer = 0);
Q_INVOKABLE void setRotation(int rotation, int layer); Q_INVOKABLE void setAngle(int angle, int layer);
Q_INVOKABLE void setRotation(int rotation); Q_INVOKABLE void setAngle(int angle);
Q_INVOKABLE void rotate(int degrees, int layer); Q_INVOKABLE void rotate(int degrees, int layer);
Q_INVOKABLE void rotate(int degrees); Q_INVOKABLE void rotate(int degrees);
Q_INVOKABLE void addText(QString text, int x, int y, QString color = "#000000", int fontSize = 12, int layer = 0); Q_INVOKABLE void addText(QString text, int x, int y, QString color = "#000000", int fontSize = 12, int layer = 0);

View file

@ -70,7 +70,7 @@ public:
Overlay() { Overlay() {
this->x = 0; this->x = 0;
this->y = 0; this->y = 0;
this->rotation = 0; this->angle = 0;
this->hScale = 1.0; this->hScale = 1.0;
this->vScale = 1.0; this->vScale = 1.0;
this->hidden = false; this->hidden = false;
@ -92,8 +92,8 @@ public:
int getVScale(); int getVScale();
void setHScale(int scale); void setHScale(int scale);
void setVScale(int scale); void setVScale(int scale);
int getRotation(); int getAngle();
void setRotation(int rotation); void setAngle(int angle);
void rotate(int degrees); void rotate(int degrees);
void setClippingRect(QRectF rect); void setClippingRect(QRectF rect);
void clearClippingRect(); void clearClippingRect();
@ -108,11 +108,12 @@ public:
bool addImage(int x, int y, QImage image); bool addImage(int x, int y, QImage image);
bool addPath(QList<int> xCoords, QList<int> yCoords, QString borderColorStr, QString fillColorStr); bool addPath(QList<int> xCoords, QList<int> yCoords, QString borderColorStr, QString fillColorStr);
private: private:
void clampAngle();
QColor getColor(QString colorStr); QColor getColor(QString colorStr);
QList<OverlayItem*> items; QList<OverlayItem*> items;
int x; int x;
int y; int y;
int rotation; int angle;
qreal hScale; qreal hScale;
qreal vScale; qreal vScale;
bool hidden; bool hidden;

View file

@ -179,19 +179,19 @@ void MapView::setVerticalScale(int scale) {
this->scene()->update(); this->scene()->update();
} }
int MapView::getRotation(int layer) { int MapView::getAngle(int layer) {
return this->getOverlay(layer)->getRotation(); return this->getOverlay(layer)->getAngle();
} }
void MapView::setRotation(int rotation, int layer) { void MapView::setAngle(int angle, int layer) {
this->getOverlay(layer)->setRotation(rotation); this->getOverlay(layer)->setAngle(angle);
this->scene()->update(); this->scene()->update();
} }
// Overload. No layer provided, set rotation of all layers // Overload. No layer provided, set angle of all layers
void MapView::setRotation(int rotation) { void MapView::setAngle(int angle) {
foreach (Overlay * layer, this->overlayMap) foreach (Overlay * layer, this->overlayMap)
layer->setRotation(rotation); layer->setAngle(angle);
this->scene()->update(); this->scene()->update();
} }

View file

@ -27,14 +27,10 @@ void Overlay::renderItems(QPainter *painter) {
QTransform transform = painter->transform(); QTransform transform = painter->transform();
transform.translate(this->x, this->y); transform.translate(this->x, this->y);
transform.rotate(this->rotation); transform.rotate(this->angle);
transform.scale(this->hScale, this->vScale); transform.scale(this->hScale, this->vScale);
painter->setTransform(transform); painter->setTransform(transform);
/*painter->translate(this->x, this->y);
painter->rotate(this->rotation);
painter->scale(this->hScale, this->vScale);*/
if (this->clippingRect) { if (this->clippingRect) {
painter->setClipping(true); painter->setClipping(true);
painter->setClipRect(*this->clippingRect); painter->setClipRect(*this->clippingRect);
@ -110,16 +106,26 @@ void Overlay::setVScale(int scale) {
this->vScale = scale; this->vScale = scale;
} }
int Overlay::getRotation() { int Overlay::getAngle() {
return this->rotation; return this->angle;
} }
void Overlay::setRotation(int rotation) { void Overlay::setAngle(int angle) {
this->rotation = rotation; this->angle = angle;
this->clampAngle();
} }
void Overlay::rotate(int degrees) { void Overlay::rotate(int degrees) {
this->rotation += degrees; this->angle += degrees;
this->clampAngle();
}
void Overlay::clampAngle() {
// transform.rotate would handle this already, but we only
// want to report angles 0-359 for Overlay::getAngle
this->angle %= 360;
if (this->angle < 0)
this->angle += 360;
} }
void Overlay::setClippingRect(QRectF rect) { void Overlay::setClippingRect(QRectF rect) {