Skip to content

Commit

Permalink
Add vertical tile orientation.
Browse files Browse the repository at this point in the history
See #5.
  • Loading branch information
Clownacy committed Jul 10, 2024
1 parent 25a2e83 commit c9cd5de
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
4 changes: 4 additions & 0 deletions main-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1618,6 +1618,9 @@ MainWindow::MainWindow(QWidget* const parent)
// Menubar: Settings/Tile Rendering //
//////////////////////////////////////

connect(ui->actionOrient_Tiles_Vertically, &QAction::triggered, &tile_viewer, &TileViewer::setVerticalOrientation);
ui->actionOrient_Tiles_Vertically->setChecked(settings.value("OrientTilesVertically", false).toBool());

connect(ui->actionHide_Duplicated_Tiles_in_Frames, &QAction::triggered, &sprite_viewer, &SpriteViewer::setHideDuplicateTiles);
ui->actionHide_Duplicated_Tiles_in_Frames->setChecked(settings.value("HideDuplicatedTilesInFrames", false).toBool());

Expand Down Expand Up @@ -1753,6 +1756,7 @@ MainWindow::~MainWindow()
// Save settings.
QSettings settings;
settings.setValue("GameFormat", QVariant::fromValue(libsonassmd::game));
settings.setValue("OrientTilesVertically", ui->actionOrient_Tiles_Vertically->isChecked());
settings.setValue("HideDuplicatedTilesInFrames", ui->actionHide_Duplicated_Tiles_in_Frames->isChecked());
settings.setValue("StartingPaletteLine", tile_viewer.paletteLine());
settings.setValue("PatternLoadCues", ui->actionPattern_Load_Cues->isChecked());
Expand Down
13 changes: 13 additions & 0 deletions main-window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@
<property name="title">
<string>Tile &amp;Rendering</string>
</property>
<addaction name="actionOrient_Tiles_Vertically"/>
<addaction name="separator"/>
<addaction name="actionHide_Duplicated_Tiles_in_Frames"/>
<addaction name="separator"/>
<addaction name="actionRender_Starting_with_Palette_Line_1"/>
Expand Down Expand Up @@ -1144,6 +1146,17 @@
<string>Shift+F9</string>
</property>
</action>
<action name="actionOrient_Tiles_Vertically">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Orient Tiles Vertically</string>
</property>
<property name="shortcut">
<string>O</string>
</property>
</action>
</widget>
<resources/>
<connections/>
Expand Down
25 changes: 17 additions & 8 deletions tile-viewer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "tile-viewer.h"

#include <QtAlgorithms>
#include <QtGlobal>
#include <QMouseEvent>
#include <QPainter>
Expand Down Expand Up @@ -80,7 +81,10 @@ void TileViewer::setSelection(const bool scroll_to_selection, const std::functio
void TileViewer::getGridDimensions(int &columns, int &rows)
{
columns = width() / TILE_WIDTH_SCALED;
rows = qMin(Utilities::DivideCeiling(height(), TILE_HEIGHT_SCALED), Utilities::DivideCeiling(tile_manager.total_tiles(), columns));
rows = qMax(1, qMin(Utilities::DivideCeiling(height(), TILE_HEIGHT_SCALED), Utilities::DivideCeiling(tile_manager.total_tiles(), columns)));

if (vertical_orientation)
qSwap(columns, rows);
}

void TileViewer::paintEvent(QPaintEvent* const event)
Expand Down Expand Up @@ -113,12 +117,16 @@ void TileViewer::paintEvent(QPaintEvent* const event)
}
};

const auto do_visible_tiles = [do_visible_rows](const std::function<void(int, const QRect&)> &callback)
const auto do_visible_tiles = [this, &do_visible_rows](const std::function<void(int, const QRect&)> &callback)
{
do_visible_rows([callback](const int tile_index, const int y, const int length_of_row)
do_visible_rows([this, &callback](const int tile_index, const int y, const int length_of_row)
{
for (int x = 0; x < length_of_row; ++x)
callback(tile_index + x, QRect(x * TILE_WIDTH_SCALED, y * TILE_HEIGHT_SCALED, TILE_WIDTH_SCALED, TILE_HEIGHT_SCALED));
{
const int actual_x = vertical_orientation ? y : x;
const int actual_y = vertical_orientation ? x : y;
callback(tile_index + x, QRect(actual_x * TILE_WIDTH_SCALED, actual_y * TILE_HEIGHT_SCALED, TILE_WIDTH_SCALED, TILE_HEIGHT_SCALED));
}
}
);
};
Expand All @@ -128,13 +136,14 @@ void TileViewer::paintEvent(QPaintEvent* const event)

// Initialise colour values to 0.
do_visible_rows(
[&painter](const int tile_index, const int y, const int length_of_row)
[this, &painter](const int tile_index, const int y, const int length_of_row)
{
Q_UNUSED(tile_index);

const QRect rect(0, y * TILE_HEIGHT_SCALED, length_of_row * TILE_WIDTH_SCALED, TILE_HEIGHT_SCALED);

painter.drawRect(rect);
if (vertical_orientation)
painter.drawRect(QRect{y * TILE_WIDTH_SCALED, 0, TILE_WIDTH_SCALED, length_of_row * TILE_HEIGHT_SCALED});
else
painter.drawRect(QRect{0, y * TILE_HEIGHT_SCALED, length_of_row * TILE_WIDTH_SCALED, TILE_HEIGHT_SCALED});
}
);

Expand Down
12 changes: 12 additions & 0 deletions tile-viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ class TileViewer : public QWidget
update();
}

bool verticalOrientation() const
{
return vertical_orientation;
}

void setVerticalOrientation(const bool enabled)
{
vertical_orientation = enabled;
update();
}

void getGridDimensions(int &width, int &height);

signals:
Expand All @@ -75,6 +86,7 @@ class TileViewer : public QWidget
bool selection_flip_flop = false;
int palette_line = 0;
int m_scroll = 0;
bool vertical_orientation = false;
};

#endif // TILE_VIEWER_H

0 comments on commit c9cd5de

Please sign in to comment.