Skip to content
Permalink
Browse files

Merge pull request #505 from mgmax/patch-2

LaserScript: support `prompt(title, defaultValue)` to request user input
  • Loading branch information...
t-oster committed May 4, 2019
2 parents a0c2fb8 + df9db9c commit f5421647c77c2f91150f0908034057dba6c9668a
@@ -0,0 +1,145 @@
function rectangle(x, y, width, height)
{
move(x, y);
line(x+width, y);
line(x+width, y+height);
line(x, y+height);
line(x, y);
}

function segmentLine(x1, y1, x2, y2)
{
move(x1, y1);
line(x2, y2);
}

function segment7draw (x,y,w,h,values)
{
var xw = x+w;
var yh = y+h;
var yh2 = y+h/2;

if (values[0] === 1) //A
{
segmentLine(x, y, xw, y);
}
if (values[1] === 1) //B
{
segmentLine(xw, y, xw, yh2);
}
if (values[2] === 1) //C
{
segmentLine(xw, yh2, xw, yh);
}
if (values[3] === 1) //D
{
segmentLine(xw, yh, x, yh);
}
if (values[4] === 1) //E
{
segmentLine(x, yh, x, yh2);
}
if (values[6] === 1) //G
{
segmentLine(x, yh2, xw, yh2);
}
if (values[5] === 1) //F
{
segmentLine(x, yh2, x, y);
}
}
function drawPlus(x,y,w) {
move(x,y+w/2);
line(x+w,y+w/2);
move(x+w/2,y);
line(x+w/2,y+w);
}
function segment7write (x,y,w,string)
{
var characterMap =
{
'0': [1, 1, 1, 1, 1, 1, 0],
'1': [0, 1, 1, 0, 0, 0, 0],
'2': [1, 1, 0, 1, 1, 0, 1],
'3': [1, 1, 1, 1, 0, 0, 1],
'4': [0, 1, 1, 0, 0, 1, 1],
'5': [1, 0, 1, 1, 0, 1, 1],
'6': [1, 0, 1, 1, 1, 1, 1],
'7': [1, 1, 1, 0, 0, 0, 0],
'8': [1, 1, 1, 1, 1, 1, 1],
'9': [1, 1, 1, 1, 0, 1, 1],
'A': [1, 1, 1, 0, 1, 1, 1],
'B': [0, 0, 1, 1, 1, 1, 1],
'C': [1, 0, 0, 1, 1, 1, 0],
'D': [0, 1, 1, 1, 1, 0, 1],
'E': [1, 0, 0, 1, 1, 1, 1],
'F': [1, 0, 0, 0, 1, 1, 1],
'G': [1, 1, 1, 1, 0, 1, 1],
'H': [0, 1, 1, 0, 1, 1, 1],
'I': [0, 0, 0, 0, 1, 1, 0],
'J': [0, 1, 1, 1, 1, 0, 0],
'K': [0, 1, 1, 0, 1, 1, 1],
'L': [0, 0, 0, 1, 1, 1, 0],
'M': [1, 0, 1, 0, 1, 0, 0],
'N': [0, 0, 1, 0, 1, 0, 1],
'O': [1, 1, 1, 1, 1, 1, 0],
'P': [1, 1, 0, 0, 1, 1, 1],
'Q': [1, 1, 1, 0, 0, 1, 1],
'R': [0, 0, 0, 0, 1, 0, 1],
'S': [1, 0, 1, 1, 0, 1, 1],
'T': [0, 0, 0, 1, 1, 1, 1],
'U': [0, 1, 1, 1, 1, 1, 0],
'V': [0, 0, 1, 1, 1, 0, 0],
'W': [0, 1, 0, 1, 0, 1, 0],
'X': [0, 1, 1, 0, 1, 1, 1],
'Y': [0, 1, 1, 1, 0, 1, 1],
'Z': [1, 1, 0, 1, 1, 0, 1],
' ': [0, 0, 0, 0, 0, 0, 0],
'_': [0, 0, 0, 1, 0, 0, 0],
'-': [0, 0, 0, 0, 0, 0, 1],
',': [0, 0, 1, 0, 0, 0, 0]
};
string=string.toUpperCase();
for (var i = 0; i < string.length; i++)
{
segment7draw(x, y, w, 2*w, characterMap[string[i]]);
x += 1.5*w;
}
}
var rectWidth = 20;
set("power",100);
set("speed", 100);
segment7write (5, 5, 5, 'Power 100 - Speed');
var speed = parseFloat(prompt("Maximum (fastest) speed to test", 100));
var minSpeed = parseFloat(prompt("Minimum (slowest) speed to test", 1));
var stepsize = parseFloat(prompt("Step size", 5));
stepsize = Math.max(stepsize, 1);
var x = 10;
var y = 30;
while (speed >= minSpeed) {
// cut rectangle
set("speed", speed);
rectangle(x,y,rectWidth,rectWidth);
var textX=x;
var textY=y+rectWidth*1.25;

// mark text
set("speed", 100);
segment7write(textX,textY,rectWidth/4,speed.toString());
x += rectWidth*1.1 + 5;
if (x > 250) {
x = 10;
y += rectWidth*2;
}
speed -= stepsize;
}
@@ -118,6 +118,13 @@ public void echo(String text)
//intercepted by decorator anyway
}

@Override
public String prompt(String title, String defaultValue)
{
//intercepted by decorator anyway
return null;
}

}), !PreferencesManager.getInstance().getPreferences().isDisableSandbox());
}
catch (IOException e)
@@ -21,6 +21,7 @@
import com.t_oster.liblasercut.laserscript.ScriptInterface;
import com.t_oster.uicomponents.LogFrame;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
*
@@ -67,5 +68,15 @@ public Object get(String property)
{
return decoratee.get(property);
}

@Override
public String prompt(String title, String defaultValue)
{
String answer = (String) JOptionPane.showInputDialog(null, title, "LaserScript", JOptionPane.QUESTION_MESSAGE, null, null, defaultValue);
if (answer == null) {
answer = defaultValue;
}
return answer;
}

}

0 comments on commit f542164

Please sign in to comment.
You can’t perform that action at this time.