Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/components/ofxDatGuiButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ class ofxDatGuiToggle : public ofxDatGuiButton {
mType = ofxDatGuiType::TOGGLE;
setTheme(ofxDatGuiComponent::theme.get());
}

ofxDatGuiToggle(ofParameter<bool> & p) : ofxDatGuiToggle(p.getName(), p.get()) {
mParamB = &p;
mParamB->addListener(this, &ofxDatGuiToggle::onParamB);
}

void setTheme(const ofxDatGuiTheme* theme)
{
Expand Down Expand Up @@ -153,6 +158,9 @@ class ofxDatGuiToggle : public ofxDatGuiButton {
void onMouseRelease(ofPoint m)
{
mChecked = !mChecked;
if (mParamB != nullptr) {
mParamB->set(mChecked);
}
ofxDatGuiComponent::onFocusLost();
ofxDatGuiComponent::onMouseRelease(m);
// dispatch event out to main application //
Expand All @@ -166,8 +174,10 @@ class ofxDatGuiToggle : public ofxDatGuiButton {

private:
bool mChecked;
ofParameter<bool>* mParamB = nullptr;
shared_ptr<ofImage> radioOn;
shared_ptr<ofImage> radioOff;
void onParamB(bool& n) { setChecked(n); }

};

Expand Down
11 changes: 10 additions & 1 deletion src/components/ofxDatGuiGroups.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,16 @@ class ofxDatGuiFolder : public ofxDatGuiGroup {
attachItem(toggle);
return toggle;
}


ofxDatGuiToggle* addToggle(ofParameter<bool> & 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);
Expand Down
34 changes: 17 additions & 17 deletions src/libs/ofxSmartFont/ofxSmartFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,28 @@


#include "ofxSmartFont.h"
vector<shared_ptr<ofxSmartFont>> ofxSmartFont::mFonts;
std::vector<std::shared_ptr<ofxSmartFont>> 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;
}
Expand All @@ -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;
}
Expand All @@ -78,22 +78,22 @@ float ofxSmartFont::getLineHeight()
static methods
*/

shared_ptr<ofxSmartFont> ofxSmartFont::add(string file, int size, string name)
std::shared_ptr<ofxSmartFont> 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<make_shared_sf>(file, size, name));
mFonts.push_back(std::make_shared<make_shared_sf>(file, size, name));
return mFonts.back();
}

shared_ptr<ofxSmartFont> ofxSmartFont::get(string name)
std::shared_ptr<ofxSmartFont> ofxSmartFont::get(std::string name)
{
for(auto f:mFonts){
if (f->name()==name) return f;
Expand All @@ -102,7 +102,7 @@ shared_ptr<ofxSmartFont> ofxSmartFont::get(string name)
return nullptr;
}

shared_ptr<ofxSmartFont> ofxSmartFont::get(string name, int size)
std::shared_ptr<ofxSmartFont> ofxSmartFont::get(std::string name, int size)
{
for(auto f:mFonts){
if (f->file().find(name) != std::string::npos && f->size()==size){
Expand All @@ -113,7 +113,7 @@ shared_ptr<ofxSmartFont> ofxSmartFont::get(string name, int size)
return nullptr;
}

shared_ptr<ofxSmartFont> ofxSmartFont::get(vector<string> keys, int size)
std::shared_ptr<ofxSmartFont> ofxSmartFont::get(std::vector<std::string> keys, int size)
{
for(auto f:mFonts){
bool match = true;
Expand Down Expand Up @@ -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;
}

32 changes: 16 additions & 16 deletions src/libs/ofxSmartFont/ofxSmartFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<ofxSmartFont> add(string file, int size, string name = "");
static shared_ptr<ofxSmartFont> get(string name);
static shared_ptr<ofxSmartFont> get(string name, int size);
static shared_ptr<ofxSmartFont> get(vector<string> keys, int size);
static std::shared_ptr<ofxSmartFont> add(std::string file, int size, std::string name = "");
static std::shared_ptr<ofxSmartFont> get(std::string name);
static std::shared_ptr<ofxSmartFont> get(std::string name, int size);
static std::shared_ptr<ofxSmartFont> get(std::vector<std::string> keys, int size);
static void list();

static vector<shared_ptr<ofxSmartFont>> mFonts;
static std::vector<std::shared_ptr<ofxSmartFont>> mFonts;

private:

ofxSmartFont(string file, int size, string name)
ofxSmartFont(std::string file, int size, std::string name)
{
mSize = size;
mFile = file;
Expand All @@ -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;

};
Expand Down
8 changes: 8 additions & 0 deletions src/ofxDatGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,14 @@ ofxDatGuiButton* ofxDatGui::addButton(string label)
return button;
}

ofxDatGuiToggle* ofxDatGui::addToggle(ofParameter<bool>& 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);
Expand Down
1 change: 1 addition & 0 deletions src/ofxDatGui.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class ofxDatGui : public ofxDatGuiInteractiveObject
ofxDatGuiLabel* addLabel(string label);
ofxDatGuiButton* addButton(string label);
ofxDatGuiToggle* addToggle(string label, bool state = false);
ofxDatGuiToggle* addToggle(ofParameter<bool>& p);
ofxDatGuiSlider* addSlider(string label, float min, float max);
ofxDatGuiSlider* addSlider(string label, float min, float max, float val);
ofxDatGuiSlider* addSlider(ofParameter<int> & p);
Expand Down