diff --git a/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.cpp b/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.cpp index ec29b51..43a5b34 100644 --- a/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.cpp +++ b/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.cpp @@ -49,33 +49,16 @@ static WorldDoc makeValid(WorldDoc doc) noexcept { [[nodiscard]] constexpr ox::Point fbPtToTileAddr( ox::Vec2 const&fbPt, - ox::Size const&fbSz, - ox::Size const&mapSz) noexcept { - // fbw - framebuffer width - // fbh - framebuffer height - // fbx - framebuffer pt x - // fby - framebuffer pt y - // sw - scaled width - // sh - scaled height - // mw - map width - // mw - map height - // mx - map loc x - // my - map loc y - // sw = fbw / mw - // sh = fbh / mh - // tile addr x = sw * fbx - // tile addr y = sh * fby - auto const fbw = static_cast(fbSz.width); - auto const fbh = static_cast(fbSz.height); - auto const mw = static_cast(mapSz.width); - auto const mh = static_cast(mapSz.height); - auto const sw = fbw / mw; - auto const sh = fbh / mh; - auto const fbx = fbPt.x / fbw; - auto const fby = fbPt.y / fbh; + ox::Vec2 const&mapSz) noexcept { + constexpr auto ColumnsOnScrn = 15; + constexpr auto RowsOnScrn = 10; + auto const fbX = static_cast(fbPt.x); + auto const fbY = static_cast(fbPt.y); + auto const tw = static_cast(mapSz.x / ColumnsOnScrn); + auto const th = static_cast(mapSz.y / RowsOnScrn); return { - static_cast(sw * fbx), - static_cast(sh * fby), + static_cast(fbX / tw), + static_cast(fbY / th), }; } @@ -190,15 +173,18 @@ void WorldEditorImGui::drawWorldView() noexcept { auto const srcH = fbHeight / fbWidth; auto const dstH = paneSize.y / paneSize.x; float xScale{}, yScale{}; + float fbPaneScale{}; if (dstH > srcH) { // crop off width xScale = srcH / dstH; yScale = 1; + fbPaneScale = paneSize.y / fbHeight; } else { auto const srcW = fbWidth / fbHeight; auto const dstW = (paneSize.x / paneSize.y); xScale = 1; yScale = srcW / dstW; + fbPaneScale = paneSize.x / fbWidth; } ImGui::Image( ig::toImTextureID(fb.color.id), @@ -208,22 +194,27 @@ void WorldEditorImGui::drawWorldView() noexcept { std::ignore = ig::dragDropTarget([&, this] { oxRequire(objId, ig::getDragDropPayload("WorldTile")); auto const&io = ImGui::GetIO(); - auto const dropPos = world::dropPos(ox::Vec2(io.MousePos)); - auto const mw = m_doc.columns * ncore::TileWidth * 2; - auto const mh = m_doc.rows * ncore::TileHeight * 2; - auto const tileAddr = fbPtToTileAddr(dropPos, fb.size(), {mw, mh}); - pushCommand( - m_doc, - m_worldStatic, - m_objCache, - ox::Vector{ - { - .layer = m_activeLayer, - .tileAddr = tileAddr, - .objId = objId.objId, - .setId = objId.setId, - }, - }); + auto const dropPos = world::dropPos(ox::Vec2{io.MousePos}); + auto const viewSz = m_view.drawSize(); + auto const tileAddr = fbPtToTileAddr( + dropPos, + ox::Vec2{ + static_cast(viewSz.width) * fbPaneScale, + static_cast(viewSz.height) * fbPaneScale}); + if (tileAddr.x < m_doc.columns && tileAddr.y < m_doc.rows) { + pushCommand( + m_doc, + m_worldStatic, + m_objCache, + ox::Vector{ + { + .layer = m_activeLayer, + .tileAddr = tileAddr, + .objId = objId.objId, + .setId = objId.setId, + }, + }); + } oxReturnError(loadWorldStatic(m_objCache, m_doc).moveTo(m_worldStatic)); return ox::Error{}; }); diff --git a/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.hpp b/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.hpp index 1c15852..c060fa4 100644 --- a/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.hpp +++ b/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.hpp @@ -29,6 +29,11 @@ class WorldEditorImGui: public studio::Editor { ox::String name; uint64_t id{}; keel::AssetRef set; + ObjSetRef(ox::String pName, uint64_t pId, keel::AssetRef pSet): + name(std::move(pName)), + id(pId), + set(std::move(pSet)) {} + constexpr ObjSetRef() = default; }; ox::Vector m_objSets; WorldStatic m_worldStatic;