Line spacing is added to the reserved size.

glPush/Pop & glTranslate around the calls to draw
Moved all the special renderers to a 2nd pass, post text.
Removed x,y from the draw signature.
Added an helper method to get the proper RenderString
This commit is contained in:
Thomas Guimbretiere committed 2015-01-03 15:52:32 +01:00
1 parent f9f2c4041e
commit 7d1c25872c
7 files changed
+64 -15

No files matched your search

@@ -5,6 +5,21 @@ import java.awt.Point;
public interface IWailaTooltipRenderer {
/**
*
* @param params Array of string parameters as passed to the RENDER arg in the tooltip ({rendername,param1,param2,...})
* @param accessor A global accessor for TileEntities and Entities
* @return Dimension of the reserved area
*/
Dimension getSize(String[] params, IWailaCommonAccessor accessor);
void draw (String[] params, IWailaCommonAccessor accessor, int x, int y);
/**
* Draw method for the renderer. The GL matrice is automatically moved to the top left of the reserved zone.<br>
* All calls should be relative to (0,0)
*
*
* @param params Array of string parameters as passed to the RENDER arg in the tooltip ({rendername,param1,param2,...})
* @param accessor A global accessor for TileEntities and Entities
*/
void draw (String[] params, IWailaCommonAccessor accessor);
}
@@ -50,6 +50,21 @@ public class SpecialChars {
public static final Pattern patternTab = Pattern.compile("(?i)" + TAB);
public static final Pattern patternRight = Pattern.compile("(?i)" + ALIGNRIGHT);
public static final Pattern patternCenter = Pattern.compile("(?i)" + ALIGNCENTER);
public static final Pattern patternIcon = Pattern.compile("(?i)(" + WailaStyle + WailaIcon + "(?<type>[0-9A-Z]))");
public static final Pattern patternIcon = Pattern.compile("(?i)(" + WailaStyle + WailaIcon + "(?<type>[0-9a-z]))");
public static final Pattern patternLineSplit = Pattern.compile("(?i)(" + WailaStyle + WailaStyle + "[^" + WailaStyle + "]+|" + WailaStyle + WailaIcon + "[0-9A-Z]|" + WailaStyle + WailaRenderer + "a\\{([^,}]*),?([^}]*)\\}|[^" + WailaStyle + "]+)");
/**
* Helper method to get a proper RENDER string. Just put the name of the renderer and the params in, and it will give back a directly usable String for the tooltip.
* @param name
* @param params
* @return
*/
public static String getRenderString(String name, String... params){
String result = RENDER + "{" + name;
for (String s : params){
result += "," + s;
}
result += "}";
return result;
}
}
@@ -70,6 +70,8 @@ public class OverlayRenderer {
tooltip.draw();
GL11.glDisable(GL11.GL_BLEND);
tooltip.draw2nd();
if (tooltip.hasIcon)
RenderHelper.enableGUIStandardItemLighting();
@@ -7,6 +7,8 @@ import java.util.regex.Pattern;
import java.awt.Dimension;
import java.awt.Point;
import org.lwjgl.opengl.GL11;
import scala.actors.threadpool.Arrays;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.config.Configuration;
@@ -30,7 +32,9 @@ public class Tooltip {
ArrayList<Integer> columnsWidth = new ArrayList<Integer>();
ArrayList<Integer> columnsPos = new ArrayList<Integer>();
ArrayList<Renderable> elements = new ArrayList<Renderable>();
ArrayList<Renderable> elements = new ArrayList<Renderable>();
ArrayList<Renderable> elements2nd = new ArrayList<Renderable>();
int w,h,x,y,ty;
int offsetX;
int maxStringW;
@@ -69,7 +73,10 @@ public class Tooltip {
}
public void draw(IWailaCommonAccessor accessor, int x, int y) {
this.renderer.draw(this.params, accessor, x + this.pos.x, y + this.pos.y);
GL11.glPushMatrix();
GL11.glTranslatef(x + this.pos.x, y + this.pos.y, 0);
this.renderer.draw(this.params, accessor);
GL11.glPopMatrix();
}
@Override
@@ -147,9 +154,11 @@ public class Tooltip {
IWailaTooltipRenderer renderer = ModuleRegistrar.instance().getTooltipRenderer(renderName);
if (renderer != null){
renderable = new Renderable(renderer, new Point(offsetX, offsetY), renderMatcher.group("args").split(","));
this.elements2nd.add(renderable);
}
} else if (iconMatcher.find()){
renderable = new Renderable(new TTRenderIcon(iconMatcher.group("type")), new Point(offsetX, offsetY));
this.elements2nd.add(renderable);
} else {
// Todo : The added offset should be based on the remaining of the column, not just the current string !
if (cs.startsWith(ALIGNRIGHT))
@@ -159,12 +168,12 @@ public class Tooltip {
offsetX += (columnsWidth.get(c) - DisplayUtil.getDisplayWidth(currentLine.substring(lineMatcher.start()))) / 2;
renderable = new Renderable(new TTRenderString(DisplayUtil.stripWailaSymbols(cs)), new Point(offsetX, offsetY));
this.elements.add(renderable);
}
if (renderable != null){
this.elements.add(renderable);
offsetX += renderable.getSize(accessor).width;
maxHeight = Math.max(maxHeight, renderable.getSize(accessor).height);
maxHeight = Math.max(maxHeight, renderable.getSize(accessor).height + 2);
}
}
}
@@ -175,7 +184,7 @@ public class Tooltip {
private int getRenderableTotalHeight(){
int result = 0;
for (Renderable r : this.elements)
result = Math.max(r.getPos().y + r.getSize(accessor).height, result);
result = Math.max(r.getPos().y + r.getSize(accessor).height + 2, result);
return result;
}
@@ -190,13 +199,13 @@ public class Tooltip {
w = maxStringW + paddingW;
h = Math.max(paddingH, this.getRenderableTotalHeight() + 10);
h = Math.max(paddingH, this.getRenderableTotalHeight() + 8);
Dimension size = DisplayUtil.displaySize();
x = ((int)(size.width / OverlayConfig.scale)-w-1)*pos.x/10000;
y = ((int)(size.height / OverlayConfig.scale)-h-1)*pos.y/10000;
ty = (h - this.getRenderableTotalHeight())/2;
ty = (h - this.getRenderableTotalHeight())/2 + 1;
}
public void draw(){
@@ -204,6 +213,11 @@ public class Tooltip {
r.draw(accessor, x + offsetX, y + ty);
}
public void draw2nd(){
for (Renderable r : this.elements2nd)
r.draw(accessor, x + offsetX, y + ty);
}
/*
public void drawIcons(){
for (int i = 0; i < lines.size(); i++){
@@ -1,5 +1,8 @@
package mcp.mobius.waila.overlay.tooltiprenderers;
import static mcp.mobius.waila.api.SpecialChars.WailaIcon;
import static mcp.mobius.waila.api.SpecialChars.WailaStyle;
import java.awt.Dimension;
import org.lwjgl.opengl.GL11;
@@ -25,8 +28,8 @@ public class TTRenderIcon implements IWailaTooltipRenderer {
}
@Override
public void draw(String[] params, IWailaCommonAccessor accessor, int x, int y) {
OverlayRenderer.renderIcon(x, y, IconSize, IconSize, IconUI.bySymbol(type));
public void draw(String[] params, IWailaCommonAccessor accessor) {
OverlayRenderer.renderIcon(0, 0, IconSize, IconSize, IconUI.bySymbol(WailaStyle + WailaIcon + type));
}
}
@@ -16,7 +16,7 @@ public class TTRenderString implements IWailaTooltipRenderer{
public TTRenderString(String data){
this.data = data;
this.size = new Dimension(DisplayUtil.getDisplayWidth(data), data.equals("") ? 0 : 10);
this.size = new Dimension(DisplayUtil.getDisplayWidth(data), data.equals("") ? 0 : 8);
}
@Override
@@ -25,8 +25,8 @@ public class TTRenderString implements IWailaTooltipRenderer{
}
@Override
public void draw(String[] params, IWailaCommonAccessor accessor, int x, int y) {
GuiDraw.drawString(data, x, y, OverlayConfig.fontcolor, true);
public void draw(String[] params, IWailaCommonAccessor accessor) {
GuiDraw.drawString(data, 0, 0, OverlayConfig.fontcolor, true);
}
}