Skip to content

Commit

Permalink
Rotation update
Browse files Browse the repository at this point in the history
  • Loading branch information
jowin202 committed Mar 11, 2024
1 parent 1caa57b commit e9c78c3
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 31 deletions.
45 changes: 25 additions & 20 deletions mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>1026</width>
<height>897</height>
<height>911</height>
</rect>
</property>
<property name="acceptDrops">
Expand All @@ -17,7 +17,7 @@
<string>OpenSprite</string>
</property>
<property name="windowIcon">
<iconset>
<iconset resource="icons.qrc">
<normaloff>:/icons/opensprite96x96.png</normaloff>:/icons/opensprite96x96.png</iconset>
</property>
<widget class="QWidget" name="centralwidget">
Expand Down Expand Up @@ -675,7 +675,7 @@
<x>0</x>
<y>0</y>
<width>609</width>
<height>772</height>
<height>786</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_2">
Expand Down Expand Up @@ -817,7 +817,7 @@
</action>
<action name="actionCut">
<property name="icon">
<iconset>
<iconset resource="icons.qrc">
<normaloff>:/icons/cut.svg</normaloff>:/icons/cut.svg</iconset>
</property>
<property name="text">
Expand All @@ -829,7 +829,7 @@
</action>
<action name="actionCopy">
<property name="icon">
<iconset>
<iconset resource="icons.qrc">
<normaloff>:/icons/copy.svg</normaloff>:/icons/copy.svg</iconset>
</property>
<property name="text">
Expand All @@ -841,7 +841,7 @@
</action>
<action name="actionPaste">
<property name="icon">
<iconset>
<iconset resource="icons.qrc">
<normaloff>:/icons/paste.svg</normaloff>:/icons/paste.svg</iconset>
</property>
<property name="text">
Expand All @@ -856,7 +856,7 @@
<bool>false</bool>
</property>
<property name="icon">
<iconset>
<iconset resource="icons.qrc">
<normaloff>:/icons/paste.svg</normaloff>:/icons/paste.svg</iconset>
</property>
<property name="text">
Expand All @@ -873,7 +873,7 @@
</action>
<action name="actionSlide_Up">
<property name="icon">
<iconset>
<iconset resource="icons.qrc">
<normaloff>:/icons/move-up.svg</normaloff>:/icons/move-up.svg</iconset>
</property>
<property name="text">
Expand All @@ -885,7 +885,7 @@
</action>
<action name="actionSlide_Down">
<property name="icon">
<iconset>
<iconset resource="icons.qrc">
<normaloff>:/icons/move-down.svg</normaloff>:/icons/move-down.svg</iconset>
</property>
<property name="text">
Expand All @@ -897,7 +897,7 @@
</action>
<action name="actionSlide_Left">
<property name="icon">
<iconset>
<iconset resource="icons.qrc">
<normaloff>:/icons/move-left.svg</normaloff>:/icons/move-left.svg</iconset>
</property>
<property name="text">
Expand All @@ -909,7 +909,7 @@
</action>
<action name="actionSlide_Right">
<property name="icon">
<iconset>
<iconset resource="icons.qrc">
<normaloff>:/icons/move-right.svg</normaloff>:/icons/move-right.svg</iconset>
</property>
<property name="text">
Expand All @@ -921,7 +921,7 @@
</action>
<action name="actionFlip_Top_to_Bottom">
<property name="icon">
<iconset>
<iconset resource="icons.qrc">
<normaloff>:/icons/flip_top-bottom.svg</normaloff>:/icons/flip_top-bottom.svg</iconset>
</property>
<property name="text">
Expand All @@ -930,7 +930,7 @@
</action>
<action name="actionFlip_Left_to_Right">
<property name="icon">
<iconset>
<iconset resource="icons.qrc">
<normaloff>:/icons/flip_left-right.svg</normaloff>:/icons/flip_left-right.svg</iconset>
</property>
<property name="text">
Expand All @@ -939,7 +939,7 @@
</action>
<action name="actionSave_Project">
<property name="icon">
<iconset>
<iconset resource="icons.qrc">
<normaloff>:/icons/save.svg</normaloff>:/icons/save.svg</iconset>
</property>
<property name="text">
Expand All @@ -951,7 +951,7 @@
</action>
<action name="actionSave_Project_As">
<property name="icon">
<iconset>
<iconset resource="icons.qrc">
<normaloff>:/icons/save.svg</normaloff>:/icons/save.svg</iconset>
</property>
<property name="text">
Expand Down Expand Up @@ -981,7 +981,7 @@
</action>
<action name="actionExport_as">
<property name="icon">
<iconset>
<iconset resource="icons.qrc">
<normaloff>:/icons/save_exp.svg</normaloff>:/icons/save_exp.svg</iconset>
</property>
<property name="text">
Expand All @@ -993,7 +993,7 @@
</action>
<action name="actionExport">
<property name="icon">
<iconset>
<iconset resource="icons.qrc">
<normaloff>:/icons/save_exp.svg</normaloff>:/icons/save_exp.svg</iconset>
</property>
<property name="text">
Expand All @@ -1005,7 +1005,7 @@
</action>
<action name="actionReflect_Left_To_Right">
<property name="icon">
<iconset>
<iconset resource="icons.qrc">
<normaloff>:/icons/reflect_left_to_right.svg</normaloff>:/icons/reflect_left_to_right.svg</iconset>
</property>
<property name="text">
Expand All @@ -1014,7 +1014,7 @@
</action>
<action name="actionReflect_Top_to_Bottom">
<property name="icon">
<iconset>
<iconset resource="icons.qrc">
<normaloff>:/icons/reflect_top_to_bottom.svg</normaloff>:/icons/reflect_top_to_bottom.svg</iconset>
</property>
<property name="text">
Expand Down Expand Up @@ -1064,6 +1064,9 @@
<property name="text">
<string>Rotate</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+R</string>
</property>
</action>
</widget>
<customwidgets>
Expand All @@ -1078,6 +1081,8 @@
<header>palette.h</header>
</customwidget>
</customwidgets>
<resources/>
<resources>
<include location="icons.qrc"/>
</resources>
<connections/>
</ui>
45 changes: 34 additions & 11 deletions rotations/rotationdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "ui_rotationdialog.h"

