Most control frames now working.

This commit is contained in:
Sandy Noble 2015-09-05 16:00:22 +01:00
parent f9ab305fad
commit d005b1bb0c
7 changed files with 496 additions and 366 deletions

View File

@ -17,34 +17,36 @@ public class ControlFrame extends PApplet {
} }
public ControlP5 cp5() { public ControlP5 cp5() {
if (this.cp5 == null) { if (this.cp5 == null) {
this.cp5 = this.setupControlP5(); this.cp5 = this.setupControlP5();
} }
return this.cp5; return this.cp5;
} }
public PApplet getParent() { public PApplet getParent() {
return this.parent; return this.parent;
} }
public void setup() { public void setup() {
size(w, h); size(w, h);
frameRate(5); frameRate(5);
} }
public ControlP5 setupControlP5() { public ControlP5 setupControlP5() {
println("About to create new ControlP5"); println("About to create new ControlP5");
ControlP5 cp5 = new ControlP5(this); ControlP5 cp5 = new ControlP5(this);
println("Created: " + cp5); println("Created: " + cp5);
while (cp5 == null) { while (cp5 == null) {
println("Was null: " + cp5); println("Was null: " + cp5);
} }
println("Finally created: " + cp5); println("Finally created: " + cp5);
return cp5; return cp5;
} }
public void draw() { public void draw() {
background(abc); background(abc);
} }
}
}

View File

