add DrawCustomPalette with drag/drop and export to clipboard
This commit is contained in:
@@ -49,7 +49,7 @@ using namespace gfx;
|
||||
|
||||
constexpr ImGuiTableFlags kPaletteTableFlags =
|
||||
ImGuiTableFlags_Reorderable | ImGuiTableFlags_Resizable |
|
||||
ImGuiTableFlags_SizingStretchSame;
|
||||
ImGuiTableFlags_SizingStretchSame | ImGuiTableFlags_Hideable;
|
||||
|
||||
namespace {
|
||||
int CustomFormatString(char* buf, size_t buf_size, const char* fmt, ...) {
|
||||
@@ -97,6 +97,8 @@ absl::Status PaletteEditor::Update() {
|
||||
TableHeadersRow();
|
||||
TableNextRow();
|
||||
TableNextColumn();
|
||||
DrawCustomPalette();
|
||||
Separator();
|
||||
gui::SnesColorEdit4("Current Color Picker", ¤t_color_,
|
||||
ImGuiColorEditFlags_NoAlpha);
|
||||
Separator();
|
||||
@@ -121,6 +123,43 @@ absl::Status PaletteEditor::Update() {
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
void PaletteEditor::DrawCustomPalette() {
|
||||
if (BeginChild("ColorPalette", ImVec2(0, 40), true,
|
||||
ImGuiWindowFlags_HorizontalScrollbar)) {
|
||||
for (int i = 0; i < custom_palette_.size(); i++) {
|
||||
PushID(i);
|
||||
if ((i % 8) != 0) SameLine(0.0f, GetStyle().ItemSpacing.y);
|
||||
gui::SnesColorEdit4("##customPalette", &custom_palette_[i],
|
||||
ImGuiColorEditFlags_NoInputs);
|
||||
// Accept a drag drop target which adds a color to the custom_palette_
|
||||
if (BeginDragDropTarget()) {
|
||||
if (const ImGuiPayload* payload =
|
||||
AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_3F)) {
|
||||
ImVec4 color = ImVec4(0, 0, 0, 1.0f);
|
||||
memcpy((float*)&color, payload->Data, sizeof(float));
|
||||
custom_palette_.push_back(SnesColor(color));
|
||||
}
|
||||
EndDragDropTarget();
|
||||
}
|
||||
|
||||
PopID();
|
||||
}
|
||||
SameLine();
|
||||
if (ImGui::Button("Add Color")) {
|
||||
custom_palette_.push_back(SnesColor(0x7FFF));
|
||||
}
|
||||
SameLine();
|
||||
if (ImGui::Button("Export to Clipboard")) {
|
||||
std::string clipboard;
|
||||
for (const auto& color : custom_palette_) {
|
||||
clipboard += absl::StrFormat("$%04X,", color.snes());
|
||||
}
|
||||
SetClipboardText(clipboard.c_str());
|
||||
}
|
||||
}
|
||||
EndChild();
|
||||
}
|
||||
|
||||
void PaletteEditor::DisplayCategoryTable() {
|
||||
if (BeginTable("Category Table", 8,
|
||||
ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable |
|
||||
@@ -248,10 +287,7 @@ absl::Status PaletteEditor::DrawPaletteGroup(int category, bool right_side) {
|
||||
absl::Status PaletteEditor::HandleColorPopup(gfx::SnesPalette& palette, int i,
|
||||
int j, int n) {
|
||||
auto col = gfx::ToFloatArray(palette[n]);
|
||||
if (gui::SnesColorEdit4("Edit Color", &palette[n], color_popup_flags)) {
|
||||
// TODO: Implement new update color function
|
||||
}
|
||||
|
||||
gui::SnesColorEdit4("Edit Color", &palette[n], color_popup_flags);
|
||||
if (Button("Copy as..", ImVec2(-1, 0))) OpenPopup("Copy");
|
||||
if (BeginPopup("Copy")) {
|
||||
int cr = F32_TO_INT8_SAT(col[0]);
|
||||
|
||||
@@ -73,7 +73,10 @@ class PaletteEditorHistory {
|
||||
*/
|
||||
class PaletteEditor : public SharedRom, public Editor {
|
||||
public:
|
||||
PaletteEditor() { type_ = EditorType::kPalette; }
|
||||
PaletteEditor() {
|
||||
type_ = EditorType::kPalette;
|
||||
custom_palette_.push_back(gfx::SnesColor(0x7FFF));
|
||||
}
|
||||
|
||||
absl::Status Update() override;
|
||||
|
||||
@@ -92,6 +95,8 @@ class PaletteEditor : public SharedRom, public Editor {
|
||||
void DrawPortablePalette(gfx::SnesPalette& palette);
|
||||
absl::Status DrawPaletteGroup(int category, bool right_side = false);
|
||||
|
||||
void DrawCustomPalette();
|
||||
|
||||
private:
|
||||
absl::Status HandleColorPopup(gfx::SnesPalette& palette, int i, int j, int n);
|
||||
absl::Status InitializeSavedPalette(const gfx::SnesPalette& palette) {
|
||||
@@ -110,6 +115,8 @@ class PaletteEditor : public SharedRom, public Editor {
|
||||
|
||||
GfxGroupEditor gfx_group_editor_;
|
||||
|
||||
std::vector<gfx::SnesColor> custom_palette_;
|
||||
|
||||
ImVec4 saved_palette_[256] = {};
|
||||
ImGuiColorEditFlags color_popup_flags =
|
||||
ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoAlpha;
|
||||
|
||||
Reference in New Issue
Block a user