Skip to content

Commit

Permalink
Node can toggle draw cursor. builder returns derived pointers, Fullsc…
Browse files Browse the repository at this point in the history
…reen/currentPanel prototype in place
  • Loading branch information
elliotwoods committed Mar 14, 2012
1 parent 13fd5d9 commit 89a0780
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 41 deletions.
2 changes: 1 addition & 1 deletion ofxCvGuiLib/ofxCvGuiLib.vcxproj
Expand Up @@ -114,7 +114,7 @@
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<AdditionalIncludeDirectories>..\..\..\addons\ofxCvGui2\src;..\..\..\libs\openFrameworks;..\..\..\libs\openFrameworks\graphics;..\..\..\libs\openFrameworks\app;..\..\..\libs\openFrameworks\sound;..\..\..\libs\openFrameworks\utils;..\..\..\libs\openFrameworks\communication;..\..\..\libs\openFrameworks\video;..\..\..\libs\openFrameworks\types;..\..\..\libs\openFrameworks\math;..\..\..\libs\openFrameworks\3d;..\..\..\libs\openFrameworks\gl;..\..\..\libs\openFrameworks\events;..\..\..\libs\glut\include;..\..\..\libs\rtAudio\include;..\..\..\libs\quicktime\include;..\..\..\libs\freetype\include;..\..\..\libs\freetype\include\freetype2;..\..\..\libs\freeImage\include;..\..\..\libs\fmodex\include;..\..\..\libs\videoInput\include;..\..\..\libs\glew\include\;..\..\..\libs\glu\include;..\..\..\libs\tess2\include;..\..\..\libs\cairo\include\cairo;..\..\..\libs\poco\include;..\..\addons;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\..\addons\ofxGrabCam\src;..\..\..\addons\ofxCvGui2\src;..\..\..\libs\openFrameworks;..\..\..\libs\openFrameworks\graphics;..\..\..\libs\openFrameworks\app;..\..\..\libs\openFrameworks\sound;..\..\..\libs\openFrameworks\utils;..\..\..\libs\openFrameworks\communication;..\..\..\libs\openFrameworks\video;..\..\..\libs\openFrameworks\types;..\..\..\libs\openFrameworks\math;..\..\..\libs\openFrameworks\3d;..\..\..\libs\openFrameworks\gl;..\..\..\libs\openFrameworks\events;..\..\..\libs\glut\include;..\..\..\libs\rtAudio\include;..\..\..\libs\quicktime\include;..\..\..\libs\freetype\include;..\..\..\libs\freetype\include\freetype2;..\..\..\libs\freeImage\include;..\..\..\libs\fmodex\include;..\..\..\libs\videoInput\include;..\..\..\libs\glew\include\;..\..\..\libs\glu\include;..\..\..\libs\tess2\include;..\..\..\libs\cairo\include\cairo;..\..\..\libs\poco\include;..\..\addons;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
Expand Down
30 changes: 15 additions & 15 deletions src/ofxCvGui/Builder.cpp
Expand Up @@ -8,41 +8,41 @@ namespace ofxCvGui {
}

