I am using:
$ (cd openFrameworks/; git log -1 --decorate | head -3)
commit 16eca45a1d45a6a98621756cabad0e2a9b85ff44 (HEAD, origin/master, origin/HEAD, master)
Author: arturo castro <arturo@openframeworks.cc>
Date: Sat Sep 19 12:18:44 2015 +0200
$ cat /etc/issue
Ubuntu 14.04.3 LTS \n \l
I have prepared the following example, first by running the command line project generator:
openFrameworks/apps/projectGenerator/commandLine/bin/projectGenerator \
-a"ofxGui" -o"openFrameworks" \
openFrameworks/examples/addons/guiBtnTest
... and then replacing the ofApp.{cpp,h}
in examples/addons/guiBtnTest/src
with these files:
ofApp.h
:
#pragma once
#include "ofMain.h"
#include "ofxGui.h" //addon here too
class ofApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
ofxButton testButton;
void testButtonChange(bool & inval);
ofxToggle testToggle;
void testToggleChange(bool & inval);
ofParameter<bool> testBoolParam;
void testBoolParamChange(bool & inval);
ofxPanel gui;
void keyPressed(int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void mouseEntered(int x, int y);
void mouseExited(int x, int y);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
};
ofApp.cpp
:
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
ofSetVerticalSync(true);
ofSetLogLevel(OF_LOG_NOTICE);
// this **** line causes:
/*
ofEvent.h:407:93: error: no matching function for call to ‘ofEvent<void>::make_function(ofApp*&, void (ofApp::*&)(bool&), int&)’
ofBaseEvent<of::priv::Function<void>,Mutex>::remove(make_function(listener,method,priority));
ofEvent.h:402:90: note: candidates are:
...
*/
//testButton.addListener(this, &ofApp::testButtonChange); //****
testToggle.addListener(this, &ofApp::testToggleChange);
testBoolParam.addListener(this, &ofApp::testBoolParamChange);
gui.setup("my panel"); // most of the time you don't need a name but don't forget to call setup
gui.add(testButton.setup("testButton ← !"));
gui.add(testToggle.setup("testToggle ← !", true));
gui.add(testBoolParam.set("testBoolParam ← !", true));
}
//--------------------------------------------------------------
void ofApp::testButtonChange(bool & inval){
if (inval) {
ofLogNotice() << "testButtonChange: true" << endl;
} else {
ofLogNotice() << "testButtonChange: false" << endl;
}
}
//--------------------------------------------------------------
void ofApp::testToggleChange(bool & inval){
if (inval) {
ofLogNotice() << "testToggleChange: true" << endl;
} else {
ofLogNotice() << "testToggleChange: false" << endl;
}
}
//--------------------------------------------------------------
void ofApp::testBoolParamChange(bool & inval){
if (inval) {
ofLogNotice() << "testBoolParamChange: true" << endl;
} else {
ofLogNotice() << "testBoolParamChange: false" << endl;
}
}
//--------------------------------------------------------------
void ofApp::update(){
}
//--------------------------------------------------------------
void ofApp::draw(){
ofBackgroundGradient(ofColor::white, ofColor::gray);
gui.draw();
}
void ofApp::keyPressed(int key){}
void ofApp::keyReleased(int key){}
void ofApp::mouseMoved(int x, int y ){}
void ofApp::mouseDragged(int x, int y, int button){}
void ofApp::mousePressed(int x, int y, int button){}
void ofApp::mouseReleased(int x, int y, int button){}
void ofApp::mouseEntered(int x, int y){}
void ofApp::mouseExited(int x, int y){}
void ofApp::windowResized(int w, int h){}
void ofApp::gotMessage(ofMessage msg){}
void ofApp::dragEvent(ofDragInfo dragInfo){}
Then I build and run with:
cd openFrameworks/examples/addons/guiBtnTest/
make -j 2 Release
MESA_GL_VERSION_OVERRIDE=2.1 ./bin/guiBtnTest
The application looks something like this:
As you can see, I can relatively easily get reaction on clicks from ofxToggle
and ofParameter<bool>
, simply by calling addListener
. However, the same is not valid for ofxButton
- as soon as I try to addListener
to it - I get compilation errors of the error: no matching function for call
type (try uncommenting the ****
line in ofApp.cpp
).
So, my questions are:
- Is it possible somehow to receive an event/trigger on press and release of
ofxButton
inofxGui
? If so, how? - The text used in the app is
"test* ← !"
; as you can see, there is an utf-8 arrow '←
' in there, however, it is not rendered in the app. Is it possible to get extended utf-8 characters in ofxGui widgets - and if so, how?
Thanks in advance for any answers,
Cheers!