euglena/src/Menu.java

313 lines
9.2 KiB
Java
Raw Normal View History

2016-07-10 00:36:44 -07:00
import processing.core.*;
import org.firmata.*;
import gab.opencv.*;
import cc.arduino.*;
import controlP5.*;
class Menu {
final int width = 200; // Width of toolbar on left side of display
private Button resetButton, calibrateButton, commitButton, lineButton, freehandButton, eraserButton, goButton;
private Textfield redField, greenField, blueField, backgroundField, penwidthField,
lagField, totaltimeField, speedField;
private DropdownList shapesList, animateList, presetsList, gamesList;
private ControlP5 cp5;
private Group g1, g2, g3;
Menu(PApplet applet){
cp5 = new ControlP5(applet).setPosition(applet.width - width, 0);
g1 = cp5.addGroup("Textfields");
g2 = cp5.addGroup("Dropdown2");
g3 = cp5.addGroup("Dropdown1");
resetButton = cp5.addButton("Reset")
.setPosition(20, 200)
.setSize(70, 35)
.moveTo(g1);
calibrateButton = cp5.addButton("Calibrate")
.setPosition(110, 200)
.setSize(70, 35)
.moveTo(g1);
redField = cp5.addTextfield("Red (0-255)")
.setPosition(20, 275)
.setSize(70, 35)
.setAutoClear(false)
.moveTo(g1);
greenField = cp5.addTextfield("Green (0-255)")
.setPosition(20, 325)
.setSize(70, 35)
.setAutoClear(false)
.moveTo(g1);
blueField = cp5.addTextfield("Blue (0-255)")
.setPosition(20, 375)
.setSize(70, 35)
.setAutoClear(false)
.moveTo(g1);
backgroundField = cp5.addTextfield("Background (0-255)")
.setPosition(20, 425)
.setSize(70, 35)
.setAutoClear(false)
.moveTo(g1);
penwidthField = cp5.addTextfield("Pen Width")
.setPosition(20, 475)
.setSize(70, 35)
.setAutoClear(false)
.moveTo(g1);
speedField = cp5.addTextfield("Speed")
.setPosition(110, 275)
.setSize(70, 35)
.setAutoClear(false)
.moveTo(g1);
lagField = cp5.addTextfield("Timelapse lag")
.setPosition(110, 325)
.setSize(70, 35)
.setAutoClear(false)
.moveTo(g1);
totaltimeField = cp5.addTextfield("Total time")
.setPosition(110, 375)
.setSize(70, 35)
.setAutoClear(false)
.moveTo(g1);
commitButton = cp5.addButton("Commit")
.setPosition(110, 450)
.setSize(70, 35)
.moveTo(g1);
lineButton = cp5.addButton("Line")
.setPosition(20, 550)
.setSize(50, 35)
.moveTo(g1);
freehandButton = cp5.addButton("Freehand")
.setPosition(75, 550)
.setSize(50, 35)
.moveTo(g1);
eraserButton = cp5.addButton("Eraser")
.setPosition(130, 550)
.setSize(50, 35)
.moveTo(g1);
shapesList = cp5.addDropdownList("Shapes")
.setPosition(20, 650)
.setSize(70, 100)
.setBarHeight(35)
.addItem("Ellipse", "Ellipse")
.addItem("Rectangle", "Rectangle")
.addItem("Triangle", "Triangle")
.addItem("None", "Default")
.close()
.moveTo(g3);
animateList = cp5.addDropdownList("Animate")
.setPosition(110, 650)
.setSize(70, 100)
.setBarHeight(35)
.addItem("Shrink", "Shrink")
.addItem("Expand", "Expand")
.addItem("Translate", "Translate")
.addItem("Rotate", "Rotate")
.addItem("None", "Default")
.close()
.moveTo(g3);
presetsList = cp5.addDropdownList("Presets")
.setPosition(20, 700)
.setSize(70, 100)
.setBarHeight(35)
.addItem("Clear screen", "Clear screen")
.addItem("Flow up", "Flow up")
.addItem("Flow down", "Flow down")
.addItem("Flow right", "Flow right")
.addItem("Flow left", "Flow left")
.addItem("Contain", "Contain")
.addItem("Split", "Split")
.addItem("Merge", "Merge")
.addItem("Slow move", "Slow move")
.addItem("Fast move", "Fast move")
.addItem("Slow compress", "Slow compress")
.addItem("Fast compress", "Fast compress")
.addItem("??","??")
.close()
.moveTo(g2);
// goButton = cp5.addButton("Go")
// .setPosition(20, 750)
// .setSize(70, 20)
// .moveTo(g1);
gamesList = cp5.addDropdownList("Games")
.setPosition(110, 700)
.setSize(70, 100)
.setBarHeight(35)
.addItem("Level 1", "Level 1")
.addItem("Level 2", "Level 2")
.addItem("Level 3", "Level 3")
.close()
.moveTo(g2);
}
void draw(EuglenaApplet a, LEDControl led) {
drawBackground(a);
drawArrows(a, led);
}
void drawArrows(EuglenaApplet a, LEDControl leds) {
a.strokeWeight(8);
int onColor = a.color(255, 255, 51);
int offColor = a.color(255, 255, 255);
int xOffset = a.width - width;
a.stroke(leds.isActive(LEDControl.Direction.RIGHT) ? onColor : offColor);
a.drawArrow(xOffset + 120, 80, 30, 0);
a.stroke(leds.isActive(LEDControl.Direction.DOWN) ? onColor : offColor);
a.drawArrow(xOffset + 100, 100, 30, 90);
a.stroke(leds.isActive(LEDControl.Direction.LEFT) ? onColor : offColor);
a.drawArrow(xOffset + 80, 80, 30, 180);
a.stroke(leds.isActive(LEDControl.Direction.UP) ? onColor : offColor);
a.drawArrow(xOffset + 100, 60, 30, 270);
}
void drawBackground(EuglenaApplet a) {
a.rectMode(EuglenaApplet.CORNER);
a.noStroke();
a.fill(0);
a.rect(a.width - width, 0, width, a.height);
}
/*
void controlEvent(ControlEvent theEvent) {
if (theEvent.isFrom(shapesList)) {
switch((int) shapesList.getValue()) {
case 0:
ellipseDrawer.reset();
drawtype = 'e';
break;
case 1:
rectangleDrawer.reset();
drawtype = 'r';
break;
case 2:
triangleDrawer.reset();
drawtype = 't';
break;
}
}
if (theEvent.isFrom(animateList)){
switch((int) animateList.getValue()) {
case 0:
shrink.reset();
drawtype = 's';
break;
case 1:
expand.reset();
drawtype = 'x';
break;
case 2:
translate.reset();
drawtype = 'm';
break;
case 3:
rotate.reset();
drawtype = 'c';
break;
}
}
if (theEvent.isFrom(presetsList)){
preset = (int) presetsList.getValue();
}
}
*/
}
/*
*/
/* Adds all features to initial display including toolbar and camera display */
/*
void Commit() {
rVal = int(menu.redField.getText());
gVal = int(menu.greenField.getText());
bVal = int(menu.blueField.getText());
penWidth = int(menu.penwidthField.getText());
bgVal = int(menu.backgroundField.getText());
lagTime = float(menu.lagField.getText());
totalTime = int(menu.totaltimeField.getText());
speed = int(menu.speedField.getText());
// print(rVal);
// print(",");
// print(gVal);
// print(",");
// print(bVal);
// print("\n");
// print(speed);
// print("\n");
}
void Reset() {
if (calibrator.active = true){
calibrator.toggle();
} else {
calibrator.active = false;
clearDisplay();
lines.clear();
ellipses.clear();
rectangles.clear();
triangles.clear();
shrinkwindows.clear();
expandwindows.clear();
translatewindows.clear();
rotatewindows.clear();
arduino.digitalWrite(left, Arduino.LOW);
arduino.digitalWrite(right, Arduino.LOW);
arduino.digitalWrite(up, Arduino.LOW);
arduino.digitalWrite(down, Arduino.LOW);
t = 0;
t2 = 0;
t3 = 0;
t_temp = 0;
}
}
void Calibrate() {
frame.setLocation(0,0);
calibrator.toggle();
}
void Eraser() {
rVal = 0;
gVal = 0;
bVal = 0;
}
void Line() {
lineDrawer.reset();
drawtype = 'l';
}
*/