Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
ofPArameter: fix arithmetic operators + add more explanations to edge…
… cases example
- Loading branch information
Showing
3 changed files
with
78 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,13 @@ void testApp::setup(){ | |
color.addListener(this,&testApp::colorChanged); | ||
|
||
color = ofColor(255); | ||
cout << color.getName() << ": " << color << endl; | ||
cout << color.getName() << ": " << color << endl; // color: 255, 255, 255, 255 | ||
|
||
// we can access the properties and const methods of objects contained | ||
// in ofParameters | ||
cout << color.getName() << ": r " << (int)color->r << ", g " << (int)color->g << ", b " << (int)color->b << endl; | ||
|
||
cout << "brightness: " << color->getBrightness() << endl; | ||
cout << "brightness: " << color->getBrightness() << endl; // brightness: 255 | ||
|
||
// but that's read only so always we change an object the internal event | ||
// in the ofParameter is triggered. Trying to do this, will fail to compile: | ||
|
@@ -22,13 +22,42 @@ void testApp::setup(){ | |
|
||
// instead we need to do: | ||
color = ofColor(127,127); | ||
cout << color.getName() << ": " << color << endl; | ||
cout << "brightness: " << color->getBrightness() << endl; | ||
cout << color.getName() << ": " << color << endl; // color: 127, 127, 127, 127 | ||
cout << "brightness: " << color->getBrightness() << endl; // brightness: 127 | ||
|
||
// arithmetic operators will work though: | ||
cout << color.getName() << ": " << color << endl; | ||
color*=2; | ||
cout << color.getName() << ": " << color << endl; | ||
cout << color.getName() << ": " << color << endl; // color: 127, 127, 127, 127 | ||
color*=.5; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
arturoc
Author
Member
|
||
cout << color.getName() << ": " << color << endl; // color: 255, 255, 255, 127 | ||
|
||
|
||
|
||
|
||
// ofParameter has shallow copy semantics | ||
a.set("a",5,0,10); | ||
ofParameter<int> reference(a); | ||
|
||
cout << reference.getName() << ": " << reference << endl; // a: 5 | ||
|
||
incrementParam(reference); | ||
cout << reference.getName() << ": " << reference << endl; // a: 6 | ||
cout << a.getName() << ": " << a << endl; // a: 6 | ||
|
||
|
||
// to avoid confusion when doing assignments and arithmetic operations | ||
// the = operator only copies the value | ||
b.set("b",0,0,10); | ||
b = a; | ||
cout << b.getName() << ": " << b << endl; // b: 6 | ||
|
||
// if you want to make a reference: | ||
b.makeReferenceTo(a); | ||
cout << b.getName() << ": " << b << endl; // a: 6 | ||
|
||
} | ||
|
||
void testApp::incrementParam(ofParameter<int> p){ | ||
p++; | ||
} | ||
|
||
void testApp::colorChanged(ofColor & color){ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@arturoc I have an error here, because *= operator is protected, and unaccessible.