v2.6 added ability to invert the mask to reveal instead of hide

This commit is contained in:
Sandy Noble 2018-09-16 01:47:25 +01:00
parent 5e7e010a79
commit 6665883c9b
4 changed files with 75 additions and 14 deletions

View File

@ -292,6 +292,16 @@ class Machine
}
}
boolean isMasked(PVector pos, float scalingFactor)
{
switch (invertMaskMode) {
case MASK_IS_UNUSED: return false;
case MASKED_COLOURS_ARE_HIDDEN: return isChromaKey(pos, scalingFactor);
case MASKED_COLOURS_ARE_SHOWN: return !isChromaKey(pos, scalingFactor);
default: return false;
}
}
boolean isChromaKey(PVector pos, float scalingFactor)
{
if (getImageFrame().surrounds(pos))
@ -626,7 +636,7 @@ class Machine
PVector cartesianCoord = asCartesianCoords(nativeCoord);
if (selectedArea.surrounds(cartesianCoord))
{
if (isChromaKey(cartesianCoord, scalingFactor))
if (isMasked(cartesianCoord, scalingFactor))
{
nativeCoord.z = MASKED_PIXEL_BRIGHTNESS; // magic number
nativeCoords.add(nativeCoord);

View File

@ -762,11 +762,16 @@ void numberbox_mode_changePolygonizerAdaptativeAngle(float value) {
setupPolygonizer();
}
void dropdown_mode_changePolygonizer(int value)
{
polygonizer = value;
setupPolygonizer();
}
void dropdown_mode_changeMaskInvert(int value)
{
invertMaskMode = value;
rebuildPixels();
}

View File

@ -279,9 +279,9 @@ Map<String, Controller> buildAllControls()
{
Button b = cp5.addButton(controlName, 0, 100, 100, 100, 100);
b.setLabel(getControlLabels().get(controlName));
controlP5.Label l = b.getCaptionLabel();
l.getStyle().marginLeft = 4; //move to the right
b.hide();
controlP5.Label l = b.getCaptionLabel();
l.align(ControlP5.LEFT, CENTER);
map.put(controlName, b);
// println("Added button " + controlName);
}
@ -291,8 +291,8 @@ Map<String, Controller> buildAllControls()
t.setLabel(getControlLabels().get(controlName));
t.hide();
controlP5.Label l = t.getCaptionLabel();
l.getStyle().marginTop = -17; //move upwards (relative to button size)
l.getStyle().marginLeft = 4; //move to the right
l.align(ControlP5.LEFT, CENTER);
l.getStyle().setPaddingLeft(4);
map.put(controlName, t);
// println("Added toggle " + controlName);
}
@ -302,8 +302,8 @@ Map<String, Controller> buildAllControls()
t.setLabel(getControlLabels().get(controlName));
t.hide();
controlP5.Label l = t.getCaptionLabel();
l.getStyle().marginTop = -17; //move upwards (relative to button size)
l.getStyle().marginLeft = 4; //move to the right
l.align(ControlP5.LEFT, CENTER);
l.getStyle().setPaddingLeft(4);
map.put(controlName, t);
// println("Added minitoggle " + controlName);
}
@ -314,8 +314,8 @@ Map<String, Controller> buildAllControls()
n.hide();
n.setDecimalPrecision(0);
controlP5.Label l = n.getCaptionLabel();
l.getStyle().marginTop = -17; //move upwards (relative to button size)
l.getStyle().marginLeft = 40; //move to the right
l.align(ControlP5.LEFT, CENTER);
l.getStyle().setPaddingLeft(35);
// change the control direction to left/right
n.setDirection(Controller.VERTICAL);
map.put(controlName, n);
@ -688,6 +688,12 @@ Map<String, Controller> initialiseDropdownContents(Map<String, Controller> map)
ScrollableList sl = (ScrollableList) map.get(key);
sl.setItems(polygonizerStyles);
}
if (MODE_CHANGE_INVERT_MASK.equals(key))
{
println("Adding " + key);
ScrollableList sl = (ScrollableList) map.get(key);
sl.setItems(invertMaskModes);
}
}
return map;
}
@ -711,6 +717,13 @@ Map<String, Controller> initialiseDropdownValues(Map<String, Controller> map)
sl.setValue(polygonizer);
sl.close();
}
else if (MODE_CHANGE_INVERT_MASK.equals(key))
{
println("Adding " + key);
ScrollableList sl = (ScrollableList) map.get(key);
sl.setValue(polygonizer);
sl.close();
}
}
return map;
}
@ -850,6 +863,7 @@ List<String> getControlNamesForInputPanel()
controlNames.add(MODE_CHANGE_GRID_SIZE);
controlNames.add(MODE_CHANGE_SAMPLE_AREA);
controlNames.add(MODE_CHOOSE_CHROMA_KEY_COLOUR);
controlNames.add(MODE_CHANGE_INVERT_MASK);
controlNames.add(MODE_CHANGE_PIXEL_SCALING);
controlNames.add(MODE_RENDER_PIXEL_DIALOG);
@ -1105,6 +1119,7 @@ Map<String, String> buildControlLabels()
result.put(MODE_MOVE_VECTOR, "Move vector");
result.put(MODE_RENDER_PIXEL_DIALOG, "Render pixels...");
result.put(MODE_CHOOSE_CHROMA_KEY_COLOUR, "Choose mask colour");
result.put(MODE_CHANGE_INVERT_MASK, "Mask mode");
result.put(MODE_CHANGE_PIXEL_SCALING, "Pixel scaling");
result.put(MODE_PEN_LIFT_UP, "Pen lift");
@ -1260,6 +1275,7 @@ Set<String> buildControlNames()
result.add(MODE_CHANGE_MIN_VECTOR_LINE_LENGTH);
result.add(MODE_CHOOSE_CHROMA_KEY_COLOUR);
result.add(MODE_CHANGE_INVERT_MASK);
result.add(MODE_CHANGE_PIXEL_SCALING);
result.add(MODE_PEN_LIFT_UP);
result.add(MODE_PEN_LIFT_DOWN);

