Skip to content
This repository has been archived by the owner on Oct 2, 2020. It is now read-only.

Commit

Permalink
Added a line length method that does not rely on rendering.
Browse files Browse the repository at this point in the history
This improves performance in Game.
  • Loading branch information
WhyAreAllTheseTaken committed Nov 27, 2019
1 parent a7e4330 commit 833c14b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
5 changes: 5 additions & 0 deletions RPGOnline2/src/io/github/tomaso2468/rpgonline/Font.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public interface Font {
* @return A positive float value.
*/
public float getHeight(String text);
/**
* Gets the height of a line of text.
* @return A positive float value.
*/
public float getHeight();
/**
* Gets the width (in pixels) of a piece of text.
* @param text The text to measure.
Expand Down
16 changes: 8 additions & 8 deletions RPGOnline2/src/io/github/tomaso2468/rpgonline/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ protected float drawDebugTitle(Graphics g, String s, float y, boolean side) {
} else {
g.drawString(s, renderer.getWidth() - 4 - g.getFont().getWidth(s), y);
}
return y + g.getFont().getHeight("[]") + 1;
return y + g.getFont().getHeight() + 1;
}

/**
Expand All @@ -615,7 +615,7 @@ protected float drawDebugLine(Graphics g, String s, float y, boolean side) {
} else {
g.drawString(s, renderer.getWidth() - 4 - g.getFont().getWidth(s), y);
}
return y + g.getFont().getHeight("[]") + 1;
return y + g.getFont().getHeight() + 1;
}

/**
Expand All @@ -635,7 +635,7 @@ protected float drawDebugLineLabel(Graphics g, String label, String data, float
} else {
g.drawString(label + ": " + data, renderer.getWidth() - 4 - g.getFont().getWidth(label + ": " + data), y);
}
return y + g.getFont().getHeight("[]") + 1;
return y + g.getFont().getHeight() + 1;
}

/**
Expand Down Expand Up @@ -671,7 +671,7 @@ protected float drawDebugLineRYWHigh(Graphics g, String label, long data, long y
}

g.setColor(Color.white.darker());
return y + g.getFont().getHeight("[]") + 1;
return y + g.getFont().getHeight() + 1;
}

/**
Expand Down Expand Up @@ -707,7 +707,7 @@ protected float drawDebugLineRYWLow(Graphics g, String label, long data, long ye
}

g.setColor(Color.white.darker());
return y + g.getFont().getHeight("[]") + 1;
return y + g.getFont().getHeight() + 1;
}

/**
Expand Down Expand Up @@ -743,7 +743,7 @@ protected float drawDebugLineRYWHigh(Graphics g, String label, double data, doub
}

g.setColor(Color.white.darker());
return y + g.getFont().getHeight("[]") + 1;
return y + g.getFont().getHeight() + 1;
}

/**
Expand Down Expand Up @@ -779,7 +779,7 @@ protected float drawDebugLineRYWLow(Graphics g, String label, double data, doubl
}

g.setColor(Color.white.darker());
return y + g.getFont().getHeight("[]") + 1;
return y + g.getFont().getHeight() + 1;
}

/**
Expand Down Expand Up @@ -817,7 +817,7 @@ protected float drawDebugLineRAM(Graphics g, String label, double data, double m
}

g.setColor(Color.white.darker());
return y + g.getFont().getHeight("[]") + 1;
return y + g.getFont().getHeight() + 1;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,10 @@ public float getHeight(String text) {
public float getWidth(String text) {
return font.getWidth(text);
}

@Override
public float getHeight() {
return font.getLineHeight();
}

}

0 comments on commit 833c14b

Please sign in to comment.