Update referenes to SnesColor members

This commit is contained in:
scawful
2024-01-31 23:58:35 -05:00
parent 7784e17768
commit 14e60b248f
10 changed files with 111 additions and 84 deletions

View File

@@ -49,7 +49,7 @@ absl::Status DungeonEditor::Update() {
int pId = paletteid / 180;
auto color = rom()->palette_group("dungeon_main")[pId][3];
room_palette_[rooms_[i].palette] = color.GetRGB();
room_palette_[rooms_[i].palette] = color.rgb();
}
std::map<int, std::vector<int>> roomsByBank;
@@ -96,8 +96,11 @@ absl::Status DungeonEditor::Update() {
graphics_bin_ = rom()->graphics_bin();
full_palette_ =
rom()->palette_group("dungeon_main")[current_palette_group_id_];
current_palette_group_ =
auto current_palette_group_status =
gfx::CreatePaletteGroupFromLargePalette(full_palette_);
if (current_palette_group_status.ok()) {
current_palette_group_ = current_palette_group_status.value();
}
// Create a vector of pointers to the current block bitmaps
for (int block : rooms_[current_room_id_].blocks()) {

View File

@@ -151,8 +151,8 @@ void GraphicsEditor::DrawGfxEditToolset() {
for (int i = 0; i < 8; i++) {
ImGui::SameLine();
auto color =
ImVec4(palette[i].GetRGB().x / 255.0f, palette[i].GetRGB().y / 255.0f,
palette[i].GetRGB().z / 255.0f, 255.0f);
ImVec4(palette[i].rgb().x / 255.0f, palette[i].rgb().y / 255.0f,
palette[i].rgb().z / 255.0f, 255.0f);
if (ImGui::ColorButton(absl::StrFormat("Palette Color %d", i).c_str(),
color)) {
current_color_ = color;
@@ -177,43 +177,48 @@ absl::Status GraphicsEditor::UpdateGfxSheetList() {
ImGuiWindowFlags_NoDecoration);
ImGui::PopStyleVar();
gui::Canvas graphics_bin_canvas_;
auto select_tile_event = [&]() {
if (value.get()->is_active()) {
auto texture = value.get()->texture();
graphics_bin_canvas_.draw_list()->AddImage(
(void*)texture,
ImVec2(graphics_bin_canvas_.zero_point().x + 2,
graphics_bin_canvas_.zero_point().y + 2),
ImVec2(graphics_bin_canvas_.zero_point().x +
value.get()->width() * sheet_scale_,
graphics_bin_canvas_.zero_point().y +
value.get()->height() * sheet_scale_));
// auto select_tile_event = [&]() {
// };
// graphics_bin_canvas_.UpdateEvent(
// select_tile_event, ImVec2(0x100 + 1, 0x40 + 1), 0x20, sheet_scale_,
// /*grid_size=*/16.0f);
if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) {
current_sheet_ = key;
open_sheets_.insert(key);
}
graphics_bin_canvas_.DrawBackground(ImVec2(0x100 + 1, 0x40 + 1));
graphics_bin_canvas_.DrawContextMenu();
if (value.get()->is_active()) {
auto texture = value.get()->texture();
graphics_bin_canvas_.draw_list()->AddImage(
(void*)texture,
ImVec2(graphics_bin_canvas_.zero_point().x + 2,
graphics_bin_canvas_.zero_point().y + 2),
ImVec2(graphics_bin_canvas_.zero_point().x +
value.get()->width() * sheet_scale_,
graphics_bin_canvas_.zero_point().y +
value.get()->height() * sheet_scale_));
// Add a slightly transparent rectangle behind the text
ImVec2 text_pos(graphics_bin_canvas_.zero_point().x + 2,
graphics_bin_canvas_.zero_point().y + 2);
ImVec2 text_size =
ImGui::CalcTextSize(absl::StrFormat("%02X", key).c_str());
ImVec2 rent_min(text_pos.x, text_pos.y);
ImVec2 rent_max(text_pos.x + text_size.x, text_pos.y + text_size.y);
graphics_bin_canvas_.draw_list()->AddRectFilled(
rent_min, rent_max, IM_COL32(0, 125, 0, 128));
graphics_bin_canvas_.draw_list()->AddText(
text_pos, IM_COL32(125, 255, 125, 255),
absl::StrFormat("%02X", key).c_str());
if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) {
current_sheet_ = key;
open_sheets_.insert(key);
}
};
graphics_bin_canvas_.UpdateEvent(
select_tile_event, ImVec2(0x100 + 1, 0x40 + 1), 0x20, sheet_scale_,
/*grid_size=*/16.0f);
// Add a slightly transparent rectangle behind the text
ImVec2 text_pos(graphics_bin_canvas_.zero_point().x + 2,
graphics_bin_canvas_.zero_point().y + 2);
ImVec2 text_size =
ImGui::CalcTextSize(absl::StrFormat("%02X", key).c_str());
ImVec2 rent_min(text_pos.x, text_pos.y);
ImVec2 rent_max(text_pos.x + text_size.x, text_pos.y + text_size.y);
graphics_bin_canvas_.draw_list()->AddRectFilled(rent_min, rent_max,
IM_COL32(0, 125, 0, 128));
graphics_bin_canvas_.draw_list()->AddText(
text_pos, IM_COL32(125, 255, 125, 255),
absl::StrFormat("%02X", key).c_str());
}
graphics_bin_canvas_.DrawGrid(16.0f);
graphics_bin_canvas_.DrawOverlay();
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
ImGui::EndChild();
}
@@ -257,16 +262,15 @@ absl::Status GraphicsEditor::UpdateGfxTabView() {
*rom()->mutable_bitmap_manager()->mutable_bitmap(sheet_id);
auto draw_tile_event = [&]() {
current_sheet_canvas_.DrawTileOnBitmap(tile_size_, current_bitmap,
current_sheet_canvas_.DrawTileOnBitmap(tile_size_, &current_bitmap,
current_color_);
rom()->UpdateBitmap(&current_bitmap);
rom()->UpdateBitmap(&current_bitmap, true);
};
current_sheet_canvas_.UpdateColorPainter(
*rom()->bitmap_manager()[sheet_id], current_color_, draw_tile_event,
tile_size_, current_scale_);
ImGui::EndChild();
ImGui::EndTabItem();
}
@@ -539,7 +543,11 @@ absl::Status GraphicsEditor::DrawPaletteControls() {
if (col_file_palette_group_.size() != 0) {
col_file_palette_group_.Clear();
}
col_file_palette_group_ = gfx::CreatePaletteGroupFromColFile(col_data_);
auto col_file_palette_group_status =
gfx::CreatePaletteGroupFromColFile(col_data_);
if (col_file_palette_group_status.ok()) {
col_file_palette_group_ = col_file_palette_group_status.value();
}
col_file_palette_ = gfx::SnesPalette(col_data_);
// gigaleak dev format based code

View File

@@ -71,7 +71,7 @@ void PaletteEditor::EditColorInPalette(gfx::SnesPalette& palette, int index) {
}
// Get the current color
auto currentColor = palette.GetColor(index).GetRGB();
auto currentColor = palette.GetColor(index).rgb();
if (ImGui::ColorPicker4("Color Picker", (float*)&palette[index])) {
// The color was modified, update it in the palette
palette(index, currentColor);
@@ -86,7 +86,7 @@ void PaletteEditor::ResetColorToOriginal(
return;
}
auto originalColor = originalPalette.GetColor(index).GetRGB();
auto originalColor = originalPalette.GetColor(index).rgb();
palette(index, originalColor);
}

View File

@@ -92,9 +92,9 @@ class PaletteEditor : public SharedROM {
void InitializeSavedPalette(const gfx::SnesPalette& palette) {
for (int n = 0; n < palette.size(); n++) {
saved_palette_[n].x = palette.GetColor(n).GetRGB().x / 255;
saved_palette_[n].y = palette.GetColor(n).GetRGB().y / 255;
saved_palette_[n].z = palette.GetColor(n).GetRGB().z / 255;
saved_palette_[n].x = palette.GetColor(n).rgb().x / 255;
saved_palette_[n].y = palette.GetColor(n).rgb().y / 255;
saved_palette_[n].z = palette.GetColor(n).rgb().z / 255;
saved_palette_[n].w = 255; // Alpha
}
}

View File

@@ -11,6 +11,7 @@
#include "absl/strings/str_format.h"
#include "app/core/common.h"
#include "app/core/constants.h"
#include "app/core/platform/clipboard.h"
#include "app/editor/modules/palette_editor.h"
#include "app/gfx/bitmap.h"
#include "app/gfx/snes_palette.h"
@@ -125,7 +126,7 @@ absl::Status OverworldEditor::DrawToolset() {
static bool show_gfx_group = false;
static bool show_properties = false;
if (BeginTable("OWToolset", 22, kToolsetTableFlags, ImVec2(0, 0))) {
if (BeginTable("OWToolset", 23, kToolsetTableFlags, ImVec2(0, 0))) {
for (const auto &name : kToolsetColumnNames)
ImGui::TableSetupColumn(name.data());
@@ -229,6 +230,19 @@ absl::Status OverworldEditor::DrawToolset() {
TEXT_COLUMN(ICON_MD_MORE_VERT) // Separator
TableNextColumn();
if (Button(ICON_MD_CONTENT_COPY)) {
std::vector<uint8_t> png_data;
if (gfx::ConvertSurfaceToPNG(maps_bmp_[current_map_].surface(),
png_data)) {
CopyImageToClipboard(png_data);
} else {
status_ = absl::InternalError(
"Failed to convert overworld map surface to PNG");
}
}
HOVER_HINT("Copy Map to Clipboard");
TableNextColumn(); // Palette
palette_editor_.DisplayPalette(palette_, overworld_.is_loaded());