#include "sprite.h"
#include "QtCore/QtMath"

RotationDialog::RotationDialog(options *opt, QWidget *parent) :
QWidget(parent),
Expand Down Expand Up @@ -52,18 +53,40 @@ QJsonObject RotationDialog::rotate_by(QJsonObject sprite, int angle)
{
Q_UNUSED(angle);

//TODO actual rotation algorithm
int rotated[24][21];

/*
//remove this
QJsonArray sprite_data1 = sprite.value("sprite_data").toArray();
QJsonArray sprite_data2 = sprite_data1.at(0).toArray();
sprite_data2.removeAt(angle);
sprite_data2.insert(angle,1);
sprite_data1.removeAt(0);
sprite_data1.insert(0,sprite_data2);
sprite.insert("sprite_data", sprite_data1);
*/
//actual rotation algorithm
int i, j;
double radians = angle * (3.14159265358979323846 / 180.0);
double cosVal = qCos(radians);
double sinVal = qSin(radians);

for (i = 0; i < 24; ++i) {
for (j = 0; j < 21; ++j) {
int x = (int)(cosVal * (i - 24 / 2) - sinVal * (j - 21 / 2) + 24 / 2);
int y = (int)(sinVal * (i - 24 / 2) + cosVal * (j - 21 / 2) + 21 / 2);

if (x >= 0 && x < 24 && y >= 0 && y < 21) {
rotated[i][j] = sprite.value("sprite_data").toArray().at(y).toArray().at(x).toInt();
} else {
rotated[i][j] = 0;
}
}
}

QJsonArray sprite_data = sprite.value("sprite_data").toArray();
for (int y = 0; y < 21; y++)
{
QJsonArray row = sprite_data.at(y).toArray();
for (int x = 0; x < 24; x++)
{
row.removeAt(x);
row.insert(x,rotated[x][y]);
}
sprite_data.removeAt(y);
sprite_data.insert(y, row);
}
sprite.insert("sprite_data", sprite_data);

return sprite;
}
Expand Down
3 changes: 3 additions & 0 deletions rotations/rotationdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="spin_angle">
<property name="minimum">
<number>45</number>
</property>
<property name="maximum">
<number>360</number>
</property>
Expand Down

0 comments on commit e9c78c3

Please sign in to comment.