widgetitemoverlay: clip dragged items when outside of parent bounds

Since dragged items are not moved until after the drag is complete, the
item still gets queued to be drawn, even if dragged outside of the
parent layer.
This commit is contained in:
Adam
2020-02-11 18:36:39 -05:00
parent a2e68634a3
commit 94ff26f3d8

View File

@@ -89,12 +89,26 @@ public abstract class WidgetItemOverlay extends Overlay
Widget parent = widget.getParent();
Rectangle parentBounds = parent.getBounds();
Rectangle itemCanvasBounds = widgetItem.getCanvasBounds();
boolean dragging = widgetItem.getDraggingCanvasBounds() != null;
boolean shouldClip;
shouldClip = itemCanvasBounds.y < parentBounds.y && itemCanvasBounds.y + itemCanvasBounds.height >= parentBounds.y;
shouldClip |= itemCanvasBounds.y < parentBounds.y + parentBounds.height && itemCanvasBounds.y + itemCanvasBounds.height >= parentBounds.y + parentBounds.height;
shouldClip |= itemCanvasBounds.x < parentBounds.x && (itemCanvasBounds.x + itemCanvasBounds.width) >= parentBounds.x;
shouldClip |= itemCanvasBounds.x < parentBounds.x + parentBounds.width && itemCanvasBounds.x + itemCanvasBounds.width >= parentBounds.x + parentBounds.width;
if (dragging)
{
// If dragging, clip if the dragged item is outside of the parent bounds
shouldClip = itemCanvasBounds.x < parentBounds.x;
shouldClip |= itemCanvasBounds.x + itemCanvasBounds.width >= parentBounds.x + parentBounds.width;
shouldClip |= itemCanvasBounds.y < parentBounds.y;
shouldClip |= itemCanvasBounds.y + itemCanvasBounds.height >= parentBounds.y + parentBounds.height;
}
else
{
// Otherwise, we only need to clip the overlay if it intersects the parent bounds,
// since items completely outside of the parent bounds are not drawn
shouldClip = itemCanvasBounds.y < parentBounds.y && itemCanvasBounds.y + itemCanvasBounds.height >= parentBounds.y;
shouldClip |= itemCanvasBounds.y < parentBounds.y + parentBounds.height && itemCanvasBounds.y + itemCanvasBounds.height >= parentBounds.y + parentBounds.height;
shouldClip |= itemCanvasBounds.x < parentBounds.x && itemCanvasBounds.x + itemCanvasBounds.width >= parentBounds.x;
shouldClip |= itemCanvasBounds.x < parentBounds.x + parentBounds.width && itemCanvasBounds.x + itemCanvasBounds.width >= parentBounds.x + parentBounds.width;
}
if (shouldClip)
{
if (curClipParent != parent)