MCPcopy Create free account
hub / github.com/ddnet/ddnet / UpdateHotEnvelopePoint

Method UpdateHotEnvelopePoint

src/game/editor/editor.cpp:4534–4587  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4532};
4533
4534void CEditor::UpdateHotEnvelopePoint(const CUIRect &View, const CEnvelope *pEnvelope, int ActiveChannels)
4535{
4536 if(!Ui()->MouseInside(&View))
4537 return;
4538
4539 const vec2 MousePos = Ui()->MousePos();
4540
4541 float MinDist = 200.0f;
4542 const void *pMinPointId = nullptr;
4543
4544 const auto UpdateMinimum = [&](vec2 Position, const void *pId) {
4545 const float CurrDist = length_squared(Position - MousePos);
4546 if(CurrDist < MinDist)
4547 {
4548 MinDist = CurrDist;
4549 pMinPointId = pId;
4550 }
4551 };
4552
4553 for(size_t i = 0; i < pEnvelope->m_vPoints.size(); i++)
4554 {
4555 for(int c = pEnvelope->GetChannels() - 1; c >= 0; c--)
4556 {
4557 if(!(ActiveChannels & (1 << c)))
4558 continue;
4559
4560 if(i > 0 && pEnvelope->m_vPoints[i - 1].m_Curvetype == CURVETYPE_BEZIER)
4561 {
4562 vec2 Position;
4563 Position.x = EnvelopeToScreenX(View, (pEnvelope->m_vPoints[i].m_Time + pEnvelope->m_vPoints[i].m_Bezier.m_aInTangentDeltaX[c]).AsSeconds());
4564 Position.y = EnvelopeToScreenY(View, fx2f(pEnvelope->m_vPoints[i].m_aValues[c] + pEnvelope->m_vPoints[i].m_Bezier.m_aInTangentDeltaY[c]));
4565 UpdateMinimum(Position, &pEnvelope->m_vPoints[i].m_Bezier.m_aInTangentDeltaX[c]);
4566 }
4567
4568 if(i < pEnvelope->m_vPoints.size() - 1 && pEnvelope->m_vPoints[i].m_Curvetype == CURVETYPE_BEZIER)
4569 {
4570 vec2 Position;
4571 Position.x = EnvelopeToScreenX(View, (pEnvelope->m_vPoints[i].m_Time + pEnvelope->m_vPoints[i].m_Bezier.m_aOutTangentDeltaX[c]).AsSeconds());
4572 Position.y = EnvelopeToScreenY(View, fx2f(pEnvelope->m_vPoints[i].m_aValues[c] + pEnvelope->m_vPoints[i].m_Bezier.m_aOutTangentDeltaY[c]));
4573 UpdateMinimum(Position, &pEnvelope->m_vPoints[i].m_Bezier.m_aOutTangentDeltaX[c]);
4574 }
4575
4576 vec2 Position;
4577 Position.x = EnvelopeToScreenX(View, pEnvelope->m_vPoints[i].m_Time.AsSeconds());
4578 Position.y = EnvelopeToScreenY(View, fx2f(pEnvelope->m_vPoints[i].m_aValues[c]));
4579 UpdateMinimum(Position, &pEnvelope->m_vPoints[i].m_aValues[c]);
4580 }
4581 }
4582
4583 if(pMinPointId != nullptr)
4584 {
4585 Ui()->SetHotItem(pMinPointId);
4586 }
4587}
4588
4589void CEditor::RenderEnvelopeEditor(CUIRect View)
4590{

Callers

nothing calls this directly

Calls 8

UiFunction · 0.85
length_squaredFunction · 0.85
fx2fFunction · 0.85
MouseInsideMethod · 0.80
MousePosMethod · 0.80
GetChannelsMethod · 0.80
SetHotItemMethod · 0.80
AsSecondsMethod · 0.45

Tested by

no test coverage detected