2 * Sixth 3D engine. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
8 package eu.svjatoslav.sixth.e3d.gui;
10 import eu.svjatoslav.sixth.e3d.geometry.Box;
11 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
12 import eu.svjatoslav.sixth.e3d.gui.humaninput.MouseInteractionController;
13 import eu.svjatoslav.sixth.e3d.gui.humaninput.UserInputHandler;
14 import eu.svjatoslav.sixth.e3d.gui.textEditorComponent.KeyboardHelper;
15 import eu.svjatoslav.sixth.e3d.math.Transform;
16 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.line.LineAppearance;
17 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape;
18 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.wireframe.WireframeBox;
20 import java.awt.event.KeyEvent;
22 public class GuiComponent extends AbstractCompositeShape implements
23 UserInputHandler, MouseInteractionController {
25 private static final String GROUP_GUI_FOCUS = "gui.focus";
26 public final ViewPanel viewPanel;
27 Box containingBox = new Box();
28 private WireframeBox borders = null;
30 private boolean borderShown = false;
32 public GuiComponent(final Transform transform,
33 final ViewPanel viewPanel, final Point3D size) {
35 this.viewPanel = viewPanel;
40 public boolean beforeRender(final ViewPanel viewPanel,
41 final int millisecondsSinceLastFrame) {
45 private WireframeBox createBorder() {
46 final LineAppearance appearance = new LineAppearance(10,
47 new eu.svjatoslav.sixth.e3d.renderer.raster.Color(255, 0, 0, 100));
49 final double borderSize = 10;
51 final Box borderArea = containingBox.clone().addBorder(borderSize);
53 return new WireframeBox(borderArea, appearance);
57 public boolean focusLost(final ViewPanel viewPanel) {
63 public boolean focusReceived(final ViewPanel viewPanel) {
68 public WireframeBox getBorders() {
70 borders = createBorder();
74 public int getDepth() {
75 return (int) containingBox.getDepth();
78 public int getHeight() {
79 return (int) containingBox.getHeight();
82 public int getWidth() {
83 return (int) containingBox.getWidth();
86 public void hideBorder() {
90 removeGroup(GROUP_GUI_FOCUS);
94 public boolean keyPressed(final KeyEvent event, final ViewPanel viewPanel) {
95 if (event.getKeyChar() == KeyboardHelper.ESC)
96 viewPanel.getKeyboardFocusStack().popFocusOwner();
101 public boolean keyReleased(final KeyEvent event, final ViewPanel viewPanel) {
106 public boolean mouseClicked() {
107 return viewPanel.getKeyboardFocusStack().pushFocusOwner(this);
111 public boolean mouseEntered() {
116 public boolean mouseExited() {
120 private void setDimensions(final Point3D size) {
121 containingBox.setSizeCentered(size);
124 private void showBorder() {
128 addShape(getBorders(), GROUP_GUI_FOCUS);