Compare commits
No commits in common. "3b8f97cc41a0b522f9eb8fa7c41f0993c2adb622" and "d6e4ab7a24a0a4b035c6578dfa30ef35170b5a01" have entirely different histories.
3b8f97cc41
...
d6e4ab7a24
@ -8,12 +8,16 @@
|
|||||||
|
|
||||||
#include <turbine/context.hpp>
|
#include <turbine/context.hpp>
|
||||||
|
|
||||||
|
#include "initparams.hpp"
|
||||||
|
|
||||||
namespace nostalgia::gfx {
|
namespace nostalgia::gfx {
|
||||||
|
|
||||||
class Context;
|
class Context;
|
||||||
|
|
||||||
void safeDelete(Context *ctx) noexcept;
|
void safeDelete(Context *ctx) noexcept;
|
||||||
|
|
||||||
|
ox::Result<ox::UPtr<Context>> init(turbine::Context &tctx, InitParams const¶ms = {}) noexcept;
|
||||||
|
|
||||||
keel::Context &keelCtx(Context &ctx) noexcept;
|
keel::Context &keelCtx(Context &ctx) noexcept;
|
||||||
|
|
||||||
turbine::Context &turbineCtx(Context &ctx) noexcept;
|
turbine::Context &turbineCtx(Context &ctx) noexcept;
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include "color.hpp"
|
#include "color.hpp"
|
||||||
#include "context.hpp"
|
#include "context.hpp"
|
||||||
|
#include "initparams.hpp"
|
||||||
#include "keelmodule.hpp"
|
#include "keelmodule.hpp"
|
||||||
#include "palette.hpp"
|
#include "palette.hpp"
|
||||||
#include "ptidxconv.hpp"
|
#include "ptidxconv.hpp"
|
||||||
@ -105,14 +106,6 @@ OX_MODEL_BEGIN(TileSheetSet)
|
|||||||
OX_MODEL_FIELD(entries)
|
OX_MODEL_FIELD(entries)
|
||||||
OX_MODEL_END()
|
OX_MODEL_END()
|
||||||
|
|
||||||
struct InitParams {
|
|
||||||
bool glInstallDrawer = true;
|
|
||||||
uint_t glSpriteCount = 128;
|
|
||||||
uint_t glBlocksPerSprite = 64;
|
|
||||||
};
|
|
||||||
|
|
||||||
ox::Result<ox::UPtr<Context>> init(turbine::Context &tctx, InitParams const¶ms = {}) noexcept;
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
int tileColumns(Context&) noexcept;
|
int tileColumns(Context&) noexcept;
|
||||||
|
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <ox/std/types.hpp>
|
||||||
|
|
||||||
|
namespace nostalgia::gfx {
|
||||||
|
|
||||||
|
struct InitParams {
|
||||||
|
bool glInstallDrawer = true;
|
||||||
|
uint_t glSpriteCount = 128;
|
||||||
|
uint_t glBlocksPerSprite = 64;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
@ -27,14 +27,11 @@ CutPasteCommand::CutPasteCommand(
|
|||||||
TileSheet::SubSheetIdx subSheetIdx,
|
TileSheet::SubSheetIdx subSheetIdx,
|
||||||
ox::Point const&dstStart,
|
ox::Point const&dstStart,
|
||||||
ox::Point dstEnd,
|
ox::Point dstEnd,
|
||||||
TileSheetClipboard const&cb):
|
TileSheetClipboard const&cb) noexcept:
|
||||||
m_commandId(commandId),
|
m_commandId(commandId),
|
||||||
m_img(img),
|
m_img(img),
|
||||||
m_subSheetIdx(std::move(subSheetIdx)) {
|
m_subSheetIdx(std::move(subSheetIdx)) {
|
||||||
auto const&ss = getSubSheet(m_img, m_subSheetIdx);
|
auto const&ss = getSubSheet(m_img, m_subSheetIdx);
|
||||||
if (dstStart.x >= ss.columns * TileWidth || dstStart.y >= ss.rows * TileHeight) {
|
|
||||||
throw ox::Exception{1, "paste starts beyond the bounds of target"};
|
|
||||||
}
|
|
||||||
dstEnd.x = std::min(ss.columns * TileWidth - 1, dstEnd.x);
|
dstEnd.x = std::min(ss.columns * TileWidth - 1, dstEnd.x);
|
||||||
dstEnd.y = std::min(ss.rows * TileHeight - 1, dstEnd.y);
|
dstEnd.y = std::min(ss.rows * TileHeight - 1, dstEnd.y);
|
||||||
for (auto const&p : cb.pixels()) {
|
for (auto const&p : cb.pixels()) {
|
||||||
|
@ -69,7 +69,7 @@ class CutPasteCommand: public TileSheetCommand {
|
|||||||
TileSheet::SubSheetIdx subSheetIdx,
|
TileSheet::SubSheetIdx subSheetIdx,
|
||||||
ox::Point const&dstStart,
|
ox::Point const&dstStart,
|
||||||
ox::Point dstEnd,
|
ox::Point dstEnd,
|
||||||
TileSheetClipboard const&cb);
|
TileSheetClipboard const&cb) noexcept;
|
||||||
|
|
||||||
ox::Error redo() noexcept final;
|
ox::Error redo() noexcept final;
|
||||||
|
|
||||||
|
@ -46,13 +46,13 @@ Palette const TileSheetEditorModel::s_defaultPalette = {
|
|||||||
|
|
||||||
TileSheetEditorModel::TileSheetEditorModel(
|
TileSheetEditorModel::TileSheetEditorModel(
|
||||||
studio::Context &sctx, ox::StringParam path, studio::UndoStack &undoStack):
|
studio::Context &sctx, ox::StringParam path, studio::UndoStack &undoStack):
|
||||||
m_sctx{sctx},
|
m_sctx(sctx),
|
||||||
m_tctx{m_sctx.tctx},
|
m_tctx(m_sctx.tctx),
|
||||||
m_path{std::move(path)},
|
m_path(std::move(path)),
|
||||||
m_img{*readObj<TileSheet>(keelCtx(m_tctx), m_path).unwrapThrow()},
|
m_img(*readObj<TileSheet>(keelCtx(m_tctx), m_path).unwrapThrow()),
|
||||||
// ignore failure to load palette
|
// ignore failure to load palette
|
||||||
m_pal{readObj<Palette>(keelCtx(m_tctx), m_img.defaultPalette).value},
|
m_pal(readObj<Palette>(keelCtx(m_tctx), m_img.defaultPalette).value),
|
||||||
m_undoStack{undoStack} {
|
m_undoStack(undoStack) {
|
||||||
normalizeSubsheets(m_img.subsheet);
|
normalizeSubsheets(m_img.subsheet);
|
||||||
m_pal.updated.connect(this, &TileSheetEditorModel::markUpdated);
|
m_pal.updated.connect(this, &TileSheetEditorModel::markUpdated);
|
||||||
m_undoStack.changeTriggered.connect(this, &TileSheetEditorModel::markUpdatedCmdId);
|
m_undoStack.changeTriggered.connect(this, &TileSheetEditorModel::markUpdatedCmdId);
|
||||||
@ -67,27 +67,19 @@ void TileSheetEditorModel::cut() {
|
|||||||
TileSheetClipboard blankCb;
|
TileSheetClipboard blankCb;
|
||||||
auto cb = ox::make_unique<TileSheetClipboard>();
|
auto cb = ox::make_unique<TileSheetClipboard>();
|
||||||
auto const&s = activeSubSheet();
|
auto const&s = activeSubSheet();
|
||||||
if (iterateSelectionRows(*m_selection, [&](int const x, int const y) {
|
iterateSelectionRows(*m_selection, [&](int const x, int const y) {
|
||||||
auto pt = ox::Point{x, y};
|
auto pt = ox::Point{x, y};
|
||||||
auto const idx = gfx::idx(s, pt);
|
auto const idx = gfx::idx(s, pt);
|
||||||
if (idx >= s.pixels.size()) {
|
auto const c = getPixel(s, idx);
|
||||||
return ox::Error{1, "invalid idx"};
|
|
||||||
}
|
|
||||||
auto const c = s.pixels[idx];
|
|
||||||
pt -= m_selection->a;
|
pt -= m_selection->a;
|
||||||
cb->addPixel(pt, c);
|
cb->addPixel(pt, c);
|
||||||
blankCb.addPixel(pt, 0);
|
blankCb.addPixel(pt, 0);
|
||||||
return ox::Error{};
|
});
|
||||||
})) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto const pt1 = m_selection->a;
|
auto const pt1 = m_selection->a;
|
||||||
auto const pt2 = ox::Point{s.columns * TileWidth, s.rows * TileHeight};
|
auto const pt2 = ox::Point{s.columns * TileWidth, s.rows * TileHeight};
|
||||||
turbine::setClipboardObject(m_tctx, std::move(cb));
|
turbine::setClipboardObject(m_tctx, std::move(cb));
|
||||||
if (auto const cmd = ox::makeCatch<CutPasteCommand>(
|
std::ignore = pushCommand(ox::make<CutPasteCommand>(
|
||||||
CommandId::Cut, m_img, m_activeSubsSheetIdx, pt1, pt2, blankCb); cmd.ok()) {
|
CommandId::Cut, m_img, m_activeSubsSheetIdx, pt1, pt2, blankCb));
|
||||||
std::ignore = pushCommand(cmd.value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TileSheetEditorModel::copy() {
|
void TileSheetEditorModel::copy() {
|
||||||
@ -95,20 +87,14 @@ void TileSheetEditorModel::copy() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto cb = ox::make_unique<TileSheetClipboard>();
|
auto cb = ox::make_unique<TileSheetClipboard>();
|
||||||
if (iterateSelectionRows(*m_selection, [&](int const x, int const y) {
|
iterateSelectionRows(*m_selection, [&](int const x, int const y) {
|
||||||
auto pt = ox::Point{x, y};
|
auto pt = ox::Point{x, y};
|
||||||
auto const&s = activeSubSheet();
|
auto const&s = activeSubSheet();
|
||||||
auto const idx = gfx::idx(s, pt);
|
auto const idx = gfx::idx(s, pt);
|
||||||
if (idx >= s.pixels.size()) {
|
auto const c = getPixel(s, idx);
|
||||||
return ox::Error{1, "invalid idx"};
|
|
||||||
}
|
|
||||||
auto const c = s.pixels[idx];
|
|
||||||
pt -= m_selection->a;
|
pt -= m_selection->a;
|
||||||
cb->addPixel(pt, c);
|
cb->addPixel(pt, c);
|
||||||
return ox::Error{};
|
});
|
||||||
})) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
turbine::setClipboardObject(m_tctx, std::move(cb));
|
turbine::setClipboardObject(m_tctx, std::move(cb));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,10 +111,8 @@ void TileSheetEditorModel::paste() {
|
|||||||
auto const&s = activeSubSheet();
|
auto const&s = activeSubSheet();
|
||||||
auto const pt1 = m_selection->a;
|
auto const pt1 = m_selection->a;
|
||||||
auto const pt2 = ox::Point{s.columns * TileWidth, s.rows * TileHeight};
|
auto const pt2 = ox::Point{s.columns * TileWidth, s.rows * TileHeight};
|
||||||
if (auto const cmd = ox::makeCatch<CutPasteCommand>(
|
std::ignore = pushCommand(ox::make<CutPasteCommand>(
|
||||||
CommandId::Paste, m_img, m_activeSubsSheetIdx, pt1, pt2, *cb); cmd.ok()) {
|
CommandId::Paste, m_img, m_activeSubsSheetIdx, pt1, pt2, *cb));
|
||||||
std::ignore = pushCommand(cmd.value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TileSheetEditorModel::acceptsClipboardPayload() const noexcept {
|
bool TileSheetEditorModel::acceptsClipboardPayload() const noexcept {
|
||||||
@ -168,7 +152,7 @@ void TileSheetEditorModel::drawCommand(ox::Point const &pt, std::size_t const pa
|
|||||||
auto const idx = gfx::idx(activeSubSheet, pt);
|
auto const idx = gfx::idx(activeSubSheet, pt);
|
||||||
if (m_ongoingDrawCommand) {
|
if (m_ongoingDrawCommand) {
|
||||||
m_updated = m_updated || m_ongoingDrawCommand->append(idx);
|
m_updated = m_updated || m_ongoingDrawCommand->append(idx);
|
||||||
} else if (activeSubSheet.pixels[idx] != palIdx) {
|
} else if (getPixel(activeSubSheet, idx) != palIdx) {
|
||||||
std::ignore = pushCommand(ox::make<DrawCommand>(
|
std::ignore = pushCommand(ox::make<DrawCommand>(
|
||||||
m_img, m_activeSubsSheetIdx, idx, static_cast<int>(palIdx)));
|
m_img, m_activeSubsSheetIdx, idx, static_cast<int>(palIdx)));
|
||||||
}
|
}
|
||||||
@ -229,7 +213,6 @@ ox::Error TileSheetEditorModel::updateSubsheet(
|
|||||||
void TileSheetEditorModel::setActiveSubsheet(TileSheet::SubSheetIdx const&idx) noexcept {
|
void TileSheetEditorModel::setActiveSubsheet(TileSheet::SubSheetIdx const&idx) noexcept {
|
||||||
m_activeSubsSheetIdx = idx;
|
m_activeSubsSheetIdx = idx;
|
||||||
this->activeSubsheetChanged.emit(m_activeSubsSheetIdx);
|
this->activeSubsheetChanged.emit(m_activeSubsSheetIdx);
|
||||||
clearSelection();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TileSheetEditorModel::fill(ox::Point const&pt, int const palIdx) noexcept {
|
void TileSheetEditorModel::fill(ox::Point const&pt, int const palIdx) noexcept {
|
||||||
@ -398,7 +381,7 @@ void TileSheetEditorModel::getFillPixels(
|
|||||||
int const oldColor) const noexcept {
|
int const oldColor) const noexcept {
|
||||||
auto const idx = ptToIdx(pt, activeSubSheet.columns);
|
auto const idx = ptToIdx(pt, activeSubSheet.columns);
|
||||||
auto const relIdx = idx % PixelsPerTile;
|
auto const relIdx = idx % PixelsPerTile;
|
||||||
if (pixels[relIdx] || activeSubSheet.pixels[idx] != oldColor) {
|
if (pixels[relIdx] || getPixel(activeSubSheet, idx) != oldColor) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// mark pixels to update
|
// mark pixels to update
|
||||||
@ -436,7 +419,7 @@ void TileSheetEditorModel::setPalPath() noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ox::Error TileSheetEditorModel::pushCommand(studio::UndoCommand *cmd) noexcept {
|
ox::Error TileSheetEditorModel::pushCommand(studio::UndoCommand *cmd) noexcept {
|
||||||
std::ignore = m_undoStack.push(ox::UPtr{cmd});
|
std::ignore = m_undoStack.push(ox::UPtr<studio::UndoCommand>{cmd});
|
||||||
m_ongoingDrawCommand = dynamic_cast<DrawCommand*>(cmd);
|
m_ongoingDrawCommand = dynamic_cast<DrawCommand*>(cmd);
|
||||||
m_updated = true;
|
m_updated = true;
|
||||||
return {};
|
return {};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user