rodecomp/Source/UI/Layout/WindowSnapping.cpp
ragnarok-clanker 5e1c3b07c8 Decompile fn_17161 (UIWindowMgr::ConstrainSnap)
Batch #18575 by eAthena: 0 byte-identical, 1 confirmed by peer review.

- fn_17161 UIWindowMgr::ConstrainSnap: logic confirmed by peer review

Peer-reviewed-by: ragnarok-clanker, cremane, bibinir
Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes).
2026-11-12 17:23:20 +00:00

87 lines
2.4 KiB
C++

#include "UI/Layout/SnapMgr.h"
#include "UI/Window/UIWindow.h"
#include "Contents/Configuration/ServiceOptions.h"
#include "UI/Window/UIWindowMgr.h"
template __declspec(noinline) std::_Tree_unchecked_const_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<UIWindow* const, SnapRectangle>>>, std::_Iterator_base0>& std::_Tree_unchecked_const_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<UIWindow* const, SnapRectangle>>>, std::_Iterator_base0>::operator++() noexcept;
// OFFSET: 0x00AAB0D0
// FUNCTION: fn_17280
void UIWindowMgr::StoreSnapRectangle(UIWindow* window) {
for (UIWindow* entry : this->snapExcluded) {
if (entry == window) {
return;
}
}
if (!g_serviceOptions.Get(141) || !window) {
return;
}
SnapRectangle& rectangle = this->snapRectangles[window];
rectangle.Set(window->geometry.x, window->geometry.y, window->geometry.width, window->geometry.height);
}
// OFFSET: 0x00A914A0
// FUNCTION: fn_17161
void UIWindowMgr::ConstrainSnap(UIWindow* window, int& dx, int& dy, int groupMember) {
bool needX = true, needY = true;
dx = 0;
dy = 0;
int x = 0, y = 0;
SnapRectangle moving;
moving.Set(window->geometry.x, window->geometry.y, window->geometry.width, window->geometry.height);
SnapRectangle screen;
screen.Set(0, 0, this->screenWidth, this->screenHeight);
screen.ReverseEdges();
screen.Snap(moving, x, y);
if (x != 0) {
needX = false;
dx = x;
}
if (y != 0) {
needY = false;
dy = y;
}
if (!needX && !needY) {
return;
}
int snapX = 0, snapY = 0;
const bool root = g_snapMgr.IsRoot(window);
for (auto it = this->snapRectangles.begin(); it != this->snapRectangles.end(); ++it) {
auto& [other, rectangle] = *it;
const bool connected = g_snapMgr.Connected(window, other);
const bool otherRoot = g_snapMgr.IsRoot(other);
const bool otherConnected = g_snapMgr.ConnectedToRoot(other);
if (groupMember != 0) {
if (window == other || otherRoot || connected || otherConnected) {
continue;
}
} else {
if (window == other || (root && (otherConnected || connected))) {
continue;
}
}
rectangle.Snap(moving, snapX, snapY);
if (snapX != 0 && needX) {
needX = false;
dx = snapX;
}
if (snapY != 0 && needY) {
needY = false;
dy = snapY;
}
if (!needX && !needY) {
return;
}
}
}