@ -6,6 +6,105 @@ public Integer renderStartDirection = DRAW_DIR_SE; // default start drawing in S
public Integer renderStartPosition = DRAW_DIR_NE; // default top right hand corner for start public Integer renderStartPosition = DRAW_DIR_NE; // default top right hand corner for start
public Integer renderStyle = PIXEL_STYLE_SQ_FREQ; // default pixel style square wave public Integer renderStyle = PIXEL_STYLE_SQ_FREQ; // default pixel style square wave
ControlFrameSimple addDrawPixelsControlFrame(String theName, int theWidth, int theHeight, int theX, int theY, int theColor ) {
final Frame f = new Frame( theName );
final ControlFrameSimple p = new ControlFrameSimple( this, theWidth, theHeight, theColor );
f.add( p );
p.init();
f.setTitle(theName);
f.setSize( p.w, p.h );
f.setLocation( theX, theY );
f.addWindowListener( new WindowAdapter() {
@Override
public void windowClosing(WindowEvent we) {
p.dispose();
f.dispose();
}
}
);
f.setResizable( true );
f.setVisible( true );
// sleep a little bit to allow p to call setup.
// otherwise a nullpointerexception might be caused.
try {
Thread.sleep( 100 );
}
catch(Exception e) {
}
// set up controls
RadioButton rPos = p.cp5().addRadioButton("radio_startPosition",10,10)
.add("Top-right", DRAW_DIR_NE)
.add("Bottom-right", DRAW_DIR_SE)
.add("Bottom-left", DRAW_DIR_SW)
.add("Top-left", DRAW_DIR_NW)
.plugTo(this, "radio_startPosition");
RadioButton rSkip = p.cp5().addRadioButton("radio_pixelSkipStyle",10,100)
.add("Lift pen over masked pixels", 1)
.add("Draw masked pixels as blanks", 2)
.plugTo(this, "radio_pixelSkipStyle");
RadioButton rStyle = p.cp5().addRadioButton("radio_pixelStyle",100,10);
rStyle.add("Variable frequency square wave", PIXEL_STYLE_SQ_FREQ);
rStyle.add("Variable size square wave", PIXEL_STYLE_SQ_SIZE);
rStyle.add("Solid square wave", PIXEL_STYLE_SQ_SOLID);
rStyle.add("Scribble", PIXEL_STYLE_SCRIBBLE);
if (currentHardware >= HARDWARE_VER_MEGA) {
rStyle.add("Spiral", PIXEL_STYLE_CIRCLE);
rStyle.add("Sawtooth", PIXEL_STYLE_SAW);
}
rStyle.plugTo(this, "radio_pixelStyle");
Button submitButton = p.cp5().addButton("submitDrawWindow",0,280,10,120,20)
.setLabel("Generate commands")
.plugTo(this, "submitDrawWindow");
return p;
}
void radio_startPosition(int pos) {
renderStartPosition = pos;
radio_rowStartDirection(1);
}
void radio_rowStartDirection(int dir) {
if (renderStartPosition == DRAW_DIR_NE || renderStartPosition == DRAW_DIR_SW)
renderStartDirection = (dir == 0) ? DRAW_DIR_NW : DRAW_DIR_SE;
else if (renderStartPosition == DRAW_DIR_SE || renderStartPosition == DRAW_DIR_NW)
renderStartDirection = (dir == 0) ? DRAW_DIR_NE : DRAW_DIR_SW;
}
void radio_pixelStyle(int style) {
renderStyle = style;
}
void radio_pixelSkipStyle(int style) {
if (style == 1)
liftPenOnMaskedPixels = true;
else if (style == 2)
liftPenOnMaskedPixels = false;
}
void submitDrawWindow(int theValue) {
println("draw.");
println("Style: " + renderStyle);
println("Start pos: " + renderStartPosition);
println("Start dir: " + renderStartDirection);
switch (renderStyle) {
case PIXEL_STYLE_SQ_FREQ: button_mode_renderSquarePixel(); break;
case PIXEL_STYLE_SQ_SIZE: button_mode_renderScaledSquarePixels(); break;
case PIXEL_STYLE_SQ_SOLID: button_mode_renderSolidSquarePixels(); break;
case PIXEL_STYLE_SCRIBBLE: button_mode_renderScribblePixels(); break;
case PIXEL_STYLE_CIRCLE: button_mode_renderCirclePixel(); break;
case PIXEL_STYLE_SAW: button_mode_renderSawPixel(); break;
}
}
class DrawPixelsWindow extends ControlFrame { class DrawPixelsWindow extends ControlFrame {
@ -32,71 +131,8 @@ class DrawPixelsWindow extends ControlFrame {
} }
}); });
RadioButton rPos = cp5().addRadioButton("radio_startPosition",10,10)
.add("Top-right", DRAW_DIR_NE)
.add("Bottom-right", DRAW_DIR_SE)
.add("Bottom-left", DRAW_DIR_SW)
.add("Top-left", DRAW_DIR_NW)
.plugTo("radio_startPosition");
RadioButton rSkip = cp5().addRadioButton("radio_pixelSkipStyle",10,100)
.add("Lift pen over masked pixels", 1)
.add("Draw masked pixels as blanks", 2)
.plugTo("radio_pixelSkipStyle");
RadioButton rStyle = cp5().addRadioButton("radio_pixelStyle",100,10);
rStyle.add("Variable frequency square wave", PIXEL_STYLE_SQ_FREQ);
rStyle.add("Variable size square wave", PIXEL_STYLE_SQ_SIZE);
rStyle.add("Solid square wave", PIXEL_STYLE_SQ_SOLID);
rStyle.add("Scribble", PIXEL_STYLE_SCRIBBLE);
if (currentHardware >= HARDWARE_VER_MEGA) {
rStyle.add("Spiral", PIXEL_STYLE_CIRCLE);
rStyle.add("Sawtooth", PIXEL_STYLE_SAW);
}
rStyle.plugTo("radio_pixelStyle");
Button submitButton = cp5().addButton("submitDrawWindow",0,280,10,120,20)
.setLabel("Generate commands")
.plugTo("submitDrawWindow");
} }
void radio_startPosition(int pos) {
renderStartPosition = pos;
radio_rowStartDirection(1);
}
void radio_rowStartDirection(int dir) {
if (renderStartPosition == DRAW_DIR_NE || renderStartPosition == DRAW_DIR_SW)
renderStartDirection = (dir == 0) ? DRAW_DIR_NW : DRAW_DIR_SE;
else if (renderStartPosition == DRAW_DIR_SE || renderStartPosition == DRAW_DIR_NW)
renderStartDirection = (dir == 0) ? DRAW_DIR_NE : DRAW_DIR_SW;
}
void radio_pixelStyle(int style) {
renderStyle = style;
}
void radio_pixelSkipStyle(int style) {
if (style == 1)
liftPenOnMaskedPixels = true;
else if (style == 2)
liftPenOnMaskedPixels = false;
}
void submitDrawWindow(int theValue) {
println("draw.");
println("Style: " + renderStyle);
println("Start pos: " + renderStartPosition);
println("Start dir: " + renderStartDirection);
switch (renderStyle) { }
case PIXEL_STYLE_SQ_FREQ: button_mode_renderSquarePixel(); break;
case PIXEL_STYLE_SQ_SIZE: button_mode_renderScaledSquarePixels(); break;
case PIXEL_STYLE_SQ_SOLID: button_mode_renderSolidSquarePixels(); break;
case PIXEL_STYLE_SCRIBBLE: button_mode_renderScribblePixels(); break;
case PIXEL_STYLE_CIRCLE: button_mode_renderCirclePixel(); break;
case PIXEL_STYLE_SAW: button_mode_renderSawPixel(); break;
}
}
}

