making controlp5 sliders invisible after setting up values

edited April 2016 in Library Questions

when executing a saveFrame command on a graphics-type application, the Controlp5 sliders I've set up get saved in the png image file. I can't seem to get the sliders to disappear on a keyPressed() function - ie. i want to press the 'x' key to have the sliders turn invisible - yet the line of code I'm using

cp5.get("nameofslider").hide();

works in the draw() function (outside of the keyPressed() routine so I know the command works - it just doesn't work where it should). Code pasting worked and is shown below - hoping for anyone that has tried the same thing to please wise me up to what needs to happen. Thank you in advance.

btw - the keyPressed routine that I'm needing to run the above hide command works fine for the saveFrame command so I know that's programmed correctly.

Answers

  • set a flag in keyPressed, act on the flag in draw.

  • edited April 2016

    @koogs - thanks for the help. In the below example, I can save the canvas (saveFrame), yet the line of code that is meant to make the slider disappear doesn't work. cp5.get("Darks1X").hide(); works fine on its own - just can't seem to trigger it to work in the function. Leaving one slider on the screen for a test comparison. Any ideas please?

       import controlP5.*;
    
    ControlP5 cp5;
    
    int myColor = color(0, 0, 0);
    int Darks1X = 1800;
    
    void setup() {
      size (1920, 1080);
      background (0);
    
      cp5 = new ControlP5(this);
    
      cp5.addSlider("Darks1X")
        .setPosition(200, 25)
        .setWidth(300)
        .setRange(0, 1800)
        .setSliderMode(Slider.FLEXIBLE)
        ;
      cp5.addSlider("Darks1Value")
        .setPosition(25, 25)
        .setRange(0, 5000)
        ;
    }
    
    void draw() {
      stroke(0);
      ellipse(100, 100, 100, 100);
    
      keyPressed();
    }
    
    void keyPressed() {
    
      if (key=='x') {
    
        cp5.get("Darks1X").hide();
      saveFrame("images/circles-###.png");
    }
    }
    
  • edited April 2016

    OK - still at sea - I duplicated my canvas drawing to a graphics buffer and found that the slider WAS being disabled but this didn't show as the canvas needed to be refreshed somehow to show this. I thought I could just save the buffer after loading it into the canvas, but this doesn't work. Here's the save drawing bit of the code where the slider disappears, the buffer must be empty as nothing appears onto the black background - just a disappearing slider.

    void saveDrawing() {
       cp5.get("Darks1Value").hide();
       background(0);
       image(buffer,0,0);
    
      saveFrame("images/circles-###.png"); 
    
Sign In or Register to comment.