Skip to content

Commit

Permalink
runelite-client: allow plugins to have multiple overlays, fix top dow…
Browse files Browse the repository at this point in the history
…n renderer right
  • Loading branch information
Adam- committed May 6, 2017
1 parent d39953a commit 71dac53
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
* (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.plugins;

import com.google.common.util.concurrent.AbstractIdleService;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import net.runelite.client.ui.overlay.Overlay;

public abstract class Plugin extends AbstractIdleService
Expand All @@ -34,4 +36,10 @@ public Overlay getOverlay()
{
return null;
}

public Collection<Overlay> getOverlays()
{
Overlay overlay = getOverlay();
return overlay != null ? Arrays.asList(overlay) : Collections.EMPTY_LIST;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
* (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;

import java.awt.image.BufferedImage;
Expand All @@ -40,24 +39,20 @@ public void render(BufferedImage clientBuffer)

for (Plugin plugin : RuneLite.getRunelite().getPluginManager().getPlugins())
{
Overlay overlay = plugin.getOverlay();

if (overlay == null)
{
continue;
}

switch (overlay.getPosition())
for (Overlay overlay : plugin.getOverlays())
{
case TOP_RIGHT:
tdr.add(overlay);
break;
case TOP_LEFT:
tdl.add(overlay);
break;
case DYNAMIC:
dr.add(overlay);
break;
switch (overlay.getPosition())
{
case TOP_RIGHT:
tdr.add(overlay);
break;
case TOP_LEFT:
tdl.add(overlay);
break;
case DYNAMIC:
dr.add(overlay);
break;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void render(BufferedImage clientBuffer)

for (Overlay overlay : overlays)
{
BufferedImage image = clientBuffer.getSubimage(BORDER_LEFT, y, clientBuffer.getWidth() - BORDER_LEFT, clientBuffer.getHeight() - y);//(int) dimension.getWidth(), (int) dimension.getHeight());
BufferedImage image = clientBuffer.getSubimage(BORDER_LEFT, y, clientBuffer.getWidth() - BORDER_LEFT, clientBuffer.getHeight() - y);
Graphics2D graphics = image.createGraphics();
Renderer.setAntiAliasing(graphics);
Dimension dimension = overlay.render(graphics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
* (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;

import java.awt.Dimension;
Expand Down Expand Up @@ -51,18 +50,29 @@ public void render(BufferedImage clientBuffer)
{
Client client = RuneLite.getClient();
overlays.sort((o1, o2) -> o2.getPriority().compareTo(o1.getPriority()));

int y = BORDER_TOP;
int clientWidth = client.getClientWidth();
int clientHeight = client.getClientHeight();

for (Overlay overlay : overlays)
{
BufferedImage image = clientBuffer.getSubimage(BORDER_RIGHT, y, client.getClientWidth(), 25);
BufferedImage image = new BufferedImage(clientWidth, clientHeight, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = image.createGraphics();
Renderer.setAntiAliasing(graphics);
Dimension dimension = overlay.render(graphics);
graphics.dispose();

if (dimension == null)
{
continue;
}

image = image.getSubimage(0, 0, (int) dimension.getWidth(), (int) dimension.getHeight());

graphics = clientBuffer.createGraphics();
graphics.drawImage(image, clientWidth - BORDER_RIGHT - (int) dimension.getWidth(), y, null);
graphics.dispose();

y += dimension.getHeight() + PADDING;
}
Expand Down

0 comments on commit 71dac53

Please sign in to comment.