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(){}