Improved code readability
[sixth-3d-demos.git] / src / main / java / eu / svjatoslav / sixth / e3d / examples / TextEditorDemo.java
1 /*
2  * Sixth 3D engine demos. Author: Svjatoslav Agejenko. 
3  * This project is released under Creative Commons Zero (CC0) license.
4  *
5 */
6
7 package eu.svjatoslav.sixth.e3d.examples;
8
9 import eu.svjatoslav.sixth.e3d.geometry.Point2D;
10 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
11 import eu.svjatoslav.sixth.e3d.geometry.Rectangle;
12 import eu.svjatoslav.sixth.e3d.gui.Avatar;
13 import eu.svjatoslav.sixth.e3d.gui.ViewFrame;
14 import eu.svjatoslav.sixth.e3d.gui.ViewPanel;
15 import eu.svjatoslav.sixth.e3d.gui.textEditorComponent.LookAndFeel;
16 import eu.svjatoslav.sixth.e3d.gui.textEditorComponent.TextEditComponent;
17 import eu.svjatoslav.sixth.e3d.math.Transform;
18 import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
19 import eu.svjatoslav.sixth.e3d.renderer.raster.ShapeCollection;
20 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.line.LineAppearance;
21 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.wireframe.Grid2D;
22
23 public class TextEditorDemo {
24
25     public static void main(final String[] args) {
26
27         final ViewFrame viewFrame = new ViewFrame();
28         final ViewPanel viewPanel = viewFrame.getViewPanel();
29
30         final ShapeCollection shapeCollection = viewFrame.getViewPanel()
31                 .getRootShapeCollection();
32
33         setAvatarLocation(viewPanel);
34
35         addGrid(shapeCollection);
36
37         addTextEditors(viewPanel, shapeCollection);
38     }
39
40     private static void addGrid(ShapeCollection shapeCollection) {
41         final Transform transform = new Transform(new Point3D(0, 100, 0), 0,
42                 Math.PI / 2);
43
44         final Rectangle rectangle = new Rectangle(2000);
45         final LineAppearance appearance = new LineAppearance(10, new Color(
46                 "00b3ad"));
47
48         shapeCollection.addShape(new Grid2D(transform, rectangle, 10, 10, appearance));
49     }
50
51     private static void addTextEditors(ViewPanel viewPanel, ShapeCollection shapeCollection) {
52         final double m = 1.5;
53         for (double z = -500 * m; z <= (500 * m); z += 250 * m)
54             for (double x = -500 * m; x <= (500 * m); x += 250 * m) {
55
56                 final TextEditComponent textEditor = new TextEditComponent(
57                         new Transform(new Point3D(x, 0, z)), viewPanel,
58                         new Point2D(200, 120), new LookAndFeel());
59
60                 shapeCollection.addShape(textEditor);
61             }
62     }
63
64     private static void setAvatarLocation(ViewPanel viewPanel) {
65         Avatar avatar = viewPanel.getAvatar();
66         avatar.setLocation(new Point3D(500, -300, -800));
67         avatar.setAngleXZ(0.6);
68         avatar.setAngleYZ(-0.5);
69     }
70 }