add palette controls to Canvas context menu if Bitmap ptr is passed
This commit is contained in:
@@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
#include "app/editor/graphics/graphics_editor.h"
|
#include "app/editor/graphics/graphics_editor.h"
|
||||||
#include "app/gfx/bitmap.h"
|
#include "app/gfx/bitmap.h"
|
||||||
|
#include "app/gui/input.h"
|
||||||
|
#include "app/gui/style.h"
|
||||||
#include "app/rom.h"
|
#include "app/rom.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
@@ -127,6 +129,35 @@ void Canvas::DrawContextMenu(gfx::Bitmap *bitmap) {
|
|||||||
Text("BytesPerPixel: %d", bitmap->surface()->format->BytesPerPixel);
|
Text("BytesPerPixel: %d", bitmap->surface()->format->BytesPerPixel);
|
||||||
EndMenu();
|
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();
|
ImGui::Separator();
|
||||||
if (BeginMenu("Grid Tile Size")) {
|
if (BeginMenu("Grid Tile Size")) {
|
||||||
@@ -144,7 +175,6 @@ void Canvas::DrawContextMenu(gfx::Bitmap *bitmap) {
|
|||||||
}
|
}
|
||||||
EndMenu();
|
EndMenu();
|
||||||
}
|
}
|
||||||
// TODO: Add a menu item for selecting the palette
|
|
||||||
|
|
||||||
ImGui::EndPopup();
|
ImGui::EndPopup();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ enum class CanvasGridSize { k8x8, k16x16, k32x32, k64x64 };
|
|||||||
* on a canvas. It supports features such as bitmap drawing, context menu
|
* on a canvas. It supports features such as bitmap drawing, context menu
|
||||||
* handling, tile painting, custom grid, and more.
|
* handling, tile painting, custom grid, and more.
|
||||||
*/
|
*/
|
||||||
class Canvas {
|
class Canvas : public SharedRom {
|
||||||
public:
|
public:
|
||||||
Canvas() = default;
|
Canvas() = default;
|
||||||
explicit Canvas(const std::string& id, ImVec2 canvas_size)
|
explicit Canvas(const std::string& id, ImVec2 canvas_size)
|
||||||
@@ -199,6 +199,11 @@ class Canvas {
|
|||||||
int current_labels_ = 0;
|
int current_labels_ = 0;
|
||||||
int highlight_tile_id = -1;
|
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 canvas_id_ = "Canvas";
|
||||||
std::string context_id_ = "CanvasContext";
|
std::string context_id_ = "CanvasContext";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user