Update GraphicsEditor, fix CommandHandler
This commit is contained in:
@@ -19,16 +19,38 @@ constexpr ImGuiButtonFlags kMouseFlags =
|
||||
|
||||
void Canvas::Update(const gfx::Bitmap &bitmap, ImVec2 bg_size, int tile_size,
|
||||
float scale, float grid_size) {
|
||||
if (scale != 1.0f) {
|
||||
bg_size.x *= scale / 2;
|
||||
bg_size.y *= scale / 2;
|
||||
}
|
||||
DrawBackground(bg_size);
|
||||
DrawContextMenu();
|
||||
DrawTileSelector(tile_size);
|
||||
DrawBitmap(bitmap, 0, 0, scale);
|
||||
DrawBitmap(bitmap, 2, scale);
|
||||
DrawGrid(grid_size);
|
||||
DrawOverlay();
|
||||
}
|
||||
|
||||
void Canvas::UpdateColorPainter(const gfx::Bitmap &bitmap, const ImVec4 &color,
|
||||
const std::function<void()> &event,
|
||||
ImVec2 bg_size, int tile_size, float scale,
|
||||
float grid_size) {
|
||||
if (scale != 1.0f) {
|
||||
bg_size.x *= scale / 2;
|
||||
bg_size.y *= scale / 2;
|
||||
}
|
||||
DrawBackground(bg_size);
|
||||
DrawContextMenu();
|
||||
DrawBitmap(bitmap, 2, scale);
|
||||
if (DrawSolidTilePainter(color, tile_size)) {
|
||||
event();
|
||||
}
|
||||
DrawGrid(grid_size);
|
||||
DrawOverlay();
|
||||
}
|
||||
|
||||
void Canvas::UpdateEvent(const std::function<void()> &event, ImVec2 bg_size,
|
||||
int tile_size, float grid_size) {
|
||||
int tile_size, float scale, float grid_size) {
|
||||
DrawBackground(bg_size);
|
||||
DrawContextMenu();
|
||||
event();
|
||||
@@ -123,6 +145,47 @@ bool Canvas::DrawTilePainter(const Bitmap &bitmap, int size, float scale) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Canvas::DrawSolidTilePainter(const ImVec4 &color, int size) {
|
||||
const ImGuiIO &io = ImGui::GetIO();
|
||||
const bool is_hovered = ImGui::IsItemHovered();
|
||||
is_hovered_ = is_hovered;
|
||||
// Lock scrolled origin
|
||||
const ImVec2 origin(canvas_p0_.x + scrolling_.x, canvas_p0_.y + scrolling_.y);
|
||||
const ImVec2 mouse_pos(io.MousePos.x - origin.x, io.MousePos.y - origin.y);
|
||||
|
||||
if (is_hovered) {
|
||||
// Reset the previous tile hover
|
||||
if (!points_.empty()) {
|
||||
points_.clear();
|
||||
}
|
||||
|
||||
// Calculate the coordinates of the mouse
|
||||
ImVec2 painter_pos;
|
||||
painter_pos.x = std::floor((double)mouse_pos.x / size) * size;
|
||||
painter_pos.y = std::floor((double)mouse_pos.y / size) * size;
|
||||
|
||||
auto painter_pos_end = ImVec2(painter_pos.x + size, painter_pos.y + size);
|
||||
points_.push_back(painter_pos);
|
||||
points_.push_back(painter_pos_end);
|
||||
|
||||
draw_list_->AddRectFilled(
|
||||
ImVec2(origin.x + painter_pos.x, origin.y + painter_pos.y),
|
||||
ImVec2(origin.x + painter_pos.x + size,
|
||||
origin.y + painter_pos.y + size),
|
||||
IM_COL32(color.x * 255, color.y * 255, color.z * 255, 255));
|
||||
|
||||
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
|
||||
drawn_tile_pos_ = painter_pos;
|
||||
return true;
|
||||
}
|
||||
|
||||
} else {
|
||||
// Erase the hover when the mouse is not in the canvas window.
|
||||
points_.clear();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Canvas::DrawTileSelector(int size) {
|
||||
const ImGuiIO &io = ImGui::GetIO();
|
||||
const bool is_hovered = ImGui::IsItemHovered(); // Hovered
|
||||
@@ -196,6 +259,14 @@ void Canvas::DrawBitmap(const Bitmap &bitmap, int border_offset, bool ready) {
|
||||
}
|
||||
}
|
||||
|
||||
void Canvas::DrawBitmap(const Bitmap &bitmap, int border_offset, float scale) {
|
||||
draw_list_->AddImage(
|
||||
(void *)bitmap.texture(),
|
||||
ImVec2(canvas_p0_.x + border_offset, canvas_p0_.y + border_offset),
|
||||
ImVec2(canvas_p0_.x + (bitmap.width() * scale),
|
||||
canvas_p0_.y + (bitmap.height() * scale)));
|
||||
}
|
||||
|
||||
void Canvas::DrawBitmap(const Bitmap &bitmap, int x_offset, int y_offset,
|
||||
float scale) {
|
||||
draw_list_->AddImage(
|
||||
|
||||
@@ -25,8 +25,13 @@ class Canvas {
|
||||
void Update(const gfx::Bitmap& bitmap, ImVec2 bg_size, int tile_size,
|
||||
float scale = 1.0f, float grid_size = 64.0f);
|
||||
|
||||
void UpdateColorPainter(const gfx::Bitmap& bitmap, const ImVec4& color,
|
||||
const std::function<void()>& event, ImVec2 bg_size,
|
||||
int tile_size, float scale = 1.0f,
|
||||
float grid_size = 64.0f);
|
||||
|
||||
void UpdateEvent(const std::function<void()>& event, ImVec2 bg_size,
|
||||
int tile_size, float grid_size = 64.0f);
|
||||
int tile_size, float scale = 1.0f, float grid_size = 64.0f);
|
||||
|
||||
// Background for the Canvas represents region without any content drawn to
|
||||
// it, but can be controlled by the user.
|
||||
@@ -40,6 +45,7 @@ class Canvas {
|
||||
// and allows the user to left click to paint the tile or right
|
||||
// click to select a new tile to paint with.
|
||||
bool DrawTilePainter(const Bitmap& bitmap, int size, float scale = 1.0f);
|
||||
bool DrawSolidTilePainter(const ImVec4& color, int size);
|
||||
|
||||
// Dictates which tile is currently selected based on what the user clicks
|
||||
// in the canvas window. Represented and split apart into a grid of tiles.
|
||||
@@ -56,6 +62,7 @@ class Canvas {
|
||||
// Draws the contents of the Bitmap image to the Canvas
|
||||
void DrawBitmap(const Bitmap& bitmap, int border_offset = 0,
|
||||
bool ready = true);
|
||||
void DrawBitmap(const Bitmap& bitmap, int border_offset, float scale);
|
||||
void DrawBitmap(const Bitmap& bitmap, int x_offset = 0, int y_offset = 0,
|
||||
float scale = 1.0f);
|
||||
|
||||
|
||||
@@ -126,8 +126,9 @@ bool InputHexWord(const char* label, uint16_t* data, float input_width) {
|
||||
ImGuiInputTextFlags_CharsHexadecimal);
|
||||
}
|
||||
|
||||
bool InputHexByte(const char* label, uint8_t* data, float input_width) {
|
||||
return ImGui::InputScalarLeft(label, ImGuiDataType_U8, data, &kStepOneHex,
|
||||
bool InputHexByte(const char* label, uint8_t* data, uint8_t step,
|
||||
float input_width) {
|
||||
return ImGui::InputScalarLeft(label, ImGuiDataType_U8, data, &step,
|
||||
&kStepFastHex, "%02X", input_width,
|
||||
ImGuiInputTextFlags_CharsHexadecimal);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ IMGUI_API bool InputHex(const char* label, uint64_t* data);
|
||||
IMGUI_API bool InputHexShort(const char* label, uint32_t* data);
|
||||
IMGUI_API bool InputHexWord(const char* label, uint16_t* data,
|
||||
float input_width = 50.f);
|
||||
IMGUI_API bool InputHexByte(const char* label, uint8_t* data,
|
||||
IMGUI_API bool InputHexByte(const char* label, uint8_t* data, uint8_t step = 0x01,
|
||||
float input_width = 50.f);
|
||||
|
||||
using ItemLabelFlags = enum ItemLabelFlag {
|
||||
|
||||
@@ -29,12 +29,6 @@ void SelectablePalettePipeline(uint64_t& palette_id, bool& refresh_graphics,
|
||||
ImGui::BeginGroup(); // Lock X position
|
||||
ImGui::Text("Palette");
|
||||
for (int n = 0; n < palette.size(); n++) {
|
||||
// static gfx::SNESColor transparent_color;
|
||||
// if ((n % 8) == 0) {
|
||||
// gui::SNESColorButton("##transparent", transparent_color, 0,
|
||||
// ImVec2(20, 20));
|
||||
// ImGui::SameLine(0.0f, ImGui::GetStyle().ItemSpacing.y);
|
||||
// }
|
||||
|
||||
ImGui::PushID(n);
|
||||
if ((n % 7) != 0) ImGui::SameLine(0.0f, ImGui::GetStyle().ItemSpacing.y);
|
||||
|
||||
Reference in New Issue
Block a user