[nostalgia] Add PaletteEditor
This commit is contained in:
@@ -4,22 +4,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
#include "nostalgia/studio/lib/undostack.hpp"
|
||||
#include <nostalgia/core/gfx.hpp>
|
||||
#include <nostalgia/studio/studio.hpp>
|
||||
#include <ox/std/memory.hpp>
|
||||
|
||||
namespace nostalgia::core {
|
||||
|
||||
struct PaletteEditorColorTableDelegate: public QStyledItemDelegate {
|
||||
|
||||
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem&, const QModelIndex &idx) const;
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &opt, const QModelIndex &idx) const;
|
||||
|
||||
};
|
||||
|
||||
class PaletteEditor: public studio::Editor {
|
||||
class PaletteEditorImGui: public studio::Editor {
|
||||
|
||||
friend class AddColorCommand;
|
||||
friend class RemoveColorCommand;
|
||||
@@ -27,58 +19,40 @@ class PaletteEditor: public studio::Editor {
|
||||
friend class MoveColorCommand;
|
||||
|
||||
private:
|
||||
PaletteEditorColorTableDelegate m_colorTableDelegate;
|
||||
const studio::Context *m_ctx = nullptr;
|
||||
QString m_itemPath;
|
||||
std::unique_ptr<NostalgiaPalette> m_pal;
|
||||
class QTableWidget *m_table = nullptr;
|
||||
class QPushButton *m_addBtn = nullptr;
|
||||
class QPushButton *m_rmBtn = nullptr;
|
||||
class QPushButton *m_moveUpBtn = nullptr;
|
||||
class QPushButton *m_moveDownBtn = nullptr;
|
||||
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;
|
||||
|
||||
public:
|
||||
PaletteEditor(QString path, const studio::Context *ctx, QWidget *parent);
|
||||
static ox::Result<PaletteEditorImGui*> make(Context *ctx, const ox::String &path) noexcept;
|
||||
|
||||
/**
|
||||
* Returns the name of item being edited.
|
||||
*/
|
||||
QString itemName() const override;
|
||||
const ox::String &itemName() const override;
|
||||
|
||||
void draw(core::Context*) noexcept override;
|
||||
|
||||
studio::UndoStack *undoStack() noexcept final;
|
||||
|
||||
protected:
|
||||
void addColor(int idx, Color16 c);
|
||||
void addColor(int idx, Color16 c) noexcept;
|
||||
|
||||
void rmColor(int idx);
|
||||
void rmColor(int idx) noexcept;
|
||||
|
||||
void updateColor(int idx, Color16);
|
||||
void updateColor(int idx, Color16) noexcept;
|
||||
|
||||
void moveColor(int idx, int offset);
|
||||
void moveColor(int idx, int offset) noexcept;
|
||||
|
||||
void saveItem() override;
|
||||
|
||||
private:
|
||||
void load();
|
||||
|
||||
[[nodiscard]] Color16 rowColor(int i) const;
|
||||
|
||||
void addTableRow(int i, Color16 c);
|
||||
|
||||
void rmTableRow(int i);
|
||||
|
||||
void setTableRow(int idx, Color16 c);
|
||||
|
||||
private slots:
|
||||
void colorSelected();
|
||||
|
||||
void cellChanged(int row, int col);
|
||||
|
||||
void addColorClicked();
|
||||
|
||||
void rmColorClicked();
|
||||
|
||||
void moveColorUpClicked();
|
||||
|
||||
void moveColorDownClicked();
|
||||
ox::Error markUnsavedChanges(int) noexcept;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user