Canvas, Palettes, Bitmap updates
This commit is contained in:
@@ -285,15 +285,15 @@ void DungeonEditor::DrawRoomGraphics() {
|
||||
int current_block = 0;
|
||||
for (int block : blocks) {
|
||||
int offset = height * (current_block + 1);
|
||||
int top_left_y = room_gfx_canvas_.GetZeroPoint().y + 2;
|
||||
int top_left_y = room_gfx_canvas_.zero_point().y + 2;
|
||||
if (current_block >= 1) {
|
||||
top_left_y = room_gfx_canvas_.GetZeroPoint().y + height * current_block;
|
||||
top_left_y = room_gfx_canvas_.zero_point().y + height * current_block;
|
||||
}
|
||||
room_gfx_canvas_.GetDrawList()->AddImage(
|
||||
(void*)graphics_bin_[block].texture(),
|
||||
ImVec2(room_gfx_canvas_.GetZeroPoint().x + 2, top_left_y),
|
||||
ImVec2(room_gfx_canvas_.GetZeroPoint().x + 0x100,
|
||||
room_gfx_canvas_.GetZeroPoint().y + offset));
|
||||
ImVec2(room_gfx_canvas_.zero_point().x + 2, top_left_y),
|
||||
ImVec2(room_gfx_canvas_.zero_point().x + 0x100,
|
||||
room_gfx_canvas_.zero_point().y + offset));
|
||||
current_block += 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,13 +142,21 @@ void GraphicsEditor::DrawGfxEditToolset() {
|
||||
}
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::ColorEdit4("Palette Color", (float*)¤t_color_,
|
||||
ImGuiColorEditFlags_NoInputs |
|
||||
ImGuiColorEditFlags_NoLabel |
|
||||
ImGuiColorEditFlags_NoAlpha);
|
||||
auto bitmap = rom()->bitmap_manager()[current_sheet_];
|
||||
auto palette = bitmap->palette();
|
||||
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);
|
||||
if (ImGui::ColorButton(absl::StrFormat("Palette Color %d", i).c_str(),
|
||||
color)) {
|
||||
current_color_ = color;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
gui::InputHexByte("Tile Size", &tile_size_, 0x02);
|
||||
gui::InputHexByte("Tile Size", &tile_size_, 0x01);
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
@@ -170,11 +178,11 @@ absl::Status GraphicsEditor::UpdateGfxSheetList() {
|
||||
auto texture = value.get()->texture();
|
||||
graphics_bin_canvas_.GetDrawList()->AddImage(
|
||||
(void*)texture,
|
||||
ImVec2(graphics_bin_canvas_.GetZeroPoint().x + 2,
|
||||
graphics_bin_canvas_.GetZeroPoint().y + 2),
|
||||
ImVec2(graphics_bin_canvas_.GetZeroPoint().x +
|
||||
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_.GetZeroPoint().y +
|
||||
graphics_bin_canvas_.zero_point().y +
|
||||
value.get()->height() * sheet_scale_));
|
||||
|
||||
if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) {
|
||||
@@ -183,8 +191,8 @@ absl::Status GraphicsEditor::UpdateGfxSheetList() {
|
||||
}
|
||||
|
||||
// Add a slightly transparent rectangle behind the text
|
||||
ImVec2 text_pos(graphics_bin_canvas_.GetZeroPoint().x + 2,
|
||||
graphics_bin_canvas_.GetZeroPoint().y + 2);
|
||||
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);
|
||||
@@ -220,11 +228,10 @@ absl::Status GraphicsEditor::UpdateGfxTabView() {
|
||||
}
|
||||
|
||||
for (auto& sheet_id : open_sheets_) {
|
||||
current_sheet_ = sheet_id;
|
||||
|
||||
bool open = true;
|
||||
if (ImGui::BeginTabItem(absl::StrFormat("%d", sheet_id).c_str(), &open,
|
||||
ImGuiTabItemFlags_None)) {
|
||||
current_sheet_ = sheet_id;
|
||||
if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
|
||||
release_queue_.push(sheet_id);
|
||||
}
|
||||
@@ -243,18 +250,17 @@ absl::Status GraphicsEditor::UpdateGfxTabView() {
|
||||
ImGuiWindowFlags_AlwaysHorizontalScrollbar);
|
||||
|
||||
auto draw_tile_event = [&]() {
|
||||
uint16_t snes_color = gfx::ConvertRGBtoSNES(current_color_);
|
||||
auto click_position = current_sheet_canvas_.drawn_tile_position();
|
||||
gfx::Bitmap& current_bitmap = *rom()->bitmap_manager()[sheet_id];
|
||||
current_sheet_canvas_.DrawTileOnBitmap(click_position, tile_size_,
|
||||
current_bitmap, snes_color);
|
||||
auto& bitmap = *rom()->bitmap_manager().mutable_bitmap(sheet_id);
|
||||
rom()->UpdateBitmap(&bitmap);
|
||||
gfx::Bitmap& current_bitmap =
|
||||
*rom()->mutable_bitmap_manager()->mutable_bitmap(sheet_id);
|
||||
current_sheet_canvas_.DrawTileOnBitmap(tile_size_, current_bitmap,
|
||||
current_color_);
|
||||
rom()->UpdateBitmap(¤t_bitmap);
|
||||
};
|
||||
|
||||
auto size = ImVec2(0x80, 0x20);
|
||||
current_sheet_canvas_.UpdateColorPainter(
|
||||
*rom()->bitmap_manager()[sheet_id], current_color_, draw_tile_event,
|
||||
ImVec2(0x100, 0x40), tile_size_, current_scale_, 8.0f);
|
||||
size, tile_size_, current_scale_, 8.0f);
|
||||
ImGui::EndChild();
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ class GraphicsEditor : public SharedROM {
|
||||
// Member Variables
|
||||
ImVec4 current_color_;
|
||||
uint16_t current_sheet_ = 0;
|
||||
uint8_t tile_size_ = 0x08;
|
||||
uint8_t tile_size_ = 0x01;
|
||||
std::set<uint16_t> open_sheets_;
|
||||
std::set<uint16_t> child_window_sheets_;
|
||||
std::stack<uint16_t> release_queue_;
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace yaze {
|
||||
namespace app {
|
||||
namespace editor {
|
||||
|
||||
using ImGui::Button;
|
||||
using ImGui::Separator;
|
||||
using ImGui::TableHeadersRow;
|
||||
using ImGui::TableNextColumn;
|
||||
@@ -93,10 +94,19 @@ absl::Status OverworldEditor::DrawToolset() {
|
||||
status_ = Redo();
|
||||
}
|
||||
|
||||
TEXT_COLUMN(ICON_MD_MORE_VERT) // Separator
|
||||
BUTTON_COLUMN(ICON_MD_ZOOM_OUT) // Zoom Out
|
||||
BUTTON_COLUMN(ICON_MD_ZOOM_IN) // Zoom In
|
||||
TEXT_COLUMN(ICON_MD_MORE_VERT) // Separator
|
||||
TEXT_COLUMN(ICON_MD_MORE_VERT) // Separator
|
||||
|
||||
NEXT_COLUMN()
|
||||
if (ImGui::Button(ICON_MD_ZOOM_OUT)) {
|
||||
ow_map_canvas_.ZoomOut();
|
||||
}
|
||||
|
||||
NEXT_COLUMN()
|
||||
if (ImGui::Button(ICON_MD_ZOOM_IN)) {
|
||||
ow_map_canvas_.ZoomIn();
|
||||
}
|
||||
|
||||
TEXT_COLUMN(ICON_MD_MORE_VERT) // Separator
|
||||
|
||||
NEXT_COLUMN()
|
||||
if (ImGui::Button(ICON_MD_DRAW)) {
|
||||
@@ -288,24 +298,6 @@ bool OverworldEditor::IsMouseHoveringOverEntrance(
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void OverworldEditor::DrawOverworldMaps() {
|
||||
int xx = 0;
|
||||
int yy = 0;
|
||||
for (int i = 0; i < 0x40; i++) {
|
||||
int world_index = i + (current_world_ * 0x40);
|
||||
int map_x = (xx * 0x200);
|
||||
int map_y = (yy * 0x200);
|
||||
ow_map_canvas_.DrawBitmap(maps_bmp_[world_index], map_x, map_y);
|
||||
xx++;
|
||||
if (xx >= 8) {
|
||||
yy++;
|
||||
xx = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void OverworldEditor::DrawOverworldSprites() {
|
||||
for (const auto &sprite : overworld_.Sprites(game_state_)) {
|
||||
// Get the sprite's bitmap and real X and Y positions
|
||||
@@ -325,12 +317,28 @@ void OverworldEditor::DrawOverworldSprites() {
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void OverworldEditor::DrawOverworldMaps() {
|
||||
int xx = 0;
|
||||
int yy = 0;
|
||||
for (int i = 0; i < 0x40; i++) {
|
||||
int world_index = i + (current_world_ * 0x40);
|
||||
int map_x = (xx * 0x200 * ow_map_canvas_.global_scale());
|
||||
int map_y = (yy * 0x200 * ow_map_canvas_.global_scale());
|
||||
ow_map_canvas_.DrawBitmap(maps_bmp_[world_index], map_x, map_y,
|
||||
ow_map_canvas_.global_scale());
|
||||
xx++;
|
||||
if (xx >= 8) {
|
||||
yy++;
|
||||
xx = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OverworldEditor::DrawOverworldEdits() {
|
||||
auto mouse_position = ow_map_canvas_.drawn_tile_position();
|
||||
auto canvas_size = ow_map_canvas_.GetCanvasSize();
|
||||
auto canvas_size = ow_map_canvas_.canvas_size();
|
||||
int x = mouse_position.x / canvas_size.x;
|
||||
int y = mouse_position.y / canvas_size.y;
|
||||
auto index = x + (y * 8);
|
||||
|
||||
// Determine which overworld map the user is currently editing.
|
||||
DetermineActiveMap(mouse_position);
|
||||
@@ -338,9 +346,6 @@ void OverworldEditor::DrawOverworldEdits() {
|
||||
// Render the updated map bitmap.
|
||||
RenderUpdatedMapBitmap(mouse_position,
|
||||
tile16_individual_data_[current_tile16_]);
|
||||
|
||||
// Queue up the raw ROM changes.
|
||||
QueueROMChanges(index, current_tile16_);
|
||||
}
|
||||
|
||||
void OverworldEditor::DetermineActiveMap(const ImVec2 &mouse_position) {
|
||||
@@ -385,7 +390,7 @@ void OverworldEditor::RenderUpdatedMapBitmap(const ImVec2 &click_position,
|
||||
rom()->UpdateBitmap(¤t_bitmap);
|
||||
}
|
||||
|
||||
void OverworldEditor::QueueROMChanges(int index, ushort new_tile16) {
|
||||
void OverworldEditor::SaveOverworldChanges() {
|
||||
// Store the changes made by the user to the ROM (or project file)
|
||||
rom()->QueueChanges([&]() {
|
||||
PRINT_IF_ERROR(overworld_.SaveOverworldMaps());
|
||||
@@ -398,8 +403,6 @@ void OverworldEditor::QueueROMChanges(int index, ushort new_tile16) {
|
||||
});
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void OverworldEditor::CheckForOverworldEdits() {
|
||||
if (!blockset_canvas_.Points().empty()) {
|
||||
// User has selected a tile they want to draw from the blockset.
|
||||
@@ -471,10 +474,11 @@ void OverworldEditor::DrawOverworldCanvas() {
|
||||
ImGuiWindowFlags_AlwaysVerticalScrollbar |
|
||||
ImGuiWindowFlags_AlwaysHorizontalScrollbar)) {
|
||||
ow_map_canvas_.DrawBackground(ImVec2(0x200 * 8, 0x200 * 8));
|
||||
ImGui::PopStyleVar(2);
|
||||
ow_map_canvas_.DrawContextMenu();
|
||||
if (overworld_.isLoaded()) {
|
||||
DrawOverworldMaps();
|
||||
DrawOverworldEntrances(ow_map_canvas_.GetZeroPoint(),
|
||||
DrawOverworldEntrances(ow_map_canvas_.zero_point(),
|
||||
ow_map_canvas_.Scrolling());
|
||||
if (flags()->kDrawOverworldSprites) {
|
||||
DrawOverworldSprites();
|
||||
@@ -486,11 +490,8 @@ void OverworldEditor::DrawOverworldCanvas() {
|
||||
ow_map_canvas_.DrawOverlay();
|
||||
}
|
||||
ImGui::EndChild();
|
||||
ImGui::PopStyleVar(2);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Tile 8 Selector
|
||||
// Displays all the individual tiles that make up a tile16.
|
||||
void OverworldEditor::DrawTile8Selector() {
|
||||
@@ -501,24 +502,22 @@ void OverworldEditor::DrawTile8Selector() {
|
||||
// for (const auto &[key, value] : graphics_bin_) {
|
||||
for (auto &[key, value] : rom()->bitmap_manager()) {
|
||||
int offset = 0x40 * (key + 1);
|
||||
int top_left_y = graphics_bin_canvas_.GetZeroPoint().y + 2;
|
||||
int top_left_y = graphics_bin_canvas_.zero_point().y + 2;
|
||||
if (key >= 1) {
|
||||
top_left_y = graphics_bin_canvas_.GetZeroPoint().y + 0x40 * key;
|
||||
top_left_y = graphics_bin_canvas_.zero_point().y + 0x40 * key;
|
||||
}
|
||||
auto texture = value.get()->texture();
|
||||
graphics_bin_canvas_.GetDrawList()->AddImage(
|
||||
(void *)texture,
|
||||
ImVec2(graphics_bin_canvas_.GetZeroPoint().x + 2, top_left_y),
|
||||
ImVec2(graphics_bin_canvas_.GetZeroPoint().x + 0x100,
|
||||
graphics_bin_canvas_.GetZeroPoint().y + offset));
|
||||
ImVec2(graphics_bin_canvas_.zero_point().x + 2, top_left_y),
|
||||
ImVec2(graphics_bin_canvas_.zero_point().x + 0x100,
|
||||
graphics_bin_canvas_.zero_point().y + offset));
|
||||
}
|
||||
}
|
||||
graphics_bin_canvas_.DrawGrid(16.0f);
|
||||
graphics_bin_canvas_.DrawOverlay();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void OverworldEditor::DrawTileSelector() {
|
||||
if (ImGui::BeginTabBar(kTileSelectorTab.data(),
|
||||
ImGuiTabBarFlags_FittingPolicyScroll)) {
|
||||
|
||||
@@ -98,7 +98,7 @@ class OverworldEditor : public Editor,
|
||||
void DrawOverworldEdits();
|
||||
void RenderUpdatedMapBitmap(const ImVec2 &click_position,
|
||||
const Bytes &tile_data);
|
||||
void QueueROMChanges(int index, ushort new_tile16);
|
||||
void SaveOverworldChanges();
|
||||
void DetermineActiveMap(const ImVec2 &mouse_position);
|
||||
|
||||
void CheckForOverworldEdits();
|
||||
@@ -109,7 +109,6 @@ class OverworldEditor : public Editor,
|
||||
void DrawTileSelector();
|
||||
|
||||
absl::Status LoadSpriteGraphics();
|
||||
|
||||
absl::Status DrawExperimentalModal();
|
||||
|
||||
enum class EditingMode {
|
||||
|
||||
Reference in New Issue
Block a user