projects
/
sixth-3d.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
a213198
)
Improved code readability
author
Svjatoslav Agejenko
<svjatoslav@svjatoslav.eu>
Tue, 23 May 2023 20:31:33 +0000
(23:31 +0300)
committer
Svjatoslav Agejenko
<svjatoslav@svjatoslav.eu>
Tue, 23 May 2023 20:31:33 +0000
(23:31 +0300)
src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/CanvasCharacter.java
patch
|
blob
|
history
src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/TextCanvas.java
patch
|
blob
|
history
src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/package-info.java
patch
|
blob
|
history
diff --git
a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/CanvasCharacter.java
b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/CanvasCharacter.java
index
b754faf
..
b181226
100644
(file)
--- a/
src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/CanvasCharacter.java
+++ b/
src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/CanvasCharacter.java
@@
-12,14
+12,26
@@
import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.solidpolygon.SolidPo
import java.awt.*;
import java.awt.*;
+import static java.lang.String.valueOf;
+
+/**
+ * Represents a single character on the text canvas.
+ */
public class CanvasCharacter extends AbstractCoordinateShape {
private static final int MAX_FONT_SIZE = 500;
public class CanvasCharacter extends AbstractCoordinateShape {
private static final int MAX_FONT_SIZE = 500;
+
+ /**
+ * Cached fonts.
+ */
private static final Font[] fonts = new Font[MAX_FONT_SIZE];
private static final Font[] fonts = new Font[MAX_FONT_SIZE];
- private String value;
+
+ /**
+ * The character to be rendered.
+ */
+ private char value;
private eu.svjatoslav.sixth.e3d.renderer.raster.Color foregroundColor;
private eu.svjatoslav.sixth.e3d.renderer.raster.Color foregroundColor;
- private Color foregroundAwtColor;
private eu.svjatoslav.sixth.e3d.renderer.raster.Color backgroundColor;
private eu.svjatoslav.sixth.e3d.renderer.raster.Color backgroundColor;
@@
-30,10
+42,9
@@
public class CanvasCharacter extends AbstractCoordinateShape {
super(5);
coordinates[0].coordinate = point;
super(5);
coordinates[0].coordinate = point;
- value =
String.valueOf(character)
;
+ value =
character
;
this.foregroundColor = foregroundColor;
this.foregroundColor = foregroundColor;
- foregroundAwtColor = foregroundColor.toAwtColor();
this.backgroundColor = backgroundColor;
this.backgroundColor = backgroundColor;
@@
-61,6
+72,16
@@
public class CanvasCharacter extends AbstractCoordinateShape {
}
}
}
}
+ /**
+ * Returns a font of the specified size.
+ * <p>
+ * If the font of the specified size is already cached, it will be
+ * returned. Otherwise, a new font will be created, cached and returned.
+ *
+ *
+ * @param size the size of the font
+ * @return the font
+ */
public static Font getFont(final int size) {
if (fonts[size] != null)
return fonts[size];
public static Font getFont(final int size) {
if (fonts[size] != null)
return fonts[size];
@@
-70,23
+91,36
@@
public class CanvasCharacter extends AbstractCoordinateShape {
return font;
}
return font;
}
+ /**
+ * Returns color of the background.
+ */
public eu.svjatoslav.sixth.e3d.renderer.raster.Color getBackgroundColor() {
return backgroundColor;
}
public eu.svjatoslav.sixth.e3d.renderer.raster.Color getBackgroundColor() {
return backgroundColor;
}
+ /**
+ * Sets color of the background.
+ */
public void setBackgroundColor(
final eu.svjatoslav.sixth.e3d.renderer.raster.Color backgroundColor) {
this.backgroundColor = backgroundColor;
}
public void setBackgroundColor(
final eu.svjatoslav.sixth.e3d.renderer.raster.Color backgroundColor) {
this.backgroundColor = backgroundColor;
}
+ /**
+ * Returns color of the foreground.
+ * @return the color
+ */
public eu.svjatoslav.sixth.e3d.renderer.raster.Color getForegroundColor() {
return foregroundColor;
}
public eu.svjatoslav.sixth.e3d.renderer.raster.Color getForegroundColor() {
return foregroundColor;
}
+ /**
+ * Sets color of the foreground.
+ * @param foregroundColor the color
+ */
public void setForegroundColor(
final eu.svjatoslav.sixth.e3d.renderer.raster.Color foregroundColor) {
this.foregroundColor = foregroundColor;
public void setForegroundColor(
final eu.svjatoslav.sixth.e3d.renderer.raster.Color foregroundColor) {
this.foregroundColor = foregroundColor;
- foregroundAwtColor = foregroundColor.toAwtColor();
}
@Override
}
@Override
@@
-124,16
+158,16
@@
public class CanvasCharacter extends AbstractCoordinateShape {
return;
renderingContext.graphics.setFont(getFont(size));
return;
renderingContext.graphics.setFont(getFont(size));
- renderingContext.graphics.setColor(foreground
AwtColor
);
+ renderingContext.graphics.setColor(foreground
Color.toAwtColor()
);
renderingContext.graphics.drawString(
renderingContext.graphics.drawString(
- value,
+ value
Of(value)
,
(int) onScreenLocation.x - (int) (size / 3.2),
(int) onScreenLocation.y + (int) (size / 2.5));
}
public void setValue(final char value) {
(int) onScreenLocation.x - (int) (size / 3.2),
(int) onScreenLocation.y + (int) (size / 2.5));
}
public void setValue(final char value) {
- this.value =
String.valueOf(value)
;
+ this.value =
value
;
}
}
}
}
diff --git
a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/TextCanvas.java
b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/TextCanvas.java
index
8c3e49f
..
4ffef13
100644
(file)
--- a/
src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/TextCanvas.java
+++ b/
src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/TextCanvas.java
@@
-186,7
+186,6
@@
public class TextCanvas extends TexturedRectangle {
new char[]{character,}, 0, 1,
(column * FONT_CHAR_WIDTH_TEXTURE_PIXELS),
(row * FONT_CHAR_HEIGHT_TEXTURE_PIXELS) + (int) (FONT_CHAR_HEIGHT_TEXTURE_PIXELS / 1.23f));
new char[]{character,}, 0, 1,
(column * FONT_CHAR_WIDTH_TEXTURE_PIXELS),
(row * FONT_CHAR_HEIGHT_TEXTURE_PIXELS) + (int) (FONT_CHAR_HEIGHT_TEXTURE_PIXELS / 1.23f));
-
getTexture().resetResampledBitmapCache();
}
getTexture().resetResampledBitmapCache();
}
diff --git
a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/package-info.java
b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/package-info.java
index
3d5e87e
..
cb4f6be
100644
(file)
--- a/
src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/package-info.java
+++ b/
src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/package-info.java
@@
-3,7
+3,7
@@
* This project is released under Creative Commons Zero (CC0) license.
* <p>
*
* This project is released under Creative Commons Zero (CC0) license.
* <p>
*
- * Text canvas is a canvas that can be used to render text.
+ * Text canvas is a
2D
canvas that can be used to render text.
*/
package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.textcanvas;
\ No newline at end of file
*/
package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.textcanvas;
\ No newline at end of file