Update SnesColorButton and PaletteEditor
This commit is contained in:
@@ -106,7 +106,7 @@ void ResourceLabelManager::SelectableLabelWithNameEdit(
|
|||||||
ImGui::Selectable(label.c_str(), selected,
|
ImGui::Selectable(label.c_str(), selected,
|
||||||
ImGuiSelectableFlags_AllowDoubleClick);
|
ImGuiSelectableFlags_AllowDoubleClick);
|
||||||
std::string label_id = type + "_" + key;
|
std::string label_id = type + "_" + key;
|
||||||
if (ImGui::IsMouseClicked(ImGuiMouseButton_Right)) {
|
if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Right)) {
|
||||||
ImGui::OpenPopup(label_id.c_str());
|
ImGui::OpenPopup(label_id.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,8 +118,6 @@ void ResourceLabelManager::SelectableLabelWithNameEdit(
|
|||||||
}
|
}
|
||||||
ImGui::EndPopup();
|
ImGui::EndPopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ImGui::PopID();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ResourceLabelManager::CreateOrGetLabel(
|
std::string ResourceLabelManager::CreateOrGetLabel(
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ class ResourceLabelManager {
|
|||||||
const std::string& defaultValue);
|
const std::string& defaultValue);
|
||||||
std::string CreateOrGetLabel(const std::string& type, const std::string& key,
|
std::string CreateOrGetLabel(const std::string& type, const std::string& key,
|
||||||
const std::string& defaultValue);
|
const std::string& defaultValue);
|
||||||
|
std::string CreateOrGetLabel(const std::string& type, const std::string& key,
|
||||||
|
const absl::string_view& defaultValue);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool labels_loaded_ = false;
|
bool labels_loaded_ = false;
|
||||||
|
|||||||
@@ -35,6 +35,15 @@ namespace app {
|
|||||||
namespace editor {
|
namespace editor {
|
||||||
|
|
||||||
absl::Status PaletteEditor::Update() {
|
absl::Status PaletteEditor::Update() {
|
||||||
|
if (rom()->is_loaded()) {
|
||||||
|
// Initialize the labels
|
||||||
|
for (int i = 0; i < kNumPalettes; i++) {
|
||||||
|
rom()->resource_label()->CreateOrGetLabel(
|
||||||
|
"Palette Group Name", std::to_string(i),
|
||||||
|
std::string(kPaletteGroupNames[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (ImGui::BeginTable("paletteEditorTable", 2,
|
if (ImGui::BeginTable("paletteEditorTable", 2,
|
||||||
ImGuiTableFlags_Reorderable |
|
ImGuiTableFlags_Reorderable |
|
||||||
ImGuiTableFlags_Resizable |
|
ImGuiTableFlags_Resizable |
|
||||||
@@ -55,7 +64,9 @@ absl::Status PaletteEditor::Update() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
ImGui::Text("Test Column");
|
if (gui::SnesColorEdit4("Color Picker", current_color_,
|
||||||
|
ImGuiColorEditFlags_NoAlpha)) {
|
||||||
|
}
|
||||||
ImGui::EndTable();
|
ImGui::EndTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,38 +108,39 @@ absl::Status PaletteEditor::DrawPaletteGroup(int category) {
|
|||||||
|
|
||||||
const auto size =
|
const auto size =
|
||||||
rom()->palette_group(kPaletteGroupNames[category].data()).size();
|
rom()->palette_group(kPaletteGroupNames[category].data()).size();
|
||||||
auto palettes = rom()->palette_group(kPaletteGroupNames[category].data());
|
auto palettes =
|
||||||
|
rom()->mutable_palette_group(kPaletteGroupNames[category].data());
|
||||||
static bool edit_color = false;
|
static bool edit_color = false;
|
||||||
for (int j = 0; j < size; j++) {
|
for (int j = 0; j < size; j++) {
|
||||||
ImGui::Text("%d", j);
|
// ImGui::Text("%d", j);
|
||||||
|
rom()->resource_label()->SelectableLabelWithNameEdit(
|
||||||
auto palette = palettes[j];
|
false, "Palette Group Name", std::to_string(j),
|
||||||
auto pal_size = palette.size();
|
std::string(kPaletteGroupNames[category]));
|
||||||
|
auto palette = palettes->mutable_palette(j);
|
||||||
|
auto pal_size = palette->size();
|
||||||
|
|
||||||
for (int n = 0; n < pal_size; n++) {
|
for (int n = 0; n < pal_size; n++) {
|
||||||
ImGui::PushID(n);
|
ImGui::PushID(n);
|
||||||
if ((n % 8) != 0) ImGui::SameLine(0.0f, ImGui::GetStyle().ItemSpacing.y);
|
if ((n % 7) != 0) ImGui::SameLine(0.0f, ImGui::GetStyle().ItemSpacing.y);
|
||||||
|
|
||||||
auto popup_id =
|
auto popup_id =
|
||||||
absl::StrCat(kPaletteCategoryNames[category].data(), j, "_", n);
|
absl::StrCat(kPaletteCategoryNames[category].data(), j, "_", n);
|
||||||
|
|
||||||
// Small icon of the color in the palette
|
// Small icon of the color in the palette
|
||||||
if (gui::SNESColorButton(popup_id, palette[n], palette_button_flags)) {
|
if (gui::SnesColorButton(popup_id, *palette->mutable_color(n),
|
||||||
edit_color = true;
|
palette_button_flags)) {
|
||||||
|
current_color_ = palette->GetColor(n);
|
||||||
|
// EditColorInPalette(*palette, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImGui::BeginPopupContextItem(popup_id.c_str())) {
|
if (ImGui::BeginPopupContextItem(popup_id.c_str())) {
|
||||||
RETURN_IF_ERROR(HandleColorPopup(palette, category, j, n))
|
RETURN_IF_ERROR(HandleColorPopup(*palette, category, j, n))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (edit_color) {
|
// if (gui::SnesColorEdit4(popup_id.c_str(), (*palette)[n],
|
||||||
// The color button was clicked, open the popup
|
// palette_button_flags)) {
|
||||||
if (ImGui::ColorEdit4(popup_id.c_str(),
|
// EditColorInPalette(*palette, n);
|
||||||
gfx::ToFloatArray(palette[n]).data(),
|
// }
|
||||||
palette_button_flags)) {
|
|
||||||
EditColorInPalette(palette, n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
}
|
}
|
||||||
@@ -139,13 +151,12 @@ absl::Status PaletteEditor::DrawPaletteGroup(int category) {
|
|||||||
absl::Status PaletteEditor::HandleColorPopup(gfx::SnesPalette& palette, int i,
|
absl::Status PaletteEditor::HandleColorPopup(gfx::SnesPalette& palette, int i,
|
||||||
int j, int n) {
|
int j, int n) {
|
||||||
auto col = gfx::ToFloatArray(palette[n]);
|
auto col = gfx::ToFloatArray(palette[n]);
|
||||||
if (ImGui::ColorEdit4("Edit Color", col.data(), color_popup_flags)) {
|
if (gui::SnesColorEdit4("Edit Color", palette[n], color_popup_flags)) {
|
||||||
RETURN_IF_ERROR(rom()->UpdatePaletteColor(kPaletteGroupNames[i].data(), j,
|
RETURN_IF_ERROR(rom()->UpdatePaletteColor(kPaletteGroupNames[i].data(), j,
|
||||||
n, palette[n]))
|
n, palette[n]))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImGui::Button("Copy as..", ImVec2(-1, 0))) ImGui::OpenPopup("Copy");
|
if (ImGui::Button("Copy as..", ImVec2(-1, 0))) ImGui::OpenPopup("Copy");
|
||||||
|
|
||||||
if (ImGui::BeginPopup("Copy")) {
|
if (ImGui::BeginPopup("Copy")) {
|
||||||
int cr = IM_F32_TO_INT8_SAT(col[0]);
|
int cr = IM_F32_TO_INT8_SAT(col[0]);
|
||||||
int cg = IM_F32_TO_INT8_SAT(col[1]);
|
int cg = IM_F32_TO_INT8_SAT(col[1]);
|
||||||
|
|||||||
@@ -26,11 +26,11 @@ static constexpr absl::string_view kPaletteGroupNames[] = {
|
|||||||
"ow_mini_map", "3d_object", "3d_object"};
|
"ow_mini_map", "3d_object", "3d_object"};
|
||||||
|
|
||||||
struct PaletteChange {
|
struct PaletteChange {
|
||||||
std::string groupName;
|
std::string group_name;
|
||||||
size_t paletteIndex;
|
size_t palette_index;
|
||||||
size_t colorIndex;
|
size_t color_index;
|
||||||
gfx::SnesColor originalColor;
|
gfx::SnesColor original_color;
|
||||||
gfx::SnesColor newColor;
|
gfx::SnesColor new_color;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PaletteEditorHistory {
|
class PaletteEditorHistory {
|
||||||
@@ -59,10 +59,10 @@ class PaletteEditorHistory {
|
|||||||
size_t paletteIndex,
|
size_t paletteIndex,
|
||||||
size_t colorIndex) const {
|
size_t colorIndex) const {
|
||||||
for (const auto& change : recentChanges) {
|
for (const auto& change : recentChanges) {
|
||||||
if (change.groupName == groupName &&
|
if (change.group_name == groupName &&
|
||||||
change.paletteIndex == paletteIndex &&
|
change.palette_index == paletteIndex &&
|
||||||
change.colorIndex == colorIndex) {
|
change.color_index == colorIndex) {
|
||||||
return change.originalColor;
|
return change.original_color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Handle error or return default (this is just an example,
|
// Handle error or return default (this is just an example,
|
||||||
@@ -104,12 +104,11 @@ class PaletteEditor : public SharedROM {
|
|||||||
PaletteEditorHistory history_;
|
PaletteEditorHistory history_;
|
||||||
|
|
||||||
ImVec4 saved_palette_[256] = {};
|
ImVec4 saved_palette_[256] = {};
|
||||||
ImVec4 current_color_;
|
gfx::SnesColor current_color_;
|
||||||
|
|
||||||
ImGuiColorEditFlags color_popup_flags =
|
ImGuiColorEditFlags color_popup_flags =
|
||||||
ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoAlpha;
|
ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoAlpha;
|
||||||
ImGuiColorEditFlags palette_button_flags =
|
ImGuiColorEditFlags palette_button_flags = ImGuiColorEditFlags_NoAlpha;
|
||||||
ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_NoTooltip;
|
|
||||||
ImGuiColorEditFlags palette_button_flags_2 = ImGuiColorEditFlags_NoAlpha |
|
ImGuiColorEditFlags palette_button_flags_2 = ImGuiColorEditFlags_NoAlpha |
|
||||||
ImGuiColorEditFlags_NoPicker |
|
ImGuiColorEditFlags_NoPicker |
|
||||||
ImGuiColorEditFlags_NoTooltip;
|
ImGuiColorEditFlags_NoTooltip;
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ std::vector<char> Convert(const std::vector<snes_color>& palette);
|
|||||||
class SnesColor {
|
class SnesColor {
|
||||||
public:
|
public:
|
||||||
SnesColor() : rgb_(0.f, 0.f, 0.f, 0.f), snes_(0) {}
|
SnesColor() : rgb_(0.f, 0.f, 0.f, 0.f), snes_(0) {}
|
||||||
|
|
||||||
explicit SnesColor(const ImVec4 val) : rgb_(val) {
|
explicit SnesColor(const ImVec4 val) : rgb_(val) {
|
||||||
snes_color color;
|
snes_color color;
|
||||||
color.red = val.x / 255;
|
color.red = val.x / 255;
|
||||||
@@ -43,6 +42,16 @@ class SnesColor {
|
|||||||
snes_(ConvertRGBtoSNES(val)),
|
snes_(ConvertRGBtoSNES(val)),
|
||||||
rom_color_(val) {}
|
rom_color_(val) {}
|
||||||
|
|
||||||
|
SnesColor(uint8_t r, uint8_t g, uint8_t b) {
|
||||||
|
rgb_ = ImVec4(r, g, b, 255.f);
|
||||||
|
snes_color color;
|
||||||
|
color.red = r;
|
||||||
|
color.green = g;
|
||||||
|
color.blue = b;
|
||||||
|
snes_ = ConvertRGBtoSNES(color);
|
||||||
|
rom_color_ = color;
|
||||||
|
}
|
||||||
|
|
||||||
ImVec4 rgb() const { return rgb_; }
|
ImVec4 rgb() const { return rgb_; }
|
||||||
void set_rgb(const ImVec4 val) {
|
void set_rgb(const ImVec4 val) {
|
||||||
rgb_.x = val.x / 255;
|
rgb_.x = val.x / 255;
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ ImVec4 ConvertSNESColorToImVec4(const SnesColor& color) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
IMGUI_API bool SNESColorButton(absl::string_view id, SnesColor& color,
|
IMGUI_API bool SnesColorButton(absl::string_view id, SnesColor& color,
|
||||||
ImGuiColorEditFlags flags,
|
ImGuiColorEditFlags flags,
|
||||||
const ImVec2& size_arg) {
|
const ImVec2& size_arg) {
|
||||||
// Convert the SNES color values to ImGui color values (normalized to 0-1
|
// Convert the SNES color values to ImGui color values (normalized to 0-1
|
||||||
@@ -34,6 +34,24 @@ IMGUI_API bool SNESColorButton(absl::string_view id, SnesColor& color,
|
|||||||
return pressed;
|
return pressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IMGUI_API bool SnesColorEdit4(absl::string_view label, SnesColor& color,
|
||||||
|
ImGuiColorEditFlags flags) {
|
||||||
|
// Convert the SNES color values to ImGui color values (normalized to 0-1
|
||||||
|
// range)
|
||||||
|
ImVec4 displayColor = ConvertSNESColorToImVec4(color);
|
||||||
|
|
||||||
|
// Call the original ImGui::ColorEdit4 with the converted color
|
||||||
|
bool pressed = ImGui::ColorEdit4(label.data(), (float*)&displayColor, flags);
|
||||||
|
|
||||||
|
// Convert the ImGui color values back to SNES color values (normalized to
|
||||||
|
// 0-255 range)
|
||||||
|
color = SnesColor(static_cast<uint8_t>(displayColor.x * 255.0f),
|
||||||
|
static_cast<uint8_t>(displayColor.y * 255.0f),
|
||||||
|
static_cast<uint8_t>(displayColor.z * 255.0f));
|
||||||
|
|
||||||
|
return pressed;
|
||||||
|
}
|
||||||
|
|
||||||
void DisplayPalette(app::gfx::SnesPalette& palette, bool loaded) {
|
void DisplayPalette(app::gfx::SnesPalette& palette, bool loaded) {
|
||||||
static ImVec4 color = ImVec4(0, 0, 0, 255.f);
|
static ImVec4 color = ImVec4(0, 0, 0, 255.f);
|
||||||
ImGuiColorEditFlags misc_flags = ImGuiColorEditFlags_AlphaPreview |
|
ImGuiColorEditFlags misc_flags = ImGuiColorEditFlags_AlphaPreview |
|
||||||
|
|||||||
@@ -20,10 +20,13 @@ using gfx::SnesColor;
|
|||||||
ImVec4 ConvertSNESColorToImVec4(const SnesColor& color);
|
ImVec4 ConvertSNESColorToImVec4(const SnesColor& color);
|
||||||
|
|
||||||
// The wrapper function for ImGui::ColorButton that takes a SnesColor reference
|
// The wrapper function for ImGui::ColorButton that takes a SnesColor reference
|
||||||
IMGUI_API bool SNESColorButton(absl::string_view id, SnesColor& color,
|
IMGUI_API bool SnesColorButton(absl::string_view id, SnesColor& color,
|
||||||
ImGuiColorEditFlags flags = 0,
|
ImGuiColorEditFlags flags = 0,
|
||||||
const ImVec2& size_arg = ImVec2(0, 0));
|
const ImVec2& size_arg = ImVec2(0, 0));
|
||||||
|
|
||||||
|
IMGUI_API bool SnesColorEdit4(absl::string_view label, SnesColor& color,
|
||||||
|
ImGuiColorEditFlags flags = 0);
|
||||||
|
|
||||||
void DisplayPalette(app::gfx::SnesPalette& palette, bool loaded);
|
void DisplayPalette(app::gfx::SnesPalette& palette, bool loaded);
|
||||||
|
|
||||||
} // namespace gui
|
} // namespace gui
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ void SelectablePalettePipeline(uint64_t& palette_id, bool& refresh_graphics,
|
|||||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 2.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 2.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gui::SNESColorButton("##palette", palette[n],
|
if (gui::SnesColorButton("##palette", palette[n],
|
||||||
ImGuiColorEditFlags_NoAlpha |
|
ImGuiColorEditFlags_NoAlpha |
|
||||||
ImGuiColorEditFlags_NoPicker |
|
ImGuiColorEditFlags_NoPicker |
|
||||||
ImGuiColorEditFlags_NoTooltip,
|
ImGuiColorEditFlags_NoTooltip,
|
||||||
|
|||||||
Reference in New Issue
Block a user