[jasper/world/studio] Fix positioning for tile placement
All checks were successful
Build / build (push) Successful in 3m9s
All checks were successful
Build / build (push) Successful in 3m9s
This commit is contained in:
parent
4c7fc5f9b4
commit
b26601fad9
@ -49,33 +49,16 @@ static WorldDoc makeValid(WorldDoc doc) noexcept {
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr ox::Point fbPtToTileAddr(
|
constexpr ox::Point fbPtToTileAddr(
|
||||||
ox::Vec2 const&fbPt,
|
ox::Vec2 const&fbPt,
|
||||||
ox::Size const&fbSz,
|
ox::Vec2 const&mapSz) noexcept {
|
||||||
ox::Size const&mapSz) noexcept {
|
constexpr auto ColumnsOnScrn = 15;
|
||||||
// fbw - framebuffer width
|
constexpr auto RowsOnScrn = 10;
|
||||||
// fbh - framebuffer height
|
auto const fbX = static_cast<float>(fbPt.x);
|
||||||
// fbx - framebuffer pt x
|
auto const fbY = static_cast<float>(fbPt.y);
|
||||||
// fby - framebuffer pt y
|
auto const tw = static_cast<float>(mapSz.x / ColumnsOnScrn);
|
||||||
// sw - scaled width
|
auto const th = static_cast<float>(mapSz.y / RowsOnScrn);
|
||||||
// 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<float>(fbSz.width);
|
|
||||||
auto const fbh = static_cast<float>(fbSz.height);
|
|
||||||
auto const mw = static_cast<float>(mapSz.width);
|
|
||||||
auto const mh = static_cast<float>(mapSz.height);
|
|
||||||
auto const sw = fbw / mw;
|
|
||||||
auto const sh = fbh / mh;
|
|
||||||
auto const fbx = fbPt.x / fbw;
|
|
||||||
auto const fby = fbPt.y / fbh;
|
|
||||||
return {
|
return {
|
||||||
static_cast<int>(sw * fbx),
|
static_cast<int>(fbX / tw),
|
||||||
static_cast<int>(sh * fby),
|
static_cast<int>(fbY / th),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,15 +173,18 @@ void WorldEditorImGui::drawWorldView() noexcept {
|
|||||||
auto const srcH = fbHeight / fbWidth;
|
auto const srcH = fbHeight / fbWidth;
|
||||||
auto const dstH = paneSize.y / paneSize.x;
|
auto const dstH = paneSize.y / paneSize.x;
|
||||||
float xScale{}, yScale{};
|
float xScale{}, yScale{};
|
||||||
|
float fbPaneScale{};
|
||||||
if (dstH > srcH) {
|
if (dstH > srcH) {
|
||||||
// crop off width
|
// crop off width
|
||||||
xScale = srcH / dstH;
|
xScale = srcH / dstH;
|
||||||
yScale = 1;
|
yScale = 1;
|
||||||
|
fbPaneScale = paneSize.y / fbHeight;
|
||||||
} else {
|
} else {
|
||||||
auto const srcW = fbWidth / fbHeight;
|
auto const srcW = fbWidth / fbHeight;
|
||||||
auto const dstW = (paneSize.x / paneSize.y);
|
auto const dstW = (paneSize.x / paneSize.y);
|
||||||
xScale = 1;
|
xScale = 1;
|
||||||
yScale = srcW / dstW;
|
yScale = srcW / dstW;
|
||||||
|
fbPaneScale = paneSize.x / fbWidth;
|
||||||
}
|
}
|
||||||
ImGui::Image(
|
ImGui::Image(
|
||||||
ig::toImTextureID(fb.color.id),
|
ig::toImTextureID(fb.color.id),
|
||||||
@ -208,22 +194,27 @@ void WorldEditorImGui::drawWorldView() noexcept {
|
|||||||
std::ignore = ig::dragDropTarget([&, this] {
|
std::ignore = ig::dragDropTarget([&, this] {
|
||||||
oxRequire(objId, ig::getDragDropPayload<WorldTileDragDrop>("WorldTile"));
|
oxRequire(objId, ig::getDragDropPayload<WorldTileDragDrop>("WorldTile"));
|
||||||
auto const&io = ImGui::GetIO();
|
auto const&io = ImGui::GetIO();
|
||||||
auto const dropPos = world::dropPos(ox::Vec2(io.MousePos));
|
auto const dropPos = world::dropPos(ox::Vec2{io.MousePos});
|
||||||
auto const mw = m_doc.columns * ncore::TileWidth * 2;
|
auto const viewSz = m_view.drawSize();
|
||||||
auto const mh = m_doc.rows * ncore::TileHeight * 2;
|
auto const tileAddr = fbPtToTileAddr(
|
||||||
auto const tileAddr = fbPtToTileAddr(dropPos, fb.size(), {mw, mh});
|
dropPos,
|
||||||
pushCommand<ModifyTilesCommand>(
|
ox::Vec2{
|
||||||
m_doc,
|
static_cast<float>(viewSz.width) * fbPaneScale,
|
||||||
m_worldStatic,
|
static_cast<float>(viewSz.height) * fbPaneScale});
|
||||||
m_objCache,
|
if (tileAddr.x < m_doc.columns && tileAddr.y < m_doc.rows) {
|
||||||
ox::Vector<ModifyTilesCommand::Mod>{
|
pushCommand<ModifyTilesCommand>(
|
||||||
{
|
m_doc,
|
||||||
.layer = m_activeLayer,
|
m_worldStatic,
|
||||||
.tileAddr = tileAddr,
|
m_objCache,
|
||||||
.objId = objId.objId,
|
ox::Vector<ModifyTilesCommand::Mod>{
|
||||||
.setId = objId.setId,
|
{
|
||||||
},
|
.layer = m_activeLayer,
|
||||||
});
|
.tileAddr = tileAddr,
|
||||||
|
.objId = objId.objId,
|
||||||
|
.setId = objId.setId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
oxReturnError(loadWorldStatic(m_objCache, m_doc).moveTo(m_worldStatic));
|
oxReturnError(loadWorldStatic(m_objCache, m_doc).moveTo(m_worldStatic));
|
||||||
return ox::Error{};
|
return ox::Error{};
|
||||||
});
|
});
|
||||||
|
@ -29,6 +29,11 @@ class WorldEditorImGui: public studio::Editor {
|
|||||||
ox::String name;
|
ox::String name;
|
||||||
uint64_t id{};
|
uint64_t id{};
|
||||||
keel::AssetRef<WorldObjectSet> set;
|
keel::AssetRef<WorldObjectSet> set;
|
||||||
|
ObjSetRef(ox::String pName, uint64_t pId, keel::AssetRef<WorldObjectSet> pSet):
|
||||||
|
name(std::move(pName)),
|
||||||
|
id(pId),
|
||||||
|
set(std::move(pSet)) {}
|
||||||
|
constexpr ObjSetRef() = default;
|
||||||
};
|
};
|
||||||
ox::Vector<ObjSetRef> m_objSets;
|
ox::Vector<ObjSetRef> m_objSets;
|
||||||
WorldStatic m_worldStatic;
|
WorldStatic m_worldStatic;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user