From 89a0780b9b8ecd9c23ea0738df3754f7706365a9 Mon Sep 17 00:00:00 2001 From: Elliot Woods Date: Wed, 14 Mar 2012 12:15:25 +0000 Subject: [PATCH] Node can toggle draw cursor. builder returns derived pointers, Fullscreen/currentPanel prototype in place --- ofxCvGuiLib/ofxCvGuiLib.vcxproj | 2 +- src/ofxCvGui/Builder.cpp | 30 +++++++-------- src/ofxCvGui/Builder.h | 10 ++--- src/ofxCvGui/Controller.cpp | 57 +++++++++++++++++++++++++---- src/ofxCvGui/Controller.h | 4 ++ src/ofxCvGui/Panels/Base.h | 2 + src/ofxCvGui/Panels/Groups/Base.h | 2 + src/ofxCvGui/Panels/Groups/Grid.cpp | 28 ++++++++++---- src/ofxCvGui/Panels/Groups/Grid.h | 4 ++ src/ofxCvGui/Panels/Node.cpp | 20 ++++++++-- src/ofxCvGui/Panels/Node.h | 5 ++- 11 files changed, 123 insertions(+), 41 deletions(-) diff --git a/ofxCvGuiLib/ofxCvGuiLib.vcxproj b/ofxCvGuiLib/ofxCvGuiLib.vcxproj index 25c2810..4641d10 100644 --- a/ofxCvGuiLib/ofxCvGuiLib.vcxproj +++ b/ofxCvGuiLib/ofxCvGuiLib.vcxproj @@ -114,7 +114,7 @@ Level3 WIN32;NDEBUG;%(PreprocessorDefinitions) NotUsing - ..\..\..\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) + ..\..\..\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) true diff --git a/src/ofxCvGui/Builder.cpp b/src/ofxCvGui/Builder.cpp index 509ab84..b679ae0 100644 --- a/src/ofxCvGui/Builder.cpp +++ b/src/ofxCvGui/Builder.cpp @@ -8,41 +8,41 @@ namespace ofxCvGui { } //---------- - PanelPtr Builder::add(ofBaseDraws& asset, string caption) { - PanelPtr newPanel( new Panels::Draws(asset) ); + ofPtr Builder::add(ofBaseDraws& asset, string caption) { + ofPtr 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 Builder::add(const ofPixels& asset, string caption) { + ofPtr newPanel( new Panels::Pixels(asset) ); newPanel->setCaption(caption); - controller.add(newPanel); + controller.add(PanelPtr(newPanel)); return newPanel; } //---------- - PanelPtr Builder::add(const vector& asset, string caption) { - PanelPtr newPanel( new Panels::PixelsVector(asset) ); + ofPtr Builder::add(const vector& asset, string caption) { + ofPtr 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 Builder::add(ofNode & asset, string caption) { + ofPtr 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 Builder::addInstructions() { + ofPtr newPanel( new Panels::Instructions() ); + controller.add(PanelPtr(newPanel)); return newPanel; } diff --git a/src/ofxCvGui/Builder.h b/src/ofxCvGui/Builder.h index ba0aee4..4bf8fab 100644 --- a/src/ofxCvGui/Builder.h +++ b/src/ofxCvGui/Builder.h @@ -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& asset, string caption=""); - PanelPtr add(ofNode & asset, string caption=""); - PanelPtr addInstructions(); + ofPtr add(ofBaseDraws& asset, string caption=""); + ofPtr add(const ofPixels& asset, string caption=""); + ofPtr add(const vector& asset, string caption=""); + ofPtr add(ofNode & asset, string caption=""); + ofPtr addInstructions(); void clear(); void drop(PanelPtr &panel); diff --git a/src/ofxCvGui/Controller.cpp b/src/ofxCvGui/Controller.cpp index cf44ec5..b117e2c 100644 --- a/src/ofxCvGui/Controller.cpp +++ b/src/ofxCvGui/Controller.cpp @@ -4,11 +4,12 @@ namespace ofxCvGui { //---------- Controller::Controller() { this->initialised = false; + this->fullscreen = false; } //---------- void Controller::init(ofPtr rootGroup) { - ofBackground(100); + ofBackground(80); ofSetVerticalSync(true); ofAddListener(ofEvents.update, this, &Controller::update); @@ -24,6 +25,7 @@ namespace ofxCvGui { rootGroup->setBounds(ofGetCurrentViewport()); this->rootGroup = rootGroup; + this->currentPanel = PanelPtr(); this->initialised = true; } @@ -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) @@ -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); } //---------- @@ -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); } //---------- diff --git a/src/ofxCvGui/Controller.h b/src/ofxCvGui/Controller.h index e1d1f8f..7f5d4a9 100644 --- a/src/ofxCvGui/Controller.h +++ b/src/ofxCvGui/Controller.h @@ -14,6 +14,8 @@ namespace ofxCvGui { void add(PanelPtr& panel); void drop(PanelPtr& panel); void clear(); + void toggleFullscreen(); + void toggleFullscreen(PanelPtr panel); protected: //// @@ -34,5 +36,7 @@ namespace ofxCvGui { bool checkInitialised(); bool initialised; PanelGroupPtr rootGroup; + PanelPtr currentPanel; + bool fullscreen; }; } \ No newline at end of file diff --git a/src/ofxCvGui/Panels/Base.h b/src/ofxCvGui/Panels/Base.h index b1add25..1c3fcda 100644 --- a/src/ofxCvGui/Panels/Base.h +++ b/src/ofxCvGui/Panels/Base.h @@ -4,6 +4,8 @@ namespace ofxCvGui { namespace Panels { class Base : public Element { + public: + virtual const ofPtr findScreen(const ofVec2f & xy) { return ofPtr(); } protected: virtual void drawPanel(const DrawArguments& arguments) = 0; private: diff --git a/src/ofxCvGui/Panels/Groups/Base.h b/src/ofxCvGui/Panels/Groups/Base.h index 62bbe1a..b3befe4 100644 --- a/src/ofxCvGui/Panels/Groups/Base.h +++ b/src/ofxCvGui/Panels/Groups/Base.h @@ -6,6 +6,8 @@ namespace ofxCvGui { namespace Panels { namespace Groups { class Base : public ElementGroup_ { + public: + virtual const PanelPtr findScreen(const ofVec2f & xy) { return PanelPtr(); } protected: void drawPanel(const DrawArguments& arguments) { this->drawSet(arguments); diff --git a/src/ofxCvGui/Panels/Groups/Grid.cpp b/src/ofxCvGui/Panels/Groups/Grid.cpp index 7a6eab5..3670554 100644 --- a/src/ofxCvGui/Panels/Groups/Grid.cpp +++ b/src/ofxCvGui/Panels/Groups/Grid.cpp @@ -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); } diff --git a/src/ofxCvGui/Panels/Groups/Grid.h b/src/ofxCvGui/Panels/Groups/Grid.h index b51a70a..0402519 100644 --- a/src/ofxCvGui/Panels/Groups/Grid.h +++ b/src/ofxCvGui/Panels/Groups/Grid.h @@ -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; }; } } diff --git a/src/ofxCvGui/Panels/Node.cpp b/src/ofxCvGui/Panels/Node.cpp index b4b8ee0..cd2f553 100644 --- a/src/ofxCvGui/Panels/Node.cpp +++ b/src/ofxCvGui/Panels/Node.cpp @@ -3,8 +3,8 @@ namespace ofxCvGui { namespace Panels { //---------- - Node::Node(ofNode & node) : - node(node) { + Node::Node(ofNode & node) { + this->push(node); } //---------- @@ -15,10 +15,22 @@ namespace ofxCvGui { ofSetColor(200, 100, 100); ofDrawGrid(10.0f, 10.0f, true); ofPopStyle(); - - this->node.draw(); + + vector::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); + } } } \ No newline at end of file diff --git a/src/ofxCvGui/Panels/Node.h b/src/ofxCvGui/Panels/Node.h index a4df478..2603deb 100644 --- a/src/ofxCvGui/Panels/Node.h +++ b/src/ofxCvGui/Panels/Node.h @@ -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 nodes; ofxGrabCam camera; }; }