client: add configuration for tooltip position

This commit is contained in:
Crypthead
2020-01-25 02:08:35 +01:00
committed by Adam
parent 273ebdeebf
commit d8d6ed34c9
3 changed files with 66 additions and 5 deletions

View File

@@ -244,6 +244,17 @@ public interface RuneLiteConfig extends Config
return true;
}
@ConfigItem(
keyName = "tooltipPosition",
name = "Tooltip Position",
description = "Configures whether to show the tooltip above or under the cursor",
position = 35
)
default TooltipPositionType tooltipPosition()
{
return TooltipPositionType.UNDER_CURSOR;
}
@ConfigItem(
keyName = "infoBoxVertical",
name = "Display infoboxes vertically",

View File

@@ -0,0 +1,44 @@
/*
* Copyright (c) 2020, Crypthead <https://github.com/Crypthead>
* 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.config;
import lombok.RequiredArgsConstructor;
import lombok.Getter;
@Getter
@RequiredArgsConstructor
public enum TooltipPositionType
{
ABOVE_CURSOR("Above cursor"),
UNDER_CURSOR("Under cursor");
private final String type;
@Override
public String toString()
{
return type;
}
}

View File

@@ -32,6 +32,8 @@ import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import net.runelite.api.Client;
import net.runelite.client.config.RuneLiteConfig;
import net.runelite.client.config.TooltipPositionType;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
@@ -41,16 +43,19 @@ import net.runelite.client.ui.overlay.components.TooltipComponent;
@Singleton
public class TooltipOverlay extends Overlay
{
private static final int OFFSET = 24;
private static final int UNDER_OFFSET = 24;
private static final int ABOVE_OFFSET = -20;
private static final int PADDING = 2;
private final TooltipManager tooltipManager;
private final Client client;
private final RuneLiteConfig runeLiteConfig;
@Inject
private TooltipOverlay(Client client, TooltipManager tooltipManager)
private TooltipOverlay(Client client, TooltipManager tooltipManager, final RuneLiteConfig runeLiteConfig)
{
this.client = client;
this.tooltipManager = tooltipManager;
this.runeLiteConfig = runeLiteConfig;
setPosition(OverlayPosition.TOOLTIP);
setPriority(OverlayPriority.HIGHEST);
setLayer(OverlayLayer.ALWAYS_ON_TOP);
@@ -81,7 +86,8 @@ public class TooltipOverlay extends Overlay
{
final Rectangle clientCanvasBounds = new Rectangle(client.getRealDimensions());
final net.runelite.api.Point mouseCanvasPosition = client.getMouseCanvasPosition();
final Point mousePosition = new Point(mouseCanvasPosition.getX(), mouseCanvasPosition.getY() + OFFSET);
final int offset = runeLiteConfig.tooltipPosition() == TooltipPositionType.UNDER_CURSOR ? UNDER_OFFSET : ABOVE_OFFSET;
final Point mousePosition = new Point(mouseCanvasPosition.getX(), mouseCanvasPosition.getY() + offset);
final Rectangle bounds = new Rectangle(getBounds());
bounds.setLocation(mousePosition);
@@ -94,7 +100,7 @@ public class TooltipOverlay extends Overlay
if (boundsY > clientY)
{
graphics.translate(0, -bounds.height - OFFSET);
graphics.translate(0, -bounds.height - offset);
}
if (boundsX > clientX)
@@ -113,7 +119,7 @@ public class TooltipOverlay extends Overlay
if (newBounds.contains(mousePosition))
{
mousePosition.move(mouseCanvasPosition.getX(), mouseCanvasPosition.getY() + OFFSET + newBounds.height);
mousePosition.move(mouseCanvasPosition.getX(), mouseCanvasPosition.getY() + offset + newBounds.height);
}
tooltipComponent.setPosition(mousePosition);