Skip to content

Commit 8091d0d

Browse files
committed
keybinds
1 parent 6be9aab commit 8091d0d

8 files changed

Lines changed: 118 additions & 31 deletions

File tree

0 Bytes
Binary file not shown.

core/src/main/java/com/amhsrobotics/tkopatheditor/display/tools/CubicSplineTool.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.amhsrobotics.tkopatheditor.parametrics.SplineManager;
55
import com.amhsrobotics.tkopatheditor.parametrics.SplineType;
66
import com.amhsrobotics.tkopatheditor.parametrics.SplineWrapper;
7+
import com.amhsrobotics.tkopatheditor.util.DragConstants;
78
import com.amhsrobotics.tkopatheditor.util.UITools;
89
import com.badlogic.gdx.Gdx;
910
import com.badlogic.gdx.scenes.scene2d.Actor;
@@ -45,6 +46,7 @@ public void changed(ChangeEvent event, Actor actor) {
4546

4647
@Override
4748
public void onClick() {
49+
DragConstants.resetAll();
4850
SplineManager.getInstance().registerSpline(
4951
new SplineWrapper(SplineType.CUBIC_HERMITE)
5052
);

core/src/main/java/com/amhsrobotics/tkopatheditor/display/tools/QuinticSplineTool.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.amhsrobotics.tkopatheditor.parametrics.SplineManager;
55
import com.amhsrobotics.tkopatheditor.parametrics.SplineType;
66
import com.amhsrobotics.tkopatheditor.parametrics.SplineWrapper;
7+
import com.amhsrobotics.tkopatheditor.util.DragConstants;
78
import com.amhsrobotics.tkopatheditor.util.UITools;
89
import com.badlogic.gdx.Gdx;
910
import com.badlogic.gdx.scenes.scene2d.Actor;
@@ -45,6 +46,7 @@ public void changed(ChangeEvent event, Actor actor) {
4546

4647
@Override
4748
public void onClick() {
49+
DragConstants.resetAll();
4850
SplineManager.getInstance().registerSpline(
4951
new SplineWrapper(SplineType.QUINTIC_HERMITE)
5052
);

core/src/main/java/com/amhsrobotics/tkopatheditor/parametrics/SplineHandle.java

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class SplineHandle {
2626
private Circle rotationCircle;
2727
private SplineWrapper spline;
2828

29-
private Sprite addPoint, deletePoint;
29+
private Sprite addButton, deleteButton;
3030

3131
private int id;
3232

@@ -37,11 +37,11 @@ public SplineHandle(Transform point, int ID, SplineWrapper wrapper) {
3737
circle = new Circle((float) point.getX(), (float) point.getY(), Constants.HANDLE_RADIUS);
3838
rotationCircle = new Circle(circle.x, circle.y, Constants.HANDLE_ROTATION_RADIUS);
3939

40-
addPoint = new Sprite(new Texture(Gdx.files.internal("png/plus.png")));
41-
deletePoint = new Sprite(new Texture(Gdx.files.internal("png/minus.png")));
40+
addButton = new Sprite(new Texture(Gdx.files.internal("png/plus.png")));
41+
deleteButton = new Sprite(new Texture(Gdx.files.internal("png/minus.png")));
4242

43-
addPoint.setOriginCenter();
44-
deletePoint.setOriginCenter();
43+
addButton.setOriginCenter();
44+
deleteButton.setOriginCenter();
4545

4646
}
4747

@@ -63,29 +63,24 @@ public void render(ShapeRenderer renderer, SpriteBatch batch) {
6363

6464
if(spline.getLastHandle() == this || spline.getFirstHandle() == this) {
6565

66-
addPoint.setOriginBasedPosition((float) point.getX() + (spline.getFirstHandle() != this ? 35 : -35), (float) point.getY() + 10);
67-
deletePoint.setOriginBasedPosition((float) point.getX() + (spline.getFirstHandle() != this ? 35 : -35), (float) point.getY() - 10);
66+
addButton.setOriginBasedPosition((float) point.getX() + (spline.getFirstHandle() != this ? 35 : -35), (float) point.getY() + 10);
67+
deleteButton.setOriginBasedPosition((float) point.getX() + (spline.getFirstHandle() != this ? 35 : -35), (float) point.getY() - 10);
6868

6969
renderer.end();
7070
Gdx.gl.glDisable(GL30.GL_BLEND);
7171

7272
batch.begin();
73-
addPoint.draw(batch);
74-
75-
if(addPoint.getBoundingRectangle().contains(CameraManager.mouseScreenToWorld()) && Gdx.input.isButtonPressed(Input.Buttons.LEFT)) {
76-
spline.addPoint(
77-
new Transform(new Vector2D(point.getX() + (spline.getFirstHandle() != this ? 50 : -50), point.getY()), new Rotation(0)),
78-
spline.getFirstHandle() != this
79-
);
80-
spline.generate();
73+
addButton.draw(batch);
74+
75+
if(addButton.getBoundingRectangle().contains(CameraManager.mouseScreenToWorld()) && Gdx.input.isButtonPressed(Input.Buttons.LEFT) && !DragConstants.draggingRotationHandle) {
76+
createPoint();
8177
}
8278

8379
if(spline.getLength() > 2) {
84-
deletePoint.draw(batch);
80+
deleteButton.draw(batch);
8581

86-
if(deletePoint.getBoundingRectangle().contains(CameraManager.mouseScreenToWorld()) && Gdx.input.isButtonPressed(Input.Buttons.LEFT)) {
87-
spline.deletePoint(this);
88-
spline.generate();
82+
if(deleteButton.getBoundingRectangle().contains(CameraManager.mouseScreenToWorld()) && Gdx.input.isButtonPressed(Input.Buttons.LEFT) && !DragConstants.draggingRotationHandle) {
83+
deletePoint();
8984
}
9085
}
9186
batch.end();
@@ -94,18 +89,17 @@ public void render(ShapeRenderer renderer, SpriteBatch batch) {
9489
Gdx.gl.glBlendFunc(GL30.GL_SRC_ALPHA, GL30.GL_ONE_MINUS_SRC_ALPHA);
9590
renderer.begin(ShapeRenderer.ShapeType.Filled);
9691
} else {
97-
deletePoint.setOriginBasedPosition((float) point.getX(), (float) point.getY() - 35);
92+
deleteButton.setOriginBasedPosition((float) point.getX(), (float) point.getY() - 35);
9893

9994
renderer.end();
10095
Gdx.gl.glDisable(GL30.GL_BLEND);
10196

10297
batch.begin();
10398

104-
deletePoint.draw(batch);
99+
deleteButton.draw(batch);
105100

106-
if(deletePoint.getBoundingRectangle().contains(CameraManager.mouseScreenToWorld()) && Gdx.input.isButtonPressed(Input.Buttons.LEFT)) {
107-
spline.deletePoint(this);
108-
spline.generate();
101+
if(deleteButton.getBoundingRectangle().contains(CameraManager.mouseScreenToWorld()) && Gdx.input.isButtonPressed(Input.Buttons.LEFT) && !DragConstants.draggingRotationHandle) {
102+
deletePoint();
109103
}
110104

111105
batch.end();
@@ -134,8 +128,23 @@ public void render(ShapeRenderer renderer, SpriteBatch batch) {
134128

135129
}
136130

131+
public void createPoint() {
132+
spline.addPoint(
133+
new Transform(new Vector2D(point.getX() + (spline.getFirstHandle() != this ? 50 : -50), point.getY()), new Rotation(0)),
134+
spline.getFirstHandle() != this
135+
);
136+
spline.generate();
137+
}
138+
139+
public void deletePoint() {
140+
if(spline.getLength() > 2) {
141+
spline.deletePoint(this);
142+
spline.generate();
143+
}
144+
}
145+
137146
public boolean isHoveringHandleModifier() {
138-
return addPoint.getBoundingRectangle().contains(CameraManager.mouseScreenToWorld()) || deletePoint.getBoundingRectangle().contains(CameraManager.mouseScreenToWorld());
147+
return addButton.getBoundingRectangle().contains(CameraManager.mouseScreenToWorld()) || deleteButton.getBoundingRectangle().contains(CameraManager.mouseScreenToWorld());
139148
}
140149

141150
public boolean isHoveringHandle() {

core/src/main/java/com/amhsrobotics/tkopatheditor/parametrics/SplineWrapper.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.amhsrobotics.tkopatheditor.util.DragConstants;
66
import com.amhsrobotics.tkopatheditor.util.Tuple;
77
import com.badlogic.gdx.Gdx;
8+
import com.badlogic.gdx.Input;
89
import com.badlogic.gdx.graphics.Color;
910
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
1011
import com.badlogic.gdx.math.Vector2;
@@ -79,13 +80,24 @@ public void draw(ModifiedShapeRenderer renderer, SpriteBatch batch) {
7980

8081
Vector2 mouse = CameraManager.mouseScreenToWorld();
8182

82-
renderer.setColor(color);
8383
for (Tuple<Double, Double> t : generatedSpline) {
8484

8585
if(Math.sqrt((Math.pow(mouse.x - t.x, 2)) + (Math.pow(mouse.y - t.y, 2))) <= Constants.LINE_WIDTH) {
86-
// TODO spline touched by mouse cursor
86+
if(Gdx.input.isButtonPressed(Input.Buttons.LEFT)) {
87+
88+
// DragConstants.resetAll();
89+
// DragConstants.splineSelected = true;
90+
// DragConstants.splineDragged = this;
91+
92+
}
8793
}
94+
//
95+
// if(DragConstants.splineSelected && DragConstants.splineDragged == this) {
96+
// renderer.setColor(Color.LIME);
97+
// renderer.circle(t.x.floatValue(), t.y.floatValue(), (float) Constants.LINE_WIDTH + 1);
98+
// }
8899

100+
renderer.setColor(color);
89101
renderer.circle(t.x.floatValue(), t.y.floatValue(), (float) Constants.LINE_WIDTH);
90102
}
91103

core/src/main/java/com/amhsrobotics/tkopatheditor/screens/WorkspaceScreen.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
import com.amhsrobotics.tkopatheditor.field.FieldManager;
55
import com.amhsrobotics.tkopatheditor.parametrics.SplineManager;
66
import com.amhsrobotics.tkopatheditor.util.CameraManager;
7-
import com.amhsrobotics.tkopatheditor.util.DragConstants;
8-
import com.amhsrobotics.tkopatheditor.util.InputCore;
7+
import com.amhsrobotics.tkopatheditor.util.input.InputCore;
98
import com.amhsrobotics.tkopatheditor.util.SnapGrid;
109
import com.badlogic.gdx.Gdx;
1110
import com.badlogic.gdx.Input;
@@ -28,7 +27,8 @@ public WorkspaceScreen() {
2827

2928
Gdx.input.setInputProcessor(new InputMultiplexer(
3029
Overlay.getInstance().getStage(),
31-
InputCore.getInstance()
30+
InputCore.getInstance(),
31+
InputCore.getMultipleKeyProcessor()
3232
));
3333
}
3434

core/src/main/java/com/amhsrobotics/tkopatheditor/util/DragConstants.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package com.amhsrobotics.tkopatheditor.util;
22

33
import com.amhsrobotics.tkopatheditor.parametrics.SplineHandle;
4+
import com.amhsrobotics.tkopatheditor.parametrics.SplineWrapper;
45

56
public class DragConstants {
67

8+
public static boolean splineSelected;
9+
public static SplineWrapper splineDragged;
10+
711
public static boolean draggingHandle = false;
812
public static SplineHandle handleDragged = null;
913

@@ -21,5 +25,7 @@ public static void resetAll() {
2125
draggingRotationHandle = false;
2226
draggingFromLeft = false;
2327
measureToolEnabled = false;
28+
splineSelected = false;
29+
splineDragged = null;
2430
}
2531
}

core/src/main/java/com/amhsrobotics/tkopatheditor/util/InputCore.java renamed to core/src/main/java/com/amhsrobotics/tkopatheditor/util/input/InputCore.java

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
1-
package com.amhsrobotics.tkopatheditor.util;
1+
package com.amhsrobotics.tkopatheditor.util.input;
22

33
import com.amhsrobotics.tkopatheditor.Constants;
44
import com.amhsrobotics.tkopatheditor.display.PropertiesWindow;
5+
import com.amhsrobotics.tkopatheditor.display.tools.CubicSplineTool;
56
import com.amhsrobotics.tkopatheditor.display.tools.MeasureTool;
7+
import com.amhsrobotics.tkopatheditor.display.tools.QuinticSplineTool;
68
import com.amhsrobotics.tkopatheditor.parametrics.SplineHandle;
79
import com.amhsrobotics.tkopatheditor.parametrics.SplineManager;
10+
import com.amhsrobotics.tkopatheditor.util.CameraManager;
11+
import com.amhsrobotics.tkopatheditor.util.DragConstants;
12+
import com.amhsrobotics.tkopatheditor.util.SnapGrid;
813
import com.badlogic.gdx.Gdx;
914
import com.badlogic.gdx.Input;
15+
import com.badlogic.gdx.InputAdapter;
1016
import com.badlogic.gdx.InputProcessor;
1117
import com.badlogic.gdx.math.Vector2;
1218
import com.badlogic.gdx.math.Vector3;
19+
import com.badlogic.gdx.utils.IntSet;
1320

1421
import static com.github.mittyrobotics.core.math.units.ConversionsKt.degrees;
1522

1623

1724
public class InputCore implements InputProcessor {
1825

1926
private static InputCore instance;
27+
private static final IntSet downKeys = new IntSet(20);
2028

2129
public static InputCore getInstance() {
2230
if(instance == null) {
@@ -25,9 +33,57 @@ public static InputCore getInstance() {
2533
return instance;
2634
}
2735

36+
public static InputAdapter getMultipleKeyProcessor() {
37+
return new InputAdapter() {
38+
public boolean keyDown (int keycode) {
39+
downKeys.add(keycode);
40+
if (downKeys.size >= 2){
41+
onMultipleKeysDown(keycode);
42+
}
43+
return true;
44+
}
45+
46+
public boolean keyUp (int keycode) {
47+
downKeys.remove(keycode);
48+
return true;
49+
}
50+
};
51+
}
52+
53+
private static void onMultipleKeysDown(int mostRecentKeycode) {
54+
55+
if(downKeys.contains(Input.Keys.SHIFT_LEFT)) {
56+
if (downKeys.size == 2 && mostRecentKeycode == Input.Keys.EQUALS){
57+
if(DragConstants.handleSelected != null) DragConstants.handleSelected.createPoint();
58+
}
59+
}
60+
61+
if (downKeys.contains(Input.Keys.ALT_LEFT) || downKeys.contains(Input.Keys.ALT_RIGHT)){
62+
if (downKeys.size == 2 && mostRecentKeycode == Input.Keys.F4){
63+
Gdx.app.exit();
64+
}
65+
}
66+
}
67+
2868
@Override
2969
public boolean keyDown(int keycode) {
3070

71+
if(keycode == Input.Keys.MINUS) {
72+
if(DragConstants.handleSelected != null) DragConstants.handleSelected.deletePoint();
73+
}
74+
75+
if(keycode == Input.Keys.M) {
76+
MeasureTool.getInstance().onClick();
77+
}
78+
79+
if(keycode == Input.Keys.Q) {
80+
QuinticSplineTool.getInstance().onClick();
81+
}
82+
83+
if(keycode == Input.Keys.C) {
84+
CubicSplineTool.getInstance().onClick();
85+
}
86+
3187
if(keycode == Input.Keys.ESCAPE) {
3288
DragConstants.resetAll();
3389
}

0 commit comments

Comments
 (0)