Squashed 'deps/nostalgia/' changes from 804d78e1..2a8e3c2d

2a8e3c2d [nostalgia/gfx] Remove unnecessary cast
998066d3 [ox/std] Add comparison functions
fefb876f [nostalgia/gfx] Add checks for GCC version for warning suppression
5979e988 [jsoncpp] Up required CMake version
a17abe46 [nfde] Up required CMake version
d62f9138 [nostalgia/gfx] Suppress some superfluous warnings
12bb7475 [nostalgia/gfx/studio/tilesheet] Adjust pixel line size on Windows
df2c7e2b [nostalgia] Update release notes
713aec88 [buildcore] Change mypy invokation
3089cd7a Change builder type to olympic
00638bc8 [nostalgia/gfx/studio/tilesheet] Mark DrawCommands as obsolete if no changes
e0021098 [studio] Make undo/redo skip over obsolete commands
b4798fd2 [nostalgia/gfx/studio/tilesheet] Make rotate only available for square subsheets or selections
3c804bf6 [studio] Give MakeCopy popup an error message for files that already exist
d39d552b [nostalgia/studio] Update icon to higher resolution
b7202a2b [nostalgia/player] Disable Keel mods on GBA
4e27a4c1 [nostalgia/core/studio/tilesheet] Fix palette path display update
4ef31762 [nostalgia/core/studio/tilesheet] Cleanup
8b22a8f3 [keel] Make buildUuidMap only read the first 40 bytes of each file
d45ff05b [ox/fs] Add new partial file read functions
671dd862 [keel,studio] Add Make Copy option to ProjectExplorer
0abadc18 [studio] Fix QuestionPopup to only emit a response when there is a response
4e068d62 [studio] Fix misrender flash on tab close
4461f99f [studio] Add Ctrl-W shortcut for closing active tab
cd1f4bda [studio] Add confirmation for closing file with unsaved changes
47286995 [studio] Add combobox that will take string views
105a1e55 [nostalgia/core/studio/tilesheet] Rework operation ctrls into a dropbox
1bc18e34 [nostalgia/core/studio/tilesheet] Add ability to rotate a selection
fb8d295f [nostalgia/core/studio/tilesheet] Add rotate functionality

git-subtree-dir: deps/nostalgia
git-subtree-split: 2a8e3c2dc44642fd9fef6bc8b645ad966f0277da
This commit is contained in:
2025-02-19 00:34:26 -06:00
parent c42adc290c
commit a6b9657268
43 changed files with 817 additions and 72 deletions

View File

@@ -443,23 +443,24 @@ ox::Error resizeSubsheet(TileSheet::SubSheet &ss, ox::Size const&sz) noexcept;
[[nodiscard]]
TileSheet::SubSheetIdx validateSubSheetIdx(TileSheet const&ts, TileSheet::SubSheetIdx idx) noexcept;
[[nodiscard]]
TileSheet::SubSheet const&getSubSheet(
ox::SpanView<uint32_t> const&idx,
std::size_t idxIt,
TileSheet::SubSheet const&pSubsheet) noexcept;
[[nodiscard]]
TileSheet::SubSheet &getSubSheet(
ox::SpanView<uint32_t> const&idx,
std::size_t idxIt,
TileSheet::SubSheet &pSubsheet) noexcept;
#if defined(__GNUC__) && __GNUC__ >= 14
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdangling-reference"
#endif
[[nodiscard]]
TileSheet::SubSheet const&getSubSheet(TileSheet const&ts, ox::SpanView<uint32_t> const &idx) noexcept;
[[nodiscard]]
TileSheet::SubSheet &getSubSheet(TileSheet &ts, ox::SpanView<uint32_t> const &idx) noexcept;
#if defined(__GNUC__) && __GNUC__ >= 14
#pragma GCC diagnostic pop
#endif
ox::Error addSubSheet(TileSheet &ts, TileSheet::SubSheetIdx const &idx) noexcept;

View File

