canvas and ow edit changes
This commit is contained in:
@@ -24,15 +24,15 @@ namespace editor {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void UpdateSelectedTile16(int selected, gfx::Bitmap &tile16_blockset,
|
void UpdateSelectedTile16(int selected, gfx::Bitmap &tile16_blockset,
|
||||||
gfx::Bitmap &selected_tile) {
|
Bytes &selected_tile) {
|
||||||
|
selected_tile.reserve(256);
|
||||||
auto blockset = tile16_blockset.GetData();
|
auto blockset = tile16_blockset.GetData();
|
||||||
auto bitmap = selected_tile.GetData();
|
|
||||||
|
|
||||||
int src_pos = ((selected - ((selected / 0x08) * 0x08)) * 0x10) +
|
int src_pos = ((selected - ((selected / 0x08) * 0x08)) * 0x10) +
|
||||||
((selected / 0x08) * 2048);
|
((selected / 0x08) * 2048);
|
||||||
for (int yy = 0; yy < 0x10; yy++) {
|
for (int yy = 0; yy < 0x10; yy++) {
|
||||||
for (int xx = 0; xx < 0x10; xx++) {
|
for (int xx = 0; xx < 0x10; xx++) {
|
||||||
bitmap[xx + (yy * 0x10)] = blockset[src_pos + xx + (yy * 0x80)];
|
selected_tile[xx + (yy * 0x10)] = blockset[src_pos + xx + (yy * 0x80)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,7 @@ absl::Status OverworldEditor::Update() {
|
|||||||
selected_tile_bmp_.Create(16, 16, 64, 256);
|
selected_tile_bmp_.Create(16, 16, 64, 256);
|
||||||
}
|
}
|
||||||
UpdateSelectedTile16(selected_tile_, tile16_blockset_bmp_,
|
UpdateSelectedTile16(selected_tile_, tile16_blockset_bmp_,
|
||||||
selected_tile_bmp_);
|
selected_tile_data_);
|
||||||
selected_tile_bmp_.ApplyPalette(palette_);
|
selected_tile_bmp_.ApplyPalette(palette_);
|
||||||
rom_.RenderBitmap(&selected_tile_bmp_);
|
rom_.RenderBitmap(&selected_tile_bmp_);
|
||||||
update_selected_tile_ = false;
|
update_selected_tile_ = false;
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ class OverworldEditor {
|
|||||||
gfx::Bitmap current_gfx_bmp_;
|
gfx::Bitmap current_gfx_bmp_;
|
||||||
gfx::Bitmap all_gfx_bmp;
|
gfx::Bitmap all_gfx_bmp;
|
||||||
gfx::Bitmap selected_tile_bmp_;
|
gfx::Bitmap selected_tile_bmp_;
|
||||||
|
Bytes selected_tile_data_;
|
||||||
|
|
||||||
gui::Canvas overworld_map_canvas_;
|
gui::Canvas overworld_map_canvas_;
|
||||||
gui::Canvas current_gfx_canvas_;
|
gui::Canvas current_gfx_canvas_;
|
||||||
|
|||||||
@@ -534,25 +534,26 @@ absl::StatusOr<Bytes> ROM::Decompress(int offset, int size, int mode) {
|
|||||||
|
|
||||||
if (mode == kNintendoMode1) { // Reversed byte order for overworld maps
|
if (mode == kNintendoMode1) { // Reversed byte order for overworld maps
|
||||||
// addr = (s2 | s1);
|
// addr = (s2 | s1);
|
||||||
addr = (rom_data_[offset + 1]) | ((rom_data_[offset]) << 8);
|
addr = (rom_data_[offset + 1] & kSnesByteMax) |
|
||||||
|
((rom_data_[offset] & kSnesByteMax) << 8);
|
||||||
|
if (addr > offset) {
|
||||||
|
return absl::InternalError(absl::StrFormat(
|
||||||
|
"DecompressOverworld: Offset for command copy exceeds "
|
||||||
|
"current position (Offset : %#04x | Pos : %#06x)\n",
|
||||||
|
addr, offset));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buffer_pos + length >= size) {
|
||||||
|
size *= 2;
|
||||||
|
buffer.resize(size);
|
||||||
|
}
|
||||||
|
|
||||||
memcpy(buffer.data() + buffer_pos, buffer.data() + addr, length);
|
memcpy(buffer.data() + buffer_pos, buffer.data() + addr, length);
|
||||||
buffer_pos += length;
|
buffer_pos += length;
|
||||||
offset += 2;
|
offset += 2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (addr > offset) {
|
|
||||||
return absl::InternalError(absl::StrFormat(
|
|
||||||
"DecompressOverworld: Offset for command copy exceeds "
|
|
||||||
"current position (Offset : %#04x | Pos : %#06x)\n",
|
|
||||||
addr, offset));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buffer_pos + length >= size) {
|
|
||||||
size *= 2;
|
|
||||||
buffer.resize(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
buffer[buffer_pos] = buffer[addr + i];
|
buffer[buffer_pos] = buffer[addr + i];
|
||||||
buffer_pos++;
|
buffer_pos++;
|
||||||
@@ -687,7 +688,7 @@ void ROM::RenderBitmap(gfx::Bitmap* bitmap) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gfx::SNESColor ROM::ReadColor(int offset) {
|
gfx::SNESColor ROM::ReadColor(int offset) {
|
||||||
short color = (short)((rom_data_[offset + 1] << 8) + rom_data_[offset]);
|
short color = toint16(offset);
|
||||||
gfx::snes_color new_color;
|
gfx::snes_color new_color;
|
||||||
new_color.red = (color & 0x1F) * 8;
|
new_color.red = (color & 0x1F) * 8;
|
||||||
new_color.green = ((color >> 5) & 0x1F) * 8;
|
new_color.green = ((color >> 5) & 0x1F) * 8;
|
||||||
@@ -701,7 +702,7 @@ gfx::SNESPalette ROM::ReadPalette(int offset, int num_colors) {
|
|||||||
std::vector<gfx::SNESColor> colors(num_colors);
|
std::vector<gfx::SNESColor> colors(num_colors);
|
||||||
|
|
||||||
while (color_offset < num_colors) {
|
while (color_offset < num_colors) {
|
||||||
short color = (short)((rom_data_[offset + 1] << 8) + rom_data_[offset]);
|
short color = toint16(offset);
|
||||||
gfx::snes_color new_color;
|
gfx::snes_color new_color;
|
||||||
new_color.red = (color & 0x1F) * 8;
|
new_color.red = (color & 0x1F) * 8;
|
||||||
new_color.green = ((color >> 5) & 0x1F) * 8;
|
new_color.green = ((color >> 5) & 0x1F) * 8;
|
||||||
@@ -783,31 +784,6 @@ void ROM::LoadAllPalettes() {
|
|||||||
palette_groups_["ow_mini_map"].AddPalette(
|
palette_groups_["ow_mini_map"].AddPalette(
|
||||||
ReadPalette(core::overworldMiniMapPalettes + (i * 256), 128));
|
ReadPalette(core::overworldMiniMapPalettes + (i * 256), 128));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: check for the paletts in the empty bank space that kan will allocate
|
|
||||||
// and read them in here
|
|
||||||
// TODO magic colors
|
|
||||||
// LW
|
|
||||||
// int j = 0;
|
|
||||||
// while (j < 64) {
|
|
||||||
// zelda3::overworld_BackgroundPalette[j++] =
|
|
||||||
// Color.FromArgb(0xFF, 0x48, 0x98, 0x48);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // DW
|
|
||||||
// while (j < 128) {
|
|
||||||
// zelda3::overworld_BackgroundPalette[j++] =
|
|
||||||
// Color.FromArgb(0xFF, 0x90, 0x88, 0x50);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // SP
|
|
||||||
// while (j < core::kNumOverworldMaps) {
|
|
||||||
// zelda3::overworld_BackgroundPalette[j++] =
|
|
||||||
// Color.FromArgb(0xFF, 0x48, 0x98, 0x48);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// zelda3::overworld_BackgroundPalette =
|
|
||||||
// ReadPalette(core::customAreaSpecificBGPalette, 160);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace app
|
} // namespace app
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "app/gfx/bitmap.h"
|
#include "app/gfx/bitmap.h"
|
||||||
|
#include "app/rom.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace gui {
|
namespace gui {
|
||||||
@@ -63,6 +64,10 @@ void Canvas::DrawContextMenu() {
|
|||||||
ImGui::OpenPopupOnItemClick("context", ImGuiPopupFlags_MouseButtonRight);
|
ImGui::OpenPopupOnItemClick("context", ImGuiPopupFlags_MouseButtonRight);
|
||||||
|
|
||||||
if (ImGui::BeginPopup("context")) {
|
if (ImGui::BeginPopup("context")) {
|
||||||
|
if (ImGui::MenuItem("Reset Position", nullptr, false)) {
|
||||||
|
scrolling_.x = 0;
|
||||||
|
scrolling_.y = 0;
|
||||||
|
}
|
||||||
if (ImGui::MenuItem("Remove all", nullptr, false, points_.Size > 0)) {
|
if (ImGui::MenuItem("Remove all", nullptr, false, points_.Size > 0)) {
|
||||||
points_.clear();
|
points_.clear();
|
||||||
}
|
}
|
||||||
@@ -70,6 +75,27 @@ void Canvas::DrawContextMenu() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Canvas::DrawTilesFromUser(app::ROM &rom, Bytes &tile,
|
||||||
|
app::gfx::SNESPalette &pal) {
|
||||||
|
ImVec2 draw_tile_outline_pos;
|
||||||
|
|
||||||
|
// Add rectangle
|
||||||
|
if (is_hovered_ && ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
|
||||||
|
draw_tile_outline_pos.x =
|
||||||
|
std::round((double)mouse_pos_in_canvas_.x / 16) * 16;
|
||||||
|
draw_tile_outline_pos.y =
|
||||||
|
std::round((double)mouse_pos_in_canvas_.y / 16) * 16;
|
||||||
|
|
||||||
|
points_.push_back(draw_tile_outline_pos);
|
||||||
|
points_.push_back(
|
||||||
|
ImVec2(draw_tile_outline_pos.x + 16, draw_tile_outline_pos.y + 16));
|
||||||
|
|
||||||
|
changed_tiles_.emplace_back(app::gfx::Bitmap(16, 16, 64, tile.data()));
|
||||||
|
changed_tiles_.back().ApplyPalette(pal);
|
||||||
|
rom.RenderBitmap(&(changed_tiles_.back()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Canvas::DrawBitmap(const Bitmap &bitmap, int border_offset) {
|
void Canvas::DrawBitmap(const Bitmap &bitmap, int border_offset) {
|
||||||
draw_list_->AddImage(
|
draw_list_->AddImage(
|
||||||
(void *)bitmap.GetTexture(),
|
(void *)bitmap.GetTexture(),
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "app/gfx/bitmap.h"
|
#include "app/gfx/bitmap.h"
|
||||||
|
#include "app/rom.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace gui {
|
namespace gui {
|
||||||
@@ -21,6 +22,8 @@ class Canvas {
|
|||||||
|
|
||||||
void DrawBackground(ImVec2 canvas_size = ImVec2(0, 0));
|
void DrawBackground(ImVec2 canvas_size = ImVec2(0, 0));
|
||||||
void DrawContextMenu();
|
void DrawContextMenu();
|
||||||
|
void DrawTilesFromUser(app::ROM& rom, Bytes& tile,
|
||||||
|
app::gfx::SNESPalette& pal);
|
||||||
void DrawBitmap(const Bitmap& bitmap, int border_offset = 0);
|
void DrawBitmap(const Bitmap& bitmap, int border_offset = 0);
|
||||||
void DrawBitmap(const Bitmap& bitmap, int x_offset, int y_offset);
|
void DrawBitmap(const Bitmap& bitmap, int x_offset, int y_offset);
|
||||||
void DrawOutline(int x, int y, int w, int h);
|
void DrawOutline(int x, int y, int w, int h);
|
||||||
@@ -39,6 +42,7 @@ class Canvas {
|
|||||||
bool enable_grid_ = true;
|
bool enable_grid_ = true;
|
||||||
bool enable_context_menu_ = true;
|
bool enable_context_menu_ = true;
|
||||||
bool custom_canvas_size_ = false;
|
bool custom_canvas_size_ = false;
|
||||||
|
bool is_hovered_ = false;
|
||||||
|
|
||||||
ImDrawList* draw_list_;
|
ImDrawList* draw_list_;
|
||||||
ImVector<ImVec2> points_;
|
ImVector<ImVec2> points_;
|
||||||
@@ -46,6 +50,9 @@ class Canvas {
|
|||||||
ImVec2 canvas_sz_;
|
ImVec2 canvas_sz_;
|
||||||
ImVec2 canvas_p0_;
|
ImVec2 canvas_p0_;
|
||||||
ImVec2 canvas_p1_;
|
ImVec2 canvas_p1_;
|
||||||
|
ImVec2 mouse_pos_in_canvas_;
|
||||||
|
|
||||||
|
std::vector<app::gfx::Bitmap> changed_tiles_;
|
||||||
|
|
||||||
std::string title_;
|
std::string title_;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user