Merge pull request #5973 from deathbeam/widget-bounds-limit
Limit widget overlay bounds to parent
This commit is contained in:
@@ -60,6 +60,7 @@ public class WidgetOverlay extends Overlay
|
|||||||
|
|
||||||
private final Client client;
|
private final Client client;
|
||||||
private final WidgetInfo widgetInfo;
|
private final WidgetInfo widgetInfo;
|
||||||
|
private final Rectangle parentBounds = new Rectangle();
|
||||||
|
|
||||||
private WidgetOverlay(final Client client, final WidgetInfo widgetInfo, final OverlayPosition overlayPosition)
|
private WidgetOverlay(final Client client, final WidgetInfo widgetInfo, final OverlayPosition overlayPosition)
|
||||||
{
|
{
|
||||||
@@ -76,17 +77,39 @@ public class WidgetOverlay extends Overlay
|
|||||||
return Objects.toString(widgetInfo);
|
return Objects.toString(widgetInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Rectangle getBounds()
|
||||||
|
{
|
||||||
|
final Rectangle bounds = super.getBounds();
|
||||||
|
final Rectangle parent = getParentBounds(client.getWidget(widgetInfo));
|
||||||
|
|
||||||
|
if (parent.isEmpty())
|
||||||
|
{
|
||||||
|
return bounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
int x = bounds.x;
|
||||||
|
int y = bounds.y;
|
||||||
|
x = Math.max(parent.x, x);
|
||||||
|
y = Math.max(parent.y, y);
|
||||||
|
x = Math.min((int)parent.getMaxX() - bounds.width, x);
|
||||||
|
y = Math.min((int)parent.getMaxY() - bounds.height, y);
|
||||||
|
bounds.setLocation(x, y);
|
||||||
|
return bounds;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension render(Graphics2D graphics)
|
public Dimension render(Graphics2D graphics)
|
||||||
{
|
{
|
||||||
final Widget widget = client.getWidget(widgetInfo);
|
final Widget widget = client.getWidget(widgetInfo);
|
||||||
if (widget == null || widget.isHidden())
|
final Rectangle bounds = super.getBounds();
|
||||||
|
final Rectangle parent = getParentBounds(widget);
|
||||||
|
|
||||||
|
if (parent.isEmpty())
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Rectangle bounds = getBounds();
|
|
||||||
final Rectangle parent = getParentBounds(widget);
|
|
||||||
int x = bounds.x;
|
int x = bounds.x;
|
||||||
int y = bounds.y;
|
int y = bounds.y;
|
||||||
x = Math.max(parent.x, x);
|
x = Math.max(parent.x, x);
|
||||||
@@ -103,12 +126,30 @@ public class WidgetOverlay extends Overlay
|
|||||||
|
|
||||||
private Rectangle getParentBounds(final Widget widget)
|
private Rectangle getParentBounds(final Widget widget)
|
||||||
{
|
{
|
||||||
final Widget parent = widget.getParent();
|
if (!client.isClientThread())
|
||||||
if (parent == null)
|
|
||||||
{
|
{
|
||||||
return new Rectangle(client.getRealDimensions());
|
return parentBounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Rectangle(parent.getCanvasLocation().getX(), parent.getCanvasLocation().getY(), parent.getWidth(), parent.getHeight());
|
if (widget == null || widget.isHidden())
|
||||||
|
{
|
||||||
|
parentBounds.setBounds(new Rectangle());
|
||||||
|
return parentBounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Widget parent = widget.getParent();
|
||||||
|
final Rectangle bounds;
|
||||||
|
|
||||||
|
if (parent == null)
|
||||||
|
{
|
||||||
|
bounds = new Rectangle(client.getRealDimensions());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bounds = new Rectangle(parent.getCanvasLocation().getX(), parent.getCanvasLocation().getY(), parent.getWidth(), parent.getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
parentBounds.setBounds(bounds);
|
||||||
|
return bounds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user