31 using namespace ystdex;
38 operator+(const Rect& r, const Padding& m)
40 return Rect(r.X + m.Left, r.Y + m.Top,
41 max<int>(0, r.Width - m.Left - m.Right),
42 max<int>(0, r.Height - m.Top - m.Bottom));
49 return Padding(r.X, s.Width - r.X - r.Width,
50 r.Y, s.Height - r.Y - r.Height);
57 if(!clip.IsUnstrictlyEmpty() &&
Clip(clip, bounds)
58 && !clip.IsUnstrictlyEmpty())
59 return clip.GetPoint() - bounds.GetPoint();
60 clip.GetSizeRef() = {};
65 ClipMargin(PaintContext& pc,
const Padding& m,
const Size& ss)
67 const Size& ds(pc.Target.GetSize());
71 const auto& pt(pc.Location);
72 const Point dp(max<int>(m.Left, pt.X), max<int>(m.Top, pt.Y));
73 const Point sp(dp - pt);
74 const auto scx(min<int>(ss.Width, ds.Width - m.Right - dp.X) - sp.X),
75 scy(min<int>(ss.Height, ds.Height - m.Bottom - dp.Y) - sp.Y);
77 if(scx > 0 && scy > 0)
79 pc.ClipArea &= Rect(dp, scx, scy);
80 return pc.ClipArea.GetPoint() - pt;
83 pc.ClipArea.GetSizeRef() = {};
94 std::copy_n(i,
GetAreaOf(GetSize()), pBuffer);
96 BitmapBuffer::BitmapBuffer(
const BitmapBuffer& buf)
99 SetSize(buf.GetWidth(), buf.GetHeight());
100 if(
const auto p = buf.GetBufferPtr())
101 std::copy_n(p,
GetAreaOf(GetSize()), pBuffer);
103 BitmapBuffer::BitmapBuffer(BitmapBuffer&& buf)
ynothrow
104 : Graphics(
nullptr, buf.GetSize())
108 std::swap<Graphics>(*
this, buf);
116 std::copy_n(s,
GetAreaOf(GetSize()), pBuffer);
136 catch(std::bad_alloc&)
141 YAssert(!((pBuffer !=
nullptr) ^ (s != 0)),
"Buffer corruptied.");
143 yunseq(size.Width = w, size.Height = h);
147 BitmapBuffer::SetSizeSwap()
168 : BitmapBuffer(), pBufferAlpha()
170 SetSize(buf.GetWidth(), buf.GetHeight());
171 if(
const auto p = buf.GetBufferPtr())
179 : BitmapBuffer(std::move(buf)), pBufferAlpha(buf.GetBufferAlphaPtr())
181 buf.pBufferAlpha =
nullptr;
211 catch(std::bad_alloc&)
218 YAssert(!((
pBuffer !=
nullptr) ^ (s != 0)),
"Buffer corruptied.");
239 if(~rot & 1 && dst &&
bool(g))
242 ? Blit<BlitLoop, false, false, BitmapPtr, ConstBitmapPtr>
243 : Blit<BlitLoop, true, true, BitmapPtr, ConstBitmapPtr>)(
244 dst, ds, g.GetBufferPtr(), g.GetSize(), dp, sp, sc);
253 if(~rot & 1 && dst &&
bool(buf))
256 ? Blit<BlitTransparentLoop, false, false, BitmapPtr, IteratorPair>
257 : Blit<BlitTransparentLoop, true, true, BitmapPtr, IteratorPair>)(
258 dst, ds,
IteratorPair(buf.GetBufferPtr(), buf.GetBufferAlphaPtr()),
259 buf.GetSize(), dp, sp, sc);
269 if(~rot & 1 && dst &&
bool(buf))
272 ? Blit<BlitBlendLoop, false, false, BitmapPtr, IteratorPair>
273 : Blit<BlitBlendLoop, true, true, BitmapPtr, IteratorPair>)(
274 dst, ds,
IteratorPair(buf.GetBufferPtr(), buf.GetBufferAlphaPtr()),
275 buf.GetSize(), dp, sp, sc);