Removed ViewListener interface. Renamed View to ViewPanel.
[sixth-3d-demos.git] / src / main / java / eu / svjatoslav / sixth / e3d / examples / TextEditorDemo.java
1 /*
2  * Sixth 3D engine demos. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of version 3 of the GNU Lesser General Public License
6  * or later as published by the Free Software Foundation.
7  */
8
9 package eu.svjatoslav.sixth.e3d.examples;
10
11 import eu.svjatoslav.sixth.e3d.geometry.Point2D;
12 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
13 import eu.svjatoslav.sixth.e3d.geometry.Rectangle;
14 import eu.svjatoslav.sixth.e3d.math.Transform;
15 import eu.svjatoslav.sixth.e3d.gui.ViewContext;
16 import eu.svjatoslav.sixth.e3d.gui.ViewFrame;
17 import eu.svjatoslav.sixth.e3d.gui.textEditorComponent.TextEditComponent;
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     private static Grid2D createGrid() {
26         final Transform transform = new Transform(new Point3D(0, 100, 0), 0,
27                 Math.PI / 2);
28
29         final Rectangle rectangle = new Rectangle(2000);
30         final LineAppearance appearance = new LineAppearance(10, new Color(
31                 "00b3ad"));
32
33         return new Grid2D(transform, rectangle, 10, 10, appearance);
34     }
35
36     public static void main(final String[] args) {
37
38         final ViewFrame viewFrame = new ViewFrame();
39         final ViewContext viewContext = viewFrame.getViewPanel().getContext();
40
41         final ShapeCollection shapeCollection = viewFrame.getViewPanel()
42                 .getContext().getRootShapeCollection();
43
44         shapeCollection.addShape(createGrid());
45
46         final double m = 1.5;
47         for (double z = -500 * m; z <= (500 * m); z += 250 * m)
48             for (double x = -500 * m; x <= (500 * m); x += 250 * m) {
49
50                 final TextEditComponent textEditor = new TextEditComponent(
51                         new Transform(new Point3D(x, 0, z)), viewContext,
52                         new Point2D(200, 120));
53
54                 shapeCollection.addShape(textEditor);
55             }
56
57         viewContext.getAvatar().setLocation(new Point3D(500, -300, -800));
58         viewContext.getAvatar().setAngleXZ(0.6);
59         viewContext.getAvatar().setAngleYZ(-0.5);
60
61     }
62 }