Quite a few things working. The window focus is still a bit weird.

This commit is contained in:
Sandy Noble 2015-08-16 12:19:19 +01:00
parent 1abe63bba6
commit cbb2678aef
5 changed files with 113 additions and 139 deletions

View File

@ -5,12 +5,12 @@ public class ControlFrame extends PApplet {
public int w, h; public int w, h;
int abc = 100; int abc = 100;
public ControlP5 cp5; public ControlP5 cp5;
protected Object parent; protected PApplet parent;
private ControlFrame() { private ControlFrame() {
} }
public ControlFrame(Object theParent, int theWidth, int theHeight) { public ControlFrame(PApplet theParent, int theWidth, int theHeight) {
this.parent = theParent; this.parent = theParent;
this.w = theWidth; this.w = theWidth;
this.h = theHeight; this.h = theHeight;
@ -23,6 +23,10 @@ public class ControlFrame extends PApplet {
return this.cp5; return this.cp5;
} }
public PApplet getParent() {
return this.parent;
}
public void setup() { public void setup() {
size(w, h); size(w, h);
frameRate(5); frameRate(5);

View File

@ -767,8 +767,6 @@ class DisplayMachine extends Machine
void previewNativePixel(PVector pos, float size, float brightness) void previewNativePixel(PVector pos, float size, float brightness)
{ {
float half = size / 2.0; float half = size / 2.0;
fill(0,0,0, 255-brightness);
beginShape();
// arcs from the left-hand corner // arcs from the left-hand corner
float distFromPointA = getOutline().getTopLeft().dist(pos); float distFromPointA = getOutline().getTopLeft().dist(pos);
@ -777,13 +775,18 @@ class DisplayMachine extends Machine
List<PVector> int1 = findIntersections(getOutline().getLeft(), distFromPointA-half, getOutline().getRight(), distFromPointB-half, size); List<PVector> int1 = findIntersections(getOutline().getLeft(), distFromPointA-half, getOutline().getRight(), distFromPointB-half, size);
List<PVector> int2 = findIntersections(getOutline().getLeft(), distFromPointA+half, getOutline().getRight(), distFromPointB-half, size); List<PVector> int2 = findIntersections(getOutline().getLeft(), distFromPointA+half, getOutline().getRight(), distFromPointB-half, size);
// plot out the vertexes if (!int1.isEmpty() && !int2.isEmpty()) {
vertex(int1.get(0).x, int1.get(0).y); fill(0,0,0, 255-brightness);
vertex(int2.get(0).x, int2.get(0).y); beginShape();
vertex(int2.get(1).x, int2.get(1).y);
vertex(int1.get(1).x, int1.get(1).y); // plot out the vertexes
vertex(int1.get(0).x, int1.get(0).y); vertex(int1.get(0).x, int1.get(0).y);
endShape(); vertex(int2.get(0).x, int2.get(0).y);
vertex(int2.get(1).x, int2.get(1).y);
vertex(int1.get(1).x, int1.get(1).y);
vertex(int1.get(0).x, int1.get(0).y);
endShape();
}
} }
void previewNativeArcPixel(PVector pos, float size, float brightness) void previewNativeArcPixel(PVector pos, float size, float brightness)

View File

@ -15,7 +15,7 @@ class SerialPortWindow extends ControlFrame {
f.setTitle(CHANGE_SERIAL_PORT_WINDOW_NAME); f.setTitle(CHANGE_SERIAL_PORT_WINDOW_NAME);
f.setSize(super.w, super.h); f.setSize(super.w, super.h);
f.setLocation(xPos, yPos); f.setLocation(xPos, yPos);
f.setResizable(false); f.setResizable(true);
f.setVisible(true); f.setVisible(true);
f.addWindowListener( new WindowAdapter() { f.addWindowListener( new WindowAdapter() {
@ -31,6 +31,8 @@ class SerialPortWindow extends ControlFrame {
.setSpacingRow(5) .setSpacingRow(5)
.plugTo(parentPapplet, "radio_serialPort"); .plugTo(parentPapplet, "radio_serialPort");
r.addItem("No serial connection", -1);
String[] ports = Serial.list(); String[] ports = Serial.list();
for (int i = 0; i < ports.length; i++) { for (int i = 0; i < ports.length; i++) {

View File

@ -63,7 +63,7 @@ void button_mode_drawWritingDialog() {
String textToWrite = ""; String textToWrite = "";
String spriteFilePrefix = "sprite/let"; String spriteFilePrefix = "sprite/let";
String spriteFileSuffix = ".txt"; String spriteFileSuffix = ".txt";
class DrawWritingWindow extends ControlFrame { public class DrawWritingWindow extends ControlFrame {
public DrawWritingWindow() { public DrawWritingWindow() {
super(parentPapplet, 450, 250); super(parentPapplet, 450, 250);
int xPos = 100; int xPos = 100;
@ -111,65 +111,70 @@ class DrawWritingWindow extends ControlFrame {
.plugTo("submitWritingWindow"); .plugTo("submitWritingWindow");
} }
void spriteFilePrefixField(String value) {
void spriteFilePrefixField(String value) spriteFilePrefix = value;
{
spriteFilePrefix = value;
} }
void textToWriteField(String value) void textToWriteField(String value) {
{ textToWrite = value;
textToWrite = value;
} }
String getTextToWrite() String getTextToWrite() {
{ return textToWrite;
return textToWrite;
} }
String getSpriteFilePrefix() String getSpriteFilePrefix() {
{ return spriteFilePrefix;
return spriteFilePrefix;
} }
String getSpriteFileSuffix() String getSpriteFileSuffix() {
{ return spriteFileSuffix;
return spriteFileSuffix;
} }
void importTextButton() void importTextButton() {
{
println("Text!"); println("Text!");
textToWrite = importTextToWriteFromFile(); selectInput("Select the text file to load the text from:", "importTextToWriteFromFile", null, this);
println(textToWrite);
Textfield tf = cp5().get(Textfield.class, "textToWriteField");
tf.setText(getTextToWrite());
tf.submit();
} }
public void importTextToWriteFromFile(File selection) {
if (selection != null) {
String fp = selection.getAbsolutePath();
println("Input file: " + fp);
List<String> rows = java.util.Arrays.asList(loadStrings(fp));
StringBuilder sb = new StringBuilder(200);
for (String row : rows) {
sb.append(row);
}
textToWriteField(sb.toString());
println("Completed text import, " + getTextToWrite().length() + " characters found.");
println("Text: " + getTextToWrite());
Textfield tf = cp5().get(Textfield.class, "textToWriteField");
tf.setText(getTextToWrite());
tf.submit();
}
}
void submitWritingWindow(int theValue) void submitWritingWindow(int theValue)
{ {
println("Write."); println("Write.");
Textfield tf = cp5().get(Textfield.class, "spriteFilePrefixField"); Textfield tf = cp5().get(Textfield.class, "spriteFilePrefixField");
tf.submit(); tf.submit();
tf.setText(getSpriteFilePrefix()); tf.setText(getSpriteFilePrefix());
Textfield wf = cp5.get(Textfield.class, "textToWriteField"); Textfield wf = cp5.get(Textfield.class, "textToWriteField");
wf.submit(); wf.submit();
wf.setText(getTextToWrite()); wf.setText(getTextToWrite());
println("Start dir: " + renderStartDirection); println("Start dir: " + renderStartDirection);
println("Sprite file prefix: " + spriteFilePrefix); println("Sprite file prefix: " + spriteFilePrefix);
println("Text: " + textToWrite); println("Text: " + textToWrite);
for (int i=0; i<getTextToWrite().length(); i++)
{
String filename = getSpriteFilePrefix() + (int) getTextToWrite().charAt(i) + getSpriteFileSuffix();
addToCommandQueue(CMD_DRAW_SPRITE + int(gridSize * pixelScalingOverGridSize) + "," + filename+",END");
println(filename);
}
for (int i=0; i<getTextToWrite().length(); i++) {
String filename = getSpriteFilePrefix() + (int) getTextToWrite().charAt(i) + getSpriteFileSuffix();
addToCommandQueue(CMD_DRAW_SPRITE + int(gridSize * pixelScalingOverGridSize) + "," + filename+",END");
println(filename);
}
} }
} }
// //
//void button_mode_drawWritingDialog() //void button_mode_drawWritingDialog()

View File

@ -1816,14 +1816,7 @@ boolean isHiddenPixel(PVector p)
return false; return false;
} }
void sizeImageToFitBox() {
void sizeImageToFitBox()
{
// PVector mmBoxSize = getDisplayMachine().inSteps(getBoxSize());
// PVector mmBoxPos = getDisplayMachine().inSteps(getBoxVector1());
// println("mm box: " + mmBoxSize);
PVector boxSize = getDisplayMachine().inSteps(getBoxSize()); PVector boxSize = getDisplayMachine().inSteps(getBoxSize());
PVector boxPos = getDisplayMachine().inSteps(getBoxVector1()); PVector boxPos = getDisplayMachine().inSteps(getBoxVector1());
println("image: " + boxSize); println("image: " + boxSize);
@ -1832,84 +1825,51 @@ void sizeImageToFitBox()
getDisplayMachine().setImageFrame(r); getDisplayMachine().setImageFrame(r);
} }
void exportQueueToFile() void exportQueueToFile() {
{ if (!commandQueue.isEmpty() || !realtimeCommandQueue.isEmpty()) {
if (!commandQueue.isEmpty() || !realtimeCommandQueue.isEmpty()) selectOutput("Enter a filename to save to:", "exportQueueToFile"); // Opens file chooser
{ }
selectOutput("Enter a filename to save to:", "fileSelected"); // Opens file chooser }
if (filePath == null)
{
// If a file was not selected
println("No output file was selected...");
}
else
{
// If a file was selected, print path to folder
println("Output file: " + filePath);
List<String> allCommands = new ArrayList<String>(realtimeCommandQueue);
allCommands.addAll(commandQueue);
String[] list = (String[]) allCommands.toArray(new String[0]); void exportQueueToFile(File selection) {
saveStrings(filePath, list); if (selection != null) {
println("Completed queue export, " + list.length + " commands exported."); filePath = selection.getAbsolutePath();
} println("User selected " + filePath);
} // If a file was selected, print path to folder
println("Output file: " + filePath);
List<String> allCommands = new ArrayList<String>(realtimeCommandQueue);
allCommands.addAll(commandQueue);
String[] list = (String[]) allCommands.toArray(new String[0]);
saveStrings(filePath, list);
println("Completed queue export, " + list.length + " commands exported.");
}
} }
void fileSelected(File selection) { void fileSelected(File selection) {
if (selection == null) { if (selection == null) {
println("Window was closed or the user hit cancel."); println("Window was closed or the user hit cancel.");
filePath = null; filePath = null;
} else { } else {
filePath = selection.getAbsolutePath(); filePath = selection.getAbsolutePath();
println("User selected " + filePath); println("User selected " + filePath);
} }
} }
void importQueueFromFile() {
void importQueueFromFile() commandQueue.clear();
{ selectInput("Select file to import queue from", "fileSelected");
commandQueue.clear(); if (filePath == null) {
selectInput("Select file to import queue from", "fileSelected"); // nothing selected
if (filePath == null) println("No input file was selected.");
{ } else {
// nothing selected println("Input file: " + filePath);
println("No input file was selected."); String commands[] = loadStrings(filePath);
} commandQueue.addAll(Arrays.asList(commands));
else println("Completed queue import, " + commandQueue.size() + " commands found.");
{ }
println("Input file: " + filePath);
String commands[] = loadStrings(filePath);
// List<String> list = Arrays
commandQueue.addAll(Arrays.asList(commands));
println("Completed queue import, " + commandQueue.size() + " commands found.");
}
} }
String importTextToWriteFromFile()
{
selectInput("Select the text file to load the text from:", "fileSelected");
String result = "";
if (filePath == null)
{
// nothing selected
println("No input file was selected.");
}
else
{
println("Input file: " + filePath);
List<String> rows = java.util.Arrays.asList(loadStrings(filePath));
StringBuilder sb = new StringBuilder(200);
for (String row : rows)
{
sb.append(row);
}
result = sb.toString();
println("Completed text import, " + result.length() + " characters found.");
}
return result;
}