projects
/
sixth-3d.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
324c5f8
)
Improved code readability
author
Svjatoslav Agejenko
<svjatoslav@svjatoslav.eu>
Tue, 23 May 2023 20:55:03 +0000
(23:55 +0300)
committer
Svjatoslav Agejenko
<svjatoslav@svjatoslav.eu>
Tue, 23 May 2023 20:55:03 +0000
(23:55 +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/RenderMode.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
b181226
..
a616dae
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,6
+12,9
@@
import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.solidpolygon.SolidPo
import java.awt.*;
import java.awt.*;
+import static eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.solidpolygon.SolidPolygon.drawPolygon;
+import static eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.textcanvas.TextCanvas.FONT_CHAR_HEIGHT;
+import static eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.textcanvas.TextCanvas.FONT_CHAR_WIDTH;
import static java.lang.String.valueOf;
/**
import static java.lang.String.valueOf;
/**
@@
-31,53
+34,55
@@
public class CanvasCharacter extends AbstractCoordinateShape {
*/
private char value;
*/
private char value;
+ /**
+ * The foreground color of the character.
+ */
private eu.svjatoslav.sixth.e3d.renderer.raster.Color foregroundColor;
private eu.svjatoslav.sixth.e3d.renderer.raster.Color foregroundColor;
+ /**
+ * The background color of the character.
+ */
private eu.svjatoslav.sixth.e3d.renderer.raster.Color backgroundColor;
private eu.svjatoslav.sixth.e3d.renderer.raster.Color backgroundColor;
- public CanvasCharacter(final Point3D
point
, final char character,
+ public CanvasCharacter(final Point3D
centerLocation
, final char character,
final eu.svjatoslav.sixth.e3d.renderer.raster.Color foregroundColor,
final eu.svjatoslav.sixth.e3d.renderer.raster.Color backgroundColor) {
final eu.svjatoslav.sixth.e3d.renderer.raster.Color foregroundColor,
final eu.svjatoslav.sixth.e3d.renderer.raster.Color backgroundColor) {
+ // There are 5 coordinates: center, upper left, upper right, lower right, lower left
super(5);
super(5);
- coordinates[0].coordinate = point;
value = character;
value = character;
-
this.foregroundColor = foregroundColor;
this.foregroundColor = foregroundColor;
-
this.backgroundColor = backgroundColor;
this.backgroundColor = backgroundColor;
- // set corner coordinates (for drawing background)
- {
- final double widthHalf = TextCanvas.FONT_CHAR_WIDTH / 2d;
- final double heightHalf = TextCanvas.FONT_CHAR_HEIGHT / 2d;
- // upper left
- coordinates[1].coordinate = point.clone().translateX(-widthHalf)
- .translateY(-heightHalf);
+ coordinates[0].coordinate = centerLocation;
+
+ final double halfWidth = FONT_CHAR_WIDTH / 2d;
+ final double halfHeight = FONT_CHAR_HEIGHT / 2d;
-
// upper righ
t
-
coordinates[2].coordinate = point.clone().translateX(widthHalf
)
-
.translateY(-heightHalf
);
+
// upper lef
t
+
coordinates[1].coordinate = centerLocation.clone().translateX(-halfWidth
)
+
.translateY(-halfHeight
);
-
// low
er right
-
coordinates[3].coordinate = point.clone().translateX(widthHalf
)
-
.translateY(heightHalf
);
+
// upp
er right
+
coordinates[2].coordinate = centerLocation.clone().translateX(halfWidth
)
+
.translateY(-halfHeight
);
-
// lower lef
t
-
coordinates[4].coordinate = point.clone().translateX(-widthHalf
)
-
.translateY(heightHalf
);
+
// lower righ
t
+
coordinates[3].coordinate = centerLocation.clone().translateX(halfWidth
)
+
.translateY(halfHeight
);
- }
+ // lower left
+ coordinates[4].coordinate = centerLocation.clone().translateX(-halfWidth)
+ .translateY(halfHeight);
}
/**
* Returns a font of the specified size.
* <p>
}
/**
* 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.
- *
+ * 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
*
* @param size the size of the font
* @return the font
@@
-108,6
+113,7
@@
public class CanvasCharacter extends AbstractCoordinateShape {
/**
* Returns color of the foreground.
/**
* Returns color of the foreground.
+ *
* @return the color
*/
public eu.svjatoslav.sixth.e3d.renderer.raster.Color getForegroundColor() {
* @return the color
*/
public eu.svjatoslav.sixth.e3d.renderer.raster.Color getForegroundColor() {
@@
-116,6
+122,7
@@
public class CanvasCharacter extends AbstractCoordinateShape {
/**
* Sets color of the foreground.
/**
* Sets color of the foreground.
+ *
* @param foregroundColor the color
*/
public void setForegroundColor(
* @param foregroundColor the color
*/
public void setForegroundColor(
@@
-123,25
+130,32
@@
public class CanvasCharacter extends AbstractCoordinateShape {
this.foregroundColor = foregroundColor;
}
this.foregroundColor = foregroundColor;
}
+ /**
+ * Paints the character on the screen.
+ * @param renderingContext the rendering context
+ */
@Override
public void paint(final RenderingContext renderingContext) {
@Override
public void paint(final RenderingContext renderingContext) {
- SolidPolygon.drawPolygon(renderingContext,
+ // Draw background rectangle first. It is composed of two triangles.
+ drawPolygon(renderingContext,
coordinates[1].onScreenCoordinate,
coordinates[2].onScreenCoordinate,
coordinates[1].onScreenCoordinate,
coordinates[2].onScreenCoordinate,
- coordinates[3].onScreenCoordinate, mouseInteractionController,
+ coordinates[3].onScreenCoordinate,
+ mouseInteractionController,
backgroundColor);
backgroundColor);
-
SolidPolygon.
drawPolygon(renderingContext,
+ drawPolygon(renderingContext,
coordinates[1].onScreenCoordinate,
coordinates[3].onScreenCoordinate,
coordinates[1].onScreenCoordinate,
coordinates[3].onScreenCoordinate,
- coordinates[4].onScreenCoordinate, mouseInteractionController,
+ coordinates[4].onScreenCoordinate,
+ mouseInteractionController,
backgroundColor);
backgroundColor);
- final int
s
ize = (int) ((renderingContext.width * 4.5) / onScreenZ);
+ final int
desiredFontS
ize = (int) ((renderingContext.width * 4.5) / onScreenZ);
// do not render too large characters
// do not render too large characters
- if (
s
ize >= MAX_FONT_SIZE)
+ if (
desiredFontS
ize >= MAX_FONT_SIZE)
return;
final Point2D onScreenLocation = coordinates[0].onScreenCoordinate;
return;
final Point2D onScreenLocation = coordinates[0].onScreenCoordinate;
@@
-157,12
+171,13
@@
public class CanvasCharacter extends AbstractCoordinateShape {
if (onScreenLocation.y > renderingContext.height)
return;
if (onScreenLocation.y > renderingContext.height)
return;
- renderingContext.graphics.setFont(getFont(size));
+ // draw the character
+ renderingContext.graphics.setFont(getFont(desiredFontSize));
renderingContext.graphics.setColor(foregroundColor.toAwtColor());
renderingContext.graphics.drawString(
valueOf(value),
renderingContext.graphics.setColor(foregroundColor.toAwtColor());
renderingContext.graphics.drawString(
valueOf(value),
- (int) onScreenLocation.x - (int) (
s
ize / 3.2),
- (int) onScreenLocation.y + (int) (
s
ize / 2.5));
+ (int) onScreenLocation.x - (int) (
desiredFontS
ize / 3.2),
+ (int) onScreenLocation.y + (int) (
desiredFontS
ize / 2.5));
}
}
diff --git
a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/RenderMode.java
b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/RenderMode.java
index
0379ab5
..
1aeb9a8
100644
(file)
--- a/
src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/RenderMode.java
+++ b/
src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/RenderMode.java
@@
-6,12
+6,14
@@
package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.textcanvas;
public enum RenderMode {
/**
public enum RenderMode {
/**
- * Text is rendered as a textured polygon.
+ * Text is rendered as pixels on textured polygon.
+ * This mode works in any orientation. Even if polygon is rotated.
*/
TEXTURE,
/**
*/
TEXTURE,
/**
- * Text is rendered as high quality, anti-aliazed tiles.
+ * Text is rendered as high quality, anti-aliased tiles.
+ * This mode works only if text is facing the camera almost directly.
*/
CHARACTERS
}
*/
CHARACTERS
}