Skip to content

Commit 89fd3ec

Browse files
author
Informatik User 3
committed
add TestController
1 parent aef6817 commit 89fd3ec

File tree

6 files changed

+242
-4
lines changed

6 files changed

+242
-4
lines changed

src/main/java/com/ivision/gamereact/ReactApplication.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ public void start(Stage stage) throws IOException {
4141

4242
setStage(stage);
4343

44-
FXMLLoader fxmlLoader = new FXMLLoader(ReactApplication.class.getResource("react-main-view.fxml"));
44+
// FXMLLoader fxmlLoader = new FXMLLoader(ReactApplication.class.getResource("react-main-view.fxml"));
45+
FXMLLoader fxmlLoader = new FXMLLoader(ReactApplication.class.getResource("react-test-view.fxml"));
4546
Scene scene = new Scene(fxmlLoader.load(), width, height);
4647
KeyPolling.getInstance().pollScene(scene);
4748

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package com.ivision.gamereact.controller;
2+
3+
import com.ivision.engine.ButtonConfig;
4+
import com.ivision.engine.GameLoopTimer;
5+
import com.ivision.engine.KeyPolling;
6+
import com.ivision.gamereact.model.MarkerListener;
7+
import com.tuio.TuioClient;
8+
import com.tuio.TuioObject;
9+
import javafx.fxml.FXML;
10+
import javafx.fxml.Initializable;
11+
import javafx.scene.Group;
12+
import javafx.scene.layout.Pane;
13+
import javafx.scene.shape.Rectangle;
14+
15+
import java.net.URL;
16+
import java.util.*;
17+
18+
import static com.ivision.gamereact.ReactApplication.stage;
19+
20+
public class TestController extends TuioClient implements Initializable {
21+
22+
@FXML
23+
private Pane root;
24+
private final KeyPolling keys = KeyPolling.getInstance();
25+
private MarkerListener listener;
26+
private GameLoopTimer timer;
27+
28+
@Override
29+
public void initialize(URL location, ResourceBundle resources) {
30+
31+
this.listener = new MarkerListener();
32+
33+
addTuioListener(this.listener);
34+
connect();
35+
36+
this.timer = new GameLoopTimer() {
37+
@Override
38+
public void tick(float secondsSinceLastFrame) {
39+
updateObjects();
40+
getUserInput();
41+
}
42+
};
43+
root.setStyle("-fx-background-color: #2F4F4F");
44+
timer.start();
45+
46+
}
47+
48+
public void updateObjects ()
49+
{
50+
for (Map.Entry<TuioObject, Group> entry : this.listener.getObjectShapes().entrySet())
51+
{
52+
TuioObject marker = entry.getKey();
53+
Group group = entry.getValue();
54+
Rectangle rectangle = (Rectangle) group.getChildren().get(0);
55+
rectangle.setX(-75);
56+
rectangle.setY(-75);
57+
rectangle.setRotate(marker.getAngleDegrees());
58+
group.setTranslateX(root.getWidth()*marker.getX());
59+
group.setTranslateY(root.getHeight()*marker.getY());
60+
61+
if (!this.root.getChildren().contains(group))
62+
{
63+
this.root.getChildren().add(group);
64+
}
65+
66+
}
67+
68+
if(this.root.getChildren().size() != this.listener.getObjectShapes().size())
69+
{
70+
this.root.getChildren().retainAll(this.listener.getObjectShapes().values());
71+
}
72+
73+
}
74+
75+
public void getUserInput () {
76+
77+
// Periodische Tastenabfragen
78+
// z.B. keys.isDown(KeyCode)
79+
80+
81+
// einmalige Tastenabfragen (innerhalb Anschlagverzögerung)
82+
if (keys.isPressed(ButtonConfig.toggleFullscreen)) toggleFullscreen();
83+
84+
}
85+
86+
@FXML
87+
protected void toggleFullscreen() {
88+
89+
stage.setFullScreen(!stage.isFullScreen());
90+
}
91+
92+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.ivision.gamereact.entity.app;
2+
3+
import com.tuio.TuioPoint;
4+
import javafx.scene.shape.Rectangle;
5+
6+
public class ObjectShape extends Rectangle {
7+
8+
private final TuioPoint object;
9+
10+
public ObjectShape (TuioPoint object) {
11+
this.object = object;
12+
}
13+
14+
public TuioPoint getObject() {
15+
return object;
16+
}
17+
18+
}

src/main/java/com/ivision/gamereact/model/GamepadListener.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ public class GamepadListener implements TuioListener {
1616
private boolean verbose = false; // Konsolenausgabe ein- oder ausschalten
1717

1818
Pane root;
19-
ArrayList<TuioObject> gamepads = new ArrayList<TuioObject>();
20-
ArrayList<TuioCursor> fingers = new ArrayList<TuioCursor>();
21-
ArrayList<TuioBlob> blobs = new ArrayList<TuioBlob>();
19+
ArrayList<TuioObject> gamepads = new ArrayList<>();
20+
ArrayList<TuioCursor> fingers = new ArrayList<>();
21+
ArrayList<TuioBlob> blobs = new ArrayList<>();
2222

2323
protected AppController controller;
2424

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package com.ivision.gamereact.model;
2+
3+
import com.tuio.*;
4+
import javafx.scene.Group;
5+
import javafx.scene.paint.Color;
6+
import javafx.scene.shape.Rectangle;
7+
import javafx.scene.text.Font;
8+
import javafx.scene.text.Text;
9+
10+
import java.util.HashMap;
11+
12+
public class MarkerListener implements TuioListener {
13+
14+
private boolean verbose = false;
15+
private HashMap<TuioObject, Group> objectShapes = new HashMap<>();
16+
17+
public MarkerListener() {
18+
19+
}
20+
21+
public MarkerListener(boolean verbose) {
22+
this.verbose = verbose;
23+
}
24+
25+
public HashMap<TuioObject, Group> getObjectShapes() {
26+
return objectShapes;
27+
}
28+
29+
@Override
30+
public void updateTuioObject(TuioObject tobj) {
31+
32+
}
33+
34+
@Override
35+
public void updateTuioCursor(TuioCursor tcur) {
36+
37+
}
38+
39+
@Override
40+
public void updateTuioBlob(TuioBlob tblb) {
41+
42+
}
43+
44+
@Override
45+
public void refresh(TuioTime ftime) {
46+
47+
}
48+
49+
@Override
50+
public void addTuioObject(TuioObject tobj) {
51+
Group rGroup = new Group();
52+
Rectangle rectangle = new Rectangle(150,150, Color.BLACK);
53+
rectangle.setArcWidth(40);
54+
rectangle.setArcHeight(40);
55+
Text symbolID = new Text("Symbol-ID: " + tobj.getSymbolID());
56+
Text sessionID = new Text("Session-ID: " + tobj.getSessionID());
57+
58+
symbolID.setFont(new Font(24));
59+
symbolID.setY(50);
60+
symbolID.setX(100);
61+
symbolID.setFill(Color.GREEN);
62+
63+
sessionID.setFont(new Font(24));
64+
sessionID.setY(25);
65+
sessionID.setX(100);
66+
sessionID.setFill(Color.BLUE);
67+
68+
rGroup.getChildren().add(rectangle);
69+
rGroup.getChildren().add(symbolID);
70+
rGroup.getChildren().add(sessionID);
71+
72+
if (!this.objectShapes.containsKey(tobj)) this.objectShapes.put(tobj,rGroup);
73+
74+
if(verbose) {
75+
System.out.printf("Objekt mit Symbol-ID %s hinzugefügt.%n",tobj.getSymbolID());
76+
}
77+
}
78+
79+
@Override
80+
public void removeTuioObject(TuioObject tobj) {
81+
this.objectShapes.remove(tobj);
82+
if(verbose) {
83+
System.out.printf("Objekt mit Symbol-ID %s entfernt.%n", tobj.getSymbolID());
84+
}
85+
}
86+
87+
@Override
88+
public void addTuioCursor(TuioCursor tcur) {
89+
90+
if(verbose) {
91+
System.out.printf("Cursor mit Finger-ID %s hinzugefügt.%n", tcur.getCursorID());
92+
}
93+
}
94+
95+
@Override
96+
public void removeTuioCursor(TuioCursor tcur) {
97+
98+
if(verbose) {
99+
System.out.printf("Cursor mit Finger-ID %s entfernt.%n", tcur.getCursorID());
100+
}
101+
}
102+
103+
@Override
104+
public void addTuioBlob(TuioBlob tblb) {
105+
106+
107+
if(verbose) {
108+
System.out.printf("Cursor mit Blob-ID %s hinzugefügt.%n", tblb.getBlobID());
109+
}
110+
}
111+
112+
@Override
113+
public void removeTuioBlob(TuioBlob tblb) {
114+
115+
if(verbose) {
116+
System.out.printf("Cursor mit Blob-ID %s entfernt.%n", tblb.getBlobID());
117+
}
118+
}
119+
120+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<?import javafx.scene.layout.StackPane?>
4+
<?import javafx.scene.layout.BorderPane?>
5+
<BorderPane fx:id="root" fx:controller="com.ivision.gamereact.controller.TestController" xmlns:fx="http://javafx.com/fxml">
6+
7+
</BorderPane>

0 commit comments

Comments
 (0)