Created
April 20, 2015 13:31
-
-
Save elliotwoods/993f9a26f56216edfbbb to your computer and use it in GitHub Desktop.
Rulr workshop #1 : example node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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