hi,
i’m using ofxDatGui with the multi-window application and i have errors when i declare the gui as a shared pointer in ofApp.h. i combined the multi-window example from oF and the data binding example from ofxDatGui. i receive a ‘no matching’ flag in ofmain.h and a ‘use of undeclared identifier’ flag for the shared pointer in ofapp.h.
src.zip (4.4 KB)
ofmain.h
#include "ofMain.h" #include "ofApp.h" #include "GuiApp.h" #include "ofAppGLFWWindow.h"
//======================================================================== int main( ){
ofGLFWWindowSettings settings;
settings.width = 600;
settings.height = 600;
settings.setPosition(ofVec2f(300,0));
settings.resizable = true;
shared_ptr mainWindow = ofCreateWindow(settings);
settings.width = 300;
settings.height = 300;
settings.setPosition(ofVec2f(0,0));
settings.resizable = false;
shared_ptr guiWindow = ofCreateWindow(settings);
shared_ptr mainApp(new ofApp);
shared_ptr guiApp(new GuiApp);
mainApp->gui = guiApp;
ofRunApp(guiWindow, guiApp);
ofRunApp(mainWindow, mainApp); //no matching function to ofRunApp
ofRunMainLoop();
}
ofApp.h
#pragma once
#include "ofMain.h" //#include "GuiApp.h" #include "ofxDatGui.h"
class ofApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
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); shared_ptr<GuiApp> gui; //use of undeclared identifier 'GuiApp' };
ofapp.cpp
#include "ofApp.h"
//-------------------------------------------------------------- void ofApp::setup(){
ofBackground(255);
ofSetCircleResolution(200);
}
//-------------------------------------------------------------- void ofApp::update(){
}
//-------------------------------------------------------------- void ofApp::draw(){ // ofSetColor(gui->color); // ofDrawCircle(ofGetWidth()*0.5,ofGetWidth()*0.5,gui->radius); // ofSetColor(0); // ofDrawBitmapString(ofGetFrameRate(),20,20); }
guiapp.h
#include "GuiApp.h"
void GuiApp::setup() { ofxDatGuiLog::quiet(); // create a simple circle and position it in the middle of the screen // circle = new Circle(150); // instantiate our gui and a couple of range sliders // gui = new ofxDatGui( ofxDatGuiAnchor::TOP_RIGHT ); gui->addHeader("ofxDATGUI DATA BINDING EXAMPLE"); sx = gui->addSlider("CIRCLE X", 0, ofGetWidth()); sy = gui->addSlider("CIRCLE Y", 0, ofGetHeight()); // bind the circle's x & y properties to the gui sliders // sx->bind(circle->x); sy->bind(circle->y); ofSetWindowPosition(0, 0); ofSetWindowShape(1920, 1080); // center the circle onscreen // circle->x = ofGetWidth() / 2; circle->y = ofGetHeight() / 2; }
void GuiApp::update() { // drag the circle around if the mouse is pressed while over it // if (ofGetMousePressed() && gui->getMouseDown() == false){ ofPoint mouse = ofPoint(ofGetMouseX(), ofGetMouseY()); if (circle->inside(mouse)) { circle->x = mouse.x; circle->y = mouse.y; } } }
void GuiApp::draw() { circle->draw(); }
void GuiApp::windowResized(int w, int h) { // update the slider boundaries // sx->setMax(ofGetWidth()); sy->setMax(ofGetHeight()); }
guiapp.h
#pragma once
#include "ofMain.h"
//#include "ofxGui.h"
#include "ofxDatGui.h"
class Circle {
public:
Circle(int radius)
{
x = 100;
y = 100;
mRadius = radius;
}
bool inside(ofPoint mouse)
{
return mouse.distance( ofPoint(x, y) ) <= mRadius;
}
void draw()
{
ofSetColor(ofColor::red);
ofSetCircleResolution(100);
ofDrawCircle(this->x, this->y, mRadius);
}
float x;
float y;
private:
int mRadius;
};
class GuiApp: public ofBaseApp {
public:
void setup();
void update();
void draw();
void windowResized(int w, int h);
bool mDragging;
Circle* circle;
ofxDatGui* gui;
ofxDatGuiSlider* sx;
ofxDatGuiSlider* sy;
};
thanks,
01