Skip to content

Commit

Permalink
Auto fit machine to window, fix tab label sizes, cycle density previe…
Browse files Browse the repository at this point in the history
…w styles, hurray
  • Loading branch information
euphy committed Oct 25, 2015
1 parent 70eaae5 commit a1bdca8
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 33 deletions.
8 changes: 5 additions & 3 deletions Panel.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
3 changes: 3 additions & 0 deletions controlsActions.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion controlsSetup.pde
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ Map<String, Panel> buildPanels() {
generalPanel.setControlPositions(buildControlPositionsForPanel(generalPanel));
generalPanel.setControlSizes(buildControlSizesForPanel(generalPanel));
panels.put(PANEL_NAME_GENERAL, generalPanel);



return panels;
}
Expand Down Expand Up @@ -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");



Expand Down
53 changes: 43 additions & 10 deletions polargraphcontroller.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -751,6 +780,10 @@ void drawImagePage()
strokeWeight(3);
stroke(150);
noFill();
if (rescaleDisplayMachine) {
fitDisplayMachineToWindow();
rescaleDisplayMachine = false;
}
getDisplayMachine().draw();
drawMoveImageOutline();
stroke(255, 0, 0);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
48 changes: 29 additions & 19 deletions tabSetup.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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);

cp5.getTab(TAB_NAME_DETAILS).setLabel(TAB_LABEL_DETAILS);
cp5.getTab(TAB_NAME_DETAILS).activateEvent(true);
cp5.getTab(TAB_NAME_DETAILS).setId(2);

cp5.getTab(TAB_NAME_ROVING).setLabel(TAB_LABEL_ROVING);
cp5.getTab(TAB_NAME_ROVING).activateEvent(true);
cp5.getTab(TAB_NAME_ROVING).setId(3);

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);
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);

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);

Tab trace = cp5.getTab(TAB_NAME_TRACE);
trace.setLabel(TAB_LABEL_TRACE);
trace.activateEvent(true);
trace.setId(4);

Tab queue = cp5.getTab(TAB_NAME_QUEUE);
queue.setLabel(TAB_LABEL_QUEUE);
queue.activateEvent(true);
queue.setId(5);
}

public Set<String> buildPanelNames()
Expand Down

0 comments on commit a1bdca8

Please sign in to comment.