View File

@ -1,48 +1,64 @@
class MachineExecWindow extends ControlFrame { ControlFrameSimple addMachineExecControlFrame(String theName, int theWidth, int theHeight, int theX, int theY, int theColor ) {
final Frame f = new Frame( theName );
final ControlFrameSimple p = new ControlFrameSimple( this, theWidth, theHeight, theColor );
void execFilename(String filename) { f.add( p );
println("Filename event: "+ filename); p.init();
if (filename != null && filename.length() <= 12) { f.setTitle(theName);
setStoreFilename(filename); f.setSize( p.w, p.h );
sendMachineExecMode(); f.setLocation( theX, theY );
} f.addWindowListener( new WindowAdapter() {
} @Override
public void windowClosing(WindowEvent we) {
void submitExecFilenameWindow(int theValue) { p.dispose();
cp5().get(Textfield.class, "execFilename").submit(); f.dispose();
} }
}
);
f.setResizable( true );
f.setVisible( true );
// sleep a little bit to allow p to call setup.
// otherwise a nullpointerexception might be caused.
try {
Thread.sleep( 100 );
}
catch(Exception e) {
}
// set up controls
Textfield filenameField = p.cp5().addTextfield("machineExec_execFilename",20,20,150,20)
.setText(getStoreFilename())
.setLabel("Filename to execute from")
.addListener( new ControlListener() {
public void controlEvent( ControlEvent ev ) {
machineExec_execFilename(ev.getController().getStringValue());
Textfield tf = p.cp5().get(Textfield.class, "machineExec_execFilename");
}
});
public MachineExecWindow() { Button submitButton = p.cp5().addButton("machineExec_submitExecFilenameWindow",0,180,20,60,20)
super(parentPapplet, 450, 150); .setLabel("Submit")
int xPos = 100; .addListener( new ControlListener() {
int yPos = 100; public void controlEvent( ControlEvent ev ) {
String name = MACHINE_EXEC_WINDOW_NAME; p.cp5().get(Textfield.class, "machineExec_execFilename").submit();
p.cp5().get(Textfield.class, "machineExec_execFilename").setText(getStoreFilename());
final Frame f = new Frame(name); }
f.add(this); });
this.init();
f.setTitle(name); filenameField.setFocus(true);
f.setSize(super.w, super.h);
f.setLocation(xPos, yPos); return p;
f.setResizable(false);
f.setVisible(true);
f.addWindowListener( new WindowAdapter() {
@Override
public void windowClosing(WindowEvent we) {
f.dispose();
}
});
Textfield filenameField = cp5().addTextfield("execFilename",20,20,150,20)
.setText(getStoreFilename())
.setLabel("Filename to execute from")
.plugTo("execFilename");
Button submitButton = cp5().addButton("submitExecFilenameWindow",0,180,20,60,20)
.setLabel("Submit")
.plugTo("submitExecFilenameWindow");
filenameField.setFocus(true);
}
} }
void machineExec_execFilename(String filename) {
println("Filename event: "+ filename);
if (filename != null
&& filename.length() <= 12
&& !"".equals(filename.trim())) {
filename = filename.trim();
setStoreFilename(filename);
sendMachineExecMode();
}
}

View File

