[nostalgia/core/studio] Break out TileSheetEditor application logic
This commit is contained in:
@@ -6,103 +6,25 @@
|
||||
|
||||
#include <ox/model/def.hpp>
|
||||
|
||||
#include <nostalgia/core/gfx.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>
|
||||
|
||||
#include "tilesheeteditormodel.hpp"
|
||||
#include "tilesheetpixelgrid.hpp"
|
||||
#include "tilesheetpixels.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 TileSheetEditor {
|
||||
|
||||
private:
|
||||
TileSheetEditorModel m_model;
|
||||
TileSheetGrid m_pixelGridDrawer;
|
||||
TileSheetPixels m_pixelsDrawer;
|
||||
bool m_updated = false;
|
||||
NostalgiaGraphic m_img;
|
||||
AssetRef<NostalgiaPalette> m_pal;
|
||||
float m_pixelSizeMod = 1;
|
||||
geo::Vec2 m_scrollOffset;
|
||||
|
||||
@@ -121,16 +43,19 @@ class TileSheetEditor {
|
||||
|
||||
void clickPixel(const geo::Vec2 &paneSize, const geo::Vec2 &clickPos) noexcept;
|
||||
|
||||
void scrollV(const geo::Vec2 paneSz, float wheel, bool zoomMod) noexcept;
|
||||
void scrollV(const geo::Vec2 &paneSz, float wheel, bool zoomMod) noexcept;
|
||||
|
||||
void scrollH(const geo::Vec2 paneSz, float wheel) noexcept;
|
||||
void scrollH(const geo::Vec2 &paneSz, float wheel) noexcept;
|
||||
|
||||
void resize(const geo::Vec2 &sz) noexcept;
|
||||
|
||||
const NostalgiaGraphic &img() const;
|
||||
[[nodiscard]]
|
||||
constexpr const NostalgiaGraphic &img() const noexcept;
|
||||
|
||||
const NostalgiaPalette &pal() const;
|
||||
[[nodiscard]]
|
||||
constexpr const NostalgiaPalette &pal() const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
bool updated() const noexcept;
|
||||
|
||||
void ackUpdate() noexcept;
|
||||
@@ -138,8 +63,6 @@ class TileSheetEditor {
|
||||
protected:
|
||||
void saveItem();
|
||||
|
||||
void getFillPixels(bool *pixels, geo::Point pt, int oldColor) const;
|
||||
|
||||
private:
|
||||
void setPalette();
|
||||
|
||||
@@ -161,4 +84,12 @@ class TileSheetEditor {
|
||||
|
||||
};
|
||||
|
||||
constexpr const NostalgiaGraphic &TileSheetEditor::img() const noexcept {
|
||||
return m_model.img();
|
||||
}
|
||||
|
||||
constexpr const NostalgiaPalette &TileSheetEditor::pal() const noexcept {
|
||||
return m_model.pal();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user