2 * Sixth 3D engine. Copyright ©2012-2018, 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.geometry.Transform;
15 import eu.svjatoslav.sixth.e3d.gui.humaninput.MouseInteractionController;
16 import eu.svjatoslav.sixth.e3d.gui.humaninput.UserInputHandler;
17 import eu.svjatoslav.sixth.e3d.gui.textEditorComponent.KeyboardHelper;
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 ViewContext viewContext;
29 Box containingBox = new Box();
30 private WireframeBox borders = null;
32 private boolean borderShown = false;
34 public GuiComponent(final Transform transform,
35 final ViewContext viewContext, final Point3D size) {
37 this.viewContext = viewContext;
42 public boolean beforeViewUpdate(final ViewContext viewContext,
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 void focusLost(final ViewContext viewContext) {
64 public void focusReceived(final ViewContext viewContext) {
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 void keyPressed(final KeyEvent event, final ViewContext viewContext) {
95 if (event.getKeyChar() == KeyboardHelper.ESC)
96 viewContext.getKeyboardFocusTracker().popFocusOwner();
100 public void keyReleased(final KeyEvent event, final ViewContext viewContext) {
104 public void mouseClicked() {
105 viewContext.getKeyboardFocusTracker().setFocusOwner(this);
109 public void mouseEntered() {
113 public void mouseExited() {
116 private void setDimensions(final Point3D size) {
117 containingBox.setSizeCentered(size);
120 public void showBorder() {
124 addShape(getBorders(), GROUP_GUI_FOCUS);