Hello.
I want to make a class which render a button and toggle.
I'm new to C++ and iit is a little bit difficult for me to understand all about links * and &.
So I think that in constructor of my class I need to set as argument link to main app and then use it in callback functions, like onButtonEvent(), that can get T *owner as first argument. How can I do it? When i use ofApp* construction i've got an error.
Here is my class
ClipLauncher.h
#pragma once
#include "ofMain.h"
#include "ofxDatGui.h"
class ClipLauncher {
public: ClipLauncher(int x, int y, ofApp* context);
string fName, status;
int idx;
ofxDatGui* gui;
ofxDatGuiButton* openFile;
ofxDatGuiToggle* playClip;
void onButtonEvent(ofxDatGuiButtonEvent e);
};
ClipLauncher.cpp
#include "clipLauncher.h"
ClipLauncher::ClipLauncher(int x, int y, ofApp* context) {
gui = new ofxDatGui(x, y);
openFile = gui -> addButton("open file");
openFile -> onButtonEvent(context, &ClipLauncher::onButtonEvent);
playClip = gui -> addToggle("run shred");
playClip -> onButtonEvent(context, &ClipLauncher::onButtonEvent);
}
void ClipLauncher::onButtonEvent(ofxDatGuiButtonEvent e) {
if (e.target == openFile) {
//Open the Open File Dialog
ofFileDialogResult openFileResult= ofSystemLoadDialog("Select .ck file");
if (openFileResult.bSuccess) {
e.target -> setLabel(openFileResult.getName());
fName = openFileResult.getPath();
}
} else if (e.target == playClip) {
if(playClip->getEnabled()) {
if(fName != ""){
string command = "chuck " + fName;
system(command.c_str());
} else {
cout << "no file" << endl;
}
}
}
}