@@ -449,7 +449,7 @@ static void setSprite(
++i;
};
if (!s.flipX) {
for (auto yIt = 0; yIt < static_cast<int>(dim.y); ++yIt) {
for (auto yIt = 0u; yIt < dim.y; ++yIt) {
for (auto xIt = 0u; xIt < dim.x; ++xIt) {
set(static_cast<int>(xIt), static_cast<int>(yIt), s.enabled);
}

View File

@@ -9,5 +9,6 @@ target_sources(
inserttilescommand.cpp
palettechangecommand.cpp
rmsubsheetcommand.cpp
rotatecommand.cpp
updatesubsheetcommand.cpp
)

View File

@@ -17,6 +17,7 @@ enum class CommandId {
DeleteTile,
FlipX,
FlipY,
Rotate,
InsertTile,
MoveSubSheet,
UpdateSubSheet,

View File

@@ -63,7 +63,7 @@ DrawCommand::DrawCommand(
TileSheet &img,
TileSheet::SubSheetIdx subSheetIdx,
std::size_t idx,
int palIdx) noexcept:
int const palIdx) noexcept:
m_img(img),
m_subSheetIdx(std::move(subSheetIdx)),
m_palIdx(palIdx) {
@@ -75,7 +75,7 @@ DrawCommand::DrawCommand(
TileSheet &img,
TileSheet::SubSheetIdx subSheetIdx,
ox::SpanView<std::size_t> const&idxList,
int palIdx) noexcept:
int const palIdx) noexcept:
m_img(img),
m_subSheetIdx(std::move(subSheetIdx)),
m_palIdx(palIdx) {
@@ -123,7 +123,9 @@ void DrawCommand::lineUpdate(ox::Point a, ox::Point b) noexcept {
for (int32_t i{}; i < range; ++i) {
auto const idx = ptToIdx(x, y + i * mod, ss.columns * TileWidth);
if (idx < ss.pixels.size()) {
m_changes.emplace_back(static_cast<uint32_t>(idx), getPixel(ss, idx));
if (m_palIdx != getPixel(ss, idx)) {
m_changes.emplace_back(static_cast<uint32_t>(idx), getPixel(ss, idx));
}
}
}
});
@@ -154,4 +156,8 @@ TileSheet::SubSheetIdx const&DrawCommand::subsheetIdx() const noexcept {
return m_subSheetIdx;
}
void DrawCommand::finish() noexcept {
setObsolete(m_changes.empty());
}
}

View File

@@ -52,6 +52,8 @@ class DrawCommand: public TileSheetCommand {
[[nodiscard]]
TileSheet::SubSheetIdx const&subsheetIdx() const noexcept override;
void finish() noexcept;
};
}

View File

@@ -6,7 +6,7 @@
namespace nostalgia::gfx {
gfx::RmSubSheetCommand::RmSubSheetCommand(TileSheet &img, TileSheet::SubSheetIdx idx) noexcept:
RmSubSheetCommand::RmSubSheetCommand(TileSheet &img, TileSheet::SubSheetIdx idx) noexcept:
m_img(img),
m_idx(std::move(idx)),
m_parentIdx(m_idx) {

View File

@@ -0,0 +1,126 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include "rotatecommand.hpp"
namespace nostalgia::gfx {
static void rotateLeft(
TileSheet::SubSheet &ss,
ox::Point const &pt,
ox::Point const &pt1,
ox::Point const &pt2,
int const depth = 0) noexcept {
if (depth >= 4) {
return;
}
auto const dstPt = ox::Point{pt1.x + pt.y, pt2.y - pt.x};
auto const srcIdx = ptToIdx(pt + pt1, ss.columns);
auto const dstIdx = ptToIdx(dstPt, ss.columns);
auto const src = ss.pixels[srcIdx];
auto &dst = ss.pixels[dstIdx];
rotateLeft(ss, dstPt - pt1, pt1, pt2, depth + 1);
dst = src;
}
static void rotateLeft(TileSheet::SubSheet &ss, ox::Point const &pt1, ox::Point const &pt2) noexcept {
auto const w = pt2.x - pt1.x;
auto const h = pt2.y - pt1.y;
for (int x = 0; x <= w / 2; ++x) {
for (int y = 0; y <= h / 2; ++y) {
rotateLeft(ss, {x, y}, pt1, pt2);
}
}
}
static void rotateRight(
TileSheet::SubSheet &ss,
ox::Point const &pt,
ox::Point const &pt1,
ox::Point const &pt2,
int const depth = 0) noexcept {
if (depth >= 4) {
return;
}
auto const dstPt = ox::Point{pt2.x - pt.y, pt1.y + pt.x};
auto const srcIdx = ptToIdx(pt + pt1, ss.columns);
auto const dstIdx = ptToIdx(dstPt, ss.columns);
auto const src = ss.pixels[srcIdx];
auto &dst = ss.pixels[dstIdx];
rotateRight(ss, dstPt - pt1, pt1, pt2, depth + 1);
dst = src;
}
static void rotateRight(TileSheet::SubSheet &ss, ox::Point const &pt1, ox::Point const &pt2) noexcept {
auto const w = pt2.x - pt1.x;
auto const h = pt2.y - pt1.y;
for (int x = 0; x <= w / 2; ++x) {
for (int y = 0; y <= h / 2; ++y) {
rotateRight(ss, {x, y}, pt1, pt2);
}
}
}
RotateCommand::RotateCommand(
TileSheet &img,
TileSheet::SubSheetIdx idx,
Direction const dir) noexcept:
m_img(img),
m_idx(std::move(idx)),
m_pt2{[this] {
auto &ss = getSubSheet(m_img, m_idx);
return ox::Point{ss.columns * TileWidth - 1, ss.rows * TileHeight - 1};
}()},
m_dir{dir} {
}
RotateCommand::RotateCommand(
TileSheet &img,
TileSheet::SubSheetIdx idx,
ox::Point const &pt1,
ox::Point const &pt2,
Direction const dir) noexcept:
m_img(img),
m_idx(std::move(idx)),
m_pt1{pt1},
m_pt2{pt2},
m_dir{dir} {
}
ox::Error RotateCommand::redo() noexcept {
auto &ss = getSubSheet(m_img, m_idx);
switch (m_dir) {
case Direction::Left:
rotateLeft(ss, m_pt1, m_pt2);
break;
case Direction::Right:
rotateRight(ss, m_pt1, m_pt2);
break;
}
return {};
}
ox::Error RotateCommand::undo() noexcept {
auto &ss = getSubSheet(m_img, m_idx);
switch (m_dir) {
case Direction::Left:
rotateRight(ss, m_pt1, m_pt2);
break;
case Direction::Right:
rotateLeft(ss, m_pt1, m_pt2);
break;
}
return {};
}
int RotateCommand::commandId() const noexcept {
return static_cast<int>(CommandId::Rotate);
}
TileSheet::SubSheetIdx const&RotateCommand::subsheetIdx() const noexcept {
return m_idx;
}
}

View File

@@ -0,0 +1,47 @@
/*
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include "commands.hpp"
namespace nostalgia::gfx {
class RotateCommand: public TileSheetCommand {
public:
enum class Direction {
Right,
Left,
};
private:
TileSheet &m_img;
TileSheet::SubSheetIdx m_idx;
ox::Point const m_pt1;
ox::Point const m_pt2;
Direction const m_dir;
public:
RotateCommand(TileSheet &img, TileSheet::SubSheetIdx idx, Direction dir) noexcept;
RotateCommand(
TileSheet &img,
TileSheet::SubSheetIdx idx,
ox::Point const &pt1,
ox::Point const &pt2,
Direction dir) noexcept;
ox::Error redo() noexcept final;
ox::Error undo() noexcept final;
[[nodiscard]]
int commandId() const noexcept final;
[[nodiscard]]
TileSheet::SubSheetIdx const&subsheetIdx() const noexcept override;
};
}

View File

@@ -246,15 +246,24 @@ void TileSheetEditorImGui::draw(studio::StudioContext&) noexcept {
//ig::ComboBox("##Operations", ox::Array<ox::CStringView, 1>{"Operations"}, i);
}
ImGui::EndChild();
ImGui::BeginChild("OperationsBox", {0, 32}, true);
ImGui::BeginChild("OperationsBox", {0, 35}, ImGuiWindowFlags_NoTitleBar);
{
auto constexpr btnSz = ImVec2{55, 16};
if (ig::PushButton("Flip X", btnSz)) {
oxLogError(m_model.flipX());
}
ImGui::SameLine();
if (ig::PushButton("Flip Y", btnSz)) {
oxLogError(m_model.flipY());
if (ImGui::BeginCombo("##Operations", "Operations", 0)) {
if (ImGui::Selectable("Flip X", false)) {
oxLogError(m_model.flipX());
}
if (ImGui::Selectable("Flip Y", false)) {
oxLogError(m_model.flipY());
}
ImGui::BeginDisabled(!m_model.rotateEligible());
if (ImGui::Selectable("Rotate Left", false)) {
oxLogError(m_model.rotateLeft());
}
if (ImGui::Selectable("Rotate Right", false)) {
oxLogError(m_model.rotateRight());
}
ImGui::EndDisabled();
ImGui::EndCombo();
}
}
ImGui::EndChild();

View File

@@ -24,6 +24,7 @@
#include "tilesheeteditormodel.hpp"
#include "commands/movesubsheetcommand.hpp"
#include "commands/rotatecommand.hpp"
namespace nostalgia::gfx {
@@ -171,7 +172,7 @@ void TileSheetEditorModel::drawLineCommand(ox::Point const &pt, std::size_t cons
if (m_ongoingDrawCommand) {
m_ongoingDrawCommand->lineUpdate(m_lineStartPt, pt);
m_updated = true;
} else if (getPixel(activeSubSheet, idx) != palIdx) {
} else {
std::ignore = pushCommand(ox::make<DrawCommand>(
m_img, m_activeSubsSheetIdx, idx, static_cast<int>(palIdx)));
m_lineStartPt = pt;
@@ -179,7 +180,10 @@ void TileSheetEditorModel::drawLineCommand(ox::Point const &pt, std::size_t cons
}
void TileSheetEditorModel::endDrawCommand() noexcept {
m_ongoingDrawCommand = nullptr;
if (m_ongoingDrawCommand) {
m_ongoingDrawCommand->finish();
m_ongoingDrawCommand = nullptr;
}
}
void TileSheetEditorModel::addSubsheet(TileSheet::SubSheetIdx const&parentIdx) noexcept {
@@ -237,6 +241,28 @@ void TileSheetEditorModel::fill(ox::Point const&pt, int const palIdx) noexcept {
}
}
ox::Error TileSheetEditorModel::rotateLeft() noexcept {
auto &ss = activeSubSheet();
ox::Point pt1, pt2{ss.columns * TileWidth - 1, ss.rows * TileHeight - 1};
if (m_selection) {
pt1 = m_selection->a;
pt2 = m_selection->b;
}
return pushCommand(ox::make<RotateCommand>(
m_img, m_activeSubsSheetIdx, pt1, pt2, RotateCommand::Direction::Left));
}
ox::Error TileSheetEditorModel::rotateRight() noexcept {
auto &ss = activeSubSheet();
ox::Point pt1, pt2{ss.columns * TileWidth - 1, ss.rows * TileHeight - 1};
if (m_selection) {
pt1 = m_selection->a;
pt2 = m_selection->b;
}
return pushCommand(ox::make<RotateCommand>(
m_img, m_activeSubsSheetIdx, pt1, pt2, RotateCommand::Direction::Right));
}
void TileSheetEditorModel::setSelection(studio::Selection const&sel) noexcept {
m_selection.emplace(sel);
m_updated = true;
@@ -277,6 +303,7 @@ ox::Error TileSheetEditorModel::markUpdatedCmdId(studio::UndoCommand const*cmd)
m_pal = keel::AssetRef<Palette>{};
}
m_palettePage = ox::min<size_t>(pal().pages.size(), 0);
setPalPath();
paletteChanged.emit();
}
auto const tsCmd = dynamic_cast<TileSheetCommand const*>(cmd);
@@ -328,6 +355,16 @@ ox::Error TileSheetEditorModel::flipY() noexcept {
return pushCommand(ox::make<FlipYCommand>(m_img, m_activeSubsSheetIdx, a, b));
}
bool TileSheetEditorModel::rotateEligible() const noexcept {
if (m_selection) {
auto const w = m_selection->b.x - m_selection->a.x;
auto const h = m_selection->b.y - m_selection->a.y;
return w == h;
}
auto const &ss = activeSubSheet();
return ss.rows == ss.columns;
}
ox::Error TileSheetEditorModel::moveSubSheet(TileSheet::SubSheetIdx src, TileSheet::SubSheetIdx dst) noexcept {
return pushCommand(ox::make<MoveSubSheetCommand>(m_img, std::move(src), std::move(dst)));
}

View File

@@ -106,6 +106,10 @@ class TileSheetEditorModel: public ox::SignalHandler {
void fill(ox::Point const&pt, int palIdx) noexcept;
ox::Error rotateLeft() noexcept;
ox::Error rotateRight() noexcept;
void setSelection(studio::Selection const&sel) noexcept;
void select(ox::Point const&pt) noexcept;
@@ -134,6 +138,9 @@ class TileSheetEditorModel: public ox::SignalHandler {
ox::Error flipY() noexcept;
[[nodiscard]]
bool rotateEligible() const noexcept;
ox::Error moveSubSheet(TileSheet::SubSheetIdx src, TileSheet::SubSheetIdx dst) noexcept;
private:

View File

@@ -22,7 +22,12 @@ ox::Error TileSheetGrid::buildShader() noexcept {
}
void TileSheetGrid::draw(bool update, ox::Vec2 const&scroll) noexcept {
glLineWidth(3 * m_pixelSizeMod * 0.5f);
// the lines just show up bigger on Windows for some reason
if constexpr(ox::defines::OS == ox::OS::Windows) {
glLineWidth(3 * m_pixelSizeMod * 0.25f);
} else {
glLineWidth(3 * m_pixelSizeMod * 0.5f);
}
glUseProgram(m_shader);
glBindVertexArray(m_bufferSet.vao);
if (update) {

View File

@@ -187,7 +187,11 @@ TileSheet::SubSheetIdx validateSubSheetIdx(TileSheet const&ts, TileSheet::SubShe
return validateSubSheetIdx(std::move(idx), 0, ts.subsheet);
}
TileSheet::SubSheet const&getSubSheet(
#if defined(__GNUC__) && __GNUC__ >= 14
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdangling-reference"
#endif
static TileSheet::SubSheet const&getSubSheet(
ox::SpanView<uint32_t> const &idx,
std::size_t const idxIt,
TileSheet::SubSheet const &pSubsheet) noexcept {
@@ -200,6 +204,9 @@ TileSheet::SubSheet const&getSubSheet(
}
return getSubSheet(idx, idxIt + 1, pSubsheet.subsheets[currentIdx]);
}
#if defined(__GNUC__) && __GNUC__ >= 14
#pragma GCC diagnostic pop
#endif
TileSheet::SubSheet &getSubSheet(
ox::SpanView<uint32_t> const &idx,
@@ -211,13 +218,20 @@ TileSheet::SubSheet &getSubSheet(
return getSubSheet(idx, idxIt + 1, pSubsheet.subsheets[idx[idxIt]]);
}
#if defined(__GNUC__) && __GNUC__ >= 14
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdangling-reference"
#endif
TileSheet::SubSheet const&getSubSheet(TileSheet const &ts, ox::SpanView<uint32_t> const &idx) noexcept {
return gfx::getSubSheet(idx, 0, ts.subsheet);
}
TileSheet::SubSheet &getSubSheet(TileSheet &ts, ox::SpanView<uint32_t> const&idx) noexcept {
TileSheet::SubSheet &getSubSheet(TileSheet &ts, ox::SpanView<uint32_t> const &idx) noexcept {
return gfx::getSubSheet(idx, 0, ts.subsheet);
}
#if defined(__GNUC__) && __GNUC__ >= 14
#pragma GCC diagnostic pop
#endif
ox::Error addSubSheet(TileSheet &ts, TileSheet::SubSheetIdx const&idx) noexcept {
auto &parent = getSubSheet(ts, idx);