}
@Override
- public boolean beforeRender(final ViewContext viewContext, final int millisecondsSinceLastFrame) {
+ public boolean beforeRender(final ViewPanel viewPanel, final int millisecondsSinceLastFrame) {
final Point3D locationBeforeUpdate = new Point3D(location);
translateAvatarLocation(millisecondsSinceLastFrame);
UserInputHandler, MouseInteractionController {
private static final String GROUP_GUI_FOCUS = "gui.focus";
- public final ViewContext viewContext;
+ public final ViewPanel viewPanel;
Box containingBox = new Box();
private WireframeBox borders = null;
private boolean borderShown = false;
public GuiComponent(final Transform transform,
- final ViewContext viewContext, final Point3D size) {
+ final ViewPanel viewPanel, final Point3D size) {
super(transform);
- this.viewContext = viewContext;
+ this.viewPanel = viewPanel;
setDimensions(size);
}
@Override
- public boolean beforeRender(final ViewContext viewContext,
+ public boolean beforeRender(final ViewPanel viewPanel,
final int millisecondsSinceLastFrame) {
return false;
}
}
@Override
- public void focusLost(final ViewContext viewContext) {
+ public void focusLost(final ViewPanel viewPanel) {
hideBorder();
}
@Override
- public void focusReceived(final ViewContext viewContext) {
+ public void focusReceived(final ViewPanel viewPanel) {
showBorder();
}
}
@Override
- public void keyPressed(final KeyEvent event, final ViewContext viewContext) {
+ public void keyPressed(final KeyEvent event, final ViewPanel viewPanel) {
if (event.getKeyChar() == KeyboardHelper.ESC)
- viewContext.getKeyboardFocusTracker().popFocusOwner();
+ viewPanel.getKeyboardFocusTracker().popFocusOwner();
}
@Override
- public void keyReleased(final KeyEvent event, final ViewContext viewContext) {
+ public void keyReleased(final KeyEvent event, final ViewPanel viewPanel) {
}
@Override
public void mouseClicked() {
- viewContext.getKeyboardFocusTracker().setFocusOwner(this);
+ viewPanel.getKeyboardFocusTracker().setFocusOwner(this);
}
@Override
+++ /dev/null
-/*
- * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 3 of the GNU Lesser General Public License
- * or later as published by the Free Software Foundation.
- *
- */
-
-package eu.svjatoslav.sixth.e3d.gui;
-
-import eu.svjatoslav.sixth.e3d.gui.humaninput.KeyboardFocusTracker;
-import eu.svjatoslav.sixth.e3d.gui.humaninput.UserInputTracker;
-import eu.svjatoslav.sixth.e3d.renderer.raster.ShapeCollection;
-
-public class ViewContext {
-
- private final UserInputTracker userInputTracker = new UserInputTracker(this);
-
- private final KeyboardFocusTracker keyboardFocusTracker = new KeyboardFocusTracker(
- this);
-
- private final Avatar avatar = new Avatar();
-
- private final ViewPanel viewPanel;
-
- private final ShapeCollection rootShapeCollection = new ShapeCollection();
-
- public ViewContext(final ViewPanel viewPanel) {
- this.viewPanel = viewPanel;
- }
-
- public Avatar getAvatar() {
- return avatar;
- }
-
- public KeyboardFocusTracker getKeyboardFocusTracker() {
- return keyboardFocusTracker;
- }
-
- public ShapeCollection getRootShapeCollection() {
- return rootShapeCollection;
- }
-
- public UserInputTracker getUserInputTracker() {
- return userInputTracker;
- }
-
- public ViewPanel getViewPanel() {
- return viewPanel;
- }
-
-}
package eu.svjatoslav.sixth.e3d.gui;
+import eu.svjatoslav.sixth.e3d.gui.humaninput.KeyboardFocusTracker;
import eu.svjatoslav.sixth.e3d.gui.humaninput.MouseInteractionController;
+import eu.svjatoslav.sixth.e3d.gui.humaninput.UserInputTracker;
+import eu.svjatoslav.sixth.e3d.renderer.raster.ShapeCollection;
import javax.swing.*;
import java.awt.*;
import java.util.Timer;
public class ViewPanel extends JPanel implements ComponentListener {
+ private final UserInputTracker userInputTracker = new UserInputTracker(this);
+
+ private final KeyboardFocusTracker keyboardFocusTracker = new KeyboardFocusTracker(
+ this);
+
+ private final Avatar avatar = new Avatar();
+
+ private final ShapeCollection rootShapeCollection = new ShapeCollection();
+
+
+ public Avatar getAvatar() {
+ return avatar;
+ }
+
+ public KeyboardFocusTracker getKeyboardFocusTracker() {
+ return keyboardFocusTracker;
+ }
+
+ public ShapeCollection getRootShapeCollection() {
+ return rootShapeCollection;
+ }
+
+ public UserInputTracker getUserInputTracker() {
+ return userInputTracker;
+ }
private static final long serialVersionUID = 1683277888885045387L;
private final List<ViewRenderListener> viewRenderListeners = new ArrayList<>();
- private final ViewContext context = new ViewContext(this);
/**
* Last time this view was updated.
*/
private boolean viewRepaintNeeded = true;
public ViewPanel() {
- viewRenderListeners.add(context.getAvatar());
-
- // initialize input tracker
- context.getUserInputTracker().bind(this);
- viewRenderListeners.add(context.getUserInputTracker());
+ viewRenderListeners.add(avatar);
+ viewRenderListeners.add(userInputTracker);
initializePanelLayout();
viewRepaintNeeded = true;
}
- public ViewContext getContext() {
- return context;
- }
-
@Override
public Dimension getMaximumSize() {
return getPreferredSize();
}
// paint root geometry collection to the offscreen render buffer
- context.getRootShapeCollection().paint(context, renderingContext);
+ rootShapeCollection.paint(this, renderingContext);
// draw rendered offscreen image to visible screen
final Graphics graphics = getGraphics();
boolean reRenderFrame = false;
for (final ViewRenderListener listener : viewRenderListeners)
- if (listener.beforeRender(context,
- millisecondsPassedSinceLastUpdate))
+ if (listener.beforeRender(this, millisecondsPassedSinceLastUpdate))
reRenderFrame = true;
// abort rendering if window size is invalid
* @return <code>true</code> if underlying view shall be re-rendered. If at least one of the view update listeners
* returns <code>true</code>, view is re-rendered.
*/
- boolean beforeRender(ViewContext viewContext, final int millisecondsSinceLastFrame);
+ boolean beforeRender(ViewPanel viewPanel, final int millisecondsSinceLastFrame);
}
package eu.svjatoslav.sixth.e3d.gui.humaninput;
-import eu.svjatoslav.sixth.e3d.gui.ViewContext;
+import eu.svjatoslav.sixth.e3d.gui.ViewPanel;
import java.util.Stack;
public class KeyboardFocusTracker {
- private final ViewContext viewContext;
+ private final ViewPanel viewPanel;
WorldNavigationTracker defaultInputHandler = new WorldNavigationTracker();
Stack<UserInputHandler> inputHandlers = new Stack<>();
private UserInputHandler currentUserInputHandler;
- public KeyboardFocusTracker(final ViewContext viewContext) {
- this.viewContext = viewContext;
+ public KeyboardFocusTracker(final ViewPanel viewPanel) {
+ this.viewPanel = viewPanel;
setFocusOwner(defaultInputHandler);
}
if (inputHandlers.isEmpty())
return;
- currentUserInputHandler.focusLost(viewContext);
+ currentUserInputHandler.focusLost(viewPanel);
currentUserInputHandler = inputHandlers.pop();
- currentUserInputHandler.focusReceived(viewContext);
+ currentUserInputHandler.focusReceived(viewPanel);
}
public void setFocusOwner(final UserInputHandler inputHandler) {
return;
if (currentUserInputHandler != null) {
- currentUserInputHandler.focusLost(viewContext);
+ currentUserInputHandler.focusLost(viewPanel);
inputHandlers.push(currentUserInputHandler);
}
currentUserInputHandler = inputHandler;
- currentUserInputHandler.focusReceived(viewContext);
+ currentUserInputHandler.focusReceived(viewPanel);
}
}
package eu.svjatoslav.sixth.e3d.gui.humaninput;
-import eu.svjatoslav.sixth.e3d.gui.ViewContext;
+import eu.svjatoslav.sixth.e3d.gui.ViewPanel;
import eu.svjatoslav.sixth.e3d.gui.ViewRenderListener;
import java.awt.event.KeyEvent;
public interface UserInputHandler extends ViewRenderListener {
- void focusLost(ViewContext viewContext);
+ void focusLost(ViewPanel viewPanel);
- void focusReceived(ViewContext viewContext);
+ void focusReceived(ViewPanel viewPanel);
- void keyPressed(KeyEvent event, ViewContext viewContext);
+ void keyPressed(KeyEvent event, ViewPanel viewPanel);
- void keyReleased(KeyEvent event, ViewContext viewContext);
+ void keyReleased(KeyEvent event, ViewPanel viewPanel);
}
import eu.svjatoslav.sixth.e3d.geometry.Point2D;
import eu.svjatoslav.sixth.e3d.gui.Avatar;
import eu.svjatoslav.sixth.e3d.gui.ViewPanel;
-import eu.svjatoslav.sixth.e3d.gui.ViewContext;
import eu.svjatoslav.sixth.e3d.gui.ViewRenderListener;
import javax.swing.*;
private int wheelMovedDirection = 0;
private Point2D mouseDraggedDirection = new Point2D();
private Point2D oldMouseCoordinatesWhenDragging;
- private ViewContext viewContext;
+ private ViewPanel viewPanel;
private Point2D currentMouseLocation;
private boolean mouseMoved;
private boolean mouseWithinWindow = false;
- public UserInputTracker(final ViewContext viewContext) {
- this.viewContext = viewContext;
+ public UserInputTracker(final ViewPanel viewPanel) {
+ this.viewPanel = viewPanel;
+ bind(viewPanel);
}
/**
* {@inheritDoc}
*/
@Override
- public boolean beforeRender(final ViewContext viewContext, final int millisecondsSinceLastFrame) {
+ public boolean beforeRender(final ViewPanel viewPanel, final int millisecondsSinceLastFrame) {
- boolean viewUpdateNeeded = handleDetectedMouseClicks(viewContext.getViewPanel());
+ boolean viewUpdateNeeded = handleDetectedMouseClicks(viewPanel);
viewUpdateNeeded |= handleDetectedKeyEvents();
- viewContext.getKeyboardFocusTracker().getCurrentFocusOwner().beforeRender(viewContext,
+ viewPanel.getKeyboardFocusTracker().getCurrentFocusOwner().beforeRender(viewPanel,
millisecondsSinceLastFrame);
viewUpdateNeeded |= trackMouse();
return viewUpdateNeeded;
}
- public void bind(final JPanel panel) {
+ private void bind(final JPanel panel) {
panel.addMouseMotionListener(this);
panel.addKeyListener(this);
private boolean handleDetectedKeyEvents() {
boolean keyEventsHandled = false;
- final UserInputHandler currentFocusOwner = viewContext.getKeyboardFocusTracker().getCurrentFocusOwner();
+ final UserInputHandler currentFocusOwner = viewPanel.getKeyboardFocusTracker().getCurrentFocusOwner();
synchronized (detectedKeyEvents) {
if (currentFocusOwner == null) {
switch (keyEvent.getID()) {
case KeyEvent.KEY_PRESSED:
- currentFocusOwner.keyPressed(keyEvent, viewContext);
+ currentFocusOwner.keyPressed(keyEvent, viewPanel);
keyEventsHandled = true;
break;
case KeyEvent.KEY_RELEASED:
- currentFocusOwner.keyReleased(keyEvent, viewContext);
+ currentFocusOwner.keyReleased(keyEvent, viewPanel);
keyEventsHandled = true;
break;
}
synchronized (detectedKeyEvents) {
pressedKeysToPressedTimeMap.put(evt.getKeyCode(), System.currentTimeMillis());
detectedKeyEvents.add(evt);
- viewContext.getViewPanel().repaintDuringNextViewUpdate();
+ viewPanel.repaintDuringNextViewUpdate();
}
}
synchronized (detectedKeyEvents) {
pressedKeysToPressedTimeMap.remove(evt.getKeyCode());
detectedKeyEvents.add(evt);
- viewContext.getViewPanel().repaintDuringNextViewUpdate();
+ viewPanel.repaintDuringNextViewUpdate();
}
}
* Interpret mouse movement
*/
private boolean trackMouse() {
- final Avatar avatar = viewContext.getAvatar();
+ final Avatar avatar = viewPanel.getAvatar();
trackDragging(avatar);
trackVerticalScrolling(avatar);
package eu.svjatoslav.sixth.e3d.gui.humaninput;
import eu.svjatoslav.sixth.e3d.gui.Avatar;
-import eu.svjatoslav.sixth.e3d.gui.ViewContext;
+import eu.svjatoslav.sixth.e3d.gui.ViewPanel;
import eu.svjatoslav.sixth.e3d.gui.textEditorComponent.KeyboardHelper;
import java.awt.event.KeyEvent;
public class WorldNavigationTracker implements UserInputHandler {
@Override
- public boolean beforeRender(final ViewContext viewContext,
+ public boolean beforeRender(final ViewPanel viewPanel,
final int millisecondsSinceLastFrame) {
- trackKeys(millisecondsSinceLastFrame, viewContext);
+ trackKeys(millisecondsSinceLastFrame, viewPanel);
return false;
}
@Override
- public void focusLost(final ViewContext viewContext) {
+ public void focusLost(final ViewPanel viewPanel) {
}
@Override
- public void focusReceived(final ViewContext viewContext) {
+ public void focusReceived(final ViewPanel viewContext) {
}
@Override
- public void keyPressed(final KeyEvent event, final ViewContext viewContext) {
+ public void keyPressed(final KeyEvent event, final ViewPanel viewContext) {
}
@Override
- public void keyReleased(final KeyEvent event, final ViewContext viewContext) {
+ public void keyReleased(final KeyEvent event, final ViewPanel viewContext) {
}
/**
* interpret currently pressed keys
*/
public void trackKeys(final long millisecondsSinceLastFrame,
- final ViewContext viewContext) {
+ final ViewPanel viewContext) {
final UserInputTracker inputTracker = viewContext.getUserInputTracker();
package eu.svjatoslav.sixth.e3d.gui.textEditorComponent;
import eu.svjatoslav.sixth.e3d.geometry.Point2D;
+import eu.svjatoslav.sixth.e3d.gui.ViewPanel;
import eu.svjatoslav.sixth.e3d.math.Transform;
import eu.svjatoslav.sixth.e3d.gui.GuiComponent;
import eu.svjatoslav.sixth.e3d.gui.TextPointer;
-import eu.svjatoslav.sixth.e3d.gui.ViewContext;
import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.textcanvas.TextCanvas;
boolean repaintPage = false;
public TextEditComponent(final Transform transform,
- final ViewContext viewContext, final Point2D size) {
- super(transform, viewContext, size.to3D());
+ final ViewPanel viewPanel, final Point2D size) {
+ super(transform, viewPanel, size.to3D());
cursorLocation = new TextPointer(0, 0);
* Parse key presses.
*/
@Override
- public void keyPressed(final KeyEvent event, final ViewContext viewContext) {
- super.keyPressed(event, viewContext);
+ public void keyPressed(final KeyEvent event, final ViewPanel viewPanel) {
+ super.keyPressed(event, viewPanel);
processKeyEvent(event);
package eu.svjatoslav.sixth.e3d.renderer.raster;
import eu.svjatoslav.sixth.e3d.geometry.Point3D;
-import eu.svjatoslav.sixth.e3d.math.Transform;
-import eu.svjatoslav.sixth.e3d.math.TransformPipe;
import eu.svjatoslav.sixth.e3d.gui.Avatar;
import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
-import eu.svjatoslav.sixth.e3d.gui.ViewContext;
+import eu.svjatoslav.sixth.e3d.gui.ViewPanel;
+import eu.svjatoslav.sixth.e3d.math.Transform;
+import eu.svjatoslav.sixth.e3d.math.TransformPipe;
import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractShape;
import java.util.ArrayList;
shapes.clear();
}
- public synchronized void paint(final ViewContext viewContext,
+ public synchronized void paint(final ViewPanel viewPanel,
final RenderingContext renderingContext) {
renderingContext.frameNumber++;
transformPipe.clear();
// translate scene according to camera current location
- final Avatar avatar = viewContext.getAvatar();
+ final Avatar avatar = viewPanel.getAvatar();
// rotate scene according to avatar looking direction
transformPipe.addTransform(new Transform(new Point3D(), avatar