MCPcopy Create free account
hub / github.com/BespokeSynth/BespokeSynth / PickNewVanityPanningDestination

Method PickNewVanityPanningDestination

Source/LocationZoomer.cpp:123–171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

121}
122
123void LocationZoomer::PickNewVanityPanningDestination()
124{
125 std::vector<IDrawableModule*> modules;
126 TheSynth->GetAllModules(modules);
127
128 ofVec2f allModulesCenter;
129 for (int i = 0; i < (int)modules.size(); ++i)
130 {
131 if (modules[i]->IsShowing() && !modules[i]->Minimized())
132 {
133 ofVec2f modulePos = modules[i]->GetRect().getCenter();
134 allModulesCenter += modulePos / (int)modules.size();
135 }
136 }
137
138 const int kRandomChoices = 3;
139 ofVec2f randomModulesCenter;
140 int attempts = 0;
141 for (int i = 0; i < kRandomChoices; ++i)
142 {
143 int choice = gRandom() % ((int)modules.size());
144 if (modules[choice]->IsShowing() && !modules[choice]->Minimized())
145 {
146 ofVec2f modulePos = modules[choice]->GetRect().getCenter();
147 randomModulesCenter += modulePos / kRandomChoices;
148 }
149 else
150 {
151 --i; //try again
152 }
153 ++attempts;
154
155 if (attempts > 100) //avoid infinite loop if all modules are hidden/minimized
156 break;
157 }
158
159 ofVec2f center = allModulesCenter * .5f + randomModulesCenter * .5f;
160
161 float newScale = ofRandom(1, 1.5f) * UserPrefs.zoom.Get();
162
163 mStart.mZoomLevel = gDrawScale;
164 mStart.mOffset = TheSynth->GetDrawOffset();
165
166 mDestination.mZoomLevel = newScale;
167 mDestination.mOffset = (center * -1) + ofVec2f(ofGetWidth(), ofGetHeight()) / newScale * .5f;
168
169 mCurrentProgress = 0;
170 mSpeed = ofRandom(.03f, .1f);
171}
172
173ofxJSONElement LocationZoomer::GetSaveData()
174{

Callers

nothing calls this directly

Calls 12

ofRandomFunction · 0.85
ofVec2fClass · 0.85
ofGetWidthFunction · 0.85
ofGetHeightFunction · 0.85
sizeMethod · 0.80
IsShowingMethod · 0.80
MinimizedMethod · 0.80
getCenterMethod · 0.80
GetMethod · 0.80
GetDrawOffsetMethod · 0.80
GetAllModulesMethod · 0.45
GetRectMethod · 0.45

Tested by

no test coverage detected