@ -11,9 +11,7 @@ class MachineStoreWindow extends ControlFrame {
} }
} }
void toggleAppendToFile(boolean theFlag) {
setOverwriteExistingStoreFile(theFlag);
}
void submitStoreFilenameWindow(int theValue) { void submitStoreFilenameWindow(int theValue) {
cp5().get(Textfield.class, "storeFilename").submit(); cp5().get(Textfield.class, "storeFilename").submit();
@ -56,4 +54,79 @@ class MachineStoreWindow extends ControlFrame {
filenameField.setFocus(true); filenameField.setFocus(true);
} }
} }
ControlFrameSimple addMachineStoreControlFrame(String theName, int theWidth, int theHeight, int theX, int theY, int theColor ) {
final Frame f = new Frame( theName );
final ControlFrameSimple p = new ControlFrameSimple( this, theWidth, theHeight, theColor );
f.add( p );
p.init();
f.setTitle(theName);
f.setSize( p.w, p.h );
f.setLocation( theX, theY );
f.addWindowListener( new WindowAdapter() {
@Override
public void windowClosing(WindowEvent we) {
p.dispose();
f.dispose();
}
}
);
f.setResizable( true );
f.setVisible( true );
// sleep a little bit to allow p to call setup.
// otherwise a nullpointerexception might be caused.
try {
Thread.sleep( 100 );
}
catch(Exception e) {
}
// set up controls
Textfield filenameField = p.cp5().addTextfield("machineStore_storeFilename",20,20,150,20)
.setText(getStoreFilename())
.setLabel("Filename to store to")
.addListener( new ControlListener() {
public void controlEvent( ControlEvent ev ) {
machineStore_storeFilename(ev.getController().getStringValue());
Textfield tf = p.cp5().get(Textfield.class, "machineExec_execFilename");
}
});
Button submitButton = p.cp5().addButton("machineStore_submitStoreFilenameWindow",0,180,20,60,20)
.setLabel("Submit")
.addListener( new ControlListener() {
public void controlEvent( ControlEvent ev ) {
p.cp5().get(Textfield.class, "machineStore_storeFilename").submit();
p.cp5().get(Textfield.class, "machineStore_storeFilename").setText(getStoreFilename());
}
});
Toggle overwriteToggle = p.cp5().addToggle("machineStore_toggleAppendToFile",true,180,50,20,20)
.setCaptionLabel("Overwrite existing file")
.plugTo(this, "machineStore_toggleAppendToFile");
filenameField.setFocus(true);
return p;
}
void machineStore_toggleAppendToFile(boolean theFlag) {
setOverwriteExistingStoreFile(theFlag);
}
void machineStore_storeFilename(String filename) {
println("Filename event: "+ filename);
if (filename != null
&& filename.length() <= 12
&& !"".equals(filename.trim())) {
filename = filename.trim();
setStoreFilename(filename);
sendMachineStoreMode();
}
}

View File

