How can I show a text with toggle button g4p

edited August 2015 in Library Questions

Hi!

I'm trying to use g4p controls and now I'm proving toggle image button. The problem is that I want to show one message when the button is "on" (all the time), and I can't, it shows the message only when it changes its state and then the message disappear even if the button is still "on". This is the code that I'm using:

import g4p_controls.*;

GImageToggleButton tag_OnOff;

public void setup() {
  size(480, 220, JAVA2D);
  G4P.setGlobalColorScheme(GCScheme.ORANGE_SCHEME);
  G4P.setCursor(ARROW);
  if (frame != null)
    frame.setTitle("Sketch Window");
  // Create image toggle buttons
  tag_OnOff  = new GImageToggleButton(this, 10, 90, "o_of.png", 2, 1);
}

public void handleToggleButtonEvents(GImageToggleButton button, GEvent event) { 
  fill(0);
  if(tag_OnOff.getState()==1)
  {
    text("On",10,10);
  }


}

public void draw() {
  background(180);
}

Can you help me please??

Answers

  • _vk_vk
    edited August 2015 Answer ✓

    Use a flag changed in handleTooggleButtonEvents() and draw in draw()

    like (pseudo)

    global

    boolean showText = false;
    

    in draw...

    if(showText){
        text("on", 10, 10);
    }
    

    in handleToggleButtonEvents

    showText = !showText; // this toogles the boolean value
    

    should work :)

  • Thanks a lot!!

Sign In or Register to comment.