add palette controls to Canvas context menu if Bitmap ptr is passed

This commit is contained in:
scawful
2024-07-21 11:39:31 -04:00
parent 29f3f2102f
commit 50589dc82c
2 changed files with 37 additions and 2 deletions

View File

@@ -7,6 +7,8 @@
#include "app/editor/graphics/graphics_editor.h"
#include "app/gfx/bitmap.h"
#include "app/gui/input.h"
#include "app/gui/style.h"
#include "app/rom.h"
namespace yaze {
@@ -127,6 +129,35 @@ void Canvas::DrawContextMenu(gfx::Bitmap *bitmap) {
Text("BytesPerPixel: %d", bitmap->surface()->format->BytesPerPixel);
EndMenu();
}
if (BeginMenu("Bitmap Palette")) {
if (rom()->is_loaded()) {
gui::TextWithSeparators("ROM Palette");
ImGui::SetNextItemWidth(100.f);
ImGui::Combo("Palette Group", (int *)&edit_palette_group_name_index_,
gfx::kPaletteGroupAddressesKeys,
IM_ARRAYSIZE(gfx::kPaletteGroupAddressesKeys));
ImGui::SetNextItemWidth(100.f);
gui::InputHexWord("Palette Group Index", &edit_palette_index_);
auto palette_group = rom()->mutable_palette_group()->get_group(
gfx::kPaletteGroupAddressesKeys[edit_palette_group_name_index_]);
auto palette = palette_group->mutable_palette(edit_palette_index_);
if (ImGui::BeginChild("Palette", ImVec2(0, 300), true)) {
gui::SelectablePalettePipeline(edit_palette_sub_index_,
refresh_graphics_, *palette);
if (refresh_graphics_) {
auto status = bitmap->ApplyPaletteWithTransparent(
*palette, edit_palette_sub_index_);
rom()->UpdateBitmap(bitmap);
refresh_graphics_ = false;
}
ImGui::EndChild();
}
}
EndMenu();
}
}
ImGui::Separator();
if (BeginMenu("Grid Tile Size")) {
@@ -144,7 +175,6 @@ void Canvas::DrawContextMenu(gfx::Bitmap *bitmap) {
}
EndMenu();
}
// TODO: Add a menu item for selecting the palette
ImGui::EndPopup();
}

View File

@@ -33,7 +33,7 @@ enum class CanvasGridSize { k8x8, k16x16, k32x32, k64x64 };
* on a canvas. It supports features such as bitmap drawing, context menu
* handling, tile painting, custom grid, and more.
*/
class Canvas {
class Canvas : public SharedRom {
public:
Canvas() = default;
explicit Canvas(const std::string& id, ImVec2 canvas_size)
@@ -199,6 +199,11 @@ class Canvas {
int current_labels_ = 0;
int highlight_tile_id = -1;
uint16_t edit_palette_index_ = 0;
uint64_t edit_palette_group_name_index_ = 0;
uint64_t edit_palette_sub_index_ = 0;
bool refresh_graphics_ = false;
std::string canvas_id_ = "Canvas";
std::string context_id_ = "CanvasContext";