overworld editor tile selector/painter routines
This commit is contained in:
@@ -24,15 +24,16 @@ namespace editor {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void UpdateSelectedTile16(int selected, gfx::Bitmap &tile16_blockset,
|
void UpdateSelectedTile16(int selected, gfx::Bitmap &tile16_blockset,
|
||||||
Bytes &selected_tile) {
|
gfx::Bitmap &selected_tile) {
|
||||||
selected_tile.reserve(256);
|
|
||||||
auto blockset = tile16_blockset.GetData();
|
auto blockset = tile16_blockset.GetData();
|
||||||
|
|
||||||
int src_pos = ((selected - ((selected / 0x08) * 0x08)) * 0x10) +
|
int src_pos = ((selected - ((selected / 0x08) * 0x08)) * 0x10) +
|
||||||
((selected / 0x08) * 2048);
|
((selected / 0x08) * 2048);
|
||||||
for (int yy = 0; yy < 0x10; yy++) {
|
for (int yy = 0; yy < 0x20; yy++) {
|
||||||
for (int xx = 0; xx < 0x10; xx++) {
|
for (int xx = 0; xx < 0x20; xx++) {
|
||||||
selected_tile[xx + (yy * 0x10)] = blockset[src_pos + xx + (yy * 0x80)];
|
int position = (xx + (yy * 0x20));
|
||||||
|
uchar value = blockset[src_pos + xx + (yy * 0x80)];
|
||||||
|
selected_tile.WriteToPixel(position, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -48,11 +49,11 @@ absl::Status OverworldEditor::Update() {
|
|||||||
|
|
||||||
RETURN_IF_ERROR(overworld_.Load(rom_))
|
RETURN_IF_ERROR(overworld_.Load(rom_))
|
||||||
palette_ = overworld_.AreaPalette();
|
palette_ = overworld_.AreaPalette();
|
||||||
current_gfx_bmp_.Create(128, 512, 64, overworld_.AreaGraphics());
|
current_gfx_bmp_.Create(0x80, 0x200, 0x40, overworld_.AreaGraphics());
|
||||||
current_gfx_bmp_.ApplyPalette(palette_);
|
current_gfx_bmp_.ApplyPalette(palette_);
|
||||||
rom_.RenderBitmap(¤t_gfx_bmp_);
|
rom_.RenderBitmap(¤t_gfx_bmp_);
|
||||||
|
|
||||||
tile16_blockset_bmp_.Create(128, 8192, 128, overworld_.Tile16Blockset());
|
tile16_blockset_bmp_.Create(0x80, 8192, 0x80, overworld_.Tile16Blockset());
|
||||||
tile16_blockset_bmp_.ApplyPalette(palette_);
|
tile16_blockset_bmp_.ApplyPalette(palette_);
|
||||||
rom_.RenderBitmap(&tile16_blockset_bmp_);
|
rom_.RenderBitmap(&tile16_blockset_bmp_);
|
||||||
map_blockset_loaded_ = true;
|
map_blockset_loaded_ = true;
|
||||||
@@ -60,23 +61,12 @@ absl::Status OverworldEditor::Update() {
|
|||||||
for (int i = 0; i < core::kNumOverworldMaps; ++i) {
|
for (int i = 0; i < core::kNumOverworldMaps; ++i) {
|
||||||
overworld_.SetCurrentMap(i);
|
overworld_.SetCurrentMap(i);
|
||||||
auto palette = overworld_.AreaPalette();
|
auto palette = overworld_.AreaPalette();
|
||||||
maps_bmp_[i].Create(512, 512, 512, overworld_.BitmapData());
|
maps_bmp_[i].Create(0x200, 0x200, 0x200, overworld_.BitmapData());
|
||||||
maps_bmp_[i].ApplyPalette(palette);
|
maps_bmp_[i].ApplyPalette(palette);
|
||||||
rom_.RenderBitmap(&(maps_bmp_[i]));
|
rom_.RenderBitmap(&(maps_bmp_[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (update_selected_tile_ && all_gfx_loaded_) {
|
|
||||||
if (!selected_tile_loaded_) {
|
|
||||||
selected_tile_bmp_.Create(16, 16, 64, 256);
|
|
||||||
}
|
|
||||||
UpdateSelectedTile16(selected_tile_, tile16_blockset_bmp_,
|
|
||||||
selected_tile_data_);
|
|
||||||
selected_tile_bmp_.ApplyPalette(palette_);
|
|
||||||
rom_.RenderBitmap(&selected_tile_bmp_);
|
|
||||||
update_selected_tile_ = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto toolset_status = DrawToolset();
|
auto toolset_status = DrawToolset();
|
||||||
RETURN_IF_ERROR(toolset_status)
|
RETURN_IF_ERROR(toolset_status)
|
||||||
|
|
||||||
@@ -97,6 +87,8 @@ absl::Status OverworldEditor::Update() {
|
|||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
absl::Status OverworldEditor::DrawToolset() {
|
absl::Status OverworldEditor::DrawToolset() {
|
||||||
if (ImGui::BeginTable("OWToolset", 17, toolset_table_flags, ImVec2(0, 0))) {
|
if (ImGui::BeginTable("OWToolset", 17, toolset_table_flags, ImVec2(0, 0))) {
|
||||||
for (const auto &name : kToolsetColumnNames)
|
for (const auto &name : kToolsetColumnNames)
|
||||||
@@ -124,6 +116,8 @@ absl::Status OverworldEditor::DrawToolset() {
|
|||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void OverworldEditor::DrawOverworldMapSettings() {
|
void OverworldEditor::DrawOverworldMapSettings() {
|
||||||
if (ImGui::BeginTable("#mapSettings", 8, ow_map_flags, ImVec2(0, 0), -1)) {
|
if (ImGui::BeginTable("#mapSettings", 8, ow_map_flags, ImVec2(0, 0), -1)) {
|
||||||
for (const auto &name : kOverworldSettingsColumnNames)
|
for (const auto &name : kOverworldSettingsColumnNames)
|
||||||
@@ -174,30 +168,11 @@ void OverworldEditor::DrawOverworldMapSettings() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverworldEditor::DrawOverworldCanvas() {
|
// ----------------------------------------------------------------------------
|
||||||
DrawOverworldMapSettings();
|
|
||||||
ImGui::Separator();
|
|
||||||
ImGuiID child_id = ImGui::GetID((void *)(intptr_t)7);
|
|
||||||
if (ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
|
|
||||||
ImGuiWindowFlags_AlwaysVerticalScrollbar |
|
|
||||||
ImGuiWindowFlags_AlwaysHorizontalScrollbar)) {
|
|
||||||
overworld_map_canvas_.DrawBackground(ImVec2(0x200 * 8, 0x200 * 8));
|
|
||||||
overworld_map_canvas_.DrawContextMenu();
|
|
||||||
if (overworld_.isLoaded()) {
|
|
||||||
int xx = 0;
|
|
||||||
int yy = 0;
|
|
||||||
for (int i = 0; i < 0x40; i++) {
|
|
||||||
overworld_map_canvas_.DrawBitmap(maps_bmp_[i + (current_world_ * 0x40)],
|
|
||||||
(xx * 0x200), (yy * 0x200));
|
|
||||||
|
|
||||||
xx++;
|
void OverworldEditor::DrawOverworldEntrances() {
|
||||||
if (xx >= 8) {
|
|
||||||
yy++;
|
|
||||||
xx = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (const auto &each : overworld_.Entrances()) {
|
for (const auto &each : overworld_.Entrances()) {
|
||||||
if (each.map_id_ < 64 + (current_world_ * 0x40) &&
|
if (each.map_id_ < 0x40 + (current_world_ * 0x40) &&
|
||||||
each.map_id_ >= (current_world_ * 0x40)) {
|
each.map_id_ >= (current_world_ * 0x40)) {
|
||||||
overworld_map_canvas_.DrawRect(each.x_, each.y_, 16, 16,
|
overworld_map_canvas_.DrawRect(each.x_, each.y_, 16, 16,
|
||||||
ImVec4(210, 24, 210, 150));
|
ImVec4(210, 24, 210, 150));
|
||||||
@@ -205,67 +180,79 @@ void OverworldEditor::DrawOverworldCanvas() {
|
|||||||
overworld_map_canvas_.DrawText(str, each.x_ - 4, each.y_ - 2);
|
overworld_map_canvas_.DrawText(str, each.x_ - 4, each.y_ - 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
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);
|
||||||
|
overworld_map_canvas_.DrawBitmap(maps_bmp_[world_index], map_x, map_y);
|
||||||
|
xx++;
|
||||||
|
if (xx >= 8) {
|
||||||
|
yy++;
|
||||||
|
xx = 0;
|
||||||
}
|
}
|
||||||
overworld_map_canvas_.DrawGrid(64.f);
|
DrawOverworldEntrances();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void OverworldEditor::DrawOverworldCanvas() {
|
||||||
|
DrawOverworldMapSettings();
|
||||||
|
ImGui::Separator();
|
||||||
|
if (ImGuiID child_id = ImGui::GetID((void *)(intptr_t)7);
|
||||||
|
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
|
||||||
|
ImGuiWindowFlags_AlwaysVerticalScrollbar |
|
||||||
|
ImGuiWindowFlags_AlwaysHorizontalScrollbar)) {
|
||||||
|
overworld_map_canvas_.DrawBackground(ImVec2(0x200 * 8, 0x200 * 8));
|
||||||
|
overworld_map_canvas_.DrawContextMenu();
|
||||||
|
overworld_map_canvas_.DrawTilePainter(selected_tile_bmp_, 32);
|
||||||
|
if (overworld_.isLoaded()) {
|
||||||
|
DrawOverworldMaps();
|
||||||
|
}
|
||||||
|
overworld_map_canvas_.DrawGrid(64.0f);
|
||||||
overworld_map_canvas_.DrawOverlay();
|
overworld_map_canvas_.DrawOverlay();
|
||||||
}
|
|
||||||
ImGui::EndChild();
|
|
||||||
}
|
|
||||||
|
|
||||||
void OverworldEditor::DrawTileSelector() {
|
if (!blockset_canvas_.Points().empty() && all_gfx_loaded_) {
|
||||||
if (ImGui::BeginTabBar("##TabBar", ImGuiTabBarFlags_FittingPolicyScroll)) {
|
|
||||||
if (ImGui::BeginTabItem("Area Graphics")) {
|
|
||||||
ImGuiID child_id = ImGui::GetID((void *)(intptr_t)3);
|
|
||||||
if (ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
|
|
||||||
ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
|
|
||||||
DrawAreaGraphics();
|
|
||||||
}
|
|
||||||
ImGui::EndChild();
|
|
||||||
ImGui::EndTabItem();
|
|
||||||
}
|
|
||||||
if (ImGui::BeginTabItem("Tile16")) {
|
|
||||||
ImGuiID child_id = ImGui::GetID((void *)(intptr_t)2);
|
|
||||||
if (ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
|
|
||||||
ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
|
|
||||||
DrawTile16Selector();
|
|
||||||
}
|
|
||||||
ImGui::EndChild();
|
|
||||||
ImGui::EndTabItem();
|
|
||||||
}
|
|
||||||
if (ImGui::BeginTabItem("Tile8")) {
|
|
||||||
ImGuiID child_id = ImGui::GetID((void *)(intptr_t)1);
|
|
||||||
if (ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
|
|
||||||
ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
|
|
||||||
DrawTile8Selector();
|
|
||||||
}
|
|
||||||
ImGui::EndChild();
|
|
||||||
ImGui::EndTabItem();
|
|
||||||
}
|
|
||||||
ImGui::EndTabBar();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void OverworldEditor::DrawAreaGraphics() {
|
|
||||||
current_gfx_canvas_.DrawBackground(ImVec2(256 + 1, 16 * 64 + 1));
|
|
||||||
current_gfx_canvas_.DrawContextMenu();
|
|
||||||
current_gfx_canvas_.DrawTileSelector(32);
|
|
||||||
current_gfx_canvas_.DrawBitmap(current_gfx_bmp_, 2, overworld_.isLoaded());
|
|
||||||
current_gfx_canvas_.DrawGrid(32.0f);
|
|
||||||
current_gfx_canvas_.DrawOverlay();
|
|
||||||
|
|
||||||
if (!current_gfx_canvas_.Points().empty()) {
|
|
||||||
// TODO(scawful): update selected tile by getting position from canvas
|
// TODO(scawful): update selected tile by getting position from canvas
|
||||||
|
// if (!selected_tile_loaded_) {
|
||||||
|
// selected_tile_loaded_ = true;
|
||||||
|
// }
|
||||||
|
|
||||||
|
selected_tile_bmp_.Create(32, 32, 0x40, 1024);
|
||||||
|
UpdateSelectedTile16(selected_tile_, tile16_blockset_bmp_,
|
||||||
|
selected_tile_bmp_);
|
||||||
|
selected_tile_bmp_.ApplyPalette(palette_);
|
||||||
|
rom_.RenderBitmap(&selected_tile_bmp_);
|
||||||
|
update_selected_tile_ = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
ImGui::EndChild();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Tile 16 Selector
|
||||||
|
// Displays all the tiles in the game.
|
||||||
void OverworldEditor::DrawTile16Selector() {
|
void OverworldEditor::DrawTile16Selector() {
|
||||||
blockset_canvas_.DrawBackground(ImVec2(0x100 + 1, (8192 * 2) + 1));
|
blockset_canvas_.DrawBackground(ImVec2(0x100 + 1, (8192 * 2) + 1));
|
||||||
blockset_canvas_.DrawContextMenu();
|
blockset_canvas_.DrawContextMenu();
|
||||||
blockset_canvas_.DrawBitmap(tile16_blockset_bmp_, 2, map_blockset_loaded_);
|
blockset_canvas_.DrawBitmap(tile16_blockset_bmp_, 2, map_blockset_loaded_);
|
||||||
|
blockset_canvas_.DrawTileSelector(32);
|
||||||
blockset_canvas_.DrawGrid(32.0f);
|
blockset_canvas_.DrawGrid(32.0f);
|
||||||
blockset_canvas_.DrawOverlay();
|
blockset_canvas_.DrawOverlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Tile 8 Selector
|
||||||
|
// Displays all the individual tiles that make up a tile16.
|
||||||
void OverworldEditor::DrawTile8Selector() {
|
void OverworldEditor::DrawTile8Selector() {
|
||||||
graphics_bin_canvas_.DrawBackground(
|
graphics_bin_canvas_.DrawBackground(
|
||||||
ImVec2(0x100 + 1, kNumSheetsToLoad * 0x40 + 1));
|
ImVec2(0x100 + 1, kNumSheetsToLoad * 0x40 + 1));
|
||||||
@@ -288,6 +275,54 @@ void OverworldEditor::DrawTile8Selector() {
|
|||||||
graphics_bin_canvas_.DrawOverlay();
|
graphics_bin_canvas_.DrawOverlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void OverworldEditor::DrawAreaGraphics() {
|
||||||
|
current_gfx_canvas_.DrawBackground(ImVec2(256 + 1, 0x10 * 0x40 + 1));
|
||||||
|
current_gfx_canvas_.DrawContextMenu();
|
||||||
|
current_gfx_canvas_.DrawTileSelector(32);
|
||||||
|
current_gfx_canvas_.DrawBitmap(current_gfx_bmp_, 2, overworld_.isLoaded());
|
||||||
|
current_gfx_canvas_.DrawGrid(32.0f);
|
||||||
|
current_gfx_canvas_.DrawOverlay();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void OverworldEditor::DrawTileSelector() {
|
||||||
|
if (ImGui::BeginTabBar("##TabBar", ImGuiTabBarFlags_FittingPolicyScroll)) {
|
||||||
|
if (ImGui::BeginTabItem("Tile16")) {
|
||||||
|
if (ImGuiID child_id = ImGui::GetID((void *)(intptr_t)2);
|
||||||
|
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
|
||||||
|
ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
|
||||||
|
DrawTile16Selector();
|
||||||
|
}
|
||||||
|
ImGui::EndChild();
|
||||||
|
ImGui::EndTabItem();
|
||||||
|
}
|
||||||
|
if (ImGui::BeginTabItem("Tile8")) {
|
||||||
|
if (ImGuiID child_id = ImGui::GetID((void *)(intptr_t)1);
|
||||||
|
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
|
||||||
|
ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
|
||||||
|
DrawTile8Selector();
|
||||||
|
}
|
||||||
|
ImGui::EndChild();
|
||||||
|
ImGui::EndTabItem();
|
||||||
|
}
|
||||||
|
if (ImGui::BeginTabItem("Area Graphics")) {
|
||||||
|
if (ImGuiID child_id = ImGui::GetID((void *)(intptr_t)3);
|
||||||
|
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
|
||||||
|
ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
|
||||||
|
DrawAreaGraphics();
|
||||||
|
}
|
||||||
|
ImGui::EndChild();
|
||||||
|
ImGui::EndTabItem();
|
||||||
|
}
|
||||||
|
ImGui::EndTabBar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void OverworldEditor::LoadGraphics() {
|
void OverworldEditor::LoadGraphics() {
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
current_palette_[i].x = (i * 0.21f);
|
current_palette_[i].x = (i * 0.21f);
|
||||||
|
|||||||
@@ -53,11 +53,15 @@ class OverworldEditor {
|
|||||||
private:
|
private:
|
||||||
absl::Status DrawToolset();
|
absl::Status DrawToolset();
|
||||||
void DrawOverworldMapSettings();
|
void DrawOverworldMapSettings();
|
||||||
|
|
||||||
|
void DrawOverworldEntrances();
|
||||||
|
void DrawOverworldMaps();
|
||||||
void DrawOverworldCanvas();
|
void DrawOverworldCanvas();
|
||||||
void DrawTileSelector();
|
|
||||||
void DrawTile16Selector();
|
void DrawTile16Selector();
|
||||||
void DrawTile8Selector();
|
void DrawTile8Selector();
|
||||||
void DrawAreaGraphics();
|
void DrawAreaGraphics();
|
||||||
|
void DrawTileSelector();
|
||||||
void LoadGraphics();
|
void LoadGraphics();
|
||||||
|
|
||||||
int current_world_ = 0;
|
int current_world_ = 0;
|
||||||
|
|||||||
@@ -96,6 +96,11 @@ void Bitmap::Create(int width, int height, int depth, Bytes data) {
|
|||||||
GrayscalePalette(surface_->format->palette);
|
GrayscalePalette(surface_->format->palette);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Bitmap::Apply(Bytes data) {
|
||||||
|
pixel_data_ = data.data();
|
||||||
|
data_ = data;
|
||||||
|
}
|
||||||
|
|
||||||
// Creates the texture that will be displayed to the screen.
|
// Creates the texture that will be displayed to the screen.
|
||||||
void Bitmap::CreateTexture(std::shared_ptr<SDL_Renderer> renderer) {
|
void Bitmap::CreateTexture(std::shared_ptr<SDL_Renderer> renderer) {
|
||||||
texture_ = std::shared_ptr<SDL_Texture>{
|
texture_ = std::shared_ptr<SDL_Texture>{
|
||||||
|
|||||||
@@ -28,10 +28,16 @@ class Bitmap {
|
|||||||
void Create(int width, int height, int depth, uchar *data, int data_size);
|
void Create(int width, int height, int depth, uchar *data, int data_size);
|
||||||
void Create(int width, int height, int depth, Bytes data);
|
void Create(int width, int height, int depth, Bytes data);
|
||||||
|
|
||||||
|
void Apply(Bytes data);
|
||||||
|
|
||||||
void CreateTexture(std::shared_ptr<SDL_Renderer> renderer);
|
void CreateTexture(std::shared_ptr<SDL_Renderer> renderer);
|
||||||
|
|
||||||
void ApplyPalette(const SNESPalette &palette);
|
void ApplyPalette(const SNESPalette &palette);
|
||||||
|
|
||||||
|
void WriteToPixel(int position, uchar value) {
|
||||||
|
this->pixel_data_[position] = value;
|
||||||
|
}
|
||||||
|
|
||||||
int GetWidth() const { return width_; }
|
int GetWidth() const { return width_; }
|
||||||
int GetHeight() const { return height_; }
|
int GetHeight() const { return height_; }
|
||||||
auto GetSize() const { return data_size_; }
|
auto GetSize() const { return data_size_; }
|
||||||
|
|||||||
@@ -63,6 +63,37 @@ void Canvas::DrawContextMenu() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Canvas::DrawTilePainter(const Bitmap& bitmap, int size) {
|
||||||
|
const ImGuiIO &io = ImGui::GetIO();
|
||||||
|
const bool is_hovered = ImGui::IsItemHovered(); // Hovered
|
||||||
|
const ImVec2 origin(canvas_p0_.x + scrolling_.x,
|
||||||
|
canvas_p0_.y + scrolling_.y); // Lock scrolled origin
|
||||||
|
const ImVec2 mouse_pos_in_canvas(io.MousePos.x - origin.x,
|
||||||
|
io.MousePos.y - origin.y);
|
||||||
|
|
||||||
|
if (is_hovered) {
|
||||||
|
if (!points_.empty()) {
|
||||||
|
points_.clear();
|
||||||
|
}
|
||||||
|
ImVec2 draw_tile_outline_pos;
|
||||||
|
draw_tile_outline_pos.x =
|
||||||
|
std::floor((double)mouse_pos_in_canvas.x / size) * size;
|
||||||
|
draw_tile_outline_pos.y =
|
||||||
|
std::floor((double)mouse_pos_in_canvas.y / size) * size;
|
||||||
|
|
||||||
|
points_.push_back(draw_tile_outline_pos);
|
||||||
|
points_.push_back(
|
||||||
|
ImVec2(draw_tile_outline_pos.x + size, draw_tile_outline_pos.y + size));
|
||||||
|
|
||||||
|
draw_list_->AddImage((void *)bitmap.GetTexture(),
|
||||||
|
ImVec2(draw_tile_outline_pos.x, draw_tile_outline_pos.y),
|
||||||
|
ImVec2(draw_tile_outline_pos.x + (bitmap.GetWidth() * 2),
|
||||||
|
draw_tile_outline_pos.y + (bitmap.GetHeight() * 2)));
|
||||||
|
} else {
|
||||||
|
points_.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Canvas::DrawTileSelector(int size) {
|
void Canvas::DrawTileSelector(int size) {
|
||||||
const ImGuiIO &io = ImGui::GetIO();
|
const ImGuiIO &io = ImGui::GetIO();
|
||||||
const bool is_hovered = ImGui::IsItemHovered(); // Hovered
|
const bool is_hovered = ImGui::IsItemHovered(); // Hovered
|
||||||
@@ -70,7 +101,7 @@ void Canvas::DrawTileSelector(int size) {
|
|||||||
canvas_p0_.y + scrolling_.y); // Lock scrolled origin
|
canvas_p0_.y + scrolling_.y); // Lock scrolled origin
|
||||||
const ImVec2 mouse_pos_in_canvas(io.MousePos.x - origin.x,
|
const ImVec2 mouse_pos_in_canvas(io.MousePos.x - origin.x,
|
||||||
io.MousePos.y - origin.y);
|
io.MousePos.y - origin.y);
|
||||||
// Add first and second point
|
|
||||||
if (is_hovered && ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
|
if (is_hovered && ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
|
||||||
if (!points_.empty()) {
|
if (!points_.empty()) {
|
||||||
points_.clear();
|
points_.clear();
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ class Canvas {
|
|||||||
|
|
||||||
void DrawBackground(ImVec2 canvas_size = ImVec2(0, 0));
|
void DrawBackground(ImVec2 canvas_size = ImVec2(0, 0));
|
||||||
void DrawContextMenu();
|
void DrawContextMenu();
|
||||||
|
void DrawTilePainter(const Bitmap& bitmap, int size);
|
||||||
void DrawTileSelector(int size);
|
void DrawTileSelector(int size);
|
||||||
void DrawBitmap(const Bitmap& bitmap, int border_offset = 0,
|
void DrawBitmap(const Bitmap& bitmap, int border_offset = 0,
|
||||||
bool ready = true);
|
bool ready = true);
|
||||||
@@ -55,6 +56,7 @@ class Canvas {
|
|||||||
ImVec2 mouse_pos_in_canvas_;
|
ImVec2 mouse_pos_in_canvas_;
|
||||||
|
|
||||||
std::vector<app::gfx::Bitmap> changed_tiles_;
|
std::vector<app::gfx::Bitmap> changed_tiles_;
|
||||||
|
app::gfx::Bitmap current_tile_;
|
||||||
|
|
||||||
std::string title_;
|
std::string title_;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user