Dynamic Sketch size.

edited July 2016 in Library Questions

Hello Friends. I am trying to control the sketch size dynamically with checkBox. So, if I select the checkbox it will change size or if I un-check the checkBox then it will comeback to normal size as before. here is code.

// Need G4P library
import g4p_controls.*;


public void setup(){
  size(500, 670, JAVA2D);
  if(chkPro.isSelected()){
  size(480, 320, JAVA2D);
  }
  else{
   size(480, 600, JAVA2D);
  }


  createGUI();
  customGUI();
  // Place your setup code here

}

public void draw(){
  background(230);

}

// Use this method to add additional statements
// to customise the GUI controls
public void customGUI(){

}


public void chkProperty(GCheckbox source, GEvent event) { //_CODE_:chkPro:390305:
  println("chkPro - GCheckbox >> GEvent." + event + " @ " + millis());
}


public void createGUI(){
  G4P.messagesEnabled(false);
  G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
  G4P.setCursor(ARROW);
  surface.setTitle("Sketch Window");
  chkPro = new GCheckbox(this, 168, 150, 120, 20);
  chkPro.setTextAlign(GAlign.LEFT, GAlign.MIDDLE);
  chkPro.setText("Characteristics");
  chkPro.setTextBold();
  chkPro.setOpaque(false);
  chkPro.addEventHandler(this, "chkProperty");
}

// Variable declarations 
// autogenerated do not edit
GCheckbox chkPro; 

Thanks in Advance

Answers

  • I am not sure if you can change the size dynamically. Could you tell us why would you like to do that? Anyways, in your code, you are changing the size in setup. However, setup only runs once, at the beginning of the sketch. I believe in the latest version of processing, you need to setup the size even before setup, using the setting function call. If you are trying to zoom in working in a picture, you would use scaling functions. If you are working with controls like from G4P, then you will resize/scale all the controls accordingly and all at the same time. I will allow the experts to pitch in regarding if multiple size function calls are allowed.

    Kf

Sign In or Register to comment.