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.
IndexProgramming Questions & HelpPrograms › Contril P5 window question.
Page Index Toggle Pages: 1
Contril P5 window question. (Read 897 times)
Contril P5 window question.
Nov 30th, 2009, 2:47am
 
Hello!,
I'd like to draw a rectangle in  a new control P5 window (not main window) by using mouse pressed function. I've tried it but it doesn't work.  Actually, I'd like to do something like mousepressed in main window and something happen in the other control P5 window.
Anybody know How to do that?

import controlP5.*;
ControlP5 controlP5;
ControlWindow controlWindow;
ControlWindowCanvas cc;

// your controlWindowCanvas class
class MyCanvas extends ControlWindowCanvas {
 public void draw(PApplet theApplet) {
  theApplet.background(255);
 }
 public void mousePressed(PApplet theApplet){
   theApplet.fill(0);
   theApplet.rect(90,10,100,100); // add rectangle
 }
}


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

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

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

}

Thanks,
Re: Contril P5 window question.
Reply #1 - Nov 30th, 2009, 2:29pm
 
I can't answer your question directly since I have not used the controlP5 libaray but I have a couple of thoughts.

Quote:
I'd like to do something like mousepressed in main window and something happen in the other control P5 window.


If you are creating an applet in a webpage or an application full screen as the main window then when you click on the webpage/application this will bring this window to the front hiding any secondary windows.

As I said I am not familiar with this library altough I am sure that it will be able to do what you want. You might look at the G4P libaray, try the examples "Simple Windows" and "Mandelbrot as they use multiple windows.
http://www.lagers.org.uk/g4p/applets/g4p_showcase/index.html

Although I created this library I am not recommending it over controlP5, controlP5 has been arround a lot longer than mine so I am sure there are many others out there that can answer your question, it's just an alternative.
Smiley
Re: Contril P5 window question.
Reply #2 - Nov 30th, 2009, 8:09pm
 
hi there, the code below shows how to do what you are looking for. since the ControlWindowCanvas cant make use of the mousePressed() function as used in your example, i added a condition inside the draw() function of the controlWindowCanvas to check if either the mouse has been pressed inside your main sketch (if so, the example below draws a red rectangle into the controlWindow) or within the controlWindow itself (in this case the example below would draw a black rectangle). hope this helps to achieve what you are looking for. (i also added an empty draw function at the end of the sketch to make it run)
best,
andreas

Quote:
import controlP5.*;
ControlP5 controlP5;
ControlWindow controlWindow;
ControlWindowCanvas cc;

// your controlWindowCanvas class
class MyCanvas extends ControlWindowCanvas {
  
  public void draw(PApplet theApplet) {
    theApplet.background(255);
     // 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,400,400,30);
  controlWindow.setUpdateMode(ControlWindow.NORMAL);

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

}

void draw(){}

Re: Contril P5 window question.
Reply #3 - Nov 30th, 2009, 9:29pm
 
Thank you very much Andreas. This is what I want. I really love control P5 library.
Also, Quark. I have tried to experiment with G4P and it works very well.

Thanks both of you.
Page Index Toggle Pages: 1