Quantcast
Channel: openFrameworks - Latest posts
Viewing all articles
Browse latest Browse all 40524

OfxGui: utf-8 and reacting on ofxButton press?

$
0
0

Many thanks for the response, @arturo - good to have my questions answered! Cheers!


EDIT: Well, I managed to make an alternate class for ofxButton that reacts on press and release. It is basically just a copy-paste of ofxButton, with some methods set to public, and with a changed valueChanged method; probably not the right best practice, but worksforme for the time being - and maybe it helps someone:

class ofxButtonB : public ofxToggle{
  friend class ofPanel;
public:
  ofxButtonB(){ value.setSerializable(false); }
  ~ofxButtonB(){ }
  ofEvent<void> triggerEvent;
  //~ ofParameter<bool> value; // ofxToggle.h; protected; don't replace here, else events are messed
  bool myval;
  template<class ListenerClass, typename ListenerMethod>
  void addListener(ListenerClass * listener, ListenerMethod method){
    ofAddListener(triggerEvent,listener,method);
  }
  template<class ListenerClass, typename ListenerMethod>
  void removeListener(ListenerClass * listener, ListenerMethod method){
    ofRemoveListener(triggerEvent,listener,method);
  }
  ofxButtonB* setup(const std::string& toggleName, float width = defaultWidth, float height = defaultHeight) {
    setName(toggleName);
    b.x = 0; b.y = 0; b.width = width; b.height = height;
    bGuiActive = false; value = false;
    checkboxRect.set(1, 1, b.height - 2, b.height - 2);
    registerMouseEvents(); value.addListener(this,&ofxButtonB::valueChanged);
    return this;
  }
  bool mouseReleased(ofMouseEventArgs & args){
    bool attended = setValue(args.x, args.y, false);
    bGuiActive = false;
    if(attended){ return true; } else { return false; }
  }
  bool mouseMoved(ofMouseEventArgs & args){ return ofxToggle::mouseMoved(args); }
  bool mousePressed(ofMouseEventArgs & args){ return ofxToggle::mousePressed(args); }
  bool mouseDragged(ofMouseEventArgs & args){ return ofxToggle::mouseDragged(args); }
  void valueChanged(bool & v){
    ofLogNotice() << "valueChanged" << v << endl;
    myval = v;
    //if(!v){
      ofNotifyEvent(triggerEvent, this);
    //}
  }
}; // expected ‘;’ after class definition

It is written like this so you can directly paste it ofApp.h; the listener is again void, like in original ofxButton, but now there is a public property myval so you can retrieve the press state, say like so:

void ofApp::testButtonChange(){
  ofLogNotice() << "testButtonChange: release" << testButton.myval ;
}

Viewing all articles
Browse latest Browse all 40524

Trending Articles



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