@@ -412,6 +412,7 @@ public color densityPreviewColour = color(0);
412412
413413public Integer previewCordOffset = 0 ;
414414
415+ public boolean debugPanels = false ;
415416
416417public boolean showingSummaryOverlay = true ;
417418public boolean showingDialogBox = false ;
@@ -526,9 +527,10 @@ String filePath = null;
526527
527528static PApplet parentPapplet = null ;
528529
530+ boolean rescaleDisplayMachine = true ;
531+
529532void 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+
601627void addEventListeners()
602628{
603629 frame. addComponentListener(new ComponentAdapter ()
@@ -632,17 +658,20 @@ void preLoadCommandQueue()
632658
633659void 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}
647676void 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));
0 commit comments