Auto fit machine to window, fix tab label sizes, cycle density preview styles, hurray

This commit is contained in:
Sandy Noble 2015-10-25 11:09:31 +00:00
parent 70eaae51bd
commit a1bdca895f
5 changed files with 80 additions and 30 deletions

View File

@ -120,9 +120,11 @@ class Panel
public void draw()
{
// stroke(outlineColour);
// strokeWeight(2);
// rect(getOutline().getLeft(), getOutline().getTop(), getOutline().getWidth(), getOutline().getHeight());
if (debugPanels) {
stroke(outlineColour);
strokeWeight(2);
rect(getOutline().getLeft(), getOutline().getTop(), getOutline().getWidth(), getOutline().getHeight());
}
drawControls();
}

View File

@ -727,6 +727,9 @@ void numberbox_mode_previewCordOffsetValue(int value)
void button_mode_cycleDensityPreviewStyle()
{
Controller c = cp5.getController(MODE_CYCLE_DENSITY_PREVIEW_STYLE);
c.setLabel(this.controlLabels.get(MODE_CYCLE_DENSITY_PREVIEW_STYLE) + ": " + densityPreviewStyle);
if (densityPreviewStyle == DENSITY_PREVIEW_STYLE_COUNT) {
densityPreviewStyle = 0;
}

View File

@ -167,6 +167,8 @@ Map<String, Panel> buildPanels() {
generalPanel.setControlPositions(buildControlPositionsForPanel(generalPanel));
generalPanel.setControlSizes(buildControlSizesForPanel(generalPanel));
panels.put(PANEL_NAME_GENERAL, generalPanel);
return panels;
}
@ -967,7 +969,7 @@ Map<String, String> buildControlLabels()
result.put(MODE_SEND_BUTTON_DEACTIVATE, "Deactivate button");
result.put(MODE_ADJUST_PREVIEW_CORD_OFFSET, "Cord offset");
result.put(MODE_CYCLE_DENSITY_PREVIEW_STYLE, "Preview style");
result.put(MODE_CYCLE_DENSITY_PREVIEW_STYLE, "Cycle preview style");

View File

@ -412,6 +412,7 @@ public color densityPreviewColour = color(0);
public Integer previewCordOffset = 0;
public boolean debugPanels = false;
public boolean showingSummaryOverlay = true;
public boolean showingDialogBox = false;
@ -526,9 +527,10 @@ String filePath = null;
static PApplet parentPapplet = null;
boolean rescaleDisplayMachine = true;
void setup()
{
size(windowWidth, windowHeight);
println("Running polargraph controller");
frame.setResizable(true);
initLogging();
@ -547,9 +549,10 @@ void setup()
}
loadFromPropertiesFile();
size(windowWidth, windowHeight);
this.cp5 = new ControlP5(this);
initTabs();
String[] serialPorts = Serial.list();
println("Serial ports available on your machine:");
println(serialPorts);
@ -598,6 +601,29 @@ void setup()
frameRate(8);
}
void fitDisplayMachineToWindow() {
Rectangle gr = panels.get(PANEL_NAME_GENERAL).getOutline();
println(gr);
Rectangle ir = panels.get(PANEL_NAME_INPUT).getOutline();
println(ir);
float targetHeight = ir.getBottom() - gr.getTop() - CONTROL_SPACING.y;
println("Target height is " + targetHeight + " pixels");
float machineHeight = getDisplayMachine().getOutline().getHeight();
println(machineHeight);
machineScaling = (targetHeight / machineHeight);
println(machineScaling);
getDisplayMachine().getOffset().x = ((gr.getRight() > ir.getRight()) ? gr.getRight() : ir.getRight()) + CONTROL_SPACING.x;
getDisplayMachine().getOffset().y = gr.getTop();
}
void addEventListeners()
{
frame.addComponentListener(new ComponentAdapter()
@ -632,17 +658,20 @@ void preLoadCommandQueue()
void windowResized()
{
println("Window resized.");
noLoop();
windowWidth = frame.getWidth();
windowHeight = frame.getHeight();
println("New window size: " + windowWidth + " x " + windowHeight);
for (String key : getPanels().keySet())
{
println("Panel: " + key);
Panel p = getPanels().get(key);
p.setSizeByHeight(frame.getHeight() - p.getOutline().getTop() - (DEFAULT_CONTROL_SIZE.y*2));
p.setSizeByHeight(windowHeight - p.getOutline().getTop() - (DEFAULT_CONTROL_SIZE.y*2));
}
// Required to tell CP5 to be able to use the new sized window
cp5.setGraphics(this,0,0);
loop();
}
void draw()
{
@ -751,6 +780,10 @@ void drawImagePage()
strokeWeight(3);
stroke(150);
noFill();
if (rescaleDisplayMachine) {
fitDisplayMachineToWindow();
rescaleDisplayMachine = false;
}
getDisplayMachine().draw();
drawMoveImageOutline();
stroke(255, 0, 0);
@ -1559,10 +1592,10 @@ boolean mouseOverPanel()
for (Panel panel : getPanelsForTab(currentTab))
{
if (panel.getOutline().surrounds(getMouseVector())) {
println("Outline: " + panel.getOutline().toString());
println("OVER PANEL!" + panel.getName());
// println("Outline: " + panel.getOutline().toString());
// println("OVER PANEL!" + panel.getName());
result = true;
break;
break;
}
}
return result;
@ -3027,8 +3060,8 @@ void savePropertiesFile()
props.setProperty("controller.density.preview.style", new Integer(getDensityPreviewStyle()).toString());
// initial screen size
props.setProperty("controller.window.width", new Integer((windowWidth < 50) ? 50 : windowWidth-16).toString());
props.setProperty("controller.window.height", new Integer((windowWidth < 50) ? 50 : windowHeight-38).toString());
props.setProperty("controller.window.width", new Integer((windowWidth < 100) ? 100 : windowWidth-16).toString());
props.setProperty("controller.window.height", new Integer((windowWidth < 100) ? 100 : windowHeight-38).toString());
props.setProperty("controller.testPenWidth.startSize", df.format(testPenWidthStartSize));
props.setProperty("controller.testPenWidth.endSize", df.format(testPenWidthEndSize));

View File

@ -83,25 +83,35 @@ List<String> buildTabNames()
void initTabs()
{
cp5.getTab(TAB_NAME_INPUT).setLabel(TAB_LABEL_INPUT);
cp5.getTab(TAB_NAME_INPUT).activateEvent(true);
cp5.getTab(TAB_NAME_INPUT).setId(1);
int tabWidth = (int)DEFAULT_CONTROL_SIZE.x;
int tabHeight = (int)DEFAULT_CONTROL_SIZE.y;
Tab.padding = 13; // that's a weird thing to do
Tab input = cp5.getTab(TAB_NAME_INPUT);
input.setLabel(TAB_LABEL_INPUT);
input.activateEvent(true);
input.setId(1);
cp5.getTab(TAB_NAME_DETAILS).setLabel(TAB_LABEL_DETAILS);
cp5.getTab(TAB_NAME_DETAILS).activateEvent(true);
cp5.getTab(TAB_NAME_DETAILS).setId(2);
Tab details = cp5.getTab(TAB_NAME_DETAILS);
details.setLabel(TAB_LABEL_DETAILS);
details.activateEvent(true);
details.setId(2);
Tab roving = cp5.getTab(TAB_NAME_ROVING);
roving.setLabel(TAB_LABEL_ROVING);
roving.activateEvent(true);
roving.setId(3);
cp5.getTab(TAB_NAME_ROVING).setLabel(TAB_LABEL_ROVING);
cp5.getTab(TAB_NAME_ROVING).activateEvent(true);
cp5.getTab(TAB_NAME_ROVING).setId(3);
Tab trace = cp5.getTab(TAB_NAME_TRACE);
trace.setLabel(TAB_LABEL_TRACE);
trace.activateEvent(true);
trace.setId(4);
cp5.getTab(TAB_NAME_TRACE).setLabel(TAB_LABEL_TRACE);
cp5.getTab(TAB_NAME_TRACE).activateEvent(true);
cp5.getTab(TAB_NAME_TRACE).setId(4);
cp5.getTab(TAB_NAME_QUEUE).setLabel(TAB_LABEL_QUEUE);
cp5.getTab(TAB_NAME_QUEUE).activateEvent(true);
cp5.getTab(TAB_NAME_QUEUE).setId(5);
Tab queue = cp5.getTab(TAB_NAME_QUEUE);
queue.setLabel(TAB_LABEL_QUEUE);
queue.activateEvent(true);
queue.setId(5);
}
public Set<String> buildPanelNames()