#include "UiSurface.hpp" #include #include "UiLayout.hpp" namespace jdi { UiSurface UiSurface::SubView(const gd::RectF& localRect) const { UiSurface view; if (!Valid()) { return view; } // 子矩形先换算到宿主坐标,再夹在本表面之内:超出本表面的部分没有属于它的像素, // 若照原样返回 `bits` 偏移会写到相邻区域(典型的"子控件涂到别人身上")。 const gd::RectF requested(rect.X + localRect.X, rect.Y + localRect.Y, localRect.Width, localRect.Height); gd::RectF clamped; if (!UiRectIntersect(rect, requested, clamped)) { return UiSurface(); } view.dc = dc; view.rect = clamped; view.stride = stride; view.version = version; view.scale = scale; if (bits != nullptr && stride > 0) { const int offsetX = static_cast(std::lround(clamped.X - rect.X)); const int offsetY = static_cast(std::lround(clamped.Y - rect.Y)); view.bits = bits + static_cast(offsetY) * (stride / 4) + offsetX; } return view; } } // namespace jdi