could be a daft question ...

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?

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

Thanks Arturo,

That’s a pretty elegant solution to my problem.

Much Appreciated!

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…

Yep “ofMain.h” is included but I but don’t have any joy.

its ofGetElapsedTimeMillis()

not

ofGetTimeElapsedMillis()

:slight_smile:

Wee typo there:

ofGetElapsedTimeMillis()


guess we know who types faster out of theo and i :slight_smile:

Bingo!

Thanks for clarifying that!