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

Method UpdatePosition

Source/PatchCableSource.cpp:157–242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

155}
156
157void PatchCableSource::UpdatePosition(bool parentMinimized)
158{
159 if (mOwner != nullptr && (mAutomaticPositioning || parentMinimized || mOwner->Minimized()))
160 {
161 float x, y, w, h;
162 mOwner->GetPosition(x, y);
163 mOwner->GetDimensions(w, h);
164
165 if (parentMinimized)
166 {
167 mOwner->GetParent()->GetPosition(x, y);
168 mOwner->GetParent()->GetDimensions(w, h);
169 }
170
171 if (mManualSide == Side::kNone || parentMinimized)
172 {
173 ofVec2f centerOfMass;
174 int count = 0;
175 for (auto cable : mPatchCables)
176 {
177 if (cable != nullptr)
178 {
179 if (cable->IsDragging())
180 {
181 centerOfMass.x += TheSynth->GetMouseX(mOwner->GetOwningContainer());
182 centerOfMass.y += TheSynth->GetMouseY(mOwner->GetOwningContainer());
183 ++count;
184 }
185 else if (cable->GetTarget())
186 {
187 float targetX, targetY, targetW, targetH;
188 cable->GetTarget()->GetPosition(targetX, targetY);
189 cable->GetTarget()->GetDimensions(targetW, targetH);
190 centerOfMass.x += targetX + targetW / 2;
191 centerOfMass.y += targetY + targetH / 2;
192 ++count;
193 }
194 }
195 }
196 centerOfMass.x /= count;
197 centerOfMass.y /= count;
198
199 if (count > 0)
200 {
201 if (centerOfMass.y > y + h)
202 mSide = Side::kBottom;
203 else if (centerOfMass.x < x + w / 2)
204 mSide = Side::kLeft;
205 else
206 mSide = Side::kRight;
207 }
208 else
209 {
210 mSide = Side::kBottom;
211 }
212 }
213 else
214 {

Callers

nothing calls this directly

Calls 9

MinimizedMethod · 0.80
GetParentMethod · 0.80
IsDraggingMethod · 0.80
GetOwningContainerMethod · 0.80
GetPositionMethod · 0.45
GetDimensionsMethod · 0.45
GetMouseXMethod · 0.45
GetMouseYMethod · 0.45
GetTargetMethod · 0.45

Tested by

no test coverage detected