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 & HelpSyntax Questions › MouseInputListener in Opengl mode
Page Index Toggle Pages: 1
MouseInputListener in Opengl mode (Read 359 times)
MouseInputListener in Opengl mode
Apr 21st, 2008, 7:20pm
 
I've been trying to add mouse input listener to objects in opengl, without success. It works fine in normal mode but for some reason doesn't in opengl.

This is the code not tracing any outputs :

Code:

import processing.opengl.*;
import javax.swing.event.*;

Cell cell;


void setup(){
size (800, 600, OPENGL);
cell = new Cell();
}


class Cell implements MouseInputListener {

Cell(){
addMouseListener(this);
addMouseMotionListener(this);
}

public void mouseDragged(MouseEvent e){
println("mouseDragged");
}

public void mousePressed(MouseEvent e) {
println("mousePressed");
}

public void mouseReleased(MouseEvent e){
println("mousePressed");
}

public void mouseMoved(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e) {}
public void mouseClicked(MouseEvent e){}
}



but changing the rendering mode to :
Code:
 size (800, 600);  


will make it work.

I've seen the buttons topic but i don't like so much having to rely on the main to notify sub classes about mouse events. http://processing.org/learning/topics/buttons.html

There might also be a better way of doing what i'm trying to do too.
I'd be happy to hear about it Wink

Thank you'
Re: MouseInputListener in Opengl mode
Reply #1 - Apr 22nd, 2008, 2:47am
 
hi,
same results here, but i can recommend processing's registerMouseEvent, seen below. the initial code was found in this mouse event handling post.


Code:

import processing.opengl.*;

Cell cell;

void setup(){
size (800, 600,OPENGL);
cell = new Cell(this);

}

void draw() {
}

public class Cell {

Cell(PApplet theParent){
theParent.registerMouseEvent(this);
}

public void mouseEvent(MouseEvent event) {
int x = event.getX();
int y = event.getY();

switch (event.getID()) {
case MouseEvent.MOUSE_PRESSED:
println("MOUSE_PRESSED");
break;
case MouseEvent.MOUSE_RELEASED:
println("MOUSE_RELEASED");
break;
case MouseEvent.MOUSE_CLICKED:
println("MOUSE_CLICKED");
break;
case MouseEvent.MOUSE_DRAGGED:
println("MOUSE_DRAGGED");
break;
case MouseEvent.MOUSE_MOVED:
println("MOUSE_MOVED");
break;
}
}
}
Re: MouseInputListener in Opengl mode
Reply #2 - Apr 22nd, 2008, 11:19am
 

Thanks for that. It's working nicely now.
Page Index Toggle Pages: 1