View File

@ -54,8 +54,8 @@ import java.awt.BorderLayout;
import java.lang.reflect.Method;
int majorVersionNo = 2;
int minorVersionNo = 5;
int buildNo = 2;
int minorVersionNo = 6;
int buildNo = 0;
String programTitle = "Polargraph Controller v" + majorVersionNo + "." + minorVersionNo + " build " + buildNo;
ControlP5 cp5;
@ -249,6 +249,7 @@ static final String MODE_CHANGE_SAMPLE_AREA = "numberbox_mode_changeSampleArea";
static final String MODE_CHANGE_GRID_SIZE = "numberbox_mode_changeGridSize";
static final String MODE_SHOW_DENSITY_PREVIEW = "minitoggle_mode_showDensityPreview";
static final String MODE_SHOW_IMAGE = "minitoggle_mode_showImage";
static final String MODE_SHOW_QUEUE_PREVIEW = "minitoggle_mode_showQueuePreview";
static final String MODE_SHOW_VECTOR = "minitoggle_mode_showVector";
@ -346,8 +347,17 @@ static final String MODE_CHANGE_POLYGONIZER = "dropdown_mode_changePolygonizer";
static final String MODE_CHANGE_POLYGONIZER_LENGTH = "numberbox_mode_changePolygonizerLength";
static final String MODE_CHANGE_POLYGONIZER_ADAPTATIVE_ANGLE = "numberbox_mode_changePolygonizerAdaptativeAngle";
static final String MODE_CHANGE_INVERT_MASK = "dropdown_mode_changeMaskInvert";
List<String> polygonizerStyles = Arrays.asList("ADAPTATIVE", "UNIFORMLENGTH");
List<String> invertMaskModes = Arrays.asList("Mask off", "Mask hides", "Mask shows");
static final int MASK_MODES_COUNT = 3;
static final int MASK_IS_UNUSED = 0;
static final int MASKED_COLOURS_ARE_HIDDEN = 1;
static final int MASKED_COLOURS_ARE_SHOWN = 2;
PVector statusTextPosition = new PVector(300.0, 12.0);
@ -412,6 +422,7 @@ static final char BITMAP_BACKGROUND_COLOUR = 0x0F;
PVector homePointCartesian = null;
public color chromaKeyColour = color(0,255,0);
public int invertMaskMode = MASK_IS_UNUSED;
// used in the preview page
public color pageColour = color(220);
@ -1554,6 +1565,11 @@ void setChromaKey(PVector p)
{
color col = getDisplayMachine().getPixelAtScreenCoords(p);
chromaKeyColour = col;
rebuildPixels();
}
void rebuildPixels()
{
if (getDisplayMachine().pixelsCanBeExtracted() && isBoxSpecified())
{
getDisplayMachine().extractPixelsFromArea(getBoxVector1(), getBoxVectorSize(), getGridSize(), sampleArea);
@ -2373,10 +2389,24 @@ void readMachineMessage(String msg)
void readMachinePosition(String sync)
{
String[] splitted = split(sync, ",");
int aPosIndex = 0;
int bPosIndex = 0;
if (splitted.length == 4)
{
String currentAPos = splitted[1];
String currentBPos = splitted[2];
aPosIndex = 1;
bPosIndex = 2;
}
else if (splitted.length == 5)
{
aPosIndex = 2;
bPosIndex = 3;
}
if (aPosIndex != 0)
{
String currentAPos = splitted[aPosIndex];
String currentBPos = splitted[bPosIndex];
Float a = Float.valueOf(currentAPos).floatValue();
Float b = Float.valueOf(currentBPos).floatValue();
currentMachinePos.x = a;