|
|
|
@ -13,6 +13,7 @@
|
|
|
|
#include <editor/editor.h>
|
|
|
|
#include <editor/editor.h>
|
|
|
|
#include <core/core.h>
|
|
|
|
#include <core/core.h>
|
|
|
|
#include <graphics/graphics.h>
|
|
|
|
#include <graphics/graphics.h>
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
|
|
|
|
#include <utils/stb/std_image_write.h>
|
|
|
|
#include <utils/stb/std_image_write.h>
|
|
|
|
|
|
|
|
|
|
|
|
@ -21,14 +22,56 @@ namespace lunarium { namespace editor
|
|
|
|
TileSetView::TileSetView(MapEditor* editor)
|
|
|
|
TileSetView::TileSetView(MapEditor* editor)
|
|
|
|
: Panel(gui::PanelType::PT_TILE_SET_VIEW, "Tile Set View", gui::PanelDockZone::DDZ_RIGHT, true),
|
|
|
|
: Panel(gui::PanelType::PT_TILE_SET_VIEW, "Tile Set View", gui::PanelDockZone::DDZ_RIGHT, true),
|
|
|
|
mpEditor(editor), mpTileSet(nullptr), mpViewImage(nullptr), mFrameBuffer(-1),
|
|
|
|
mpEditor(editor), mpTileSet(nullptr), mpViewImage(nullptr), mFrameBuffer(-1),
|
|
|
|
mViewOffset({0, 0}), mViewZoom(1.0f)
|
|
|
|
mViewOffset({0, 0}), mViewZoom(1.0f), mMouseDown(false)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TileSetView::Update(float delta)
|
|
|
|
void TileSetView::Update(float delta)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!mpViewImage)
|
|
|
|
if (ImGui::GetIO().MouseDown[ImGuiMouseButton_Left] && !mMouseDown)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mMouseDown = true;
|
|
|
|
|
|
|
|
float x = ImGui::GetMousePos().x;
|
|
|
|
|
|
|
|
float y = ImGui::GetMousePos().y;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Logger::Log(Editor::LogCat, LogLevel::INFO_VERBOSE, "Mouse clicked at (%f, %f)", x, y);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Adjust for window pos
|
|
|
|
|
|
|
|
x -= mWorkAreaPos.X;
|
|
|
|
|
|
|
|
y -= mWorkAreaPos.Y;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Logger::Log(Editor::LogCat, LogLevel::INFO_VERBOSE, "Mouse Pos Adjusted (%f, %f)", x, y);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check that it's within the window
|
|
|
|
|
|
|
|
bool is_in_window = x >= 0.0f && x < mWorkAreaSize.X && y >= 0.0f && y < mWorkAreaSize.Y;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (is_in_window && mpTileSet)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Adjust for scrolling
|
|
|
|
|
|
|
|
x += mScrollOffset.X;
|
|
|
|
|
|
|
|
y += mScrollOffset.Y;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Logger::Log(Editor::LogCat, LogLevel::INFO_VERBOSE, "Mouse Pos scrolled (%f, %f)", x, y);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Find selected tile
|
|
|
|
|
|
|
|
mSelectedTile.X = x / mpTileSet->GetTileSize().Width;
|
|
|
|
|
|
|
|
mSelectedTile.Y = y / mpTileSet->GetTileSize().Height;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Logger::Log(Editor::LogCat, LogLevel::INFO_VERBOSE, "Updating Tile Selection: tile (%d, %d)", mSelectedTile.X, mSelectedTile.Y);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Invalidate();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!ImGui::GetIO().MouseDown[ImGuiMouseButton_Left] && mMouseDown)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//Logger::Log(Editor::LogCat, LogLevel::INFO_VERBOSE, "Mouse Released");
|
|
|
|
|
|
|
|
mMouseDown = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mInvalidate)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (mpTileSet)
|
|
|
|
if (mpTileSet)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -37,17 +80,29 @@ namespace lunarium { namespace editor
|
|
|
|
mFrameBuffer = Core::Graphics().CreateRenderTexture(mpTileSet->GetImage()->GetWidth(), mpTileSet->GetImage()->GetHeight(), 4);
|
|
|
|
mFrameBuffer = Core::Graphics().CreateRenderTexture(mpTileSet->GetImage()->GetWidth(), mpTileSet->GetImage()->GetHeight(), 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Logger::Log(Editor::LogCat, LogLevel::INFO_VERBOSE, "Invalidating tile set window");
|
|
|
|
|
|
|
|
|
|
|
|
Color prev = Core::Graphics().GetClearColor();
|
|
|
|
Color prev = Core::Graphics().GetClearColor();
|
|
|
|
Core::Graphics().SetClearColor(Color::Transparent());
|
|
|
|
Core::Graphics().SetClearColor(Color::Transparent());
|
|
|
|
Core::GetInstance().BeginRenderToTexture(mFrameBuffer).LogIfFailed(Editor::LogCat);
|
|
|
|
Core::GetInstance().BeginRenderToTexture(mFrameBuffer).LogIfFailed(Editor::LogCat);
|
|
|
|
|
|
|
|
|
|
|
|
mpTileSet->Render(&Core::Graphics());
|
|
|
|
mpTileSet->Render(&Core::Graphics());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Draw selected tile highlight
|
|
|
|
|
|
|
|
if (mSelectedTile.X >= 0 && mSelectedTile.Y >= 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Rectangle selection = mpTileSet->GetTileRect(mSelectedTile);
|
|
|
|
|
|
|
|
Core::Graphics().DrawBox(selection, Color::Red(), 1.5f);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mpViewImage = Core::GetInstance().EndRenderToTexture();
|
|
|
|
mpViewImage = Core::GetInstance().EndRenderToTexture();
|
|
|
|
Core::Graphics().SetClearColor(prev);
|
|
|
|
Core::Graphics().SetClearColor(prev);
|
|
|
|
|
|
|
|
|
|
|
|
//stbi_flip_vertically_on_write(1);
|
|
|
|
// //stbi_flip_vertically_on_write(1);
|
|
|
|
stbi_write_png("tileset_test_image.png", mpViewImage->GetWidth(), mpViewImage->GetHeight(), 4,
|
|
|
|
// stbi_write_png("tileset_test_image.png", mpViewImage->GetWidth(), mpViewImage->GetHeight(), 4,
|
|
|
|
mpViewImage->GetData(), mpViewImage->GetWidth() * 4);
|
|
|
|
// mpViewImage->GetData(), mpViewImage->GetWidth() * 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mInvalidate = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -56,31 +111,74 @@ namespace lunarium { namespace editor
|
|
|
|
if (!mIsOpen)
|
|
|
|
if (!mIsOpen)
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
if (!ImGui::Begin(GetName(), &mIsOpen))
|
|
|
|
ImGui::PushStyleVar( ImGuiStyleVar_WindowRounding, 0.0f );
|
|
|
|
|
|
|
|
ImGui::PushStyleVar( ImGuiStyleVar_WindowBorderSize, 0.0f );
|
|
|
|
|
|
|
|
ImGui::PushStyleVar( ImGuiStyleVar_WindowPadding, ImVec2( 0.0f, 0.0f ) );
|
|
|
|
|
|
|
|
if (!ImGui::Begin(GetName(), &mIsOpen, ImGuiWindowFlags_HorizontalScrollbar))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
ImGui::PopStyleVar(3);
|
|
|
|
ImGui::End();
|
|
|
|
ImGui::End();
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ImVec2 pos = ImGui::GetWindowPos();
|
|
|
|
ImGui::PopStyleVar(3);
|
|
|
|
ImVec2 size = ImGui::GetWindowSize();
|
|
|
|
mWorkAreaPos = { ImGui::GetWindowPos().x, ImGui::GetWindowPos().y };
|
|
|
|
|
|
|
|
mWorkAreaSize = { ImGui::GetWindowSize().x, ImGui::GetWindowSize().y };
|
|
|
|
// Adjust for the tab bar
|
|
|
|
mScrollOffset = { ImGui::GetScrollX(), ImGui::GetScrollY() };
|
|
|
|
pos.y += ImGui::GetFrameHeight();
|
|
|
|
|
|
|
|
size.y -= ImGui::GetFrameHeight();
|
|
|
|
// Adjust pos and size to account for the title bar
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
mWorkAreaPos.Y += ImGui::GetFrameHeight();
|
|
|
|
float x = io.MousePos.x - pos.x;
|
|
|
|
mWorkAreaSize.Y -= ImGui::GetFrameHeight();
|
|
|
|
float y = io.MousePos.y - pos.y;
|
|
|
|
|
|
|
|
|
|
|
|
// Adjust for info box
|
|
|
|
|
|
|
|
// float child_height = 90.0f;
|
|
|
|
|
|
|
|
// size.y -= child_height;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ImGuiIO& io = ImGui::GetIO();
|
|
|
|
|
|
|
|
// float x = io.MousePos.x - pos.x;
|
|
|
|
|
|
|
|
// float y = io.MousePos.y - pos.y;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// bool is_in_window = x >= 0.0f && x < size.x && y >= 0.0f && y < size.y;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // Check for mouse click
|
|
|
|
|
|
|
|
// if (ImGui::IsMouseDown(ImGuiMouseButton_Left) && is_in_window && mpTileSet)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// // Adjust for scrolling
|
|
|
|
|
|
|
|
// x += ImGui::GetScrollX();
|
|
|
|
|
|
|
|
// y += ImGui::GetScrollY();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // Find selected tile
|
|
|
|
|
|
|
|
// mSelectedTile.X = x / mpTileSet->GetTileSize().Width;
|
|
|
|
|
|
|
|
// mSelectedTile.Y = y / mpTileSet->GetTileSize().Height;
|
|
|
|
|
|
|
|
// Invalidate();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
if (mpViewImage)
|
|
|
|
if (mpViewImage)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ImGui::Image((ImTextureID)mpViewImage->GetGLTextureID64(), ImVec2(mpViewImage->GetWidth(), mpViewImage->GetHeight()));
|
|
|
|
ImGui::Image((ImTextureID)mpViewImage->GetGLTextureID64(),
|
|
|
|
|
|
|
|
ImVec2(mpViewImage->GetWidth(), mpViewImage->GetHeight()), ImVec2(0, 1), ImVec2(1, 0)); // the last 2 params are flipping the image on the y
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: If a tile on the map was changed this frame null out the canvas image so it will be redrawn
|
|
|
|
// TODO: If a tile on the map was changed this frame null out the canvas image so it will be redrawn
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ImGui::SetNextWindowPos(ImVec2(ImGui::GetWindowPos().x, ImGui::GetWindowPos().y + (ImGui::GetWindowSize().y - child_height)), ImGuiCond_Always);
|
|
|
|
|
|
|
|
// ImGui::BeginChild(ImGui::GetID(GetName()), ImVec2(size.x, child_height), true);
|
|
|
|
|
|
|
|
// std::ostringstream oss;
|
|
|
|
|
|
|
|
// oss << "Mouse Pos: (" << x << ", " << y << ")";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (mpTileSet)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// oss << "\nSelected Tile Would be: (" << (int)x / mpTileSet->GetTileSize().Width << ", " << (int)y / mpTileSet->GetTileSize().Height << ")";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Rectangle selection = mpTileSet->GetTileRect(mSelectedTile);
|
|
|
|
|
|
|
|
// oss << "\n Selection: (" << selection.left() << ", " << selection.top()
|
|
|
|
|
|
|
|
// << ") size: (" << selection.HalfWidth * 2 << ", " << selection.HalfHeight * 2 << ")";
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ImGui::TextUnformatted(oss.str().c_str());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ImGui::EndChild();
|
|
|
|
ImGui::End();
|
|
|
|
ImGui::End();
|
|
|
|
return mIsOpen;
|
|
|
|
return mIsOpen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -88,6 +186,7 @@ namespace lunarium { namespace editor
|
|
|
|
void TileSetView::SetTileSet(TileSet* set)
|
|
|
|
void TileSetView::SetTileSet(TileSet* set)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mpTileSet = set;
|
|
|
|
mpTileSet = set;
|
|
|
|
|
|
|
|
Invalidate(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TileSet* TileSetView::GetTileSet()
|
|
|
|
TileSet* TileSetView::GetTileSet()
|
|
|
|
@ -95,10 +194,16 @@ namespace lunarium { namespace editor
|
|
|
|
return mpTileSet;
|
|
|
|
return mpTileSet;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Vec2i TileSetView::GetSelectedTile()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return mSelectedTile;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TileSetView::Invalidate(bool remake_frame_buffer)
|
|
|
|
void TileSetView::Invalidate(bool remake_frame_buffer)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mpViewImage = nullptr;
|
|
|
|
mInvalidate = true;
|
|
|
|
if (remake_frame_buffer)
|
|
|
|
if (remake_frame_buffer && mFrameBuffer != -1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Core::Graphics().DestroyRenderTexture(mFrameBuffer);
|
|
|
|
Core::Graphics().DestroyRenderTexture(mFrameBuffer);
|
|
|
|
mFrameBuffer = -1;
|
|
|
|
mFrameBuffer = -1;
|
|
|
|
|