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,6 +775,10 @@ 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);
if (!int1.isEmpty() && !int2.isEmpty()) {
fill(0,0,0, 255-brightness);
beginShape();
// plot out the vertexes // plot out the vertexes
vertex(int1.get(0).x, int1.get(0).y); vertex(int1.get(0).x, int1.get(0).y);
vertex(int2.get(0).x, int2.get(0).y); vertex(int2.get(0).x, int2.get(0).y);
@ -785,6 +787,7 @@ class DisplayMachine extends Machine
vertex(int1.get(0).x, int1.get(0).y); vertex(int1.get(0).x, int1.get(0).y);
endShape(); 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,39 +111,47 @@ 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); }
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"); Textfield tf = cp5().get(Textfield.class, "textToWriteField");
tf.setText(getTextToWrite()); tf.setText(getTextToWrite());
tf.submit(); tf.submit();
} }
}
void submitWritingWindow(int theValue) void submitWritingWindow(int theValue)
{ {
@ -161,15 +169,12 @@ class DrawWritingWindow extends ControlFrame {
println("Sprite file prefix: " + spriteFilePrefix); println("Sprite file prefix: " + spriteFilePrefix);
println("Text: " + textToWrite); println("Text: " + textToWrite);
for (int i=0; i<getTextToWrite().length(); i++) for (int i=0; i<getTextToWrite().length(); i++) {
{
String filename = getSpriteFilePrefix() + (int) getTextToWrite().charAt(i) + getSpriteFileSuffix(); String filename = getSpriteFilePrefix() + (int) getTextToWrite().charAt(i) + getSpriteFileSuffix();
addToCommandQueue(CMD_DRAW_SPRITE + int(gridSize * pixelScalingOverGridSize) + "," + filename+",END"); addToCommandQueue(CMD_DRAW_SPRITE + int(gridSize * pixelScalingOverGridSize) + "," + filename+",END");
println(filename); 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,18 +1825,16 @@ 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 }
{
void exportQueueToFile(File selection) {
if (selection != null) {
filePath = selection.getAbsolutePath();
println("User selected " + filePath);
// If a file was selected, print path to folder // If a file was selected, print path to folder
println("Output file: " + filePath); println("Output file: " + filePath);
List<String> allCommands = new ArrayList<String>(realtimeCommandQueue); List<String> allCommands = new ArrayList<String>(realtimeCommandQueue);
@ -1853,7 +1844,6 @@ void exportQueueToFile()
saveStrings(filePath, list); saveStrings(filePath, list);
println("Completed queue export, " + list.length + " commands exported."); println("Completed queue export, " + list.length + " commands exported.");
} }
}
} }
void fileSelected(File selection) { void fileSelected(File selection) {
@ -1866,50 +1856,20 @@ void fileSelected(File selection) {
} }
} }
void importQueueFromFile() {
void importQueueFromFile()
{
commandQueue.clear(); commandQueue.clear();
selectInput("Select file to import queue from", "fileSelected"); selectInput("Select file to import queue from", "fileSelected");
if (filePath == null) if (filePath == null) {
{
// nothing selected // nothing selected
println("No input file was selected."); println("No input file was selected.");
} } else {
else
{
println("Input file: " + filePath); println("Input file: " + filePath);
String commands[] = loadStrings(filePath); String commands[] = loadStrings(filePath);
// List<String> list = Arrays
commandQueue.addAll(Arrays.asList(commands)); commandQueue.addAll(Arrays.asList(commands));
println("Completed queue import, " + commandQueue.size() + " commands found."); 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;
}