[nostalgia] Split PaletteEditor into Imgui and general files, other cleanup

This commit is contained in:
2022-04-08 01:05:32 -05:00
parent 632ade60b9
commit 56964e197a
16 changed files with 390 additions and 379 deletions
+84 -38
View File
@@ -4,58 +4,104 @@
#pragma once
#include "nostalgia/studio/lib/undostack.hpp"
#include <nostalgia/core/gfx.hpp>
#include <nostalgia/studio/studio.hpp>
#include <ox/std/memory.hpp>
namespace nostalgia::core {
class PaletteEditorImGui: public studio::Editor {
enum class PaletteEditorCommandId {
AddColor,
RemoveColor,
UpdateColor,
MoveColor,
};
friend class AddColorCommand;
friend class RemoveColorCommand;
friend class UpdateColorCommand;
friend class MoveColorCommand;
class AddColorCommand: public studio::UndoCommand {
private:
Context *m_ctx = nullptr;
ox::String m_itemName;
ox::String m_itemPath;
Palette m_pal;
std::size_t m_selectedRow = 0;
studio::UndoStack m_undoStack;
PaletteEditorImGui() noexcept = default;
Palette *m_pal = nullptr;
Color16 m_color = 0;
int m_idx = -1;
public:
static ox::Result<PaletteEditorImGui*> make(Context *ctx, const ox::String &path) noexcept;
AddColorCommand(Palette *pal, Color16 color, int idx) noexcept;
/**
* Returns the name of item being edited.
*/
const ox::String &itemName() const override;
~AddColorCommand() noexcept override = default;
const ox::String &itemDisplayName() const noexcept override;
[[nodiscard]]
int commandId() const noexcept override;
void draw(core::Context*) noexcept override;
void redo() noexcept override;
studio::UndoStack *undoStack() noexcept final;
protected:
void addColor(int idx, Color16 c) noexcept;
void rmColor(int idx) noexcept;
void updateColor(int idx, Color16) noexcept;
void moveColor(int idx, int offset) noexcept;
void saveItem() override;
private:
ox::Error markUnsavedChanges(int) noexcept;
void undo() noexcept override;
};
}
class RemoveColorCommand: public studio::UndoCommand {
private:
Palette *m_pal = nullptr;
Color16 m_color = 0;
int m_idx = -1;
public:
RemoveColorCommand(Palette *pal, Color16 color, int idx) noexcept;
~RemoveColorCommand() noexcept override = default;
[[nodiscard]]
int commandId() const noexcept override;
void redo() noexcept override;
void undo() noexcept override;
};
class UpdateColorCommand: public studio::UndoCommand {
private:
Palette *m_pal = nullptr;
Color16 m_oldColor = 0;
Color16 m_newColor = 0;
int m_idx = -1;
public:
UpdateColorCommand(Palette *pal, int idx, Color16 oldColor, Color16 newColor) noexcept;
~UpdateColorCommand() noexcept override = default;
[[nodiscard]]
bool mergeWith(const UndoCommand *cmd) noexcept final;
[[nodiscard]]
int commandId() const noexcept final;
void redo() noexcept final;
void undo() noexcept final;
};
class MoveColorCommand: public studio::UndoCommand {
private:
Palette *m_pal = nullptr;
std::size_t m_idx = 0;
int m_offset = 0;
public:
MoveColorCommand(Palette *pal, std::size_t idx, int offset) noexcept;
~MoveColorCommand() noexcept override = default;
[[nodiscard]]
int commandId() const noexcept override;
public:
void redo() noexcept override;
void undo() noexcept override;
private:
void moveColor(int idx, int offset) noexcept;
};
}