ControlP5 caption label: secondary label text overwrite initial text

edited July 2017 in Library Questions

I am trying to change the label on a toggle control from the controlP5 library. The toggle is initialized to "true" with a caption label text of "Running". (Of course, cp5 displays all-caps RUNNING.) When the toggle (identified as "RunPauseToggle") is clicked on, the draw() loop is suspended (Pause mode) until the next toggle. The code fragments -- thanks to kfrajer -- make the run/pass action work. But I can't make the PAUSE text appear alone, it overwrites the preceding RUNNING label.

Here are the important bits. First, near the top is:

boolean runPause = true;

In the setup() block, among other lines, is this:

    RunPauseToggle = cp5.addToggle("runPause")
       .setPosition(ctrlOffsetX, ctrlOffsetY)
       .setSize(100, ctrlSizeY)
       .setFont(font)
       .setCaptionLabel("Running")
       .setColorCaptionLabel(0)
       .setValue(true)
       .setMode(ControlP5.SWITCH)
       ;

At the beginning of the draw() loop is this:

void draw() {
    if(runPause == false){
        RunPauseToggle.setCaptionLabel("Paused");
        return;
    } else {
        RunPauseToggle.setCaptionLabel("Running");
    }

As above, the first toggle of RunPauseToggle suspends draw() but writes PAUSED over RUNNING. The 2nd toggle displays a clean copy of RUNNING. This behavior continues on successive toggles. I've tried setting the label to all blanks (" ") and to no text ("") ahead of the "Paused" command line but that doesn't work. I've browsed the heck out of the forum but without finding a working example of what I want to do.

Thanks for looking and (fingers crossed) responding.

Answers

  • Answer ✓

    but writes PAUSED over RUNNING. The 2nd toggle displays a clean copy of RUNNING.

    If I understand correctly, you could solve your problem like this:

    void draw() {
      background(0);
       if(runPause == false){
    

    In other words, background(0); should be the first line of your code in draw().

    Kf

  • That fixed the overwrite problem. To preserve the appearance at the suspended point I also had to add lines in the if (runPause==false) branch to display the frame count output and the last image generated for the 3D inner window.

    It now looks like this (although some of the functions aren't explained):

    void draw() {
        background(240);
    
        if(runPause==false){
            // display last frame count and image generated below
            text(myFrameCount, xOffset3D + 150, (yOffset3D / 4) + 20);
            image(pg, xOffset3D, yOffset3D);
            RunPauseToggle.setLabel("   Paused");
            return;
        } else {
            RunPauseToggle.setLabel("Running");
        }
    
        fill(100);
        myFrameCount++;
        text(myFrameCount, xOffset3D + 150, (yOffset3D / 4) + 20);
        make3dScene(pg);
        image(pg, xOffset3D, yOffset3D);
    
        // Evolve surface after initial frame
        convolve2D_4Pt(hf.z, hfLap.z, hf.nX, hf.nY, reflectBC);
        scaleArray(hfLap.z, hf.nX, hf.nY, 0.99);
        addArrays(hf.z, hfLap.z, hf.nX, hf.nY);
    }
    

    Thanks again "Kf". I expect not to bother the forum again unless problem is better thought out.

  • Glad everything is working. Good luck!

    Kf

Sign In or Register to comment.