From d0aac5240e88b662cc82089e104cd28815a79517 Mon Sep 17 00:00:00 2001 From: Pierre Proske Date: Sun, 24 Apr 2016 17:32:00 +1000 Subject: [PATCH 1/3] initial commit --- src/components/ofxDatGuiButton.h | 10 ++++++++++ src/components/ofxDatGuiGroups.h | 11 ++++++++++- src/ofxDatGui.cpp | 8 ++++++++ src/ofxDatGui.h | 1 + 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/components/ofxDatGuiButton.h b/src/components/ofxDatGuiButton.h index edc5627..f239fb9 100644 --- a/src/components/ofxDatGuiButton.h +++ b/src/components/ofxDatGuiButton.h @@ -102,6 +102,11 @@ class ofxDatGuiToggle : public ofxDatGuiButton { mType = ofxDatGuiType::TOGGLE; setTheme(ofxDatGuiComponent::theme.get()); } + + ofxDatGuiToggle(ofParameter & p) : ofxDatGuiToggle(p.getName(), p.get()) { + mParamB = &p; + mParamB->addListener(this, &ofxDatGuiToggle::onParamB); + } void setTheme(ofxDatGuiTheme* theme) { @@ -155,6 +160,9 @@ class ofxDatGuiToggle : public ofxDatGuiButton { void onMouseRelease(ofPoint m) { mEnabled = !mEnabled; + if (mParamB != nullptr) { + mParamB->set(mEnabled); + } ofxDatGuiComponent::onFocusLost(); ofxDatGuiComponent::onMouseRelease(m); // dispatch event out to main application // @@ -168,8 +176,10 @@ class ofxDatGuiToggle : public ofxDatGuiButton { private: bool mEnabled; + ofParameter* mParamB = nullptr; shared_ptr radioOn; shared_ptr radioOff; + void onParamB(bool& n) { setEnabled(n); } }; diff --git a/src/components/ofxDatGuiGroups.h b/src/components/ofxDatGuiGroups.h index 29bf32d..3940184 100644 --- a/src/components/ofxDatGuiGroups.h +++ b/src/components/ofxDatGuiGroups.h @@ -261,7 +261,16 @@ class ofxDatGuiFolder : public ofxDatGuiGroup { attachItem(toggle); return toggle; } - + + ofxDatGuiToggle* addToggle(ofParameter & p) + { + ofxDatGuiToggle* toggle = new ofxDatGuiToggle(p); + toggle->setStripeColor(mStyle.stripe.color); + toggle->onButtonEvent(this, &ofxDatGuiFolder::dispatchButtonEvent); + attachItem(toggle); + return toggle; + } + ofxDatGuiSlider* addSlider(string label, float min, float max) { ofxDatGuiSlider* slider = addSlider(label, min, max, (max+min)/2); diff --git a/src/ofxDatGui.cpp b/src/ofxDatGui.cpp index 001121c..6d6ae68 100644 --- a/src/ofxDatGui.cpp +++ b/src/ofxDatGui.cpp @@ -271,6 +271,14 @@ ofxDatGuiButton* ofxDatGui::addButton(string label) return button; } +ofxDatGuiToggle* ofxDatGui::addToggle(ofParameter& p) +{ + ofxDatGuiToggle* button = new ofxDatGuiToggle(p); + button->onButtonEvent(this, &ofxDatGui::onButtonEventCallback); + attachItem(button); + return button; +} + ofxDatGuiToggle* ofxDatGui::addToggle(string label, bool enabled) { ofxDatGuiToggle* button = new ofxDatGuiToggle(label, enabled); diff --git a/src/ofxDatGui.h b/src/ofxDatGui.h index 4212dea..f13f189 100644 --- a/src/ofxDatGui.h +++ b/src/ofxDatGui.h @@ -64,6 +64,7 @@ class ofxDatGui : public ofxDatGuiInteractiveObject ofxDatGuiLabel* addLabel(string label); ofxDatGuiButton* addButton(string label); ofxDatGuiToggle* addToggle(string label, bool state = false); + ofxDatGuiToggle* addToggle(ofParameter& p); ofxDatGuiSlider* addSlider(string label, float min, float max); ofxDatGuiSlider* addSlider(string label, float min, float max, float val); ofxDatGuiSlider* addSlider(ofParameter & p); From 410751b77d306b7024fff22a194090f0fc14a0d0 Mon Sep 17 00:00:00 2001 From: Pierre Proske Date: Wed, 13 Jul 2016 17:12:14 +1000 Subject: [PATCH 2/3] fix for bug introduced during merge --- src/components/ofxDatGuiButton.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/ofxDatGuiButton.h b/src/components/ofxDatGuiButton.h index be5ea55..253f1d7 100644 --- a/src/components/ofxDatGuiButton.h +++ b/src/components/ofxDatGuiButton.h @@ -159,7 +159,7 @@ class ofxDatGuiToggle : public ofxDatGuiButton { { mChecked = !mChecked; if (mParamB != nullptr) { - mParamB->set(mEnabled); + mParamB->set(mChecked); } ofxDatGuiComponent::onFocusLost(); ofxDatGuiComponent::onMouseRelease(m); @@ -177,7 +177,7 @@ class ofxDatGuiToggle : public ofxDatGuiButton { ofParameter* mParamB = nullptr; shared_ptr radioOn; shared_ptr radioOff; - void onParamB(bool& n) { setEnabled(n); } + void onParamB(bool& n) { setChecked(n); } }; From 4ca7cfeeed35f2235f80c17f9edc522c176e273c Mon Sep 17 00:00:00 2001 From: Pierre Proske Date: Fri, 14 Feb 2020 18:28:32 +1100 Subject: [PATCH 3/3] fix for missing std:: headers --- src/libs/ofxSmartFont/ofxSmartFont.cpp | 34 +++++++++++++------------- src/libs/ofxSmartFont/ofxSmartFont.h | 32 ++++++++++++------------ 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/libs/ofxSmartFont/ofxSmartFont.cpp b/src/libs/ofxSmartFont/ofxSmartFont.cpp index 49d13da..cdc9050 100644 --- a/src/libs/ofxSmartFont/ofxSmartFont.cpp +++ b/src/libs/ofxSmartFont/ofxSmartFont.cpp @@ -23,28 +23,28 @@ #include "ofxSmartFont.h" -vector> ofxSmartFont::mFonts; +std::vector> ofxSmartFont::mFonts; /* instance methods */ -void ofxSmartFont::draw(string s, int x, int y) +void ofxSmartFont::draw(std::string s, int x, int y) { ttf.drawString(s, x, y); } -string ofxSmartFont::name() +std::string ofxSmartFont::name() { return mName; } -void ofxSmartFont::name(string name) +void ofxSmartFont::name(std::string name) { mName = name; } -string ofxSmartFont::file() +std::string ofxSmartFont::file() { return mFile; } @@ -54,17 +54,17 @@ int ofxSmartFont::size() return mSize; } -ofRectangle ofxSmartFont::rect(string s, int x, int y) +ofRectangle ofxSmartFont::rect(std::string s, int x, int y) { return ttf.getStringBoundingBox(s, x, y); } -float ofxSmartFont::width(string s, int x, int y) +float ofxSmartFont::width(std::string s, int x, int y) { return ttf.getStringBoundingBox(s, x, y).width; } -float ofxSmartFont::height(string s, int x, int y) +float ofxSmartFont::height(std::string s, int x, int y) { return ttf.getStringBoundingBox(s, x, y).height; } @@ -78,22 +78,22 @@ float ofxSmartFont::getLineHeight() static methods */ -shared_ptr ofxSmartFont::add(string file, int size, string name) +std::shared_ptr ofxSmartFont::add(std::string file, int size, std::string name) { for(auto f:mFonts){ if (f->file()==file && f->size()==size){ - // log(f->name() + "@ pt size "+std::to_string(f->size()) + " is already in memory."); + // log(f->name() + "@ pt size "+std::to_std::string(f->size()) + " is already in memory."); return f; } } struct make_shared_sf : public ofxSmartFont { - make_shared_sf(string file, int size, string name) : ofxSmartFont(file, size, name){} + make_shared_sf(std::string file, int size, std::string name) : ofxSmartFont(file, size, name){} }; - mFonts.push_back(make_shared(file, size, name)); + mFonts.push_back(std::make_shared(file, size, name)); return mFonts.back(); } -shared_ptr ofxSmartFont::get(string name) +std::shared_ptr ofxSmartFont::get(std::string name) { for(auto f:mFonts){ if (f->name()==name) return f; @@ -102,7 +102,7 @@ shared_ptr ofxSmartFont::get(string name) return nullptr; } -shared_ptr ofxSmartFont::get(string name, int size) +std::shared_ptr ofxSmartFont::get(std::string name, int size) { for(auto f:mFonts){ if (f->file().find(name) != std::string::npos && f->size()==size){ @@ -113,7 +113,7 @@ shared_ptr ofxSmartFont::get(string name, int size) return nullptr; } -shared_ptr ofxSmartFont::get(vector keys, int size) +std::shared_ptr ofxSmartFont::get(std::vector keys, int size) { for(auto f:mFonts){ bool match = true; @@ -141,8 +141,8 @@ void ofxSmartFont::list() log("----------------------------------"); } -void ofxSmartFont::log(string msg) +void ofxSmartFont::log(std::string msg) { - cout << "ofxSmartFont :: "<< msg << endl; + std::cout << "ofxSmartFont :: "<< msg << std::endl; } diff --git a/src/libs/ofxSmartFont/ofxSmartFont.h b/src/libs/ofxSmartFont/ofxSmartFont.h index 47f6cd1..06c2cff 100644 --- a/src/libs/ofxSmartFont/ofxSmartFont.h +++ b/src/libs/ofxSmartFont/ofxSmartFont.h @@ -32,31 +32,31 @@ class ofxSmartFont { instance methods */ - string file(); + std::string file(); int size(); - string name(); - void name(string name); - void draw(string s, int x, int y); + std::string name(); + void name(std::string name); + void draw(std::string s, int x, int y); - ofRectangle rect(string s, int x=0, int y=0); - float width(string s, int x=0, int y=0); - float height(string s, int x=0, int y=0); + ofRectangle rect(std::string s, int x=0, int y=0); + float width(std::string s, int x=0, int y=0); + float height(std::string s, int x=0, int y=0); float getLineHeight(); /* static methods */ - static shared_ptr add(string file, int size, string name = ""); - static shared_ptr get(string name); - static shared_ptr get(string name, int size); - static shared_ptr get(vector keys, int size); + static std::shared_ptr add(std::string file, int size, std::string name = ""); + static std::shared_ptr get(std::string name); + static std::shared_ptr get(std::string name, int size); + static std::shared_ptr get(std::vector keys, int size); static void list(); - static vector> mFonts; + static std::vector> mFonts; private: - ofxSmartFont(string file, int size, string name) + ofxSmartFont(std::string file, int size, std::string name) { mSize = size; mFile = file; @@ -72,11 +72,11 @@ class ofxSmartFont { } } - static void log(string msg); + static void log(std::string msg); int mSize; - string mFile; - string mName; + std::string mFile; + std::string mName; ofTrueTypeFont ttf; };