Need help with mouse stuff


I recently started using OF and I’m starting to get a grasp of the basics. I’m currently working on a project and I want to have images act as buttons. is this possible? If so, how do I do this.


Hi, using a mod to the code I posted here, Rectangular Button

in ofApp.h

class ofApp: public ofBaseApp{
//... what ever else you might have in this class
ofRectangle myRect;

ofImage img;

in ofApp.cpp

void ofApp::setup(){

//leave what ever else you have here.
//set the position of your rectangle. you can change this at any point during the apps lifetime.
img.load("someImage.png"); //just load whichever image you want to use.
myRect.set(100,100, img.getWidth(), img.getHeight()); // x, y, width, height. we will make the button the same size as the image.

void ofApp::draw(){
// leave whatever else you are drawing

ofSetColor(255);// if you dont set the color to white the image might get drawn with the wrong color. 

void ofApp::mousePressed(int x, int y, int button){
if( myRect.inside(x,y)){
 //the button got clicked. do something


thank you so much!