Adding Active tripod project
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
//#define IS_DATA_SIMULATED
|
||||
@@ -0,0 +1,96 @@
|
||||
#include "DataManager.h"
|
||||
#include "testApp.h"
|
||||
#include "Globals.h"
|
||||
|
||||
void DataManager::setup()
|
||||
{
|
||||
app = (testApp*)ofGetAppPtr();
|
||||
|
||||
ofFile file;
|
||||
if(file.open("c:\\CRITICAL_INFRASTRUCTURE_config.txt"))
|
||||
{
|
||||
ofBuffer buf = file.readToBuffer() ;
|
||||
file.close();
|
||||
string appIDStr = buf.getFirstLine();
|
||||
appId = ofToInt(appIDStr);
|
||||
printf("config loaded - appIDStr:%s\n", appIDStr.c_str());
|
||||
//string port = buf.getNextLine();
|
||||
publisher0Name = appIDStr + "_0";
|
||||
publisher1Name = appIDStr + "_1";
|
||||
}
|
||||
|
||||
newData.resize(2);
|
||||
|
||||
isPublisher0DataReceived = false;
|
||||
isPublisher1DataReceived = false;
|
||||
|
||||
setupSpacebrew();
|
||||
}
|
||||
|
||||
|
||||
void DataManager::setupSpacebrew()
|
||||
{
|
||||
string host = "54.200.6.109"; // Spacebrew::SPACEBREW_CLOUD; // "localhost";
|
||||
string name = "CRITTICAL INFRASTRUCTURE";
|
||||
string description = "Description goes here. Not sure why.";
|
||||
|
||||
spacebrew.addSubscribe(publisher0Name, Spacebrew::TYPE_RANGE);
|
||||
spacebrew.addSubscribe(publisher1Name, Spacebrew::TYPE_RANGE);
|
||||
spacebrew.connect( host, name, description );
|
||||
|
||||
// listen to spacebrew events
|
||||
Spacebrew::addListener(this, spacebrew);
|
||||
}
|
||||
|
||||
|
||||
void DataManager::update()
|
||||
{
|
||||
if (isPublisher0DataReceived && isPublisher1DataReceived)
|
||||
{
|
||||
isPublisher0DataReceived = false;
|
||||
isPublisher1DataReceived = false;
|
||||
|
||||
// send a DataReceived event
|
||||
app->scene.barGraph.addNewData(newData);
|
||||
}
|
||||
|
||||
|
||||
if (isDataSimulated)
|
||||
{
|
||||
if (ofGetFrameNum() % (int)simulationSpeed == 0)
|
||||
{
|
||||
//newData[0] = (int)(ofNoise(newData.size() * 0.04, ofGetFrameNum() * 0.03, ofGetElapsedTimef() * 0.1) * 1000);
|
||||
newData[0] = (int)(ofNoise(newData.size() * perlinXScale, ofGetElapsedTimef() * perlinYScale) * 1000);
|
||||
newData[1] = (int)(ofNoise((newData.size() + 500) * perlinXScale, (ofGetElapsedTimef() + 1000) * perlinYScale) * 1000);
|
||||
app->scene.barGraph.addNewData(newData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DataManager::draw()
|
||||
{
|
||||
ofPushStyle();
|
||||
ofSetColor(255, 0, 0);
|
||||
ofCircle(sin(ofGetElapsedTimef() * 0.5) * 300 + 300, 100, 20);
|
||||
ofPopStyle();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void DataManager::onMessage( Spacebrew::Message & m )
|
||||
{
|
||||
if (m.name == publisher0Name)
|
||||
{
|
||||
isPublisher0DataReceived = true;
|
||||
//printf("frameNum: %i, publisher0Name: %i \n", ofGetFrameNum(), m.valueRange());
|
||||
newData[0] = m.valueRange();
|
||||
}
|
||||
else if (m.name == publisher1Name)
|
||||
{
|
||||
isPublisher1DataReceived = true;
|
||||
//printf("frameNum: %i, publisher1Name: %i \n", ofGetFrameNum(), m.valueRange());
|
||||
newData[1] = m.valueRange();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include "ofMain.h"
|
||||
|
||||
#include "ofxSpacebrew.h"
|
||||
|
||||
#include "ofMain.h"
|
||||
#include "ofxSpacebrew.h"
|
||||
|
||||
class testApp;
|
||||
|
||||
class DataManager
|
||||
{
|
||||
|
||||
public:
|
||||
void setup();
|
||||
void setupSpacebrew();
|
||||
void update();
|
||||
void draw();
|
||||
|
||||
testApp* app;
|
||||
|
||||
int appId;
|
||||
|
||||
// create your spacebrew object
|
||||
Spacebrew::Connection spacebrew;
|
||||
|
||||
string publisher0Name;
|
||||
string publisher1Name;
|
||||
|
||||
vector<int> newData;
|
||||
|
||||
bool isPublisher0DataReceived;
|
||||
bool isPublisher1DataReceived;
|
||||
|
||||
bool isDataSimulated;
|
||||
float perlinXScale;
|
||||
float perlinYScale;
|
||||
float simulationSpeed;
|
||||
|
||||
// listen to spacebrew Messages
|
||||
void onMessage( Spacebrew::Message & m );
|
||||
};
|
||||
@@ -0,0 +1,175 @@
|
||||
//
|
||||
// gui->cpp
|
||||
// emptyExample
|
||||
//
|
||||
// Created by James Alliban on 25/06/2013.
|
||||
//
|
||||
//
|
||||
|
||||
#include "GUI.h"
|
||||
#include "testApp.h"
|
||||
|
||||
void GUI::setup()
|
||||
{
|
||||
app = (testApp*)ofGetAppPtr();
|
||||
GUIManager::setup();
|
||||
|
||||
dim = 8;
|
||||
|
||||
addKeyboardShortcutsGUI();
|
||||
addGraphAnimationGUI();
|
||||
addBarGraphDesignGUI();
|
||||
addGraphSimulationGUI();
|
||||
addBackgroundGUI();
|
||||
addVariousGUI();
|
||||
|
||||
setGUIColour();
|
||||
}
|
||||
|
||||
|
||||
bool GUI::getVisible()
|
||||
{
|
||||
return GUIManager::getVisible();
|
||||
}
|
||||
|
||||
void GUI::addKeyboardShortcutsGUI()
|
||||
{
|
||||
string title = "KEYBOARD SHORTCUTS";
|
||||
ofxUICanvas* gui = getNewGUI(title);
|
||||
|
||||
gui->addLabel("SPACE - SHOW/HIDE GUI", OFX_UI_FONT_SMALL);
|
||||
gui->addLabel("'[' - PREVIOUS GUI", OFX_UI_FONT_SMALL);
|
||||
gui->addLabel("']' - NEXT GUI", OFX_UI_FONT_SMALL);
|
||||
|
||||
|
||||
finaliseCanvas(gui, true);
|
||||
}
|
||||
|
||||
|
||||
void GUI::addGraphAnimationGUI()
|
||||
{
|
||||
string title = "GRAPH ANIMATION";
|
||||
ofxUICanvas* gui = getNewGUI(title);
|
||||
|
||||
finaliseCanvas(gui, true);
|
||||
}
|
||||
|
||||
|
||||
void GUI::addBarGraphDesignGUI()
|
||||
{
|
||||
string title = "BAR GRAPH DESIGN";
|
||||
ofxUICanvas* gui = getNewGUI(title);
|
||||
|
||||
gui->addSlider("Graph Item X Gap", 5, 50, &app->scene.barGraph.graphItemXGap, length, dim);
|
||||
gui->addSlider("BarWidth", 2, 50, &app->scene.barGraph.barWidth, length, dim);
|
||||
|
||||
gui->addSlider("Data0 red", 0, 255, &app->scene.barGraph.col0[0], length, dim);
|
||||
gui->addSlider("Data0 green", 0, 255, &app->scene.barGraph.col0[1], length, dim);
|
||||
gui->addSlider("Data0 blue", 0, 255, &app->scene.barGraph.col0[2], length, dim);
|
||||
gui->addSlider("Data0 alpha", 0, 255, &app->scene.barGraph.col0[3], length, dim);
|
||||
gui->addSlider("Data1 red", 0, 255, &app->scene.barGraph.col1[0], length, dim);
|
||||
gui->addSlider("Data1 green", 0, 255, &app->scene.barGraph.col1[1], length, dim);
|
||||
gui->addSlider("Data1 blue", 0, 255, &app->scene.barGraph.col1[2], length, dim);
|
||||
gui->addSlider("Data1 alpha", 0, 255, &app->scene.barGraph.col1[3], length, dim);
|
||||
|
||||
finaliseCanvas(gui, true);
|
||||
}
|
||||
|
||||
|
||||
void GUI::addGraphSimulationGUI()
|
||||
{
|
||||
string title = "SIMULATION";
|
||||
ofxUICanvas* gui = getNewGUI(title);
|
||||
|
||||
gui->addToggle("Toggle Data Simulation", &app->dataManager.isDataSimulated, toggleDim, toggleDim);
|
||||
gui->addSlider("Speed (data per frame)", 1, 60, &app->dataManager.simulationSpeed, length, dim);
|
||||
gui->addSlider("Perlin X Scale (data size)", 0.001, 0.5, &app->dataManager.perlinXScale, length, dim);
|
||||
gui->addSlider("Perlin Y Scale (time f)", 0.001, 0.5, &app->dataManager.perlinYScale, length, dim);
|
||||
|
||||
finaliseCanvas(gui, true);
|
||||
}
|
||||
|
||||
|
||||
void GUI::addBackgroundGUI()
|
||||
{
|
||||
string title = "BACKGROUND";
|
||||
ofxUICanvas* gui = getNewGUI(title);
|
||||
|
||||
gui->addLabel("GRADIENT COLOUR");
|
||||
gui->addSlider("Start red", 0, 255, &app->scene.bgGradStartCol[0], length, dim);
|
||||
gui->addSlider("Start green", 0, 255, &app->scene.bgGradStartCol[1], length, dim);
|
||||
gui->addSlider("Start blue", 0, 255, &app->scene.bgGradStartCol[2], length, dim);
|
||||
gui->addSlider("Start alpha", 0, 255, &app->scene.bgGradStartCol[3], length, dim);
|
||||
gui->addSlider("End red", 0, 255, &app->scene.bgGradEndCol[0], length, dim);
|
||||
gui->addSlider("End green", 0, 255, &app->scene.bgGradEndCol[1], length, dim);
|
||||
gui->addSlider("End blue", 0, 255, &app->scene.bgGradEndCol[2], length, dim);
|
||||
gui->addSlider("End alpha", 0, 255, &app->scene.bgGradEndCol[3], length, dim);
|
||||
|
||||
ofAddListener(gui->newGUIEvent, this, &GUI::variousGUIEvent);
|
||||
finaliseCanvas(gui, true);
|
||||
}
|
||||
|
||||
|
||||
void GUI::addVariousGUI()
|
||||
{
|
||||
string title = "VARIOUS";
|
||||
ofxUICanvas* gui = getNewGUI(title);
|
||||
|
||||
//gui->addLabel("GRID");
|
||||
//gui->addToggle("GRID VISIBLE", &app->scene.isGridVisible, toggleDim, toggleDim);
|
||||
//gui->addSlider("GRID ALPHA", 0, 255, &app->scene.gridAlpha, length, dim);
|
||||
|
||||
gui->addLabel("GUI DESIGN");
|
||||
gui->addSlider("RED", 0, 255, 255, length, dim);
|
||||
gui->addSlider("GREEN", 0, 255, 1, length, dim);
|
||||
gui->addSlider("BLUE", 0, 255, 1, length, dim);
|
||||
gui->addSlider("ALPHA", 0, 255, 255, length, dim);
|
||||
|
||||
ofAddListener(gui->newGUIEvent, this, &GUI::variousGUIEvent);
|
||||
finaliseCanvas(gui, true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void GUI::update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void GUI::draw()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GUI::variousGUIEvent(ofxUIEventArgs &e)
|
||||
{
|
||||
string name = e.widget->getName();
|
||||
|
||||
if (name == "RED")
|
||||
{
|
||||
ofxUISlider *slider = (ofxUISlider *) e.widget;
|
||||
color.r = slider->getScaledValue();
|
||||
setGUIColour();
|
||||
}
|
||||
else if (name == "GREEN")
|
||||
{
|
||||
ofxUISlider *slider = (ofxUISlider *) e.widget;
|
||||
color.g = slider->getScaledValue();
|
||||
setGUIColour();
|
||||
}
|
||||
else if (name == "BLUE")
|
||||
{
|
||||
ofxUISlider *slider = (ofxUISlider *) e.widget;
|
||||
color.b = slider->getScaledValue();
|
||||
setGUIColour();
|
||||
}
|
||||
else if (name == "ALPHA")
|
||||
{
|
||||
ofxUISlider *slider = (ofxUISlider *) e.widget;
|
||||
color.a = slider->getScaledValue();
|
||||
setGUIColour();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// GUI.h
|
||||
// emptyExample
|
||||
//
|
||||
// Created by James Alliban on 25/06/2013.
|
||||
//
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ofMain.h"
|
||||
#include "GUIManager.h"
|
||||
|
||||
class testApp;
|
||||
|
||||
class GUI : GUIManager
|
||||
{
|
||||
public:
|
||||
virtual void setup();
|
||||
virtual bool getVisible();
|
||||
|
||||
void addKeyboardShortcutsGUI();
|
||||
void addGraphAnimationGUI();
|
||||
void addBarGraphDesignGUI();
|
||||
void addGraphSimulationGUI();
|
||||
void addBackgroundGUI();
|
||||
void addVariousGUI();
|
||||
|
||||
void variousGUIEvent(ofxUIEventArgs &e);
|
||||
|
||||
virtual void update();
|
||||
virtual void draw();
|
||||
|
||||
testApp* app;
|
||||
vector<string> publishers;
|
||||
};
|
||||
@@ -0,0 +1,204 @@
|
||||
//
|
||||
// GUIManager.cpp
|
||||
//
|
||||
// Created by James Alliban on 25/06/2013.
|
||||
//
|
||||
|
||||
#include "GUIManager.h"
|
||||
|
||||
void GUIManager::setup()
|
||||
{
|
||||
ofAddListener(ofEvents().keyPressed, this, &GUIManager::keyPressed);
|
||||
ofAddListener(ofEvents().exit, this, &GUIManager::exit);
|
||||
|
||||
currentUIID = 0;
|
||||
dim = 16;
|
||||
toggleDim = 16;
|
||||
canvasW = 320;
|
||||
canvasH = ofGetScreenHeight();
|
||||
xInit = OFX_UI_GLOBAL_WIDGET_SPACING;
|
||||
length = canvasW - xInit* 2;
|
||||
toggleSize = 32;
|
||||
spacerW = canvasW - xInit* 2;
|
||||
spacerH = 1;
|
||||
color = ofColor(100, 100, 210, 230);
|
||||
isVisible = false;
|
||||
isAutoSave = true;
|
||||
|
||||
buildTopBarGUI();
|
||||
}
|
||||
|
||||
|
||||
bool GUIManager::getVisible()
|
||||
{
|
||||
return isVisible;
|
||||
}
|
||||
|
||||
|
||||
void GUIManager::buildTopBarGUI()
|
||||
{
|
||||
topBarGui = new ofxUICanvas(canvasW, 0, 600, 146);
|
||||
topBarGui->setColorBack(color);
|
||||
topBarGui->setName(TOP_TITLE);
|
||||
|
||||
topBarGui->addWidgetRight(new ofxUIFPS(OFX_UI_FONT_MEDIUM));
|
||||
topBarGui->addWidgetRight(new ofxUILabelToggle(true, TOP_AUTO_SAVE));
|
||||
topBarGui->addWidgetRight(new ofxUILabelButton(false, TOP_SAVE));
|
||||
topBarGui->addWidgetRight(new ofxUILabelButton(false, TOP_PREVIOUS));
|
||||
topBarGui->addWidgetRight(new ofxUILabelButton(false, TOP_NEXT));
|
||||
|
||||
topBarGui->autoSizeToFitWidgets();
|
||||
|
||||
ofAddListener(topBarGui->newGUIEvent, this, &GUIManager::topBarGUIEvent);
|
||||
finaliseCanvas(topBarGui, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
ofxUICanvas* GUIManager::getNewGUI(string title)
|
||||
{
|
||||
ofxUICanvas* gui = new ofxUICanvas(0, 0, canvasW, canvasH);
|
||||
gui->setColorBack(color);
|
||||
gui->setName(title);
|
||||
gui->addWidgetDown(new ofxUILabel(gui->getName(), OFX_UI_FONT_MEDIUM));
|
||||
gui->addSpacer(spacerW, spacerH);
|
||||
return gui;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GUIManager::finaliseCanvas(ofxUICanvas* gui, bool isAddedToArray)
|
||||
{
|
||||
string name = gui->getName();
|
||||
string xmlPath = "GUI/" + name + "GuiPageSettings.xml";
|
||||
gui->loadSettings(xmlPath);
|
||||
gui->setVisible(false);
|
||||
gui->autoSizeToFitWidgets();
|
||||
if (isAddedToArray) guiPages.push_back(gui);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GUIManager::topBarGUIEvent(ofxUIEventArgs &e) //---------------- Top bar
|
||||
{
|
||||
string name = e.widget->getName();
|
||||
|
||||
if (name == TOP_AUTO_SAVE)
|
||||
{
|
||||
ofxUIToggle *toggle = (ofxUIToggle *)e.widget;
|
||||
isAutoSave = toggle->getValue();
|
||||
}
|
||||
else if (name == TOP_SAVE)
|
||||
{
|
||||
saveSettings();
|
||||
}
|
||||
else if (name == TOP_NEXT)
|
||||
{
|
||||
ofxUIButton *button = (ofxUIButton *)e.widget;
|
||||
if (button->getValue()) nextPage();
|
||||
}
|
||||
else if (name == TOP_PREVIOUS)
|
||||
{
|
||||
ofxUIButton *button = (ofxUIButton *)e.widget;
|
||||
if (button->getValue()) previousPage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GUIManager::keyPressed(ofKeyEventArgs& eventArgs) //int key)
|
||||
{
|
||||
printf("keyPressed - key = %c \n", eventArgs.key);
|
||||
switch (eventArgs.key)
|
||||
{
|
||||
case '[':
|
||||
previousPage();
|
||||
break;
|
||||
|
||||
case ']':
|
||||
nextPage();
|
||||
break;
|
||||
|
||||
case ' ':
|
||||
toggleVisible();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GUIManager::nextPage()
|
||||
{
|
||||
printf("next\n");
|
||||
++currentUIID;
|
||||
showGUI();
|
||||
}
|
||||
|
||||
|
||||
void GUIManager::previousPage()
|
||||
{
|
||||
printf("prev\n");
|
||||
--currentUIID;
|
||||
if (currentUIID < 0) currentUIID = guiPages.size() - 1;
|
||||
showGUI();
|
||||
}
|
||||
|
||||
void GUIManager::showGUI()
|
||||
{
|
||||
for (int i = 0; i < (int)guiPages.size(); i++)
|
||||
{
|
||||
guiPages[i]->setVisible(false);
|
||||
}
|
||||
isVisible = true;
|
||||
if (guiPages.size() > 0)
|
||||
{
|
||||
int newVisibleGUIID = currentUIID % (int)guiPages.size();
|
||||
guiPages[newVisibleGUIID]->setVisible(true);
|
||||
}
|
||||
topBarGui->setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
void GUIManager::toggleVisible()
|
||||
{
|
||||
isVisible = !isVisible;
|
||||
if (isVisible)
|
||||
{
|
||||
showGUI();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < (int)guiPages.size(); i++)
|
||||
{
|
||||
guiPages[i]->setVisible(false);
|
||||
}
|
||||
topBarGui->setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GUIManager::saveSettings()
|
||||
{
|
||||
for (int i = 0; i < (int)guiPages.size(); i++)
|
||||
{
|
||||
string xmlPath = "GUI/" + guiPages[i]->getName() + "guiPagesettings.xml";
|
||||
guiPages[i]->saveSettings(xmlPath);
|
||||
}
|
||||
//topBarGui->saveSettings("GUI/" + topBarGui->getName() + "guiPagesettings.xml");
|
||||
}
|
||||
|
||||
|
||||
void GUIManager::setGUIColour()
|
||||
{
|
||||
for (int i = 0; i < (int)guiPages.size(); i++)
|
||||
{
|
||||
guiPages[i]->setColorBack(color);
|
||||
}
|
||||
topBarGui->setColorBack(color);
|
||||
}
|
||||
|
||||
|
||||
void GUIManager::exit(ofEventArgs& eventArgs)
|
||||
{
|
||||
if (isAutoSave) saveSettings();
|
||||
delete topBarGui;
|
||||
for (int i = 0; i < guiPages.size(); i++)
|
||||
delete guiPages[i];
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
//
|
||||
// GUIManager.h
|
||||
//
|
||||
// Created by James Alliban on 25/06/2013.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ofMain.h"
|
||||
#include "ofEvents.h"
|
||||
#include "ofxUI.h"
|
||||
|
||||
// gui titles
|
||||
#define TOP_TITLE "TOP"
|
||||
|
||||
#define TOP_AUTO_SAVE "AUTO SAVE"
|
||||
#define TOP_SAVE "SAVE"
|
||||
#define TOP_NEXT "NEXT"
|
||||
#define TOP_PREVIOUS "PREV"
|
||||
|
||||
|
||||
class GUIManager
|
||||
{
|
||||
public:
|
||||
//GUIManager();
|
||||
virtual void setup();
|
||||
virtual bool getVisible();
|
||||
|
||||
ofColor color;
|
||||
|
||||
protected:
|
||||
|
||||
virtual void buildTopBarGUI();
|
||||
virtual ofxUICanvas* getNewGUI(string title);
|
||||
virtual void keyPressed(ofKeyEventArgs& eventArgs);
|
||||
virtual void exit(ofEventArgs& eventArgs);
|
||||
virtual void finaliseCanvas(ofxUICanvas* gui, bool isAddedToArray);
|
||||
virtual void topBarGUIEvent(ofxUIEventArgs &e);
|
||||
void guiEvent(ofxUIEventArgs &e);
|
||||
|
||||
|
||||
|
||||
void nextPage();
|
||||
void previousPage();
|
||||
void showGUI();
|
||||
void toggleVisible();
|
||||
|
||||
void saveSettings();
|
||||
|
||||
void setGUIColour();
|
||||
|
||||
ofxUICanvas* topBarGui;
|
||||
|
||||
vector<ofxUICanvas *> guiPages;
|
||||
int currentUIID;
|
||||
|
||||
float dim;
|
||||
float toggleDim;
|
||||
float xInit;
|
||||
float length;
|
||||
float canvasW;
|
||||
float canvasH;
|
||||
float toggleSize;
|
||||
float spacerW, spacerH;
|
||||
bool isVisible;
|
||||
bool isAutoSave;
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
#include "ofMain.h"
|
||||
#include "testApp.h"
|
||||
#include "ofAppGlutWindow.h"
|
||||
|
||||
//========================================================================
|
||||
int main( ){
|
||||
|
||||
ofAppGlutWindow window;
|
||||
ofSetupOpenGL(&window, 1400, 1024, OF_WINDOW); // <-------- setup the GL context
|
||||
|
||||
// this kicks off the running of my app
|
||||
// can be OF_WINDOW or OF_FULLSCREEN
|
||||
// pass in width and height too:
|
||||
ofRunApp( new testApp());
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
#include "testApp.h"
|
||||
|
||||
// TODO
|
||||
// ====
|
||||
// - Make graph system with 3 simple (for now) but different graphs that can be interchanged
|
||||
// - Make events system to send data to scene
|
||||
// -
|
||||
// -
|
||||
// - Add to GUI
|
||||
// - - Publisher choice
|
||||
// - - IP address
|
||||
// - - Host name
|
||||
// - - App name
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// NOTES
|
||||
// =====
|
||||
// - Each publisher should have a unique number. There should be a config file kept in c:/ containing a unique ID
|
||||
// - Check that the local data sources always have the same amount of data.
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void testApp::setup()
|
||||
{
|
||||
ofSetFrameRate(30);
|
||||
ofSetLogLevel(OF_LOG_SILENT);
|
||||
ofSetWindowPosition(0, 100);
|
||||
ofEnableSmoothing();
|
||||
ofSeedRandom(ofRandom(23243));
|
||||
|
||||
dataManager.setup();
|
||||
scene.setup();
|
||||
gui.setup();
|
||||
|
||||
isPaused = false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void testApp::update()
|
||||
{
|
||||
if (isPaused) return;
|
||||
|
||||
dataManager.update();
|
||||
scene.update();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void testApp::draw(){
|
||||
dataManager.draw();
|
||||
scene.draw();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void testApp::mousePressed(int x, int y, int button)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void testApp::keyPressed(int key)
|
||||
{
|
||||
if (key == 'p')
|
||||
{
|
||||
isPaused = !isPaused;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "ofMain.h"
|
||||
|
||||
#include "DataManager.h"
|
||||
#include "Scene.h"
|
||||
#include "GUI.h"
|
||||
|
||||
class testApp : public ofBaseApp{
|
||||
|
||||
public:
|
||||
void setup();
|
||||
void update();
|
||||
void draw();
|
||||
void mousePressed(int x, int y, int button);
|
||||
void keyPressed(int key);
|
||||
|
||||
DataManager dataManager;
|
||||
Scene scene;
|
||||
GUI gui;
|
||||
|
||||
bool isPaused;
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// gui->cpp
|
||||
// emptyExample
|
||||
//
|
||||
// Created by James Alliban on 25/06/2013.
|
||||
//
|
||||
//
|
||||
|
||||
#include "Scene.h"
|
||||
|
||||
|
||||
void Scene::setup()
|
||||
{
|
||||
barGraph.setup();
|
||||
}
|
||||
|
||||
|
||||
void Scene::update()
|
||||
{
|
||||
barGraph.update();
|
||||
}
|
||||
|
||||
|
||||
void Scene::draw()
|
||||
{
|
||||
ofBackgroundGradient(ofColor(bgGradStartCol[0], bgGradStartCol[1], bgGradStartCol[2], bgGradStartCol[3]),
|
||||
ofColor(bgGradEndCol[0], bgGradEndCol[1], bgGradEndCol[2], bgGradEndCol[3]),
|
||||
OF_GRADIENT_CIRCULAR);
|
||||
|
||||
barGraph.draw();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// GUI.h
|
||||
// emptyExample
|
||||
//
|
||||
// Created by James Alliban on 25/06/2013.
|
||||
//
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ofMain.h"
|
||||
#include "BarGraph.h"
|
||||
|
||||
class testApp;
|
||||
|
||||
class Scene
|
||||
{
|
||||
public:
|
||||
void setup();
|
||||
void update();
|
||||
void draw();
|
||||
|
||||
BarGraph barGraph;
|
||||
|
||||
float bgGradStartCol[4];
|
||||
float bgGradEndCol[4];
|
||||
|
||||
};
|
||||
@@ -0,0 +1,42 @@
|
||||
//
|
||||
// gui->cpp
|
||||
// emptyExample
|
||||
//
|
||||
// Created by James Alliban on 25/06/2013.
|
||||
//
|
||||
//
|
||||
|
||||
#include "AbstractGraph.h"
|
||||
|
||||
|
||||
void AbstractGraph::setup()
|
||||
{
|
||||
printf("AbstractGraph::setup()\n");
|
||||
}
|
||||
|
||||
|
||||
void AbstractGraph::update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void AbstractGraph::draw()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void AbstractGraph::addNewData(vector<int> newData)
|
||||
{
|
||||
publisher0Data.push_back(newData[0]);
|
||||
publisher1Data.push_back(newData[1]);
|
||||
|
||||
maxData = ofGetWidth() / graphItemXGap;
|
||||
|
||||
if (publisher0Data.size() > maxData && publisher0Data.size() > maxData)
|
||||
{
|
||||
publisher0Data.erase(publisher0Data.begin());
|
||||
publisher1Data.erase(publisher1Data.begin());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// AbstractGraph.h
|
||||
// emptyExample
|
||||
//
|
||||
// Created by James Alliban on 25/06/2013.
|
||||
//
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ofMain.h"
|
||||
|
||||
class AbstractGraph
|
||||
{
|
||||
public:
|
||||
void setup();
|
||||
void update();
|
||||
void draw();
|
||||
virtual void addNewData(vector<int> newData);
|
||||
|
||||
vector<int> publisher0Data;
|
||||
vector<int> publisher1Data;
|
||||
int maxData; // calculated from graphWidth and graphItemXGap
|
||||
|
||||
float graphItemXGap;
|
||||
ofPoint startPnt;
|
||||
int graphWidth;
|
||||
int graphHeight;
|
||||
|
||||
};
|
||||
@@ -0,0 +1,90 @@
|
||||
//
|
||||
// gui->cpp
|
||||
// emptyExample
|
||||
//
|
||||
// Created by James Alliban on 25/06/2013.
|
||||
//
|
||||
//
|
||||
|
||||
#include "BarGraph.h"
|
||||
|
||||
|
||||
void BarGraph::setup()
|
||||
{
|
||||
AbstractGraph::setup();
|
||||
|
||||
graphItemXGap = 10;
|
||||
}
|
||||
|
||||
|
||||
void BarGraph::update()
|
||||
{
|
||||
// if (ofGetFrameNum() % 30 == 0)
|
||||
// printf("publisher0Data.size():%i \n", publisher0Data.size());
|
||||
}
|
||||
|
||||
|
||||
void BarGraph::draw()
|
||||
{
|
||||
if (publisher0Data.size() > 1)
|
||||
{
|
||||
for (int i = 0; i < publisher0Data.size() - 1; i++)
|
||||
{
|
||||
if (i < publisher0Data.size() - 2)
|
||||
{
|
||||
ofPushStyle();
|
||||
ofSetColor(0, 0, 0);
|
||||
ofLine(i * graphItemXGap, publisher0Data[i], (i + 1) * graphItemXGap, publisher0Data[i + 1]);
|
||||
ofSetColor(0, 0, 0);
|
||||
ofLine(i * graphItemXGap, publisher1Data[i], (i + 1) * graphItemXGap, publisher1Data[i + 1]);
|
||||
ofPopStyle();
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < publisher0Data.size() - 1; i++)
|
||||
{
|
||||
//ofPushStyle();
|
||||
//ofSetColor(255, 0, 0);
|
||||
//ofCircle(i * graphItemXGap, publisher0Data[i], 5);
|
||||
//ofSetColor(0, 255, 0);
|
||||
//ofCircle(i * graphItemXGap, publisher1Data[i], 5);
|
||||
//ofPopStyle();
|
||||
}
|
||||
|
||||
for (int i = 0; i < publisher0Data.size() - 1; i++)
|
||||
{
|
||||
ofPushStyle();
|
||||
|
||||
ofMesh bar;
|
||||
bar.addVertex(ofVec3f(i * graphItemXGap - (barWidth * 0.5), publisher0Data[i], 0));
|
||||
bar.addVertex(ofVec3f(i * graphItemXGap - (barWidth * 0.5) + barWidth, publisher0Data[i], 0));
|
||||
bar.addVertex(ofVec3f(i * graphItemXGap - (barWidth * 0.5), publisher1Data[i], 0));
|
||||
bar.addVertex(ofVec3f(i * graphItemXGap - (barWidth * 0.5) + barWidth, publisher1Data[i], 0));
|
||||
bar.addIndex(0);
|
||||
bar.addIndex(1);
|
||||
bar.addIndex(3);
|
||||
bar.addIndex(0);
|
||||
bar.addIndex(3);
|
||||
bar.addIndex(2);
|
||||
bar.addColor(ofColor(col0[0],col0[1],col0[2], col0[3]));
|
||||
bar.addColor(ofColor(col0[0],col0[1],col0[2], col0[3]));
|
||||
bar.addColor(ofColor(col1[0],col1[1],col1[2], col1[3]));
|
||||
bar.addColor(ofColor(col1[0],col1[1],col1[2], col1[3]));
|
||||
|
||||
bar.drawFaces();
|
||||
|
||||
//ofSetColor(255, 255, 0);
|
||||
//ofRect(i * graphItemXGap - (barWidth * 0.5), publisher0Data[i], barWidth, publisher1Data[i] - publisher0Data[i]);
|
||||
//ofSetColor(0, 0, 0);
|
||||
//ofLine(i * graphItemXGap, publisher0Data[i], i * graphItemXGap, publisher1Data[i]);
|
||||
ofPopStyle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void BarGraph::addNewData(vector<int> newData)
|
||||
{
|
||||
AbstractGraph::addNewData(newData);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// BarGraph.h
|
||||
// emptyExample
|
||||
//
|
||||
// Created by James Alliban on 25/06/2013.
|
||||
//
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ofMain.h"
|
||||
#include "AbstractGraph.h"
|
||||
|
||||
class BarGraph : public AbstractGraph
|
||||
{
|
||||
public:
|
||||
void setup();
|
||||
void update();
|
||||
void draw();
|
||||
virtual void addNewData(vector<int> newData);
|
||||
|
||||
float barWidth;
|
||||
|
||||
float col0[4];
|
||||
float col1[4];
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user