mouseX mouseY

This is a simple question but not sure how to figure it out. I see in ofConstants.h you added mouseX and mouseY (like processing nice!) I want to make it global. I thought that it would be seeing I pull ofMain.h in everything. I want to just use mouseX in a class simple.

any suggestions.

I don’t think it’s working like that . we have a mouseX and mouseY inside of the ofSimpleApp that you can use in a processing style. but that doesn’t help you with other classes, etc.

we were trying to do it like p5, accessible everywhere, but we weren’t able to implement it yet. What we need to do it is make extern variables:

http://www.phim.unibe.ch/comp-doc/c-man-…-class.html

but I don’t think we finished in 0.02 – I remember some issues compiling, and not sure really how clean that is. With processing, the reason that other classes can access mouseX is because they are compiled as inner classes (this is why extra tabs in processing extension will be “.pde”, if you call them “.java” they won’t know about mouseX or mouseY)

we will take a look at what’s needed to get it accessible everywhere. in the worst case we can certainly just make functions like ofGetMouseX() that are accessible everywhere.

take care,
zach

ps : a quick test shows it’s possible, but it’s not implemented in 0.02.

//--------------------------------------------
a) put:

extern int mouseXpos; // for now a different name to avoid clashing with the ofSimpleApp mouseX
extern int mouseYpos;

in ofConstants.h

b) put:

int mouseXpos;
int mouseYpos;

near the top of ofAppGlutGlue.h

in the callbacks for mouse, you can alter the variables -
mouseXpos = y, etc…
//--------------------------------------------

I think you should now be able to use mouseXpos anywhere in any code that includes ofMain. you don’t need to define the variable (since it already is defined), you can just go ahead and use it.

we will definitely take a look at this for 0.03 -

thanks

  • z

Works perfect. Why not just add

extern int mouseX
extern int mouseY

to ofConstant.h

seems like a good idea, we will put it in 0.03, and try to add some functions that allow you to query about keyboard states, etc…

thanks for the suggestion

take care!
zach