Permalink
Browse files

some small code fixes, added todd's custom impl drawing demo, Closes #1

Closes #4
  • Loading branch information...
1 parent bdfe742 commit fa3b68e1ec3fc6f516ec8086716504d2d4861c61 @ofTheo committed Apr 2, 2010
@@ -25,6 +25,7 @@
A1A2F20E111F57F9000703E4 /* tinyxmlerror.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1A2F1E7111F57F9000703E4 /* tinyxmlerror.cpp */; };
A1A2F20F111F57F9000703E4 /* tinyxmlparser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1A2F1E8111F57F9000703E4 /* tinyxmlparser.cpp */; };
A1A2F210111F57F9000703E4 /* ofxXmlSettings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1A2F1EA111F57F9000703E4 /* ofxXmlSettings.cpp */; };
+ E4245AAE11665F9C00F68A73 /* customDrawer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4245AAD11665F9C00F68A73 /* customDrawer.cpp */; };
E45BE0AA0E8CC67C009D7055 /* GLee.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E45BE0A90E8CC67C009D7055 /* GLee.a */; };
E45BE2E40E8CC69C009D7055 /* rtAudio.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E45BE2E30E8CC69C009D7055 /* rtAudio.a */; };
E45BE97B0E8CC7DD009D7055 /* AGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E45BE9710E8CC7DD009D7055 /* AGL.framework */; };
@@ -187,6 +188,8 @@
A1A2F1EA111F57F9000703E4 /* ofxXmlSettings.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ofxXmlSettings.cpp; sourceTree = "<group>"; };
A1A2F1EB111F57F9000703E4 /* ofxXmlSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ofxXmlSettings.h; sourceTree = "<group>"; };
A1A2F1F9111F57F9000703E4 /* ofxControlPanelDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ofxControlPanelDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
+ E4245AAC11665F9C00F68A73 /* customDrawer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = customDrawer.h; sourceTree = "<group>"; };
+ E4245AAD11665F9C00F68A73 /* customDrawer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = customDrawer.cpp; sourceTree = "<group>"; };
E45BE0390E8CC647009D7055 /* FreeImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FreeImage.h; path = ../../../libs/freeimage/include/FreeImage.h; sourceTree = SOURCE_ROOT; };
E45BE03F0E8CC650009D7055 /* fmod.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = fmod.h; path = ../../../libs/fmodex/include/fmod.h; sourceTree = SOURCE_ROOT; };
E45BE0400E8CC650009D7055 /* fmod.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = fmod.hpp; path = ../../../libs/fmodex/include/fmod.hpp; sourceTree = SOURCE_ROOT; };
@@ -761,6 +764,8 @@
A1A2F134111F5772000703E4 /* ofAddons.h */,
A1A2F138111F5772000703E4 /* vectorField.cpp */,
A1A2F139111F5772000703E4 /* vectorField.h */,
+ E4245AAD11665F9C00F68A73 /* customDrawer.cpp */,
+ E4245AAC11665F9C00F68A73 /* customDrawer.h */,
E4E48D411163E4F6007DCE2F /* backgroundSubtractionExample.cpp */,
E4E48D401163E4F6007DCE2F /* backgroundSubtractionExample.h */,
E4E48C951163DB25007DCE2F /* videoMotionExample.cpp */,
@@ -977,6 +982,7 @@
E4BD0D251164F30700A20636 /* guiBaseObject.cpp in Sources */,
E4BD0E3911651F3A00A20636 /* guiTypeVairableLister.cpp in Sources */,
E4BD0F711165310C00A20636 /* guiTypeChartPlotter.cpp in Sources */,
+ E4245AAE11665F9C00F68A73 /* customDrawer.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
@@ -0,0 +1,11 @@
+/*
+ * customDrawer.cpp
+ * ofxControlPanelDemo
+ *
+ * Created by theo on 02/04/2010.
+ * Copyright 2010 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#include "customDrawer.h"
+
View
@@ -0,0 +1,117 @@
+/*
+ * customDrawer.h
+ * ofxControlPanelDemo
+ *
+ * Created by theo on 02/04/2010.
+ * Copyright 2010 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#pragma once
+#include "guiCustomImpl.h"
+#include "guiBaseObject.h" //theo added for isInsideRect()
+
+class customDrawer : public guiCustomImpl {
+
+private:
+
+ vector < vector <ofPoint> > pts;
+
+public:
+
+ bool mouseIsRelative;
+ //ofRectangle boundingRect; //theo changed
+
+ customDrawer(){
+
+ }
+
+ // -------------------------------------
+ void saveSettings(string filename){
+ }
+
+ void reloadSettings(){
+
+ }
+
+ void saveSettings(){
+
+ }
+
+ void loadSettings(string filename) {
+
+ }
+
+ // -------------------------------------
+ float getWidth() {
+ return boundingRect.width;
+ }
+ float getHeight() {
+ return boundingRect.height;
+ }
+
+ // -------------------------------------
+ void clearPoints() {
+ for (int i=0; i<pts.size(); i++) {
+ pts[i].clear();
+ }
+ }
+
+ // -------------------------------------
+ void addPoint(float x, float y) {
+ pts.back().push_back(ofPoint(x, y));
+ }
+
+ void draw(float x, float y, float w, float h) {
+
+ //printf("x is %f y is %f w is %f h is %f\n", x, y, w, h);
+ //printf("bounds x is %f y is %f w is %f h is %f\n", boundingRect.x, boundingRect.y, boundingRect.width, boundingRect.height);
+
+ glPushMatrix();
+ glTranslatef(x, y, 0); //theo changed
+
+ //always check if you are diving by zero - or do h/MAX(1, boundingRect.height)
+ glScalef(w/boundingRect.width, h/boundingRect.height, 0);
+
+ ofNoFill();
+ ofSetColor(255, 90, 9);
+
+ for (int i=0; i<pts.size(); i++) {
+
+ ofBeginShape();
+ for (int j=0; j<pts[i].size(); j++) {
+ ofVertex(pts[i][j].x, pts[i][j].y);
+ }
+ ofEndShape(false);
+
+ }
+
+ glPopMatrix();
+
+ ofNoFill();
+ ofSetColor(255, 33, 33);
+ ofRect(x, y, w, h);
+ }
+
+ // -------------------------------------
+ void mousePressed(float x, float y) {
+ vector <ofPoint> newPoints;
+ pts.push_back(newPoints);
+ }
+
+ //these values come in with 0,0 being the top left of your bounding rect
+ // -------------------------------------
+ void mouseDragged(float x, float y){
+
+ //theo changed
+
+ if( isInsideRect(x, y, ofRectangle(0, 0, boundingRect.width, boundingRect.height) ) ){
+ addPoint(x, y);
+ }
+ }
+
+ void mouseReleased(){
+
+ }
+
+};
@@ -1,5 +1,7 @@
#pragma once
+#include "ofMain.h"
+
class guiCustomImpl{
public:
@@ -26,7 +26,7 @@ void guiTypeMultiToggle::setup(string multiToggleName, int defaultBox, vector <s
}
//-----------------------------------------------
-virtual void guiTypeMultiToggle::updateValue(){
+void guiTypeMultiToggle::updateValue(){
//CB
notify();
}
@@ -10,10 +10,10 @@ class simpleColor{
simpleColor();
//----------------------------------------------------------
- simpleColor::simpleColor(int _r, int _g, int _b, int _a);
+ simpleColor(int _r, int _g, int _b, int _a);
//----------------------------------------------------------
- simpleColor::simpleColor(int hexColor);
+ simpleColor(int hexColor);
//----------------------------------------------------------
void setColor(int _r, int _g, int _b, int _a);
View
@@ -27,7 +27,7 @@ void testApp::setup(){
ofxControlPanel::setBackgroundColor(simpleColor(30, 30, 30, 200));
- //--------- PANEL 0
+ //--------- PANEL 1
gui.setWhichPanel(0);
gui.setWhichColumn(0);
@@ -74,7 +74,7 @@ void testApp::setup(){
names.push_back("less than");
gui.addTextDropDown("difference mode", "DIFF_MODE", 0, names);
- //--------- PANEL 1
+ //--------- PANEL 2
gui.setWhichPanel(1);
gui.setWhichColumn(0);
@@ -91,6 +91,13 @@ void testApp::setup(){
gui.addSlider("motion threshold", "MOTION_THRESHOLD", 29.0, 1.0, 255.0, false);
gui.addSlider("motion fade amnt", "MOTION_FADE", 0.67, 0.0, 1.0, false);
gui.addSlider("field draw scale", "FIELD_DRAW_SCALE", 1.0, 1.0, 10.0, false);
+
+ //------- PANEL 3
+ gui.setWhichPanel(2);
+ gui.addCustomRect("custom implementation demo", &pointAdder, 500, 375);
+
+
+ //SETTINGS AND EVENTS
//load from xml!
gui.loadSettings("controlPanelSettings.xml");
@@ -99,14 +106,14 @@ void testApp::setup(){
gui.setupEvents();
gui.enableEvents();
-// -- this approach creates an event group and only sends you events for the elements you describe.
+// -- SPECIFIC EVENTS -- this approach creates an event group and only sends you events for the elements you describe.
// vector <string> list;
// list.push_back("FIELD_DRAW_SCALE");
// list.push_back("DIFF_MODE");
// gui.createEventGroup("TEST_GROUP", list);
// ofAddListener(gui.getEventGroup("TEST_GROUP"), this, &testApp::eventsIn);
-// -- this approach gives you back an ofEvent for only the events from panel 0
+// -- PANEL EVENTS -- this approach gives you back an ofEvent for only the events from panel 0
// ofAddListener(gui.getEventsForPanel(0), this, &testApp::eventsIn);
// -- this gives you back an ofEvent for all events in this control panel object
@@ -124,33 +131,26 @@ void testApp::eventsIn(guiCallbackData & data){
bgExample.captureBackground();
gui.setValueB("GRAB_BACKGROUND", false);
}
-
- if( data.groupName != "events logger"){
+ //lets send all events to our logger
+ if( data.groupName != "events logger"){
string logStr = data.groupName;
if( data.fVal.size() ){
- for(int i = 0; i < data.fVal.size(); i++){
- logStr += " - "+ofToString(data.fVal[i], 4);
- }
+ for(int i = 0; i < data.fVal.size(); i++) logStr += " - "+ofToString(data.fVal[i], 4);
}
if( data.iVal.size() ){
- for(int i = 0; i < data.iVal.size(); i++){
- logStr += " - "+ofToString(data.iVal[i]);
- }
+ for(int i = 0; i < data.iVal.size(); i++) logStr += " - "+ofToString(data.iVal[i]);
}
if( data.sVal.size() ){
- for(int i = 0; i < data.sVal.size(); i++){
- logStr += " - "+data.sVal[i];
- }
+ for(int i = 0; i < data.sVal.size(); i++) logStr += " - "+data.sVal[i];
}
logger.log(OF_LOG_NOTICE, "event - %s", logStr.c_str());
-
}
+ // print to terminal if you want to
//this code prints out the name of the events coming in and all the variables passed
-
printf("testApp::eventsIn - name is %s - \n", data.groupName.c_str());
if( data.elementName != "" ){
printf(" element name is %s \n", data.elementName.c_str());
@@ -200,7 +200,6 @@ void testApp::update(){
bgExample.setDifferenceMode(gui.getValueI("DIFF_MODE"));
bgExample.setThreshold(gui.getValueI("BG_THRESHOLD"));
-
gui.update();
}
View
@@ -6,6 +6,8 @@
#include "ofxControlPanel.h"
#include "backgroundSubtractionExample.h"
+#include "customDrawer.h"
+
class testApp : public ofSimpleApp{
public:
@@ -34,6 +36,7 @@ class testApp : public ofSimpleApp{
ofVideoGrabber grabber;
backgroundSubtractionExample bgExample;
+ customDrawer pointAdder;
float elapsedTime;
int appFrameCount;

0 comments on commit fa3b68e

Please sign in to comment.