@ -1,113 +1,112 @@
/*------------------------------------------------------------------------ /*------------------------------------------------------------------------
Class and controllers on the "serial port" subwindow Class and controllers on the "serial port" subwindow
------------------------------------------------------------------------*/ ------------------------------------------------------------------------*/
class SerialPortWindow extends ControlFrame { ControlFrameSimple addSerialPortControlFrame(String theName, int theWidth, int theHeight, int theX, int theY, int theColor ) {
public SerialPortWindow() { final Frame f = new Frame( theName );
super(parentPapplet, 150, 350); final ControlFrameSimple p = new ControlFrameSimple( this, theWidth, theHeight, theColor );
int xPos = 100;
int yPos = 100;
final Frame f = new Frame(CHANGE_SERIAL_PORT_WINDOW_NAME); f.add( p );
f.add(this); p.init();
this.init(); f.setTitle(theName);
f.setTitle(CHANGE_SERIAL_PORT_WINDOW_NAME); f.setSize( p.w, p.h );
f.setSize(super.w, super.h); f.setLocation( theX, theY );
f.setLocation(xPos, yPos); f.addWindowListener( new WindowAdapter() {
f.setResizable(true); @Override
f.setVisible(true); public void windowClosing(WindowEvent we) {
p.dispose();
f.addWindowListener( new WindowAdapter() { f.dispose();
@Override }
public void windowClosing(WindowEvent we) { }
f.dispose(); );
} f.setResizable( true );
}); f.setVisible( true );
// sleep a little bit to allow p to call setup.
RadioButton r = cp5().addRadioButton("radio_serialPort") // otherwise a nullpointerexception might be caused.
.setPosition(10, 10) try {
.setSize(15,15) Thread.sleep( 100 );
.setSpacingRow(5) }
.plugTo(parentPapplet, "radio_serialPort"); catch(Exception e) {
}
r.addItem("No serial connection", -1); // set up controls
RadioButton r = p.cp5().addRadioButton("radio_serialPort")
String[] ports = Serial.list(); .setPosition(10, 10)
.setSize(15, 15)
for (int i = 0; i < ports.length; i++) { .setSpacingRow(5)
println("Adding " + ports[i]); .plugTo(this, "radio_serialPort");
r.addItem(ports[i], i);
}
int portNo = getSerialPortNumber(); r.addItem("No serial connection", -1);
if (portNo >= 0 && portNo < ports.length)
r.activate(ports[portNo]); String[] ports = Serial.list();
else
r.activate("No serial connection"); for (int i = 0; i < ports.length; i++) {
} println("Adding " + ports[i]);
r.addItem(ports[i], i);
}
int portNo = getSerialPortNumber();
if (portNo >= 0 && portNo < ports.length)
r.activate(ports[portNo]);
else
r.activate("No serial connection");
return p;
} }
void radio_serialPort(int newSerialPort) void radio_serialPort(int newSerialPort)
{ {
println("In radio_serialPort"); println("In radio_serialPort");
if (newSerialPort == -2) if (newSerialPort == -2)
{ {
} }
else if (newSerialPort == -1) else if (newSerialPort == -1) {
{ println("Disconnecting serial port.");
println("Disconnecting serial port."); useSerialPortConnection = false;
useSerialPortConnection = false; if (myPort != null)
if (myPort != null) {
{ myPort.stop();
myPort.stop(); myPort = null;
myPort = null; }
} drawbotReady = false;
drawbotReady = false; drawbotConnected = false;
drawbotConnected = false; serialPortNumber = newSerialPort;
serialPortNumber = newSerialPort; }
} else if (newSerialPort != getSerialPortNumber()) {
else if (newSerialPort != getSerialPortNumber()) println("About to connect to serial port in slot " + newSerialPort);
{ // Print a list of the serial ports, for debugging purposes:
println("About to connect to serial port in slot " + newSerialPort); if (newSerialPort < Serial.list().length) {
// Print a list of the serial ports, for debugging purposes: try {
if (newSerialPort < Serial.list().length) drawbotReady = false;
{ drawbotConnected = false;
try if (myPort != null) {
{ myPort.stop();
drawbotReady = false; myPort = null;
drawbotConnected = false; }
if (myPort != null)
{ if (getSerialPortNumber() >= 0)
myPort.stop(); println("closing " + Serial.list()[getSerialPortNumber()]);
myPort = null;
} serialPortNumber = newSerialPort;
if (getSerialPortNumber() >= 0) String portName = Serial.list()[serialPortNumber];
println("closing " + Serial.list()[getSerialPortNumber()]);
myPort = new Serial(this, portName, getBaudRate());
serialPortNumber = newSerialPort; //read bytes into a buffer until you get a linefeed (ASCII 10):
String portName = Serial.list()[serialPortNumber]; myPort.bufferUntil('\n');
useSerialPortConnection = true;
myPort = new Serial(this, portName, getBaudRate()); println("Successfully connected to port " + portName);
//read bytes into a buffer until you get a linefeed (ASCII 10): }
myPort.bufferUntil('\n'); catch (Exception e) {
useSerialPortConnection = true; println("Attempting to connect to serial port in slot " + getSerialPortNumber()
println("Successfully connected to port " + portName); + " caused an exception: " + e.getMessage());
} }
catch (Exception e) } else {
{ println("No serial ports found.");
println("Attempting to connect to serial port in slot " + getSerialPortNumber() useSerialPortConnection = false;
+ " caused an exception: " + e.getMessage()); }
} } else {
} println("no serial port change.");
else
{
println("No serial ports found.");
useSerialPortConnection = false;
}
}
else
{
println("no serial port change.");
} }
} }

View File

