159 lines
3.1 KiB
C++
159 lines
3.1 KiB
C++
/*
|
|
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <ox/std/string.hpp>
|
|
|
|
#include <nostalgia/geo/bounds.hpp>
|
|
#include <nostalgia/geo/vec.hpp>
|
|
#include <nostalgia/core/gfx.hpp>
|
|
#include <nostalgia/glutils/glutils.hpp>
|
|
#include <nostalgia/studio/studio.hpp>
|
|
|
|
namespace nostalgia::core {
|
|
|
|
// Command IDs to use with QUndoCommand::id()
|
|
enum class CommandId {
|
|
UpdatePixel = 1,
|
|
ModPixel = 2,
|
|
UpdateDimension = 3,
|
|
InsertTile = 4,
|
|
ClipboardPaste = 5,
|
|
};
|
|
|
|
enum class TileSheetTool: int {
|
|
Select,
|
|
Draw,
|
|
Fill,
|
|
};
|
|
|
|
[[nodiscard]]
|
|
constexpr auto toString(TileSheetTool t) noexcept {
|
|
switch (t) {
|
|
case TileSheetTool::Select:
|
|
return "Select";
|
|
case TileSheetTool::Draw:
|
|
return "Draw";
|
|
case TileSheetTool::Fill:
|
|
return "Fill";
|
|
}
|
|
return "";
|
|
}
|
|
|
|
struct PixelChunk {
|
|
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.studio.PixelChunk";
|
|
static constexpr auto TypeVersion = 1;
|
|
geo::Point pt;
|
|
int size = 0;
|
|
};
|
|
|
|
oxModelBegin(PixelChunk)
|
|
oxModelField(pt)
|
|
oxModelField(size)
|
|
oxModelEnd()
|
|
|
|
struct TileSheetClipboard {
|
|
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.studio.TileSheetClipboard";
|
|
static constexpr auto TypeVersion = 1;
|
|
|
|
oxModelFriend(TileSheetClipboard);
|
|
|
|
protected:
|
|
ox::Vector<int> m_pixels;
|
|
geo::Point m_p1;
|
|
geo::Point m_p2;
|
|
|
|
public:
|
|
void addPixel(int color);
|
|
|
|
[[nodiscard]]
|
|
bool empty() const;
|
|
|
|
void pastePixels(const geo::Point &pt, ox::Vector<int> *tgt, int tgtColumns) const;
|
|
|
|
void setPoints(const geo::Point &p1, const geo::Point &p2);
|
|
|
|
[[nodiscard]]
|
|
geo::Point point1() const;
|
|
|
|
[[nodiscard]]
|
|
geo::Point point2() const;
|
|
|
|
};
|
|
|
|
template<typename T>
|
|
constexpr ox::Error model(T *io, TileSheetClipboard *b) noexcept {
|
|
io->template setTypeInfo<TileSheetClipboard>();
|
|
oxReturnError(io->field("pixels", &b->m_pixels));
|
|
oxReturnError(io->field("p1", &b->m_p1));
|
|
oxReturnError(io->field("p2", &b->m_p2));
|
|
return OxError(0);
|
|
}
|
|
|
|
class TileSheetEditorModel {
|
|
|
|
private:
|
|
NostalgiaGraphic m_img;
|
|
AssetRef<NostalgiaPalette> m_pal;
|
|
|
|
public:
|
|
TileSheetEditorModel(Context *ctx, const ox::String &path);
|
|
|
|
~TileSheetEditorModel() = default;
|
|
|
|
void cut();
|
|
|
|
void copy();
|
|
|
|
void paste();
|
|
|
|
[[nodiscard]]
|
|
constexpr const NostalgiaGraphic &img() const noexcept;
|
|
|
|
[[nodiscard]]
|
|
constexpr NostalgiaGraphic &img() noexcept;
|
|
|
|
[[nodiscard]]
|
|
constexpr const NostalgiaPalette &pal() const noexcept;
|
|
|
|
protected:
|
|
void saveItem();
|
|
|
|
void getFillPixels(bool *pixels, geo::Point pt, int oldColor) const noexcept;
|
|
|
|
private:
|
|
void setPalette();
|
|
|
|
void saveState();
|
|
|
|
void restoreState();
|
|
|
|
[[nodiscard]]
|
|
ox::String paletteName(const ox::String &palettePath) const;
|
|
|
|
[[nodiscard]]
|
|
ox::String palettePath(const ox::String &palettePath) const;
|
|
|
|
// slots
|
|
public:
|
|
ox::Error colorSelected() noexcept;
|
|
|
|
ox::Error setColorTable() noexcept;
|
|
|
|
};
|
|
|
|
constexpr const NostalgiaGraphic &TileSheetEditorModel::img() const noexcept {
|
|
return m_img;
|
|
}
|
|
|
|
constexpr NostalgiaGraphic &TileSheetEditorModel::img() noexcept {
|
|
return m_img;
|
|
}
|
|
|
|
constexpr const NostalgiaPalette &TileSheetEditorModel::pal() const noexcept {
|
|
return *m_pal;
|
|
}
|
|
|
|
} |