Quantcast
Viewing all articles
Browse latest Browse all 40524

[SOLVED] Reference to Method's Object, ofEvents

Hey there,

I've got a ButtonClass that draws a button and creates events when the button is clicked or hovered over. In the ofApp.cpp file I've added a listener for the event, which then calls a method called 'middleMan'.

Here's where the question comes in; what would the syntax be if I wanted to change 'this' in ofListener to point directly to 'myvideo'? For example something like...

	ofAddListener(saveButton.clickevent, this, &ofApp::middleMan);

becomes

	ofAddListener(saveButton.clickevent, myvideo, &VideoClass::saveImage);

but this doesn't seem to work.

Essentially, I'd like to cut out the 'middleMan'.

I don't want to add the ofAddListener inside the VideoClass if possible.

Here's the code (intially I put code from all files but it got too messy so I just cut it down to this:

ofApp.cpp

#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){

	// Set bg to dark grey and cap framerate
	ofSetBackgroundColor(20, 20, 20);
	ofSetFrameRate(60);

	saveButton.setup("Snap!", 30, 30);

	// ********************************************************** //
	// HOW DO I CHANGE "this" to instead refer to the 'myvideo' instance of the VideoClass?
	ofAddListener(saveButton.clickevent, this, &ofApp::middleMan);

}

void ofApp::middleMan()
{
	myvideo.saveImage();
}




//--------------------------------------------------------------	
void ofApp::update(){

	myvideo.update();
}

//--------------------------------------------------------------
void ofApp::draw(){

	myvideo.draw();
}

I understand that a lot of what I said might have not made sense because I'm trying to explain things as I understand them. I don't have much programming experience so your help is appreciated Image may be NSFW.
Clik here to view.
:smile:

Thanks,


Viewing all articles
Browse latest Browse all 40524

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>