//----------
PanelPtr Builder::add(ofBaseDraws& asset, string caption) {
PanelPtr newPanel( new Panels::Draws(asset) );
ofPtr<Panels::Draws> Builder::add(ofBaseDraws& asset, string caption) {
ofPtr<Panels::Draws> newPanel( new Panels::Draws(asset) );
newPanel->setCaption(caption);
controller.add(newPanel);
controller.add(PanelPtr(newPanel));
return newPanel;
}

//----------
PanelPtr Builder::add(const ofPixels& asset, string caption) {
PanelPtr newPanel( new Panels::Pixels(asset) );
ofPtr<Panels::Pixels> Builder::add(const ofPixels& asset, string caption) {
ofPtr<Panels::Pixels> newPanel( new Panels::Pixels(asset) );
newPanel->setCaption(caption);
controller.add(newPanel);
controller.add(PanelPtr(newPanel));
return newPanel;
}

//----------
PanelPtr Builder::add(const vector<ofPixels>& asset, string caption) {
PanelPtr newPanel( new Panels::PixelsVector(asset) );
ofPtr<Panels::PixelsVector> Builder::add(const vector<ofPixels>& asset, string caption) {
ofPtr<Panels::PixelsVector> newPanel;
newPanel->setCaption(caption);
controller.add(newPanel);
controller.add(PanelPtr(newPanel));
return newPanel;
}

//----------
PanelPtr Builder::add(ofNode & asset, string caption) {
PanelPtr newPanel( new Panels::Node(asset) );
ofPtr<Panels::Node> Builder::add(ofNode & asset, string caption) {
ofPtr<Panels::Node> newPanel( new Panels::Node(asset) );
newPanel->setCaption(caption);
controller.add(newPanel);
controller.add(PanelPtr(newPanel));
return newPanel;
}

//----------
PanelPtr Builder::addInstructions() {
PanelPtr newPanel( new Panels::Instructions() );
controller.add(newPanel);
ofPtr<Panels::Instructions> Builder::addInstructions() {
ofPtr<Panels::Instructions> newPanel( new Panels::Instructions() );
controller.add(PanelPtr(newPanel));
return newPanel;
}

Expand Down
10 changes: 5 additions & 5 deletions src/ofxCvGui/Builder.h
Expand Up @@ -19,11 +19,11 @@ namespace ofxCvGui {
class Builder {
public:
void init();
PanelPtr add(ofBaseDraws& asset, string caption="");
PanelPtr add(const ofPixels& asset, string caption="");
PanelPtr add(const vector<ofPixels>& asset, string caption="");
PanelPtr add(ofNode & asset, string caption="");
PanelPtr addInstructions();
ofPtr<Panels::Draws> add(ofBaseDraws& asset, string caption="");
ofPtr<Panels::Pixels> add(const ofPixels& asset, string caption="");
ofPtr<Panels::PixelsVector> add(const vector<ofPixels>& asset, string caption="");
ofPtr<Panels::Node> add(ofNode & asset, string caption="");
ofPtr<Panels::Instructions> addInstructions();

void clear();
void drop(PanelPtr &panel);
Expand Down
57 changes: 50 additions & 7 deletions src/ofxCvGui/Controller.cpp
Expand Up @@ -4,11 +4,12 @@ namespace ofxCvGui {
//----------
Controller::Controller() {
this->initialised = false;
this->fullscreen = false;
}

//----------
void Controller::init(ofPtr<Panels::Groups::Base> rootGroup) {
ofBackground(100);
ofBackground(80);
ofSetVerticalSync(true);

ofAddListener(ofEvents.update, this, &Controller::update);
Expand All @@ -24,6 +25,7 @@ namespace ofxCvGui {

rootGroup->setBounds(ofGetCurrentViewport());
this->rootGroup = rootGroup;
this->currentPanel = PanelPtr();
this->initialised = true;
}

Expand All @@ -48,6 +50,18 @@ namespace ofxCvGui {
this->rootGroup->clear();
}

//----------
void Controller::toggleFullscreen() {
this->fullscreen ^= true;
ofSetFullscreen(this->fullscreen);
}

//----------
void Controller::toggleFullscreen(PanelPtr panel) {
this->currentPanel = panel;
this->toggleFullscreen();
}

//----------
void Controller::update(ofEventArgs& args) {
if (!initialised)
Expand All @@ -59,21 +73,42 @@ namespace ofxCvGui {
void Controller::draw(ofEventArgs& args) {
if (!initialised)
return;
rootGroup->draw(DrawArguments(ofGetCurrentViewport(), true));
if (this->fullscreen) {
this->currentPanel->draw( DrawArguments(ofGetCurrentViewport(), true) );
} else {
if (currentPanel != PanelPtr()) {
ofPushStyle();
ofEnableAlphaBlending();
ofSetColor(100, 100, 100, 100);
ofRect(currentPanel->getBounds());
ofPopStyle();
}
rootGroup->draw(DrawArguments(ofGetCurrentViewport(), true));
}
}

//----------
void Controller::mouseMoved(ofMouseEventArgs &args) {
if (!initialised)
return;
rootGroup->mouseAction(MouseArguments(args, MouseMoved, rootGroup->getBounds()));
MouseArguments action(MouseArguments(args, MouseMoved, rootGroup->getBounds()));
if (this->fullscreen)
currentPanel->mouseAction(action);
else {
rootGroup->mouseAction(action);
this->currentPanel = PanelPtr(rootGroup->findScreen( ofVec2f(args.x, args.y) ));
}
}

//----------
void Controller::mousePressed(ofMouseEventArgs &args) {
if (!initialised)
return;
rootGroup->mouseAction(MouseArguments(args, MousePressed, rootGroup->getBounds()));
MouseArguments action(MouseArguments(args, MousePressed, rootGroup->getBounds()));
if (this->fullscreen)
currentPanel->mouseAction(action);
else
rootGroup->mouseAction(action);
}

//----------
Expand All @@ -93,18 +128,26 @@ namespace ofxCvGui {
//----------
void Controller::keyPressed(ofKeyEventArgs &args) {
if (args.key == 'f')
ofToggleFullscreen();
this->toggleFullscreen();

if (!initialised)
return;
rootGroup->keyboardAction(KeyboardArguments(args, KeyPressed));

KeyboardArguments action(args, KeyPressed);
if (this->fullscreen)
currentPanel->keyboardAction(action);
else
rootGroup->keyboardAction(action);
}

//----------
void Controller::windowResized(ofResizeEventArgs &args) {
if (!initialised)
return;
rootGroup->setBounds(ofRectangle(0,0,ofGetWidth(), ofGetHeight()));
ofRectangle bounds(0,0,ofGetWidth(), ofGetHeight());
rootGroup->setBounds(bounds);
if (this->fullscreen)
currentPanel->setBounds(bounds);
}

//----------
Expand Down
4 changes: 4 additions & 0 deletions src/ofxCvGui/Controller.h
Expand Up @@ -14,6 +14,8 @@ namespace ofxCvGui {
void add(PanelPtr& panel);
void drop(PanelPtr& panel);
void clear();
void toggleFullscreen();
void toggleFullscreen(PanelPtr panel);

protected:
////
Expand All @@ -34,5 +36,7 @@ namespace ofxCvGui {
bool checkInitialised();
bool initialised;
PanelGroupPtr rootGroup;
PanelPtr currentPanel;
bool fullscreen;
};
}
2 changes: 2 additions & 0 deletions src/ofxCvGui/Panels/Base.h
Expand Up @@ -4,6 +4,8 @@
namespace ofxCvGui {
namespace Panels {
class Base : public Element {
public:
virtual const ofPtr<Panels::Base> findScreen(const ofVec2f & xy) { return ofPtr<Panels::Base>(); }
protected:
virtual void drawPanel(const DrawArguments& arguments) = 0;
private:
Expand Down
2 changes: 2 additions & 0 deletions src/ofxCvGui/Panels/Groups/Base.h
Expand Up @@ -6,6 +6,8 @@ namespace ofxCvGui {
namespace Panels {
namespace Groups {
class Base : public ElementGroup_<Panels::Base> {
public:
virtual const PanelPtr findScreen(const ofVec2f & xy) { return PanelPtr(); }
protected:
void drawPanel(const DrawArguments& arguments) {
this->drawSet(arguments);
Expand Down
28 changes: 20 additions & 8 deletions src/ofxCvGui/Panels/Groups/Grid.cpp
Expand Up @@ -3,27 +3,39 @@
namespace ofxCvGui {
namespace Panels {
namespace Groups {
//----------
const PanelPtr Grid::findScreen(const ofVec2f & xy) {
unsigned int index = floor(xy.x / panelWidth) + xCount * floor(xy.y / panelHeight);
if (index < this->elements.size()) {
PanelPtr element = this->elements[index];
ofVec2f localXY = xy - ofVec2f(element->getBounds().x, element->getBounds().y);
if (element->findScreen(localXY) == PanelPtr())
return element;
}
return PanelPtr();
}

//----------
void Grid::boundsChange() {
float count = this->elements.size();
float xCount = ceil(sqrt(count));
float yCount = ceil(count / xCount);
xCount = ceil(sqrt(count));
yCount = ceil(count / xCount);

float width = this->bounds.width / xCount;
float height = this->bounds.height / yCount;
panelWidth = this->bounds.width / xCount;
panelHeight = this->bounds.height / yCount;

PanelIterator it;
int i=0;
int iX, iY;
ofRectangle bounds;
bounds.width = width;
bounds.height = height;
bounds.width = panelWidth;
bounds.height = panelHeight;

for (it = elements.begin(); it != elements.end(); it++, i++) {
iX = i % (int)xCount;
iY = i / (int)xCount;
bounds.x = iX * width;
bounds.y = iY * height;
bounds.x = iX * panelWidth;
bounds.y = iY * panelHeight;

(*it)->setBounds(bounds);
}
Expand Down
4 changes: 4 additions & 0 deletions src/ofxCvGui/Panels/Groups/Grid.h
Expand Up @@ -6,8 +6,12 @@ namespace ofxCvGui {
namespace Panels {
namespace Groups {
class Grid : public Groups::Base {
public:
const PanelPtr findScreen(const ofVec2f & xy);
protected:
void boundsChange();
float xCount, yCount;
float panelWidth, panelHeight;
};
}
}
Expand Down
20 changes: 16 additions & 4 deletions src/ofxCvGui/Panels/Node.cpp
Expand Up @@ -3,8 +3,8 @@
namespace ofxCvGui {
namespace Panels {
//----------
Node::Node(ofNode & node) :
node(node) {
Node::Node(ofNode & node) {
this->push(node);
}

//----------
Expand All @@ -15,10 +15,22 @@ namespace ofxCvGui {
ofSetColor(200, 100, 100);
ofDrawGrid(10.0f, 10.0f, true);
ofPopStyle();

this->node.draw();

vector<ofNode*>::iterator it;
for (it = this->nodes.begin(); it != this->nodes.end(); it++)
(**it).draw();

this->camera.end();
}

//----------
void Node::setCursorEnabled(bool cursorEnabled) {
this->camera.setCursorDraw(cursorEnabled);
}

//----------
void Node::push(ofNode & node) {
this->nodes.push_back(&node);
}
}
}
5 changes: 4 additions & 1 deletion src/ofxCvGui/Panels/Node.h
Expand Up @@ -9,10 +9,13 @@ namespace ofxCvGui {
namespace Panels {
class Node : public Panels::Base {
public:
Node() { }
Node(ofNode & node);
void setCursorEnabled(bool cursorEnabled=true);
void push(ofNode & node);
protected:
void drawPanel(const DrawArguments& arguments);
ofNode & node;
vector<ofNode*> nodes;
ofxGrabCam camera;
};
}
Expand Down

0 comments on commit 89a0780

Please sign in to comment.