@ -1,36 +1,36 @@
/** /**
Polargraph controller Polargraph controller
Copyright Sandy Noble 2015. Copyright Sandy Noble 2015.
This file is part of Polargraph Controller. This file is part of Polargraph Controller.
Polargraph Controller is free software: you can redistribute it and/or modify Polargraph Controller is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
Polargraph Controller is distributed in the hope that it will be useful, Polargraph Controller is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with Polargraph Controller. If not, see <http://www.gnu.org/licenses/>. along with Polargraph Controller. If not, see <http://www.gnu.org/licenses/>.
Requires the excellent ControlP5 GUI library available from http://www.sojamo.de/libraries/controlP5/. Requires the excellent ControlP5 GUI library available from http://www.sojamo.de/libraries/controlP5/.
Requires the excellent Geomerative library available from http://www.ricardmarxer.com/geomerative/. Requires the excellent Geomerative library available from http://www.ricardmarxer.com/geomerative/.
This is an application for controlling a polargraph machine, communicating using ASCII command language over a serial link. This is an application for controlling a polargraph machine, communicating using ASCII command language over a serial link.
sandy.noble@gmail.com sandy.noble@gmail.com
http://www.polargraph.co.uk/ http://www.polargraph.co.uk/
https://github.com/euphy/polargraphcontroller https://github.com/euphy/polargraphcontroller
*/ */
void button_mode_sendMachineLiveMode() { void button_mode_sendMachineLiveMode() {
sendMachineLiveMode(); sendMachineLiveMode();
} }
String CHANGE_SERIAL_PORT_WINDOW_NAME = "changeSerialPortWindow"; String CHANGE_SERIAL_PORT_WINDOW_NAME = "changeSerialPortWindow";
String MACHINE_STORE_WINDOW_NAME = "chooseStoreFilenameWindow"; String MACHINE_STORE_WINDOW_NAME = "chooseStoreFilenameWindow";
String MACHINE_EXEC_WINDOW_NAME = "chooseExecFilenameWindow"; String MACHINE_EXEC_WINDOW_NAME = "chooseExecFilenameWindow";
@ -38,23 +38,26 @@ String DRAW_PIXELS_WINDOW_NAME = "drawPixelsWindow";
String DRAW_WRITING_WINDOW_NAME = "drawWritingWindow"; String DRAW_WRITING_WINDOW_NAME = "drawWritingWindow";
void button_mode_serialPortDialog() { void button_mode_serialPortDialog() {
final SerialPortWindow serialPortWindow = new SerialPortWindow(); ControlFrameSimple cf = addSerialPortControlFrame("Serial Port", 200, 200, 20, 240, color( 100 ) );
} }
void button_mode_machineStoreDialog() { void button_mode_machineStoreDialog() {
final MachineStoreWindow machineStoreWindow = new MachineStoreWindow(); ControlFrameSimple cf = addMachineStoreControlFrame("Machine Store", 450, 250, 20, 240, color( 100 ) );
// final MachineStoreWindow machineStoreWindow = new MachineStoreWindow();
} }
void button_mode_machineExecDialog() { void button_mode_machineExecDialog() {
final MachineExecWindow machineExecWindow = new MachineExecWindow(); ControlFrameSimple cf = addMachineExecControlFrame("Machine Execute", 450, 250, 20, 240, color( 100 ) );
// final MachineExecWindow machineExecWindow = new MachineExecWindow();
} }
void button_mode_drawPixelsDialog() { void button_mode_drawPixelsDialog() {
final DrawPixelsWindow drawPixelsWindow = new DrawPixelsWindow(); ControlFrameSimple cf = addDrawPixelsControlFrame("Render pixels", 450, 250, 20, 240, color( 100 ) );
// final DrawPixelsWindow drawPixelsWindow = new DrawPixelsWindow();
} }
void button_mode_drawWritingDialog() { void button_mode_drawWritingDialog() {
final DrawWritingWindow drawWritingWindow = new DrawWritingWindow(); final DrawWritingWindow drawWritingWindow = new DrawWritingWindow();
} }
///*------------------------------------------------------------------------ ///*------------------------------------------------------------------------
@ -64,117 +67,118 @@ String textToWrite = "";
String spriteFilePrefix = "sprite/let"; String spriteFilePrefix = "sprite/let";
String spriteFileSuffix = ".txt"; String spriteFileSuffix = ".txt";
public 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;
int yPos = 100; int yPos = 100;
String name = DRAW_WRITING_WINDOW_NAME; String name = DRAW_WRITING_WINDOW_NAME;
final Frame f = new Frame(name); final Frame f = new Frame(name);
f.add(this); f.add(this);
this.init(); this.init();
f.setTitle(name); f.setTitle(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(false);
f.setVisible(true); f.setVisible(true);
f.addWindowListener( new WindowAdapter() { f.addWindowListener( new WindowAdapter() {
@Override @Override
public void windowClosing(WindowEvent we) { public void windowClosing(WindowEvent we) {
f.dispose(); f.dispose();
} }
}); }
Textfield spriteFileField = cp5().addTextfield("spriteFilePrefixField",20,20,150,20) );
.setText(getSpriteFilePrefix()) Textfield spriteFileField = cp5().addTextfield("spriteFilePrefixField", 20, 20, 150, 20)
.setLabel("File prefix") .setText(getSpriteFilePrefix())
.plugTo("spriteFilePrefixField"); .setLabel("File prefix")
.plugTo("spriteFilePrefixField");
Textfield writingField = cp5().addTextfield("textToWriteField",20,60,400,20) Textfield writingField = cp5().addTextfield("textToWriteField", 20, 60, 400, 20)
.setText(getTextToWrite()) .setText(getTextToWrite())
.setLabel("Text to write") .setLabel("Text to write")
.plugTo("textToWriteField"); .plugTo("textToWriteField");
Button importTextButton = cp5().addButton("importTextButton",0,20,100,120,20) Button importTextButton = cp5().addButton("importTextButton", 0, 20, 100, 120, 20)
.setLabel("Load text from file") .setLabel("Load text from file")
.plugTo("importTextButton"); .plugTo("importTextButton");
RadioButton rPos = cp5().addRadioButton("radio_drawWritingDirection",20,140); RadioButton rPos = cp5().addRadioButton("radio_drawWritingDirection", 20, 140);
// rPos.add("North-east", DRAW_DIR_NE); // rPos.add("North-east", DRAW_DIR_NE);
rPos.add("South-east", DRAW_DIR_SE); rPos.add("South-east", DRAW_DIR_SE);
// rPos.add("South-west", DRAW_DIR_SW); // rPos.add("South-west", DRAW_DIR_SW);
// rPos.add("North-west", DRAW_DIR_NW); // rPos.add("North-west", DRAW_DIR_NW);
rPos.plugTo("radio_drawWritingDirection"); rPos.plugTo("radio_drawWritingDirection");
Button submitButton = cp5.addButton("submitWritingWindow",0,300,100,120,20) Button submitButton = cp5.addButton("submitWritingWindow", 0, 300, 100, 120, 20)
.setLabel("Generate commands") .setLabel("Generate commands")
.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!");
selectInput("Select the text file to load the text from:", "importTextToWriteFromFile", null, this); selectInput("Select the text file to load the text from:", "importTextToWriteFromFile", null, this);
} }
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) public void importTextToWriteFromFile(File selection) {
{ if (selection != null) {
println("Write."); String fp = selection.getAbsolutePath();
println("Input file: " + fp);
Textfield tf = cp5().get(Textfield.class, "spriteFilePrefixField"); List<String> rows = java.util.Arrays.asList(loadStrings(fp));
tf.submit(); StringBuilder sb = new StringBuilder(200);
tf.setText(getSpriteFilePrefix()); for (String row : rows) {
sb.append(row);
Textfield wf = cp5.get(Textfield.class, "textToWriteField"); }
wf.submit(); textToWriteField(sb.toString());
wf.setText(getTextToWrite()); println("Completed text import, " + getTextToWrite().length() + " characters found.");
println("Start dir: " + renderStartDirection);
println("Sprite file prefix: " + spriteFilePrefix);
println("Text: " + textToWrite);
for (int i=0; i<getTextToWrite().length(); i++) { println("Text: " + getTextToWrite());
String filename = getSpriteFilePrefix() + (int) getTextToWrite().charAt(i) + getSpriteFileSuffix();
addToCommandQueue(CMD_DRAW_SPRITE + int(gridSize * pixelScalingOverGridSize) + "," + filename+",END"); Textfield tf = cp5().get(Textfield.class, "textToWriteField");
println(filename); tf.setText(getTextToWrite());
} tf.submit();
} }
}
void submitWritingWindow(int theValue)
{
println("Write.");
Textfield tf = cp5().get(Textfield.class, "spriteFilePrefixField");
tf.submit();
tf.setText(getSpriteFilePrefix());
Textfield wf = cp5.get(Textfield.class, "textToWriteField");
wf.submit();
wf.setText(getTextToWrite());
println("Start dir: " + renderStartDirection);
println("Sprite file prefix: " + spriteFilePrefix);
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);
}
}
} }
// //
//void button_mode_drawWritingDialog() //void button_mode_drawWritingDialog()

View File

@ -944,7 +944,7 @@ void sendMachineStoreMode()
} }
void sendMachineLiveMode() void sendMachineLiveMode()
{ {
addToRealtimeCommandQueue(CMD_MACHINE_MODE_LIVE+"END"); addToCommandQueue(CMD_MACHINE_MODE_LIVE+"END");
} }
void sendMachineExecMode() void sendMachineExecMode()
{ {