+
+ // Clips "other" to "this"
+ inline TRect Clip(const TRect& other) const
+ {
+ TRect clipped = other;
+ if (clipped.x < x)
+ {
+ clipped.w += clipped.x - x;
+ clipped.x = x;
+ }
+ if (clipped.y < y)
+ {
+ clipped.h += clipped.y - y;
+ clipped.y = 0;
+ }
+ if (clipped.x + clipped.w > x + w)
+ {
+ clipped.w += ((x + w) - (clipped.x + clipped.w));
+ }
+ if (clipped.y + clipped.h > y + h)
+ {
+ clipped.h += ((y + h) - (clipped.y + clipped.h));
+ }
+ return clipped;
+ }