Skip to content

Instantly share code, notes, and snippets.

@elliotwoods
Created April 20, 2015 13:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elliotwoods/993f9a26f56216edfbbb to your computer and use it in GitHub Desktop.
Save elliotwoods/993f9a26f56216edfbbb to your computer and use it in GitHub Desktop.
Rulr workshop #1 : example node
#include "MyTestNode.h"
#include "ofxDigitalEmulsion/Item/Board.h"
using namespace ofxDigitalEmulsion;
//----------
MyTestNode::MyTestNode() {
OFXDIGITALEMULSION_NODE_INIT_LISTENER;
}
//----------
string MyTestNode::getTypeName() const {
return "MyTestNode";
}
//----------
void MyTestNode::init() {
OFXDIGITALEMULSION_NODE_INSPECTOR_LISTENER;
OFXDIGITALEMULSION_NODE_SERIALIZATION_LISTENERS;
this->addInput<Item::Board>();
this->x.set("Position x", 0.0f, -10.0f, 10.0f);
}
//----------
void MyTestNode::drawWorld() {
ofPushStyle();
ofSetColor(ofColor::red);
ofPushMatrix();
ofTranslate(this->x, 0.0f, 0.0f);
ofSphere(0.5);
ofPopMatrix();
ofPopStyle();
}
//----------
ofxCvGui::PanelPtr MyTestNode::getView() {
auto view = make_shared<ofxCvGui::Panels::Base>();
view->onDraw += [this](ofxCvGui::DrawArguments & args) {
ofDrawBitmapString("Hello World", 10, 10);
auto board = this->getInput<Item::Board>();
if (board) {
auto size = board->getSize();
ofDrawBitmapString(ofToString(size.width) + ", " + ofToString(size.height), 10, 20);
}
};
return view;
}
//----------
void MyTestNode::populateInspector(ofxCvGui::ElementGroupPtr inspector) {
auto slider = make_shared<ofxCvGui::Widgets::Slider>(this->x);
inspector->add(slider);
}
//----------
void MyTestNode::serialize(Json::Value & json) {
ofxDigitalEmulsion::Utils::Serializable::serialize(x, json);
}
//----------
void MyTestNode::deserialize(const Json::Value & json) {
ofxDigitalEmulsion::Utils::Serializable::deserialize(x, json);
}
#include "ofxDigitalEmulsion.h"
class MyTestNode : public ofxDigitalEmulsion::Graph::Node {
public:
MyTestNode();
string getTypeName() const override;
void init();
void drawWorld() override;
ofxCvGui::PanelPtr getView() override;
void populateInspector(ofxCvGui::ElementGroupPtr);
void serialize(Json::Value &);
void deserialize(const Json::Value &);
ofParameter<float> x;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment