We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Pages: 1 ... 12 13 14 15 16 17
controlP5 (Read 126746 times)
Re: controlP5
Reply #195 - Mar 17th, 2010, 9:49pm
 
Greetings!

I wonder if it would be possible to use image() in the dual window configuration of controlp5. I modified the cancas example as per following:

import controlP5.*;
ControlP5 controlP5;
ControlWindow controlWindow;
ControlWindowCanvas cc;
// your controlWindowCanvas class
class MyCanvas extends ControlWindowCanvas {
 
 public PImage P;
 
 public void setup(PApplet theApplet) {
   
        P = loadImage("paint_bucket.gif");

   
 }
 
 public void draw(PApplet theApplet) {
   theApplet.background(255);
   image(P,0,0);
   
    // a rectangle will be drawn if the mouse has been
   // pressed inside the main sketch window.
   // mousePressed here refers to the mousePressed
   // variable of your main sketch
   if(mousePressed) {
     theApplet.fill(255,0,0);
     theApplet.rect(10,10,100,100);
     theApplet.fill(0);
     theApplet.ellipse(mouseX,mouseY,20,20);
   }
   // will draw a rectangle into the controlWindow
   // if the mouse has been pressed inside the controlWindow itself.
   // theApplet.mousePressed here refers to the
   // mousePressed variable of the controlWindow.
   if(theApplet.mousePressed) {
     theApplet.fill(0);
     theApplet.rect(10,10,100,100);
     theApplet.fill(255,0,0);
     theApplet.ellipse(theApplet.mouseX,theApplet.mouseY,20,20);
   }
   
 }

}



void setup() {
 size(400,400);
 frameRate(30);
 controlP5 = new ControlP5(this);

 controlWindow = controlP5.addControlWindow("controlP5window",100,100,width,height,30);
 controlWindow.setUpdateMode(ControlWindow.NORMAL);

 cc = new MyCanvas();
 cc.pre();
 controlWindow.addCanvas(cc);



}

void draw(){
 
}

and it gives an exception, please help!
Re: controlP5
Reply #196 - Mar 18th, 2010, 1:11am
 
Hello,

in my program I use the library "ControlP5". I want to create a Slider that uses int values. I use the code

controlP5.addSlider("my Slider",1,20, 5, 10,10,50,15);

But with this Slider I can only Slide within float values. How can I change the Slider-Mode to int?
Re: controlP5
Reply #197 - Mar 18th, 2010, 6:18am
 
@bkizzy i adjusted your sketch and made comments inside the code accordingly (indicated with // * ). works for you?

Code:

import controlP5.*;

ControlP5 controlP5;
ControlWindow controlWindow;
ControlWindowCanvas cc;

class MyCanvas extends ControlWindowCanvas {
 
 public PImage P;

 // * change void setup(PApplet theApplet) to MyCanvas()
 // * setup does not exist in ControlWindowCanvas and would
 // * there for not be called automatically, the constructor will though,
 // * so the loadImage call is made here (once).
 public MyCanvas() {
   P = loadImage("sonicacts.png");
 }

 public void draw(PApplet theApplet) {
   theApplet.background(255);
   theApplet.image(P,0,0);
 }
}



void setup() {
 size(400,400);
 frameRate(30);
 controlP5 = new ControlP5(this);

 controlWindow = controlP5.addControlWindow("controlP5window",100,100,width,height,30);
 controlWindow.setUpdateMode(ControlWindow.NORMAL);

 cc = new MyCanvas();
 cc.pre();
 controlWindow.addCanvas(cc);
}

void draw() {
}
Re: controlP5
Reply #198 - Mar 18th, 2010, 6:43am
 
@donnar try the following. i include explanations in the source code, see the comments.

Code:

import controlP5.*;
ControlP5 controlP5;

// in the following variable intSlider will be linked to
// the first slider added to controlP5 in setup below.
// notice that the name of the slider and the name of the
// variable are identical. controlP5 can detect this match and
// will forward changes in the controller value to this variable
// automatically. controlP5 will also know about the type
// of the variable, here int (change int to float and
// see what happens).

int intSlider;

void setup() {
 size(400,400);
 controlP5 = new ControlP5(this);
 controlP5.addSlider("intSlider",1,20, 5, 10,10,50,15);
 controlP5.addSlider("intSliderFunc",1,20, 5, 10,40,50,15);
}


// just as described above, controlP5 can link the name of
// a controller with either a function or variable if the
// names are identical. for the second slider as added above,
// the following function below will be called with
// each change in controller 'intSliderFunc'. here, the
// parameter of function intSliderFunc() is of type int, try
// changing the parameter to float and see what happens.
void  intSliderFunc(int theValue) {
 println(theValue);
}

void draw() {
 background(0);  
}
Re: controlP5
Reply #199 - Mar 18th, 2010, 11:34am
 
Perfect thanks!!
Re: controlP5
Reply #200 - Mar 19th, 2010, 1:32am
 
Thanks a lot, that works fine.
Re: controlP5
Reply #201 - Mar 19th, 2010, 3:53pm
 
Hello again!

I am really loving the ControlP5 library!

I have, however, been fighting with a simple action.

On roll over of a button, I'd like a drop down menu to fly down.
On roll out, I'd like for the drop down menu to fly back up.

I have tried a few things with my code and think I have over complicated it. Are there any short examples you are aware of for me to review?

Thank you as always for your time!

--
Ayari

Re: controlP5
Reply #202 - Mar 22nd, 2010, 12:45pm
 
Sorry to be a bother, just hoping for some help with my above post. Drop down menus on Roll Over anyone?

Even just a simple example.

Thank you!

--
Ayari
Re: controlP5
Reply #203 - Mar 22nd, 2010, 4:10pm
 
You could do a couple things I think.  The control itself has the ability to detect mouseover.

if (controlP5.window(this).isMouseOver() == true) {
//do something with the button
}

or you could check the mouse position every draw and compare it with your slider position.

if (mouseX < 20 && mouseX > 10 && mouseY < 30 && mouseY > 10) {
//do something with the button
}
Re: controlP5
Reply #204 - Mar 23rd, 2010, 2:03am
 
I wish to disable all keyboard shortcuts for this library.

so far I've found the lock() function which disables repositioning of the various elements.

how can I prevent the user from hiding them or saving/loading the data?

cheers
Re: controlP5
Reply #205 - Mar 28th, 2010, 7:00pm
 
Hello again :-)

