2 * Sixth 3D engine. Copyright ©2012-2019, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
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.
10 package eu.svjatoslav.sixth.e3d.gui;
12 import eu.svjatoslav.sixth.e3d.geometry.Box;
13 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
14 import eu.svjatoslav.sixth.e3d.gui.humaninput.MouseInteractionController;
15 import eu.svjatoslav.sixth.e3d.gui.humaninput.UserInputHandler;
16 import eu.svjatoslav.sixth.e3d.gui.textEditorComponent.KeyboardHelper;
17 import eu.svjatoslav.sixth.e3d.math.Transform;
18 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.line.LineAppearance;
19 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape;
20 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.wireframe.WireframeBox;
22 import java.awt.event.KeyEvent;
24 public class GuiComponent extends AbstractCompositeShape implements
25 UserInputHandler, MouseInteractionController {
27 private static final String GROUP_GUI_FOCUS = "gui.focus";
28 public final ViewPanel viewPanel;
29 Box containingBox = new Box();
30 private WireframeBox borders = null;
32 private boolean borderShown = false;
34 public GuiComponent(final Transform transform,
35 final ViewPanel viewPanel, final Point3D size) {
37 this.viewPanel = viewPanel;
42 public boolean beforeRender(final ViewPanel viewPanel,
43 final int millisecondsSinceLastFrame) {
47 private WireframeBox createBorder() {
48 final LineAppearance appearance = new LineAppearance(10,
49 new eu.svjatoslav.sixth.e3d.renderer.raster.Color(255, 0, 0, 100));
51 final double borderSize = 10;
53 final Box borderArea = containingBox.clone().addBorder(borderSize);
55 return new WireframeBox(borderArea, appearance);
59 public boolean focusLost(final ViewPanel viewPanel) {
65 public boolean focusReceived(final ViewPanel viewPanel) {
70 public WireframeBox getBorders() {
72 borders = createBorder();
76 public int getDepth() {
77 return (int) containingBox.getDepth();
80 public int getHeight() {
81 return (int) containingBox.getHeight();
84 public int getWidth() {
85 return (int) containingBox.getWidth();
88 public void hideBorder() {
92 removeGroup(GROUP_GUI_FOCUS);
96 public boolean keyPressed(final KeyEvent event, final ViewPanel viewPanel) {
97 if (event.getKeyChar() == KeyboardHelper.ESC)
98 viewPanel.getKeyboardFocusStack().popFocusOwner();
103 public boolean keyReleased(final KeyEvent event, final ViewPanel viewPanel) {
108 public boolean mouseClicked() {
109 return viewPanel.getKeyboardFocusStack().pushFocusOwner(this);
113 public boolean mouseEntered() {
118 public boolean mouseExited() {
122 private void setDimensions(final Point3D size) {
123 containingBox.setSizeCentered(size);
126 private void showBorder() {
130 addShape(getBorders(), GROUP_GUI_FOCUS);