babel
#1
In trying to port a Processing sketch to OF I’ve got stuck for the second time.
It’s a simple finger painting application that uses a double click to switch between a brush and an eraser.
This was straight forward to achieve in Processing but I can’t figure out how to detect a double click in OF.
Would anyone have any suggestions please?
arturo
#2
you can control the time that has passed between a click and the second one, if its less than for example 300ms then you have a double click:
in testApp.h:
int prevClickTime;
int testApp.cpp:
void mousePressed(int x, int y, int button){
if(ofGetTimeElapsedMillis()-prevClickTime>300){
// switch brush
}
prevClickTime = ofGetTimeElapsedMillis();
}
babel
#3
Thanks Arturo,
That’s a pretty elegant solution to my problem.
Much Appreciated!
babel
#4
Er I still seem to have a problem…
Using ofGetTimeElapsedMillis()
gives me a “not declared in this scope message” when I try to compile.
Do I need to include any particular .h file to gain access to this function?
I’m pretty new to OF too so I might be wrong;
I think you need to add: #include “ofMain.h”
to the top of you’re own header file (.h file).
This imports all the OF functions…
babel
#6
Yep “ofMain.h” is included but I but don’t have any joy.
theo
#7
its ofGetElapsedTimeMillis()
not
ofGetTimeElapsedMillis()

Wee typo there:
ofGetElapsedTimeMillis()
guess we know who types faster out of theo and i 
babel
#9
Bingo!
Thanks for clarifying that!