Canvas Gui and styling improvements, helper fns

This commit is contained in:
scawful
2024-01-23 10:14:52 -05:00
parent db51acd12a
commit d183f1d784
8 changed files with 113 additions and 53 deletions

View File

@@ -375,7 +375,7 @@ void DungeonEditor::DrawRoomGraphics() {
if (current_block >= 1) {
top_left_y = room_gfx_canvas_.zero_point().y + height * current_block;
}
room_gfx_canvas_.GetDrawList()->AddImage(
room_gfx_canvas_.draw_list()->AddImage(
(void*)graphics_bin_[block].texture(),
ImVec2(room_gfx_canvas_.zero_point().x + 2, top_left_y),
ImVec2(room_gfx_canvas_.zero_point().x + 0x100,

View File

@@ -180,7 +180,7 @@ absl::Status GraphicsEditor::UpdateGfxSheetList() {
auto select_tile_event = [&]() {
if (value.get()->is_active()) {
auto texture = value.get()->texture();
graphics_bin_canvas_.GetDrawList()->AddImage(
graphics_bin_canvas_.draw_list()->AddImage(
(void*)texture,
ImVec2(graphics_bin_canvas_.zero_point().x + 2,
graphics_bin_canvas_.zero_point().y + 2),
@@ -202,10 +202,10 @@ absl::Status GraphicsEditor::UpdateGfxSheetList() {
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_.GetDrawList()->AddRectFilled(
graphics_bin_canvas_.draw_list()->AddRectFilled(
rent_min, rent_max, IM_COL32(0, 125, 0, 128));
graphics_bin_canvas_.GetDrawList()->AddText(
graphics_bin_canvas_.draw_list()->AddText(
text_pos, IM_COL32(125, 255, 125, 255),
absl::StrFormat("%02X", key).c_str());
}
@@ -261,10 +261,9 @@ absl::Status GraphicsEditor::UpdateGfxTabView() {
rom()->UpdateBitmap(&current_bitmap);
};
auto size = ImVec2(0x80, 0x20);
current_sheet_canvas_.UpdateColorPainter(
*rom()->bitmap_manager()[sheet_id], current_color_, draw_tile_event,
size, tile_size_, current_scale_, 8.0f);
tile_size_, current_scale_);
ImGui::EndChild();
ImGui::EndTabItem();
}
@@ -293,12 +292,13 @@ absl::Status GraphicsEditor::UpdateGfxTabView() {
ImGui::Begin(absl::StrFormat("##GfxEditPaletteChildWindow%d", id).c_str(),
&active, ImGuiWindowFlags_AlwaysUseWindowPadding);
current_sheet_ = id;
// ImVec2(0x100, 0x40),
current_sheet_canvas_.UpdateColorPainter(
*rom()->bitmap_manager()[id], current_color_,
[&]() {
},
ImVec2(0x100, 0x40), tile_size_, current_scale_, 8.0f);
tile_size_, current_scale_);
ImGui::End();
if (active == false) {

View File

@@ -182,7 +182,8 @@ class GraphicsEditor : public SharedROM {
gui::Canvas import_canvas_;
gui::Canvas scr_canvas_;
gui::Canvas super_donkey_canvas_;
gui::Canvas current_sheet_canvas_;
gui::Canvas current_sheet_canvas_{ImVec2(0x80, 0x20),
gui::CanvasGridSize::k8x8};
absl::Status status_;
};

View File

@@ -751,41 +751,47 @@ void OverworldEditor::DrawOverworldCanvas() {
DrawOverworldMapSettings();
Separator();
}
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
if (ImGuiID child_id = ImGui::GetID((void *)(intptr_t)7);
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
ImGuiWindowFlags_AlwaysVerticalScrollbar |
ImGuiWindowFlags_AlwaysHorizontalScrollbar)) {
ow_map_canvas_.DrawBackground(ImVec2(0x200 * 8, 0x200 * 8));
ImGui::PopStyleVar(2);
ow_map_canvas_.DrawContextMenu();
if (overworld_.is_loaded()) {
DrawOverworldMaps();
DrawOverworldEntrances(ow_map_canvas_.zero_point(),
ow_map_canvas_.Scrolling());
DrawOverworldExits(ow_map_canvas_.zero_point(),
ow_map_canvas_.Scrolling());
if (flags()->kDrawOverworldSprites) {
DrawOverworldSprites();
}
CheckForCurrentMap();
CheckForOverworldEdits();
gui::BeginNoPadding();
gui::BeginChildBothScrollbars(7);
ow_map_canvas_.DrawBackground();
gui::EndNoPadding();
ow_map_canvas_.DrawContextMenu();
if (overworld_.is_loaded()) {
DrawOverworldMaps();
DrawOverworldEntrances(ow_map_canvas_.zero_point(),
ow_map_canvas_.scrolling());
DrawOverworldExits(ow_map_canvas_.zero_point(), ow_map_canvas_.scrolling());
if (flags()->kDrawOverworldSprites) {
DrawOverworldSprites();
}
ow_map_canvas_.DrawGrid(64.0f);
ow_map_canvas_.DrawOverlay();
// CheckForCurrentMap(); Performance Bottleneck
CheckForOverworldEdits();
}
ow_map_canvas_.DrawGrid();
ow_map_canvas_.DrawOverlay();
ImGui::EndChild();
}
void OverworldEditor::DrawTile16Selector() {
gui::BeginPadding(3);
gui::BeginChildWithScrollbar(/*id=*/1);
blockset_canvas_.DrawBackground();
gui::EndNoPadding();
blockset_canvas_.DrawContextMenu();
blockset_canvas_.DrawBitmap(tile16_blockset_bmp_, /*border_offset=*/2,
map_blockset_loaded_);
blockset_canvas_.DrawTileSelector(32.0f);
blockset_canvas_.DrawGrid();
blockset_canvas_.DrawOverlay();
ImGui::EndChild();
}
// Tile 8 Selector
// Displays all the individual tiles that make up a tile16.
void OverworldEditor::DrawTile8Selector() {
graphics_bin_canvas_.DrawBackground(
ImVec2(0x100 + 1, kNumSheetsToLoad * 0x40 + 1));
graphics_bin_canvas_.DrawBackground();
graphics_bin_canvas_.DrawContextMenu();
if (all_gfx_loaded_) {
// 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_.zero_point().y + 2;
@@ -793,38 +799,48 @@ void OverworldEditor::DrawTile8Selector() {
top_left_y = graphics_bin_canvas_.zero_point().y + 0x40 * key;
}
auto texture = value.get()->texture();
graphics_bin_canvas_.GetDrawList()->AddImage(
graphics_bin_canvas_.draw_list()->AddImage(
(void *)texture,
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_.DrawGrid();
graphics_bin_canvas_.DrawOverlay();
}
void OverworldEditor::DrawAreaGraphics() {
gui::BeginPadding(3);
gui::BeginChildWithScrollbar(/*id=*/2);
current_gfx_canvas_.DrawBackground();
gui::EndPadding();
current_gfx_canvas_.DrawContextMenu();
current_gfx_canvas_.DrawBitmap(current_gfx_bmp_, /*border_offset=*/2,
overworld_.is_loaded());
current_gfx_canvas_.DrawTileSelector(32.0f);
current_gfx_canvas_.DrawGrid();
current_gfx_canvas_.DrawOverlay();
ImGui::EndChild();
}
void OverworldEditor::DrawTileSelector() {
if (BeginTabBar(kTileSelectorTab.data(),
ImGuiTabBarFlags_FittingPolicyScroll)) {
if (BeginTabItem("Tile16")) {
gui::BitmapCanvasPipeline(blockset_canvas_, tile16_blockset_bmp_, 0x100,
(8192 * 2), 0x20, map_blockset_loaded_, true,
1);
DrawTile16Selector();
EndTabItem();
}
if (BeginTabItem("Tile8")) {
if (ImGui::BeginChild("##tile8viewer", ImGui::GetContentRegionAvail(),
true, ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
DrawTile8Selector();
}
gui::BeginPadding(3);
gui::BeginChildWithScrollbar(/*id=*/2);
DrawTile8Selector();
ImGui::EndChild();
gui::EndNoPadding();
EndTabItem();
}
if (BeginTabItem("Area Graphics")) {
gui::BitmapCanvasPipeline(current_gfx_canvas_, current_gfx_bmp_, 256,
0x10 * 0x40, 0x20, overworld_.is_loaded(), true,
3);
DrawAreaGraphics();
EndTabItem();
}
EndTabBar();

View File

@@ -115,7 +115,9 @@ class OverworldEditor : public Editor,
void CheckForCurrentMap();
void DrawOverworldCanvas();
void DrawTile16Selector();
void DrawTile8Selector();
void DrawAreaGraphics();
void DrawTileSelector();
absl::Status LoadSpriteGraphics();
@@ -187,10 +189,15 @@ class OverworldEditor : public Editor,
PaletteEditor palette_editor_;
zelda3::Overworld overworld_;
gui::Canvas ow_map_canvas_;
gui::Canvas current_gfx_canvas_;
gui::Canvas blockset_canvas_;
gui::Canvas graphics_bin_canvas_;
gui::Canvas ow_map_canvas_{ImVec2(0x200 * 8, 0x200 * 8),
gui::CanvasGridSize::k64x64};
gui::Canvas current_gfx_canvas_{ImVec2(0x100 + 1, 0x10 * 0x40 + 1),
gui::CanvasGridSize::k32x32};
gui::Canvas blockset_canvas_{ImVec2(0x100 + 1, 0x2000 + 1),
gui::CanvasGridSize::k32x32};
gui::Canvas graphics_bin_canvas_{
ImVec2(0x100 + 1, kNumSheetsToLoad * 0x40 + 1),
gui::CanvasGridSize::k16x16};
gui::Canvas properties_canvas_;
gfx::SNESPalette palette_;