/*
 * Copyright (c) 2017, Tomas Slusny <slusnucky@gmail.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package net.runelite.client.ui.overlay.components;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.Setter;
import net.runelite.client.ui.overlay.RenderableEntity;

@NoArgsConstructor
@AllArgsConstructor
public class BackgroundComponent implements RenderableEntity
{
	public static final Color DEFAULT_BACKGROUND_COLOR = new Color(70, 61, 50, 156);

	private static final int BORDER_OFFSET = 2;

	private static final int OUTSIDE_STROKE_RED_OFFSET = 14;
	private static final int OUTSIDE_STROKE_GREEN_OFFSET = 13;
	private static final int OUTSIDE_STROKE_BLUE_OFFSET = 15;
	private static final int OUTSIDE_STROKE_ALPHA = 255;

	private static final int INSIDE_STROKE_RED_OFFSET = 20;
	private static final int INSIDE_STROKE_GREEN_OFFSET = 21;
	private static final int INSIDE_STROKE_BLUE_OFFSET = 19;
	private static final int INSIDE_STROKE_ALPHA = 255;

	@Setter
	private Color backgroundColor = DEFAULT_BACKGROUND_COLOR;

	@Setter
	private Rectangle rectangle = new Rectangle();

	@Override
	public Dimension render(Graphics2D graphics, Point parent)
	{
		Color outsideStrokeColor = new Color(
			Math.max(0, backgroundColor.getRed() - OUTSIDE_STROKE_RED_OFFSET),
			Math.max(0, backgroundColor.getGreen() - OUTSIDE_STROKE_GREEN_OFFSET),
			Math.max(0, backgroundColor.getBlue() - OUTSIDE_STROKE_BLUE_OFFSET),
			OUTSIDE_STROKE_ALPHA
		);

		Color insideStrokeColor = new Color(
			Math.min(255, backgroundColor.getRed() + INSIDE_STROKE_RED_OFFSET),
			Math.min(255, backgroundColor.getGreen() + INSIDE_STROKE_GREEN_OFFSET),
			Math.min(255, backgroundColor.getBlue() + INSIDE_STROKE_BLUE_OFFSET),
			INSIDE_STROKE_ALPHA
		);

		// Render background
		graphics.setColor(backgroundColor);
		graphics.fill(rectangle);

		// Render outside stroke
		final Rectangle outsideStroke = new Rectangle(rectangle);
		outsideStroke.grow(-BORDER_OFFSET / 2,- BORDER_OFFSET / 2);
		graphics.setColor(outsideStrokeColor);
		graphics.draw(outsideStroke);

		// Render inside stroke
		final Rectangle insideStroke = new Rectangle(rectangle);
		insideStroke.grow(-BORDER_OFFSET, -BORDER_OFFSET);
		graphics.setColor(insideStrokeColor);
		graphics.draw(insideStroke);
		return new Dimension(rectangle.getSize());
	}
}

@@ -3343,60 +3343,144 @@
 gle(
-rectangle);%0A%09%09outsideStroke.grow(-BORDER_OFFSET / 2,
+);%0A%09%09outsideStroke.setLocation(rectangle.x, rectangle.y);%0A%09%09outsideStroke.setSize(rectangle.width - BORDER_OFFSET / 2, rectangle.height 
 - BO
@@ -3648,57 +3648,204 @@
 gle(
-rectangle);%0A%09%09insideStroke.grow(-BORDER_OFFSET,
+);%0A%09%09insideStroke.setLocation(rectangle.x + BORDER_OFFSET / 2, rectangle.y + BORDER_OFFSET / 2);%0A%09%09insideStroke.setSize(rectangle.width - BORDER_OFFSET - BORDER_OFFSET / 2,%0A%09%09%09%09rectangle.height
  -
+ 
 BORD
@@ -3853,16 +3853,36 @@
 R_OFFSET
+ - BORDER_OFFSET / 2
 );%0A%09%09gra
@@ -3947,16 +3947,17 @@
 troke);%0A
+%0A
 %09%09return

Fix BackgroundComponent's background overflow