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 & HelpOther Libraries › ControlP5 ControlCanvas coordinates
Page Index Toggle Pages: 1
ControlP5 ControlCanvas coordinates (Read 460 times)
ControlP5 ControlCanvas coordinates
Jan 4th, 2009, 6:37pm
 
hi,
i am trying to use extended ControlCanvas instances that i can move around and open/collapse in my application.
my problem is that i can't find out how to access their x and y positions. i have rollover functions inside them and at the moment they detect the main applet's mouseX and mouseY coordinates.
thank you for your help,
barbara
Re: ControlP5 ControlCanvas coordinates
Reply #1 - Jan 5th, 2009, 12:39pm
 
hi barbara,
ControlCanvas is just an empty container in controlP5 and doesnt have an x and y position. a controlCanvas only knows PApplet as its parent, this is why the mouseX and mouseY dont work (coordinates are shifted) inside e.g. a ControlGroup which i am assuming you are using. using a controlCanvas from within a ControlGroup requires the canvas to know the coordinates of the group, the current parent. these coordinates should then be used to be subtracted from mouseX and mouseY.
maybe the following example does/shows what you are looking for? (square turns red when mouse is outside, changes color randomly when inside).

Code:

import controlP5.*;

ControlP5 controlP5;
ControlGroup l;

void setup() {
size(400,400);
frameRate(30);

controlP5 = new ControlP5(this);
l = controlP5.addGroup("myGroup",100,40);
l.addCanvas(new TestCanvas());
}

void draw() {
background(0);
}


void controlEvent(ControlEvent theEvent) {
println("got an event from "+theEvent.controller().name());
}


class TestCanvas extends ControlCanvas {
public void draw(PApplet theApplet) {
// store mousePosition relative to ControlGroup l's position
float myMouseX = mouseX - l.position().x;
float myMouseY = mouseY - l.position().y;

// check mousePosition against myMouseX and myMouseY
if(myMouseX>0 && myMouseX<100 && myMouseY>0 && myMouseY<100) {
theApplet.fill(int(random(244)));
}
else {
theApplet.fill(255,0,0);
}
theApplet.rect(0,0,100,100);
}
}

Re: ControlP5 ControlCanvas coordinates
Reply #2 - Jan 5th, 2009, 1:34pm
 
hi,
thank you very much for the detailed reply!
it helps a lot & answers my question fully.
have a good day!
b
Page Index Toggle Pages: 1