Is it possible to change the function that is called when a button is clicked?

controlP5.Button b1 = controlP5.addButton(“myButton”,someValue,currentButtonX,currentButtonY,buttonWid
th,buttonHeight);

The button created above will call a function called myButton when it’s clicked because that is the name given to the button.

But what if I want to create 20 buttons that all call the same function?  Is that possible?  I couldn’t find anything in the documentation that suggested this…

Thanks as always!

--
Ayari
Re: controlP5
Reply #206 - Mar 29th, 2010, 4:28am
 
hi, you could use the following strategy to achieve what you are looking for: 20 buttons, named-id for each button starts with 'button', inside controlEvent, each button-click gets forwarded to function checkButton. further details see comments inside the source code below.

Quote:
import controlP5.*;
ControlP5 controlP5;

void setup() {
  size(400,400);
  controlP5 = new ControlP5(this);
  // add 20 buttons, the named-id for each button will start
  // with 'button' followed by a number. in controlP5 each
  // controller should have its own unique named-id.
  // each button click will result in control event
  // which will trigger function controlEvent() below.
  for(int i=0;i<20;i++) {
    int x = 100 + (i%4) * 55;
    int y = 100 + (i/4) * 25;
    controlP5.addButton("button"+i, i, x, y, 50, 20);
  }
}


void draw() {
  background(255);
}


void controlEvent(ControlEvent theEvent) {
  // with every control event triggered, we check
  // the named-id of a controller. if the named-id
  // starts with 'button', the ControlEvent - actually
  // the value of the button - will be forwarded to
  // function checkButton() below.
  if(theEvent.name().startsWith("button")) {
    checkButton(theEvent.controller().value());
  }
}


void checkButton(float theButton) {
  println("got a click, value : "+theButton);
}



Re: controlP5
Reply #207 - Mar 29th, 2010, 7:21am
 
Thank you so much! Works perfectly!!
Smiley
Re: controlP5
Reply #208 - Apr 1st, 2010, 2:35pm
 
Having problem with removing a controller.
When I do.. controlP5.remove("button1");  I get this...

java.lang.reflect.InvocationTargetException
     at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
a:25)
     at java.lang.reflect.Method.invoke(Method.java:597)
     at processing.core.PApplet$RegisteredMethods.handle(PApplet.java:849)
     at processing.core.PApplet.handleMouseEvent(PApplet.java:1759)
     at processing.core.PApplet.dequeueMouseEvents(PApplet.java:1713)
     at processing.core.PApplet.handleDraw(PApplet.java:1605)
     at processing.core.PApplet.run(PApplet.java:1496)
     at java.lang.Thread.run(Thread.java:637)
Caused by: java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 0
     at java.util.Vector.get(Vector.java:694)
     at controlP5.ControllerList.get(ControllerList.java:64)
     at controlP5.ControllerGroup.setMousePressed(ControllerGroup.java:582)
     at controlP5.ControllerGroup.setMousePressed(ControllerGroup.java:582)
     at controlP5.ControlWindow.mouseEvent(Unknown Source)
Re: controlP5
Reply #209 - Apr 1st, 2010, 6:50pm
 
Figured it out.. I was running the commands for the button I was trying to rebuild.  Guess you can't remove it, if your still in the execution of the button click.  So... you can't create a button, then use that button to remove and readd itself.  I had to set up a boolean to do it in the next draw.
Pages: 1 ... 12 13 14 15 16 17