2 * Sixth 3D engine. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
5 package eu.svjatoslav.sixth.e3d.gui;
7 import eu.svjatoslav.sixth.e3d.geometry.Box;
8 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
9 import eu.svjatoslav.sixth.e3d.gui.humaninput.KeyboardHelper;
10 import eu.svjatoslav.sixth.e3d.gui.humaninput.KeyboardInputHandler;
11 import eu.svjatoslav.sixth.e3d.gui.humaninput.MouseInteractionController;
12 import eu.svjatoslav.sixth.e3d.math.Transform;
13 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.line.LineAppearance;
14 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape;
15 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.wireframe.WireframeBox;
17 import java.awt.event.KeyEvent;
19 public class GuiComponent extends AbstractCompositeShape implements
20 KeyboardInputHandler, MouseInteractionController {
22 private static final String GROUP_GUI_FOCUS = "gui.focus";
23 public final ViewPanel viewPanel;
24 Box containingBox = new Box();
25 private WireframeBox borders = null;
27 private boolean borderShown = false;
29 public GuiComponent(final Transform transform,
30 final ViewPanel viewPanel, final Point3D size) {
32 this.viewPanel = viewPanel;
36 private WireframeBox createBorder() {
37 final LineAppearance appearance = new LineAppearance(10,
38 new eu.svjatoslav.sixth.e3d.renderer.raster.Color(255, 0, 0, 100));
40 final double borderSize = 10;
42 final Box borderArea = containingBox.clone().enlarge(borderSize);
44 return new WireframeBox(borderArea, appearance);
48 public boolean focusLost(final ViewPanel viewPanel) {
54 public boolean focusReceived(final ViewPanel viewPanel) {
59 public WireframeBox getBorders() {
61 borders = createBorder();
65 public int getDepth() {
66 return (int) containingBox.getDepth();
69 public int getHeight() {
70 return (int) containingBox.getHeight();
73 public int getWidth() {
74 return (int) containingBox.getWidth();
77 public void hideBorder() {
81 removeGroup(GROUP_GUI_FOCUS);
85 public boolean keyPressed(final KeyEvent event, final ViewPanel viewPanel) {
86 if (event.getKeyChar() == KeyboardHelper.ESC)
87 viewPanel.getKeyboardFocusStack().popFocusOwner();
92 public boolean keyReleased(final KeyEvent event, final ViewPanel viewPanel) {
97 public boolean mouseClicked(int button) {
98 return viewPanel.getKeyboardFocusStack().pushFocusOwner(this);
102 public boolean mouseEntered() {
107 public boolean mouseExited() {
111 private void setDimensions(final Point3D size) {
112 containingBox.setBoxSize(size);
115 private void showBorder() {
119 addShape(getBorders(), GROUP_GUI_FOCUS);