Skip to content

Commit a1bdca8

Browse files
committed
Auto fit machine to window, fix tab label sizes, cycle density preview styles, hurray
1 parent 70eaae5 commit a1bdca8

File tree

5 files changed

+83
-33
lines changed

5 files changed

+83
-33
lines changed

Panel.pde

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,11 @@ class Panel
120120

121121
public void draw()
122122
{
123-
// stroke(outlineColour);
124-
// strokeWeight(2);
125-
// rect(getOutline().getLeft(), getOutline().getTop(), getOutline().getWidth(), getOutline().getHeight());
123+
if (debugPanels) {
124+
stroke(outlineColour);
125+
strokeWeight(2);
126+
rect(getOutline().getLeft(), getOutline().getTop(), getOutline().getWidth(), getOutline().getHeight());
127+
}
126128

127129
drawControls();
128130
}

controlsActions.pde

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,9 @@ void numberbox_mode_previewCordOffsetValue(int value)
727727

728728
void button_mode_cycleDensityPreviewStyle()
729729
{
730+
Controller c = cp5.getController(MODE_CYCLE_DENSITY_PREVIEW_STYLE);
731+
c.setLabel(this.controlLabels.get(MODE_CYCLE_DENSITY_PREVIEW_STYLE) + ": " + densityPreviewStyle);
732+
730733
if (densityPreviewStyle == DENSITY_PREVIEW_STYLE_COUNT) {
731734
densityPreviewStyle = 0;
732735
}

controlsSetup.pde

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ Map<String, Panel> buildPanels() {
167167
generalPanel.setControlPositions(buildControlPositionsForPanel(generalPanel));
168168
generalPanel.setControlSizes(buildControlSizesForPanel(generalPanel));
169169
panels.put(PANEL_NAME_GENERAL, generalPanel);
170+
171+
170172

171173
return panels;
172174
}
@@ -967,7 +969,7 @@ Map<String, String> buildControlLabels()
967969
result.put(MODE_SEND_BUTTON_DEACTIVATE, "Deactivate button");
968970

969971
result.put(MODE_ADJUST_PREVIEW_CORD_OFFSET, "Cord offset");
970-
result.put(MODE_CYCLE_DENSITY_PREVIEW_STYLE, "Preview style");
972+
result.put(MODE_CYCLE_DENSITY_PREVIEW_STYLE, "Cycle preview style");
971973

972974

973975

polargraphcontroller.pde

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ public color densityPreviewColour = color(0);
412412

413413
public Integer previewCordOffset = 0;
414414

415+
public boolean debugPanels = false;
415416

416417
public boolean showingSummaryOverlay = true;
417418
public boolean showingDialogBox = false;
@@ -526,9 +527,10 @@ String filePath = null;
526527

527528
static PApplet parentPapplet = null;
528529

530+
boolean rescaleDisplayMachine = true;
531+
529532
void setup()
530533
{
531-
size(windowWidth, windowHeight);
532534
println("Running polargraph controller");
533535
frame.setResizable(true);
534536
initLogging();
@@ -547,9 +549,10 @@ void setup()
547549
}
548550
loadFromPropertiesFile();
549551

552+
size(windowWidth, windowHeight);
550553
this.cp5 = new ControlP5(this);
551554
initTabs();
552-
555+
553556
String[] serialPorts = Serial.list();
554557
println("Serial ports available on your machine:");
555558
println(serialPorts);
@@ -598,6 +601,29 @@ void setup()
598601

599602
frameRate(8);
600603
}
604+
605+
void fitDisplayMachineToWindow() {
606+
607+
Rectangle gr = panels.get(PANEL_NAME_GENERAL).getOutline();
608+
println(gr);
609+
610+
Rectangle ir = panels.get(PANEL_NAME_INPUT).getOutline();
611+
println(ir);
612+
613+
float targetHeight = ir.getBottom() - gr.getTop() - CONTROL_SPACING.y;
614+
println("Target height is " + targetHeight + " pixels");
615+
616+
float machineHeight = getDisplayMachine().getOutline().getHeight();
617+
println(machineHeight);
618+
619+
machineScaling = (targetHeight / machineHeight);
620+
println(machineScaling);
621+
622+
getDisplayMachine().getOffset().x = ((gr.getRight() > ir.getRight()) ? gr.getRight() : ir.getRight()) + CONTROL_SPACING.x;
623+
getDisplayMachine().getOffset().y = gr.getTop();
624+
625+
}
626+
601627
void addEventListeners()
602628
{
603629
frame.addComponentListener(new ComponentAdapter()
@@ -632,17 +658,20 @@ void preLoadCommandQueue()
632658

633659
void windowResized()
634660
{
635-
println("Window resized.");
661+
noLoop();
636662
windowWidth = frame.getWidth();
637663
windowHeight = frame.getHeight();
664+
println("New window size: " + windowWidth + " x " + windowHeight);
638665

639666
for (String key : getPanels().keySet())
640667
{
641-
println("Panel: " + key);
642668
Panel p = getPanels().get(key);
643-
p.setSizeByHeight(frame.getHeight() - p.getOutline().getTop() - (DEFAULT_CONTROL_SIZE.y*2));
669+
p.setSizeByHeight(windowHeight - p.getOutline().getTop() - (DEFAULT_CONTROL_SIZE.y*2));
644670
}
671+
672+
// Required to tell CP5 to be able to use the new sized window
645673
cp5.setGraphics(this,0,0);
674+
loop();
646675
}
647676
void draw()
648677
{
@@ -751,6 +780,10 @@ void drawImagePage()
751780
strokeWeight(3);
752781
stroke(150);
753782
noFill();
783+
if (rescaleDisplayMachine) {
784+
fitDisplayMachineToWindow();
785+
rescaleDisplayMachine = false;
786+
}
754787
getDisplayMachine().draw();
755788
drawMoveImageOutline();
756789
stroke(255, 0, 0);
@@ -1559,10 +1592,10 @@ boolean mouseOverPanel()
15591592
for (Panel panel : getPanelsForTab(currentTab))
15601593
{
15611594
if (panel.getOutline().surrounds(getMouseVector())) {
1562-
println("Outline: " + panel.getOutline().toString());
1563-
println("OVER PANEL!" + panel.getName());
1595+
// println("Outline: " + panel.getOutline().toString());
1596+
// println("OVER PANEL!" + panel.getName());
15641597
result = true;
1565-
break;
1598+
break;
15661599
}
15671600
}
15681601
return result;
@@ -3027,8 +3060,8 @@ void savePropertiesFile()
30273060
props.setProperty("controller.density.preview.style", new Integer(getDensityPreviewStyle()).toString());
30283061

30293062
// initial screen size
3030-
props.setProperty("controller.window.width", new Integer((windowWidth < 50) ? 50 : windowWidth-16).toString());
3031-
props.setProperty("controller.window.height", new Integer((windowWidth < 50) ? 50 : windowHeight-38).toString());
3063+
props.setProperty("controller.window.width", new Integer((windowWidth < 100) ? 100 : windowWidth-16).toString());
3064+
props.setProperty("controller.window.height", new Integer((windowWidth < 100) ? 100 : windowHeight-38).toString());
30323065

30333066
props.setProperty("controller.testPenWidth.startSize", df.format(testPenWidthStartSize));
30343067
props.setProperty("controller.testPenWidth.endSize", df.format(testPenWidthEndSize));

tabSetup.pde

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,35 @@ List<String> buildTabNames()
8383

8484
void initTabs()
8585
{
86-
cp5.getTab(TAB_NAME_INPUT).setLabel(TAB_LABEL_INPUT);
87-
cp5.getTab(TAB_NAME_INPUT).activateEvent(true);
88-
cp5.getTab(TAB_NAME_INPUT).setId(1);
89-
90-
cp5.getTab(TAB_NAME_DETAILS).setLabel(TAB_LABEL_DETAILS);
91-
cp5.getTab(TAB_NAME_DETAILS).activateEvent(true);
92-
cp5.getTab(TAB_NAME_DETAILS).setId(2);
93-
94-
cp5.getTab(TAB_NAME_ROVING).setLabel(TAB_LABEL_ROVING);
95-
cp5.getTab(TAB_NAME_ROVING).activateEvent(true);
96-
cp5.getTab(TAB_NAME_ROVING).setId(3);
97-
98-
cp5.getTab(TAB_NAME_TRACE).setLabel(TAB_LABEL_TRACE);
99-
cp5.getTab(TAB_NAME_TRACE).activateEvent(true);
100-
cp5.getTab(TAB_NAME_TRACE).setId(4);
101-
102-
cp5.getTab(TAB_NAME_QUEUE).setLabel(TAB_LABEL_QUEUE);
103-
cp5.getTab(TAB_NAME_QUEUE).activateEvent(true);
104-
cp5.getTab(TAB_NAME_QUEUE).setId(5);
86+
int tabWidth = (int)DEFAULT_CONTROL_SIZE.x;
87+
int tabHeight = (int)DEFAULT_CONTROL_SIZE.y;
88+
89+
Tab.padding = 13; // that's a weird thing to do
90+
91+
Tab input = cp5.getTab(TAB_NAME_INPUT);
92+
input.setLabel(TAB_LABEL_INPUT);
93+
input.activateEvent(true);
94+
input.setId(1);
95+
96+
Tab details = cp5.getTab(TAB_NAME_DETAILS);
97+
details.setLabel(TAB_LABEL_DETAILS);
98+
details.activateEvent(true);
99+
details.setId(2);
100+
101+
Tab roving = cp5.getTab(TAB_NAME_ROVING);
102+
roving.setLabel(TAB_LABEL_ROVING);
103+
roving.activateEvent(true);
104+
roving.setId(3);
105+
106+
Tab trace = cp5.getTab(TAB_NAME_TRACE);
107+
trace.setLabel(TAB_LABEL_TRACE);
108+
trace.activateEvent(true);
109+
trace.setId(4);
110+
111+
Tab queue = cp5.getTab(TAB_NAME_QUEUE);
112+
queue.setLabel(TAB_LABEL_QUEUE);
113+
queue.activateEvent(true);
114+
queue.setId(5);
105115
}
106116

107117
public Set<String> buildPanelNames()

0 commit comments

Comments
 (0)